php - Why does Wordpress add_menu not work when seperated from Initial plugin page? -
so i'm working on very basic plugin wordpress. copied following internet menu item plugin named menu.php
<?php /* plugin name: test plugin description: test plugin demonstrate wordpress functionality author: simon lissack version: 0.1 */ defined( 'abspath' ) or die( 'no script kiddies please!' ); add_action('admin_menu', 'test_plugin_setup_menu'); function test_plugin_setup_menu(){ add_menu_page( 'test plugin page', 'test plugin', 'manage_options', 'test-plugin', 'test_init' ); } function test_init(){ echo "<h1>hello world!</h1>"; } ?>
this works expected it's stand alone plugin. have different plugin
<?php /* plugin name: plugin description: blah blah author: me version: 0.1 */ defined( 'abspath' ) or die( 'no script kiddies please!' ); fun fun database work on register_activation_hook ?>
the problem i'd have in 1 plugin not 2 tried , deleted commenting made register plugin in menu.php
/* plugin name: plugin description: blah blah author: me version: 0.1 */ defined( 'abspath' ) or die( 'no script kiddies please!' ); include_once('menu.php'); fun fun database work ?>
fatal error: call undefined function wp_get_current_user() in wp-includes\capabilities.php on line 1387 , error get. doing following gives me desired result
/* plugin name: plugin description: blah blah author: me version: 0.1 */ defined( 'abspath' ) or die( 'no script kiddies please!' ); add_action('admin_menu', 'test_plugin_setup_menu'); function test_plugin_setup_menu(){ add_menu_page( 'test plugin page', 'test plugin', 'manage_options', 'test-plugin', 'test_init' ); } function test_init(){ echo "<h1>hello world!</h1>"; } fun fun database work ?>
the reason i'd know how work using include or require or @ least know why can't because i'm sure plugin grow , have in bunch of smaller easier me maintain files 1 big initial file.
thank ohh i've tried
<?php /* plugin name: plugin description: blah blah author: me version: 0.1 */ defined( 'abspath' ) or die( 'no script kiddies please!' ); // add_action('plugins_loaded','load_menu');//didn't work same error add_action('init','load_menu');//didn't work same error function load_menu(){ include_once('menu.php'); } fun fun database work ?>
thanks again help
Comments
Post a Comment