I’m an experienced dev, but new to WordPress. I’m following along with a course on udemy and they suggested I encapsulate my plugin functions in a class to help avoid namespace conflicts. However, inside one of my action hooks (not sure that’s the right term), I try to call add_menu_page()
to add some menu items to the admin sidebar and I can’t figure out how to reference my function. If I just give it the name of the function inside my class "testing_options_page"
, then WP can’t find the function. If I try to wrap it in an array to declare the class name and the function like I did with the add_action()
call, then the WP code horks because it doesn’t expect an array for that param array('kenny_plugin6', 'testing_options_page')
.
How can I reference the function inside the class when calling the add_menu_page()
function?
Side question: Is wrapping my code in a class going to be more pain that its worth?
add_action( 'admin_menu', array( 'kenny_plugin6', 'add_menu_items' ) );
class kenny_plugin6 {
function add_menu_items() {
add_menu_page( 'Browser Tab Title', 'Menu Item Title', 'manage_options',
'testing_menu_page', 'testing_options_page', '', '25' );
add_submenu_page( 'testing_menu_page', 'Test Links', 'Test Title', 'manage_options',
'get_test_links' );
}
function testing_options_page() {
?>
<h3>Testing Options</h3>
<div>Put more stuff here</div>
<?php
}
function get_test_links() {
?>
<h3>Test Links</h3>
<div> Put more stuff here.</div>
<?php
}
}