WordPress.org

Ready to get started?Download WordPress

Forums

simple wordpress plugin to add actionable text after blog content - feedback? (3 posts)

  1. Paul Jarvis
    Member
    Posted 3 years ago #

    hi all, i've written a SUPER simple plugin that appends text after the content if you're viewing a blog post, and the text is editable via the admin system. i'll post the code below, does this look right? represent any security risks? any help or suggestions or feedback would be appreciated as it's my first plugin.

    <?php
    /*
    Plugin Name: Now What
    Plugin URI: http://pjrvs.com/now-what-wordpress-plugin
    Description: Putting action-item text at the end of every post
    Version: 1.0
    Author: Paul Jarvis
    Author URI: http://pjrvs.com
    
    Released under the GNU General Public License (GPL)
    http://www.gnu.org/licenses/gpl.txt
    
    */
    
    add_filter('the_content','now_what_pjrvs');	
    
    register_activation_hook(__FILE__,'now_what_pjrvs_install');
    	function hello_world_install() { add_option("now_what_pjrvs_data", 'Default', '', 'yes'); }
    
    register_deactivation_hook( __FILE__, 'now_what_pjrvs_remove' );
    	function hello_world_remove() { delete_option('now_what_pjrvs_data'); }
    
    if (is_admin()) {
    	add_action('admin_menu', 'now_what_pjrvs_admin_menu');
    
    	function now_what_pjrvs_admin_menu() {
    	add_options_page('Now What Options', 'Now What', 'administrator',
    	'now-what', 'now_what_html_page');
    	}
    } // end if
    
    function now_what_html_page() { ?>
    
    	<div class="wrap">
    		<h2>Now What Options</h2>
    
    		<p><em>Adding actionable items to the end of each post (like tweet this, share on facebook, subscribe to the RSS).</em></p>
    
    		<p>Enter Your "Now What" Text:</p>
    		<form method="post" action="options.php">
    			<?php wp_nonce_field('update-options'); ?>
    
    			<table class="form-table" cellpadding="20">
    				<tr valign="top">
    					<td>
    						<textarea name="now_what_pjrvs_data" type="text" id="now_what_pjrvs_data" rows="10" cols="80"><?php echo get_option('now_what_pjrvs_data'); ?></textarea>
    					</td>
    				</tr>
    			</table>
    
    			<input type="hidden" name="action" value="update" />
    			<input type="hidden" name="page_options" value="now_what_pjrvs_data" />
    			<br />
    			<button type="submit" class="button-primary"><?php _e('Save Changes') ?></button>
    		</form>
    
    		<h3><br /><br />Sample Text to share your RSS link, RSS email subscription link (feedburner), twitter share widget and facebook share widget (copy and paste to the above field to use it - and make sure to change the feedburner URLs to your own URL):</h3>
    		<textarea rows="10" cols="80"><div class="now-what"><strong>thanks for reading my article!</strong><br />
    you can subscribe to my <a href="http://feeds.feedburner.com/pjrvs">rss feed</a> or <a href="http://feedburner.google.com/fb/a/mailverify?uri=pjrvs&loc=en_US">via email</a> so you never miss a new article. if you'd like to share what you just read, you can do it on <a href="javascript:void(0);" onclick="return fbs_click()">facebook</a> or on <a href="javascript:void(0);" onclick="return twitter_click()">twitter</a>.
    </div>
    
    <script type="text/javascript">
    function fbs_click(){
    u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}
    function twitter_click(){
    u=location.href;t=document.title;window.open('http://twitter.com/share?url='+encodeURIComponent(u)+'&text='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}
    </script></textarea>
    
    		<h3><br /><br />Here's what you've got currently:</h3>
    
    		<p><?php echo get_option('now_what_pjrvs_data'); ?></p>
    
    		<h3><br /><br />Learn More</h3>
    		<p><a href="http://pjrvs.com/now-what-wordpress-plugin">Read the</a> post that started this plugin.</p>
    	</div><!--wrap-->	
    
    <?php	}
    
    function now_what_pjrvs($content = '') {
    	$text = get_option('now_what_pjrvs_data');
    
    	if(is_single()) {
    		return $content . $text;
    	} else {
    		return $content;
    	}
    
    }	
    
    ?>
  2. digitalrenewal
    Member
    Posted 2 years ago #

    have you been using this alot? looks like an awesome SIMPLE plugin and there are no others out there like it.

    I tried it and its working perfectly. any updates or tweaks?

  3. digitalrenewal
    Member
    Posted 2 years ago #

    EXCELLENT name for the plugin by the way :D

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags