• Resolved tta

    (@tykho)


    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.

    Thread Starter tta

    (@tykho)

    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.

    Thread Starter tta

    (@tykho)

    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.

    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.

    Moderator bcworkz

    (@bcworkz)

    @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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Creating a plugin, getting Warning: call_user_func_array() expects parameter 1’ is closed to new replies.