Right in my main plugin file, wp-email-capture.php I am calling this:-
add_action( 'admin_init', 'wp_email_capture_add_custom_boxes');
This calls this function:-
function wp_email_capture_add_custom_boxes()
{
add_meta_box("wp_email_capture_admin_supportbox", __('Support', 'WPEC'), "wp_email_capture_admin_supportbox", "wpemailcaptureoptions","side");
//do_meta_boxes( 'wpemailcaptureoptions', 'normal' , NULL); - removed as per SE advice
}
And separately this function:-
function wp_email_capture_admin_supportbox()
{
echo "<p>If you are having problems with this plugin, please read the Frequently Asked Questions, or alternatively submit a support request.</p>";
}
I open the WP Email Capture Options page (which has a slug of wpemailcaptureoptions) and I don’t see any box, or anything in the sidebar. It’s completely baffled me.
I suspect it is something on how it is called, I tried with add_action('add_meta_box',...
, but then even the function wasn’t being called.
Ideas?
If you need anything else, please let me know 🙂
Edit
I have now moved the “do_meta_boxes” to the options page where I want the meta box displayed and still having no joy, here’s the function that manages the option page:-
function wp_email_capture_show_lists()
{
$lists = wpecp_get_all_lists();
do_meta_boxes( 'wpemailcaptureoptions', 'normal' , NULL);
echo '<div class="wrap">';
echo '<img src="'.plugins_url('images/logolarge.png' , dirname(__FILE__)).'" align="right" style="padding-right: 5%" alt="WP Email Capture"> <h2>Lists</h2>';
?>
<table class="widefat">
<thead>
<tr>
<th><?php _e('List Name','WPEC'); ?></th>
<th><?php _e('Edit','WPEC'); ?></th>
<th><?php _e('Delete','WPEC'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th><?php _e('List Name','WPEC'); ?></th>
<th><?php _e('Edit','WPEC'); ?></th>
<th><?php _e('Delete','WPEC'); ?></th>
</tr>
</tfoot>
<tbody>
<?php
foreach ($lists as $list)
{
?>
<tr valign="top">
<th scope="row" style="width:400px"><?php echo $list->listid .". ". $list->listname; ?></th>
<?php
if ($list->listtype == 2)
{
$url = $_SERVER["REQUEST_URI"] . "&wpecr_listid=".$list->listid."&external=1";
} else {
$url = $_SERVER["REQUEST_URI"] . "&wpecr_listid=".$list->listid;
}
?>
<td><a href="<?php echo $url; ?>">Edit</a></td><td>
<?php
if ($list->listid != get_option('wp_wpecp_default_list'))
{
$url = $_SERVER["REQUEST_URI"] . "&delete_listid=".$list->listid;
?>
<a href="<?php echo $url; ?>">Delete</a>
<?php
}
?>
</td>
</tr>
<?php
}
echo '</tbody></table>';
echo "<p><a href='" . $_SERVER["REQUEST_URI"] ."&wpecr_listid=0' class='button-secondary'>Add New WP Email Capture List</a> <a href='" . $_SERVER["REQUEST_URI"] ."&wpecr_listid=0&external=1' class='button-secondary'>Add New External List</a></p>";
echo '</div></div>';
} ?>
You need to call
do_meta_boxes()
in your plugin options page and not in theadmin_init
hook.The reason you’re having problems with the meta box is that your contexts don’t match up.
When you call
add_meta_box
you specify the$context
argument (the fifth one) as side. Yet when you calldo_meta_boxes
you do so with the context (second argument)normal
. You need to change one or the other, but they should match up.To get the metaboxes to look right, you’ll also need to make sure you put them inside a container with the class
metabox-holder
.Your code would become:
This question got me curious, so I wrote an example of how one could use meta boxes + the settings API on custom page. Might help you out: