<?php
/*
Plugin Name: Facebook URL Inserter
Plugin URI: https://example.com
Description: Inserts a Facebook URL after every post with customizable link color.
Version: 1.0
Author: Your Name
Author URI: https://example.com
License: GPL2
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Add settings menu
function fb_url_settings_menu() {
add_options_page('Facebook URL Settings', 'Facebook URL', 'manage_options', 'fb-url-settings', 'fb_url_settings_page');
}
add_action('admin_menu', 'fb_url_settings_menu');
// Register settings
function fb_url_register_settings() {
register_setting('fb_url_settings_group', 'fb_url');
register_setting('fb_url_settings_group', 'fb_url_color');
}
add_action('admin_init', 'fb_url_register_settings');
// Settings page content
function fb_url_settings_page() {
?>
<div class="wrap">
<h1>Facebook URL Settings</h1>
<form method="post" action="options.php">
<?php settings_fields('fb_url_settings_group'); ?>
<?php do_settings_sections('fb_url_settings_group'); ?>
<table class="form-table">
<tr>
<th scope="row"><label for="fb_url">Facebook URL:</label></th>
<td><input type="text" id="fb_url" name="fb_url" value="<?php echo esc_attr(get_option('fb_url', 'https://facebook.com')); ?>" class="regular-text" /></td>
</tr>
<tr>
<th scope="row"><label for="fb_url_color">Link Color:</label></th>
<td><input type="color" id="fb_url_color" name="fb_url_color" value="<?php echo esc_attr(get_option('fb_url_color', '#1877F2')); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
// Append Facebook link to content
function fb_url_append_content($content) {
if (is_single()) {
$fb_url = get_option('fb_url', 'https://facebook.com');
$fb_color = get_option('fb_url_color', '#1877F2');
$fb_link = '<p style="margin-top: 20px;"><a href="' . esc_url($fb_url) . '" target="_blank" style="color:' . esc_attr($fb_color) . '; font-weight: bold;">Follow us on Facebook</a></p>';
$content .= $fb_link;
}
return $content;
}
add_filter('the_content', 'fb_url_append_content');