Results 1 to 6 of 6

Thread: Extending an Existing Plugin

  1. #1
    OldManRiver is offline Hello World
    Join Date
    Nov 2011
    Posts
    4

    Default Extending an Existing Plugin

    All,

    Been trying to learn howto extend plugins. I find no HOWTO that directly addresses "Extending an Existing Plugin". I did find these howtos, which give some principles, but no howto is directly addressed:
    Code:
     codex.wordpress.org/Administration_Menus, codex.wordpress.org/Plugin_API,  
     
     codex.wordpress.org/Function_Reference/add_action, codex.wordpress.org/Function_Reference/add_action,        
     
     codex.wordpress.org/Function_Reference/add_action, codex.wordpress.org/Writing_a_Plugin,     
     
     return-true.com/2009/02/creating-an-options-admin-page-for-your-wordpress-plugin/,      
     
     ditio.net/2007/08/09/how-to-create-wordpress-plugin-from-a-scratch/,   
     
     www.wp-starter.com/2011/02/how-to-create-a-new-admin-page-in-wordpress/,   
     
     kovshenin.com/2010/02/wordpress-extending-the-contact-form-7-plugin-1985/,
    I'm sure to the writers these are clear, assume nothing and have logical flow, but in fact they assume so much that none of these make any sense at all, to those actually trying to learn. I think these are some of the most prime examples of ambiguity.

    Example: In the "Add Methods", from the first link, they throw out these commands as though they are something issued from either a command (can not be for a browser app) or some command api interfaces where the commands can be interactively issued, but one finds there is no such interface in WP, and studying other plugins, one finds all have a "wp-install.php" file, not mentioned in any of these helps, that all these commands go in and which is uses to actually install the plugin or any extensions to an existing plugin.

    Also what is left out, is there is a group of files, still do not have an accurate list of them, that are required before the plugin, or plugin extension is recognized and allowed to be seen within the "PlugIN" admin option set, so until the list is correct, you will not be able to execute any install to get the plugin installed. Futher confusion comes, as what I read the list of files is different for a stand alone plugin than for a plugin extension. The problem I'm finding is both in what goes into the install file and how are the files and directories organized to work.

    IN my case, I have a plugin that needs to be extended where I must add 3 pages to the admin side to set values in the 6 new database tables, then allow the user to choose the old forms, from the original plugin, or the new forms from the extension, where the new allow assignments and cross table linking that is not available in the old plugin.

    The new forms, as I understand WP standards, must have the same name as the original forms, but will reside in the directories under the home directory assigned to the plugin extension. A simple set of exclusive check boxes on the admin side should show which set of forms are being used.

    Hope there really is a good howto out there on this, but I can not find it.

    Also I tried posting on the main WP Forums and got no response at all on this.

    I finally got it partly working. The plugin shows as registered and I can activate it, but something has changed in the "add_menu" and "add_submenu" in 3.2.1, and I can not get the menu items and pages of the plugin to register and show correctly.

    Right now concentrating on getting the admin menu option inserted and it's option page working.

    Oh my comment about all the files, is not right, since I got the plugin registered and activated, I found out the thing that is required is the right set of header comment tags and then the plugin is seen. Back again to my ambiguity comment, this should be explained up front.

    Thanks!

    OMR
    Last edited by OldManRiver; 11-11-2011 at 11:39 PM.

  2. #2
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    595

    Default

    Well there is no one way to extend a plugin. It all depends on the plugin.
    And since we don't really know what you want to do its hard to help.
    You create 6 tables for some reason and want to add some new menu pages with options on them that connects to those database tables?
    Are you a PHP programmer or in training to become one?

  3. #3
    OldManRiver is offline Hello World
    Join Date
    Nov 2011
    Posts
    4

    Default Really Stuggling

    Quote Originally Posted by andreasnrb View Post
    Well there is no one way to extend a plugin. It all depends on the plugin. And since we don't really know what you want to do its hard to help. You create 6 tables for some reason and want to add some new menu pages with options on them that connects to those database tables? Are you a PHP programmer or in training to become one?
    As for your Q on PHP, been programming since 2000. As to what I suspect, I think there is a change in things between 3.2 and 3.2.1 that is giving me this crap shoot.


    Example:
    Code:
    <?php
       /***************************************************************************/
       /*  Plugin Name: WPS Poll                                */
       /*             URI: ../wp-content/plugins/wps-poll                       */
       /*  Description: This plugin is a test plugin for learning purpose.        */
       /*      Version: 0.1        Author: Nyle Davis                             */
       /*    Author URI: http://URI_Of_The_Plugin_Author                           */
       /*      License: GPL2  - most WordPress plugins are released under GPL2    */
       /***************************************************************************/
    
       function wps_poll_options_page () {
          ?>
          <div class=”wrap”>
          <h2>WPS Poll Admin</h2>
          <p>Here comes the options page content</p>
          </div>
          <?php
       }
    
       function wps_poll_menu () {
        $plug_str = "'WPS Poll', __('WPS Poll'),__('WPS Poll'),'manage_options',".
                basename(__FILE__) . ", 'wps_poll_options_page'".
          add_menu_page($plug_str);
       }
    
       add_action(‘admin_menu’,'wps_poll_menu');
    
    ?>
    This is from HOWTO at:

    http://www.wp-starter.com/2011/02/ho...-in-wordpress/

    and should create the menu item, but does not.

    Additionally I ran a test by renaming it all to AAA Poll, so it would appear at the top of the plugins display page, and when I did I started getting "session restart" errors from em-notice.php, part of another plugin I have installed.

    I also added a second custom plugin from the HOWTO at:

    http://codex.wordpress.org/Creating_Options_Pages

    And then I really got all kinds of errors.

    None of the Plugins will create an "Admin" menu item, nor register their pages. Nothing I have tried with the "add_menu_page" or "add_submenu_page" commands have worked.

    Either they made a significant change between 3.2 and 3.2.1 or I may have corrupted source, but not sure which.

    If I have corrupted source would not know if it is base WP code or one or more of the plugins. I have 6 active and 15 loaded.

    Oh, I created all the pages I want to load, mocked then up in another subdirectory and they display fine, but can not get them to come up at all with my code. Would need to pastebin the code someplace as way too lengthy for here. I'm at the point where I need this install/activate to work so I can test the functions in my OOP class module to see if the pages and their functions work right.

    All help appreciated!

    Thanks!

    OMR

  4. #4
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    595

    Default

    add_menu_page does not accept a string. the function accept separated parameters as it is written on the pages that you link too, not a string or array. Its just WP query functions that uses that parameter method.

  5. #5
    OldManRiver is offline Hello World
    Join Date
    Nov 2011
    Posts
    4

    Default Working - Sorta

    All,

    Here is my code that works on this:
    Code:
    <?php
       /***************************************************************************/
       /*  Plugin Name: WPS Poll                                */
       /*             URI: ../wp-content/plugins/wps-poll                       */
       /*  Description: This plugin is a test plugin for learning purpose.        */
       /*      Version: 0.1        Author: Nyle Davis                             */
       /*    Author URI: http://URI_Of_The_Plugin_Author                           */
       /*      License: GPL2  - most WordPress plugins are released under GPL2    */
       /***************************************************************************/
    
       function wps_poll_options_page () {
          ?>
          <div class=”wrap”>
          <h2>WPS Poll Admin</h2>
          <p>Here comes the options page content.</p>
          </div>
          <?php
       }  // end function
    
       function wps_poll_new_page () {
          include ( ABSPATH.'wp-content/plugins/events-manager-ext/admin/emxt-admin-options.php');
       }  // end function
    
       function emxt_new_page () {
          include ( ABSPATH.'wp-content/plugins/events-manager-ext/admin/emxt-admin-optform.php');
       }  // end function
    
       function wps_poll_menu () {
          // #1 Works    
          add_menu_page('WPS Poll', __('WPS Poll'),'manage_options',basename(__FILE__), 'wps_poll_options_page');
    
          // #2 Works
          $parent_slug = 'wps-poll.php';
          $page_title  = 'Options';
          $menu_title  = 'Options';
          $capability  = 'manage_options';
          $menu_slug   = 'emxt-admin-options.php';
          $function    = 'wps_poll_new_page';
          add_submenu_page($parent_slug, __($page_title), __($menu_title), $capability, $menu_slug, $function);
    
          // #3 Works
          $source_file = ABSPATH.'wp-content/plugins/events-manager-ext/events-manager-ext.php';
          $page_title  = 'EMXT Options';
          $menu_title  = 'EMXT Options';
          $function    = 'emxt_new_page';
        //echo "PS=> $parent_slug <br>";
          add_menu_page($page_title, __($menu_title), $capability, basename($source_file), $function);
    
          // #4 Works Now ==> Problem was the __(var) syntax in the add_submenu_page line 
          //              and "activate_plugins" for capability
          // Test writing a submenu to existing Events manger admin menu
          $parent_slug = 'events-manager';
          $page_title  = 'Ext Options';
          $menu_title  = 'Ext Options';
          $capability  = 'activate_plugins';
          $menu_slug   = 'events-manager-ext';
          $function    = 'emxt_new_page';
          add_submenu_page($parent_slug, __($page_title), __($menu_title), $capability, $menu_slug, $function);
       }  // end function
    
       add_action('admin_menu','wps_poll_menu');
    
    ?>
    Items 1-3 are experimental, but work, and showed me how to use the vars for command substitution. None of the codex HOWTOs showed this, but the syntax is very significant and the __(var) values must be there or the commands do not work. add_menu_page is much more forgiven than the submenu command.

    Anyway got the menu items added, but get errors from something else, so starting with clean code and adding one item at a time to find the activation problem with my other code. Will open a different thread, as I think that will not be related to these commands anymore.

    Thanks!

    OMR

  6. #6
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    595

    Default

    A suggestion is to add the options pages to the settings menu. That way settings are all in one place and don't cluttered up the menus. You rarely visit the settings pages.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •