Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I was looking on Wordpress function reference and find that add_menu_page takes simple function as arg while add_meta_box call it as call back. I am new to programming.. help me understand this

share|improve this question
add comment

1 Answer

The parameters have the same meaning, they are just named inconsistent. Both accept calls to a function. This can even be the same function.

Here is a simple demo as a plugin. Download

/*
Plugin Name: Callback Demo
Description: Demonstrating how a meta box and a menu page can take the same callback function.
Version:     1.0
Required:    3.1
Author:      Thomas Scholz
Author URI:  http://toscho.de
License:     GPL
Plugin URI:  http://wordpress.stackexchange.com/q/24481/
*/
! defined( 'ABSPATH' ) and exit;

add_action( 'admin_menu', 'wpse_24481_demo' );

/**
* Adds a menu page and a meta box with the same callback function.
*
* @return void
*/
function wpse_24481_demo()
{
    $title    = 'Callback Demo';
    $callback = 'wpse_24481_callback';

    add_menu_page( $title, $title, 'edit_posts', 'callback-demo', $callback );
    add_meta_box( 'callback-demo', $title, $callback, 'post' );
}

/**
* Prints the content.
*
* @return void
*/
function wpse_24481_callback()
{
    print 'Here may be dragons.';
}

.

Result

enter image description here

page menu


enter image description here

meta box

share|improve this answer
    
Tried to fix the end of that code block 3 times now, no idea what the issue is, doesn't seem to want to format it correctly, whilst preview shows it all in the code block, SE/SO bug of some kind i guess.. –  t31os Jul 30 '11 at 12:11
    
I added a Magic Dot. #fixed :) –  toscho Jul 30 '11 at 12:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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