| <?php |
| /** |
| * Plugin Name: UI Mastodon Verification Link |
| * Description: Adds mastodon rel=me profile link to the html head. |
| * Version: 1.0 |
| * Author: Fabian Wolf |
| * Author URI: https://usability-idealist.net/ |
| * License: GNU GPL v2 |
| */ |
| |
| /** |
| * Adds mastodon rel=me profile link to the html head as a test. |
| */ |
| |
| if( !class_exists( '_ui_Mastodon_Verification_Link' ) ) { |
| |
| class _ui_Mastodon_Verification_Link { |
| |
| public $plugin_prefix; |
| |
| public static function init() { |
| new self(); |
| } |
| |
| function __construct() { |
| $this->plugin_prefix = '_ui_mvl_'; |
| |
| add_action( 'wp_head', array( $this, 'add_mastodon_verification_link' ), 9 ); |
| |
| |
| // Adding options to registered field |
| add_action( 'admin_menu', array( $this, 'add_settings_to_admin_page' ) ); |
| } |
| |
| function add_mastodon_verification_link() { |
| |
| $verification_url = apply_filters( $this->plugin_prefix . 'get_verification_url', |
| get_option( $this->plugin_prefix . 'verification_url', '' ) |
| ); |
| |
| |
| |
| $link_template = apply_filters( $this->plugin_prefix . 'get_link_template', '<link type="href" rel="me" href="%s" />' ); |
| |
| if( !empty( $verification_url ) && !empty( $link_template ) ) { |
| // <link type="href" rel="me" href="https://kosmos.social/@ginsterbusch" /> |
| |
| if( !is_array( $verification_url ) ) { |
| $verification_url = explode("\n", trim( $verification_url ) ); |
| |
| /** |
| * NOTE: NO duplicates wanted! |
| */ |
| |
| $verification_url = array_unique( $verification_url ); |
| |
| } |
| |
| $added_by = "\n" . '<!– added by ' . basename( __FILE__, '.php' ) . ' v1.0 –>' . "\n"; |
| |
| echo "\n" . $added_by; |
| |
| foreach( $verification_url as $url ) { |
| echo "\n" . sprintf( $link_template, trim( $url ) ); |
| } |
| |
| echo "\n" . $added_by . "\n"; |
| } |
| } |
| |
| function add_settings_to_admin_page() { |
| |
| $settings_page = 'general'; |
| $settings_page = 'discussion'; |
| |
| register_setting( $settings_page, $this->plugin_prefix . 'verification_url' ); |
| |
| |
| add_settings_field( |
| sanitize_html_class( $this->plugin_prefix . 'verification-url' ), |
| 'Mastodon Profile URL(s)', |
| array( $this, 'display_settings_field' ), |
| $settings_page, |
| 'default', |
| array( |
| 'id' => sanitize_html_class( $this->plugin_prefix . 'verification-url' ), |
| 'option_name' => $this->plugin_prefix . 'verification_url', |
| ) |
| ); |
| } |
| |
| function display_settings_field( $input_data ) { |
| $id = $input_data['id']; |
| $option_name = $input_data['option_name']; |
| $option_data = get_option( $option_name ); |
| |
| ?> |
| <textarea name="<?php echo esc_attr( $option_name ); ?>" |
| id="<?php echo esc_attr( $id ); ?>" |
| cols="40" rows="4"><?php |
| if( !empty( $option_data ) ) { |
| echo esc_attr( $option_data ); |
| } ?></textarea> |
| <?php |
| } |
| } |
| |
| |
| add_action( 'plugins_loaded', array( '_ui_Mastodon_Verification_Link', 'init' ) ); |
| } |