Created
November 7, 2022 05:49
-
-
Save ginsterbusch/ce9497e4e1c416dc7e0b49e767a994b1 to your computer and use it in GitHub Desktop.
UI Mastodon Verification Link plugin for ClassicPress and WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment