WordPress.org

Forums

how do I write the function to open the page? (2 posts)

  1. xymalf
    Member
    Posted 1 year ago #

    <?php
    
    /*
    Plugin Name: Menu Test
    Plugin URI: http://codex.wordpress.org/Adding_Administration_Menus
    Description: Menu Test
    Author: Codex authors
    Author URI: http://example.com
    
    warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'boj_menuexample_settings_page' not found or invalid function name in C:\wamp\www\WPDev\wp-includes\plugin.php on line 470
    */
    
    add_action( 'admin_menu', 'boj_menuexample_create_menu' );
    
    function boj_menuexample_create_menu() {
    
    add_menu_page( 'My Plugin Settings Page', 'Menu Example Settings','manage_options', _FILE_, 'boj_menuexample_settings_page', plugins_url( '/images/wp-icon.png', _FILE__));
    
    }
    
    add_action( 'about_menu', 'boj_menuexample_about_page');
    function boj_menuexample_about_page() {
    add_submenu_page( _FILE_, 'About My Plugin', 'About', 'manage_options',_FILE_.'_about', boj_menuexample_about_page);
    
    }
    
    add_action( 'uninstall_menu', 'boj_menuexample_uninstall_page');
    function boj_menuexample_uninstall_page() {
    
    add_submenu_page( _FILE_,'Uninstall My Plugin', 'uninstall', 'manage_options',
    _FILE_.'_uninstall', boj_menuexample_uninstall_page);
    
    }
    
    ?>
  2. Chris
    Member
    Posted 1 year ago #

    /*
    Plugin Name:  Menu Test
    Plugin URI:   http://codex.wordpress.org/Adding_Administration_Menus
    Description:  Menu Test
    Author:       Codex authors
    Author URI:   http://example.com
    */
    
    // You can do all the menu creation at once.
    function boj_menuexample_create_menu() {
    
      add_menu_page( 'My Plugin Settings Page', 'Menu Example Settings','manage_options', __FILE__, 'boj_menuexample_settings_page', plugins_url( '/images/wp-icon.png', __FILE__ ) );
    
      add_submenu_page( __FILE__, 'About My Plugin', 'About', 'manage_options', __FILE__ . '_about', 'boj_menuexample_about_page' );
    
      add_submenu_page( __FILE__,'Uninstall My Plugin', 'uninstall', 'manage_options', __FILE__ . '_uninstall', 'boj_menuexample_uninstall_page' );
    
    }
    add_action( 'admin_menu', 'boj_menuexample_create_menu' );
    
    //  Then you actually have to declare the functions that will generate the pages/page content.
    function boj_menuexample_settings_page() {
    
      echo "<h1>Settings Page</h1>";
    
    }
    function boj_menuexample_about_page() {
    
      echo "<h1>About Page</h1>";
    
    }
    function boj_menuexample_uninstall_page() {
    
      echo "<h1>Uninstall Page</h1>";
    
    }

    You also don't need an extra uninstall page. Plugins should be installed and uninstalled by using the WordPress plugin administration page.

    If you're plugin requires to delete options, database stuff in general or certain files when being uninstalled you should create a separate file for this, called uninstall.php (http://codex.wordpress.org/Function_Reference/register_uninstall_hook#uninstall.php)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags