WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Creating a plugin, getting Warning: call_user_func_array() expects parameter 1 (6 posts)

  1. tta
    Member
    Posted 2 years ago #

    I'm trying to put together my own little plugin. Everything went fine and I decided I'd try breaking the code up into several different files. Bear with me as I'm fairly new to making plugins, I've only made very simple personal ones before.

    I started getting this error after dividing it into multiple files, is it something obvious I've missed? I looked at what other plugins did to see how it's done (or how I think it is).

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'create_fvmenu' not found or invalid function name in /Users/name/Sites/wordpress/wp-includes/plugin.php on line 405

    fvshop.php:

    <?php
    /*
    Plugin Name: FVshop
    Version: 0.1
    */
    
    define( 'FVSHOP_URL', WP_PLUGIN_URL.'/fvshop' );
    define( 'FVSHOP_DIR', WP_PLUGIN_URL.'/fvshop' );
    
    if (is_admin()) {
        require_once( FVSHOP_DIR . '/includes/fvshop-admin-core.php');
    }
    
    if (is_admin()) {
        add_action('admin_init', 'create_fvmenu');
    }

    /includes/fvshop-admin-core.php:

    <?php
    function create_fvmenu() {
        add_action('admin_menu', 'fvshop_menu');
    
        function fvshop_menu() {
    
            $args = array(
                'page_title'    =>  'FV Shop',
                'menu_title'    =>  'FV Shop',
                'capability'    =>  'manage_options',
                'menu_slug'     =>  'fv_shop',
                'function'      =>  '',
                'icon_url'      =>  '',
                'position'      =>  ''
            );
            add_menu_page('FV Shop', 'FV Shop', 'manage_options', 'fv_shop', 'fv_shop_options', '', '3');
    
            add_submenu_page( 'fv_shop', 'Options', 'Options', 'manage_options', 'opt', 'fv_shop_options');
        //    add_options_page('FV Shop Options', 'FV Shop', 'manage_options', 'fvshopbutik', 'fv_shop_options');
        }
    
        function fv_shop_options() {
            if (!current_user_can('manage_options')) {
                wp_die(__('You do not have sufficient permissions to access this page.') );
            }
            echo '<div class="wrap">';
            echo '<p>FVshoppens options.</p>';
            echo '</div>';
        }
    }

    Doesn't really matter what kind of function I put in the second file, I still get the same error.

    Could someone shine some light on what I'm doing wrong, or what it is that could be happening?

  2. Rebecca Schaefer
    Member
    Posted 2 years ago #

    Why do you have functions within the main function? It almost looks like you're trying to create a class.

    Generally speaking, I try to keep all my controller functions in the main plugin file. Anything that generates a menu, adds a hook, etc, goes in that file. Everything else can be scattered around in whatever order makes the most sense to me.

    So, short answer: try separating out those two other functions and moving everything into the main file.

  3. tta
    Member
    Posted 2 years ago #

    Thanks a lot for the reply.

    Yeah, I don't know why there's a function inside a function, got angry and tired, rewriting a lot of it over and over, trying to figure out what the problem was. Blaming it on that. :)

    I tried making all kinds of different "test" functions just to see if they worked, and I got the same error. It does load the fvshop-admin-core.php file, but still gives me that error about the functions. So if I keep those in the main file, I fear I'll still get the same error from the other ones.

  4. tta
    Member
    Posted 2 years ago #

    Oh boy, look at this

    define( 'FVSHOP_URL', WP_PLUGIN_URL.'/fvshop' );
    define( 'FVSHOP_DIR', WP_PLUGIN_URL.'/fvshop' );

    Had WP_PLUGIN_URL on both *facepalm*

    Fixed that, now I don't get the error anymore.

  5. jcabezuelo
    Member
    Posted 1 year ago #

    I instaled in my site wordpress 3.4.1 + buddyboss 2.0 theme + buddypress 1.6.1.
    I was folowing these instructions:
    http://www.buddyboss.com/instructions-2/
    And when I was in Settings > General. Select “Anyone can register” under Membership.
    Give me this error:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'remove_merged_menus' not found or invalid function name in /home/content/03/9567903/html/vintecinco.com/wp-includes/plugin.php on line 403

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/03/9567903/html/vintecinco.com/wp-includes/plugin.php:403) in /home/content/03/9567903/html/vintecinco.com/wp-includes/pluggable.php on line 881

    When i go to http://vintecinco.com/wp-admin or http://vintecinco.com also give me the same error. How can I solve it?. I have to reinstall wordpress.

  6. bcworkz
    Member
    Posted 1 year ago #

    @jcabezuelo, You should have started your own thread, this one is old, and resolved and unrelated to your issue.

    Try disabling various plugins to see if the problem goes away. Then try a different theme. You may just need a fresh version of whatever is causing the error, but you'll have to determine which is causing the problem. If it does turn out to be buddyboss, you should seek their assistance.

Topic Closed

This topic has been closed to new replies.

About this Topic