The Extra Post Info WordPress plugin was a plugin developed for my create your first WordPress plugin tutorial.

This basic WordPress plugin simply allows users to add some extra info to all their posts, but serves to teach how a WordPress plugin should be built. It was a lot of fun to create, and I hope to continue to add to it.

extra post info admin page read setting from database

I tried to keep the tutorial information packed, while still approaching WordPress plugin development from a step by step format. If you were just looking to grab the full WordPress plugin script that's what this page is for.

Completed Extra Post Info WordPress plugin

Here is my plugin in all its glory, this version is heavily commented, so hopefully you can easily tell what's going on.

You can also grab the raw text version as well. Follow the steps from the create WordPress plugin script guide if you are unsure what to do with this full plugin script. You would just want to save this script to the file:

/home/userna5/public_html/wp-content/plugins/extra-post-info/extra-post-info.php

<?php
/*
Plugin name: WordPress Extra Post Info
Plugin URI: http://example.com/wordpress-extra-post-info
Description: A simple plugin to add extra info to posts.
Author: Jacob Nicholson
Author URI: http://InMotionHosting.com
Version: 0.5
*/

// Call extra_post_info_menu function to load plugin menu in dashboard
add_action( 'admin_menu', 'extra_post_info_menu' );

// Create WordPress admin menu
function extra_post_info_menu(){

  $page_title = 'WordPress Extra Post Info';
  $menu_title = 'Extra Post Info';
  $capability = 'manage_options';
  $menu_slug  = 'extra-post-info';
  $function   = 'extra_post_info_page';
  $icon_url   = 'dashicons-media-code';
  $position   = 4;

  add_menu_page( $page_title,
                 $menu_title,
                 $capability,
                 $menu_slug,
                 $function,
                 $icon_url,
                 $position );

  // Call update_extra_post_info function to update database
  add_action( 'admin_init', 'update_extra_post_info' );

}

// Create function to register plugin settings in the database
function update_extra_post_info() {
  register_setting( 'extra-post-info-settings', 'extra_post_info' );
}

// Create WordPress plugin page
function extra_post_info_page(){
?>
  <h1>WordPress Extra Post Info</h1>
  <form method="post" action="options.php">
    <?php settings_fields( 'extra-post-info-settings' ); ?>
    <?php do_settings_sections( 'extra-post-info-settings' ); ?>
    <table class="form-table">
      <tr valign="top">
      <th scope="row">Extra post info:</th>
      <td><input type="text" name="extra_post_info" value="<?php echo get_option('extra_post_info'); ?>"/></td>
      </tr>
    </table>
  <?php submit_button(); ?>
  </form>
<?php
}

// Plugin logic for adding extra info to posts
if( !function_exists("extra_post_info") )
{
  function extra_post_info($content)
  {
    $extra_info = get_option('extra_post_info');
    return $content . $extra_info;
  }

// Apply the extra_post_info function on our content  
add_filter('the_content', 'extra_post_info');
}

?>
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

News / Announcements

WordPress wp-login.php brute force attack
Updated 2014-07-17 06:43 pm EST
Hits: 201637

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!