WordPress and Call to undefined function add_menu_page()

Asked
Active3 hr before
Viewed126 times

9 Answers

wordpressfunctionundefined
90%

Meta Stack Overflow ,Stack Overflow en español,Stack Overflow em Português, Stack Overflow Public questions & answers

I don't know how your code looks but this is how I just tested and it worked:

add_action('admin_menu', 'my_menu');

function my_menu() {
   add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-page-slug', 'my_function');
}

function my_function() {
   echo 'Hello world!';
}
load more v
88%

If the function already existed, it wouldn't throw a Call to undefined function ... error, but rather Cannot redeclare ..., no?! Am I missing something here? – Johannes Pille Apr 15 '13 at 20:57 ,I am attempting to activate a theme that works perfectly on one WordPress install. I have matched the plugins installed up and copied the theme over but when I go to activate it I get..., Evolutionary pressures for carnivorous elves , I still cannot comment :( please don't down-vote Could another plugin be calling your function, try changing the function's name, or wrapping add_menu_page in an if(function_exists( "add_menu_page" ) ) statement.? – Jamie Apr 15 '13 at 20:48

I am attempting to activate a theme that works perfectly on one WordPress install. I have matched the plugins installed up and copied the theme over but when I go to activate it I get...

Fatal error: Call to undefined
function add_menu_page()
load more v
72%

You are directly calling theme's index file which is not correct way, as your theme must be using some default functions of WordPress, like get_header() in this case. ,Apparently this is happening because the file /wp-includes/pluggable which contains the function doesn't get loaded until after the plugins are loaded.,I recently got into WordPress plugin development and I would like to add a menu page (the links in the left hand side menu). Previous SO questions and the WordPress codex say that it's as simple as calling:,There's something called permalinks which allows you to create friendly URLs to your site without changing any names in your template files. That would be impossible if your URLs were directly attached to the file names.

I recently got into WordPress plugin development and I would like to add a menu page (the links in the left hand side menu). Previous SO questions and the WordPress codex say that it's as simple as calling:

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

However when I try this in my plugin setup file it tells me that the function is undefined:

PHP Fatal error: Call to undefined
function add_menu_page()
load more v
65%

Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in …… public_html/wp-includes/capabilities.php on line 652,https://developer.wordpress.org/reference/functions/add_submenu_page/,function xls_download_menu(){ add_menu_page(‘XLS Download’, ‘XLS Download’, ‘manage_options’, ‘download’, ”); }, Resolved Pamela (@infoknutsford-softwarecouk) 1 year, 9 months ago I have tried adding this to my plugin to add a menu to the dashboard `add_submenu_page( ‘xls-download’, __( ‘XLS Download’, ‘xls-download’ ), __( ‘XLS Download’, ‘xls-download’ ), ‘export’, ‘xls-download’ );` But I am getting Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in …… public_html/wp-includes/capabilities.php on line 652

Working fine at my end, use below code

function custom_options_panel() {
   add_menu_page('Custom page title', 'Custom menu label', 'manage_options', 'Custom-options', 'wps_Custom_func');
   add_submenu_page('Custom-options', 'Settings page title', 'Settings menu label', 'manage_options', 'Custom-op-settings', 'wps_Custom_func_settings');
   add_submenu_page('Custom-options', 'FAQ page title', 'FAQ menu label', 'manage_options', 'Custom-op-faq', 'wps_Custom_func_faq');
}
add_action('admin_menu', 'custom_options_panel');
load more v
75%

hello I'm new to wordpress plugin development I have recently added a menu page to my dashboard using procedural php , and it worked perfectly ,but when I jumped to oop php I have faced this problem "Fatal error: Uncaught Error: Call to undefined function add_menu_page() " I have looked to the same problems but no helped me,first of all, I need to tell you that my php knowledge is very low. I'm using a Wordpress plugin called WP User Frontend and I'm charging users to post articles...,I would like to understand the sequence various classes are loaded in Wordpress. There are many plugins available in Wordpress, then who will be loaded earlier...,You don't need to run the addingpage method. WordPress works on hooks. Just add a hook and the hook's callback will be run in a needed time when all functions for this functionality loaded.

hello I'm new to wordpress plugin development I have recently added a menu page to my dashboard using procedural php , and it worked perfectly ,but when I jumped to oop php I have faced this problem "Fatal error: Uncaught Error: Call to undefined function add_menu_page() " I have looked to the same problems but no helped me

`class abc_adding_page{
    public function addingpage(){
        add_menu_page('abcba_products' ,'abcba_products' ,'manage_options' ,'abcba_products', function(){} ,'dashicons-store' ,110);
        return $this ;
}
    public function hooking(){
        add_action('admin_menu' ,  array($this ,'addingpage'));
    }
    }

 $x = new abc_adding_page();

 $x->addingpage()->hooking();
load more v
40%

I am attempting to activate a theme that works perfectly on one WordPress install. I have matched the plugins installed up and copied the theme over but when I go to activate it I get...,If you find copyright violations, you can contact us at info-generacodice.com to request the removal of the content.,Would you like to read this article or give it a correct answer?,   themes  -  fatal-error  -  theme-development  -  errors  -  admin-menu

I am attempting to activate a theme that works perfectly on one WordPress install. I have matched the plugins installed up and copied the theme over but when I go to activate it I get...

Fatal error: Call to undefined
function add_menu_page()
load more v
22%

Calling WordPress hook from within a class: call to undefined function error,Whoops\Exception\ErrorException thrown with message "call_user_func_array() expects parameter 1 to be a valid callback, function 'create_admin_page' not found or invalid function name" ,This will apply to any WordPress function that has a 'callback' as a parameter. You can read more about callbacks in PHP here.,You are correctly passing the create_menu_item method of the current class to callback argument of the add_action() function. You just need to apply the same principle for the callbacks in the add_menu_page() function:

Here is my class.

namespace MyNamespace;


class MyClass {


    public function __construct() {
        add_action('admin_menu', array($this, 'create_menu_item'));
        //add_action('admin_bar_menu', 'remove_wp_logo', 999);
        //add_filter( 'admin_bar_menu', 'change_howdy', 25 );

        ddd($this->create_menu_item());


    }

//Get all pages

    public function get_all_pages() {
        $allpages = get_pages( array( 'post_type' => 'page', 'posts_per_page' => '-1') );
        return $allpages;

    }

    //Get Parent Page ID
    protected function get_location_id() {
        $parents = get_page_by_title('Locations');        
        return  $parents->ID;
    }

    //Get all locations excluding grandchildren
    protected function get_top_level_pages() {
        $children = get_page_children( $this->get_location_id(), $this->get_all_pages() );
        $locations = array();
        foreach ($children as $key => $value) {
            if ($this->get_location_id() == $value->post_parent) {
                $locations[$key] = $this->{$key} = $value;
            }
        }
        return $locations;
    }
    //Create top level menu item
    public function create_menu_item() {

        $locations = $this->get_top_level_pages();
        foreach ($locations as $key => $value) {
            add_menu_page( 
                $value->post_title, 
                $value->post_title, 
                'manage_options', 
                $value->post_name.'-admin-page.php', 
                'create_admin_page', //here is where I am calling the next function
                'dashicons-location-alt', 
                6  
            );

        }

    }

//Create Admin Page -----should be it's own class? 
    public function create_admin_page() {
        $children = get_page_children( $this->get_location_id(), $this->get_all_pages() );
        ?>
        <div class="wrap">
            <h2>Welcome Child Pages</h2>
        </div>
            <ul>
            <?php 
                if(!empty($children)){
                    echo '<ul>';
                    foreach($children as $child){
                        echo '<li><a href="'.get_permalink($child->ID).'">'.$child->post_title.'</a></li>';
                    }
                    echo '</ul>';
                }    
            ?>
            </ul>
        <?php

    }
load more v
60%

I’m new to wordpress and started creating a plugin using classes. when I run the plugin it throws the error “Call to undefined function add_menu_page()”. I’ve checked the support docs on wordpress.org but that doesn’t help either (https://codex.wordpress.org/Adding_Administration_Menus#Inserting_the_Pages), How to remove form validation errors when the fields are generated with localstorage data , shareitHQ Customize Follow Following Sign up Log in Report this content View site in Reader Manage subscriptions Collapse this bar , How to use auto increment field in insert for CI 3

heres my code below please can you tell me what I’m doing wrong:

class SetupAdminMenu {

   public static
   function add_menu($menu) {
      add_action('admin_menu', self::load_menu($menu));
      //I've used it according to the docs as well
      //add_action('admin_menu', array(self, self::load_menu($menu) );
   }

   public static
   function load_menu($menu) {
      $page = add_menu_page($menu['page_title'], $menu['menu_title'], $menu['capability'], $menu['menu_slug'],
         array(self, self::load_view($menu['function'])), $menu['icon_url'], $menu['position']);
      self::load_page($page);
   }

   protected static
   function load_view($view) {
      if (!current_user_can('activate_plugins')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
      }
      //The actual page to display
      include_once($view);
   }

   protected static
   function load_page($page) {
      add_action('admin_print_styles-'.$page, 'admin_styles');
   }

}
48%

I recently got into WordPress plugin development and I would like to add a menu page (the links in the left hand side menu). Previous SO questions and the WordPress codex say that it's as simple as calling:,http://codex.wordpress.org/Function_Reference/add_menu_page,You are getting this error message because either you have used the function add_menu_page outside any hook or hooked it too early.,See the following WordPress codex page for information about it.

I recently got into WordPress plugin development and I would like to add a menu page (the links in the left hand side menu). Previous SO questions and the WordPress codex say that it's as simple as calling:

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

However when I try this in my plugin setup file it tells me that the function is undefined:

PHP Fatal error: Call to undefined
function add_menu_page()
load more v

Other "wordpress-function" queries related to "WordPress and Call to undefined function add_menu_page()"