WordPress.org

Ready to get started?Download WordPress

Forums

Building a Plugin From Scratch (11 posts)

  1. Russ Powers
    Member
    Posted 9 months ago #

    So I'm just getting into plugin development and I figured for my first very first plugin, I would make something super simple and useful. What I'm trying to accomplish is a plugin that adds a metabox to the "edit post" page in the admin panel that allows users to add some simple meta tags - description, keywords, etc.

    I'm really good at php, but this is my first time trying to build a plugin, let alone one that adds metaboxes for meta tags lol

    A little guidance would be greatly appreciated! :)

  2. WPyogi
    Volunteer Moderator
    Posted 9 months ago #

  3. jafardhada
    Member
    Posted 9 months ago #

    Hello, you could find guide here as said by WP Yogi - http://codex.wordpress.org/Writing_a_Plugin. I'm also starting to write a plugin for Gmail Login blog, if you get some more resources, also share with me.

  4. WPyogi
    Volunteer Moderator
    Posted 9 months ago #

    @jafardhada - please be aware that using these forums to post unnecessary links to your site is not permitted. They will be deleted.

  5. Pioneer Valley Web Design
    Member
    Posted 9 months ago #

    Might also want to review using 'gmail' in a url as it's a trademark of a rather large multibillion dollar corporation that has a very large legal dept. :-)

    Edit: Mod removed link...

  6. WPyogi
    Volunteer Moderator
    Posted 9 months ago #

    Excellent point - in fact it's right on this page:
    http://www.google.com/permissions/trademark/rules.html

  7. Russ Powers
    Member
    Posted 9 months ago #

    I've checked out the writing a plugin page, but what I'm hoping to find is a simple plugin example that has somewhat similar functionality that I can toy around with. I've already created this functionality when I learned how to use custom fields, but I would like a more user friendly way to enter the data and not have it limited to the theme. I'm thinking that once I learn how to create meta-boxes with a plugin, that would open the door for me to be able to create a whole slew of useful plugins.

    Which leads me to my next question lol is it possible to use meta-boxes to fill in data for custom fields? I'm almost positive this is plausible but just want to make sure lol

  8. Russ Powers
    Member
    Posted 9 months ago #

    this is what I have so far lol

    <?php
    /*
    Plugin Name: custom meta box
    Plugin URI: http://wordpress.org
    Description: This plugin adds a custom meta box to the post page on the admin panel that allows user to enter post related data.
    Version: Beta
    Author: Russ Powers
    Author URI: http://wordpress.org
    */
    ?>
    
    <?php
        add_action( 'add_meta_boxes', 'cd_meta_box_add' );
        function cd_meta_box_add() {
            add_meta_box( 'my-meta-box-id', 'My First Meta Box', 'cd_meta_box_cb', 'post', 'normal', 'high' );
        }
    ?>
    <?php
        function cd_meta_box_cb( $post ) {
    		$values = get_post_custom( $post->ID );
    		$text = isset( $values['my_meta_box_text'] ) ? esc_attr( $values['my_meta_box_text'][0] ) : ”;
    		$selected = isset( $values['my_meta_box_select'] ) ? esc_attr( $values['my_meta_box_select'][0] ) : ”;
    		$check = isset( $values['my_meta_box_check'] ) ? esc_attr( $values['my_meta_box_check'][0] ) : ”;
    		<p>
    			<label for="my_meta_box_text">Text Label</label>
    			<input type="text" name="my_meta_box_text" id="my_meta_box_text" value="<?php echo $text; ?>" />
    		</p>
        }
     ?>
  9. WPyogi
    Volunteer Moderator
    Posted 9 months ago #

    Have you looked at these?

    http://wordpress.org/plugins/search.php?q=meta+boxes

    (Sorry for the diversion above, BTW.)

  10. Russ Powers
    Member
    Posted 9 months ago #

    No worries, I completely understand the diversion :) I made sure to replace my URL's with wordpress.org in the code snippet above lol I was able to get the code above to work for a split second, generated the metabox and everything - but I had some code showing up at the top of all the pages in the admin panel.

    I've checked out a few of the pre-existing meta-box plugins but some of them are a little to complicated for me to find the very basic functions and syntax required. I've been looking for a plugin that adds a single meta-box for something silly like current mood or current song but haven't found anything useful lol

  11. WPyogi
    Volunteer Moderator
    Posted 9 months ago #

    How about the Codex -

    http://codex.wordpress.org/Function_Reference/add_meta_box

    I'm really not the one to help with code questions and you will likely get better help on the Hacks forum for something like this.

    http://wordpress.org/support/forum/hacks

Reply

You must log in to post.

About this Topic