0

I'm trying to add an admin sub-level menu on WordPress. The menu link is working fine but the page which I want to show is throwing an error.

error:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'print_admin_config' not found or invalid function name in /var/www/html/woocommerce-print/wp-includes/class-wp-hook.php on line 286

Hook:

add_action( 'admin_menu', 'print_admin_menu' );

function print_admin_menu() {
    add_options_page( 'Print Configuration', 'Print Configuration', 'manage_options', 
    'woocommerce-print/admin/print-admin-config.php', 'print_admin_config', 'dashicons-tickadmin-generic', 31 );
}

Callback function (woocommerce-print/admin/print-admin-config.php):

<?php
function print_admin_config(){
    ?>
    <div class="wrap">
        <h2>Welcome To My Plugin</h2>
    </div>
    <?php
}
  • @JacobPeattie, my print_admin_config() is in woocommerce-print/admin directory and the file in which my hook is written is also in the same directory – Akash Agrawal Feb 6 '18 at 13:00
  • That's not how PHP works. You still need to include the file. – Jacob Peattie Feb 6 '18 at 13:01
  • then can you show me how to do it? – Akash Agrawal Feb 6 '18 at 13:04
  • Check add_options_page() arguments. You have one unnecessary. – Max Yudin Feb 6 '18 at 13:04
0

Got it working like this:

function print_admin_menu() {
    add_options_page( 'Print Configuration', 'Print Configuration', 'manage_options', 
    'print_admin_config_page', 'my_callback' );
}

function my_callback(){
    ?>
    <div class="wrap">
        <h2>Welcome To My Plugin</h2>
    </div>
    <?php
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.