Created
October 23, 2018 11:37
-
-
Save ziogaschr/4bbcd530543786866a877d481a9600f6 to your computer and use it in GitHub Desktop.
Example plugin for the presentation "WordPress hooks
and plugin development" at the Larissa WordPress meetup
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: Plugin Development Larissa Meetup | |
* Description: Intro to plugin development at WordPress Larissa Meetup | |
* Plugin URI: https://speakerdeck.com/wpgr/ | |
* Author: Chris Ziogas | |
* Author URI: https://www.linkedin.com/in/ziogaschr/ | |
* Version: 1.0 | |
*/ | |
defined('ABSPATH') or die(); | |
/* | |
* Init action | |
* http://codex.wordpress.org/Function_Reference/add_action | |
*/ | |
function pdlm_init() | |
{ | |
if (is_admin() ) { | |
return; | |
} | |
$pdlm_convert_links = get_option('pdlm_convert_links', 0); | |
if ($pdlm_convert_links) { | |
add_filter('the_content', 'pdlm_convert_text_links_to_html_links'); | |
} | |
$pdlm_disable_emoji = get_option('pdlm_disable_emoji', 0); | |
if ($pdlm_disable_emoji) { | |
remove_action('wp_head', 'print_emoji_detection_script', 7); | |
remove_action('wp_print_styles', 'print_emoji_styles'); | |
} | |
} | |
add_action('init', 'pdlm_init'); | |
/* | |
* Add add_menu page | |
* http://codex.wordpress.org/Function_Reference/add_menu_page | |
*/ | |
function pdlm_admin_menu() | |
{ | |
add_menu_page('Plugin Development - Larissa Meetup', | |
'Larissa Meetup', | |
'manage_options', | |
'plugin_development_larissa_meetup', | |
'plugin_development_larissa_meetup_settings'); | |
} | |
add_action('admin_menu', 'pdlm_admin_menu'); | |
/* | |
* add_menu_page callback | |
*/ | |
function plugin_development_larissa_meetup_settings() | |
{ | |
// save the submission | |
if (isset($_GET['pdlm_save'])) { | |
update_option('pdlm_convert_links', intval($_POST['pdlm_convert_links'])); | |
update_option('pdlm_disable_emoji', intval($_POST['pdlm_disable_emoji'])); | |
// redirect back to form | |
wp_safe_redirect($_SERVER['HTTP_REFERER']); | |
die(); | |
} | |
// show the form | |
plugin_development_larissa_meetup_settings_form(); | |
} | |
/* | |
* Settings page form | |
*/ | |
function plugin_development_larissa_meetup_settings_form() | |
{ | |
$pdlm_convert_links = get_option('pdlm_convert_links', 0); | |
$pdlm_disable_emoji = get_option('pdlm_disable_emoji', 0); | |
?> | |
<div class="wrap"> | |
<h1>Plugin Development - Larissa Meetup</h1> | |
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?page=plugin_development_larissa_meetup&noheader=true&pdlm_save=true" | |
method="post"> | |
<div> | |
<label for="pdlm_convert_links"> | |
<input type="checkbox" id="pdlm_convert_links" name="pdlm_convert_links" value="1" | |
<?php if ($pdlm_convert_links == 1) { | |
echo ' checked="checked"'; | |
} | |
?> | |
/> | |
Μετατροπή διευθύνσεων μέσα στο κείμενο σε HTML συνδέσμους. | |
</label> | |
<br /> | |
<label for="pdlm_disable_emoji"> | |
<input type="checkbox" id="pdlm_disable_emoji" name="pdlm_disable_emoji" value="1" | |
<?php if ($pdlm_disable_emoji == 1) { | |
echo ' checked="checked"'; | |
} | |
?> | |
/> | |
Απενεργοποιήση WordPress εικόνων emoji, και χρήση χαρακτήρων unicode. | |
</label> | |
</div> | |
<?php submit_button();?> | |
</form> | |
</div> | |
<?php | |
} | |
/* | |
* Convert text links into HTML links | |
*/ | |
function pdlm_convert_text_links_to_html_links($content) | |
{ | |
return make_clickable($content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment