0

Does includes/admin.php have special status I don't understand?

This is my dash widget code:


add_action('wp_dashboard_setup', 'custom_dashboard_widgets');

function custom_dashboard_widgets() {
  global $wp_meta_boxes;
  error_log("I love testing!");
  wp_add_dashboard_widget('test_dash', 'Test Dash', 'test_dash');
}

function test_dash(){
  echo "Test";
}
?>

If I put that code in includes/dash.php it works perfectly. If I put it in includes/admin.php nothing happens. Both files are included in the plugin using the same method:

require_once('includes/admin.php');
require_once('includes/dash.php');
1
  • 1
    To what plugin are you referring?
    – vancoder
    Jul 22, 2022 at 18:32

1 Answer 1

0

The problem is here:

require_once('includes/admin.php');

It should be:

require_once(plugin_dir_path( __FILE__ ).'/includes/admin.php');

The original code actually sources a core WordPress file with the same name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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