Created
December 15, 2016 00:28
-
-
Save bacalj/53a854ab31f79d82ab0cc6ae3efe5b53 to your computer and use it in GitHub Desktop.
Ultra-simple example of using a filter to write a basic WordPress plugin
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: Sign Up Message | |
Description: A basic plugin for illustration/learning purposes. Thanks subscribers at the end of a post. Not logged in users get asked to sign up. | |
Version: 0.1 | |
Author URI: http://www.digitalblockarea.com | |
*/ | |
function simple_sign_up_message($content){ | |
if ( is_user_logged_in() ) { | |
$current_user = wp_get_current_user(); | |
$message = 'Hi, ' . $current_user->user_firstname . '.'; | |
$message .= ' Thanks for reading!'; | |
} | |
else { | |
$message = 'Hi, and thanks for reading! '; | |
$message .= '<a href="'. wp_registration_url() .'">Subscribe to get cool stuff!</a>'; | |
} | |
return $content . $message; | |
} | |
add_filter('the_content', 'simple_sign_up_message'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment