Whenever you would use a class method within add_action function, then within the array parameter, you have to pass an instance of that class as the first value and then you the method name as the second value of the array. In your code, you did not pass any instance actually. And that’s why it did not work.
Try this:
class customFields {
private function createMenu () {
add_media_page('Custom Media Options', 'Add Fields to Media', 'manage_options', 'custom_media_options', $this->createMenuOptionsPage());
}
private function createMenuOptionsPage () {
echo 'test';
}
public function buildOptions () {
$this->createMenu();
}
}
$customFields = new customFields();
add_action('admin_menu', array($customFields, 'buildOptions'));
Related Posts:
- How to get menu location in wp_update_nav_menu hook
- I cannot include a file in my plugin settings page
- My wp_update_nav_menu action is firing twice
- Plugin developer automated documentation
- Custom plugin init action causing general slowness
- Is there a hook to Intercept al urls from a webpage and redirect to a page
- Delete mobile menu button [closed]
- html generated by theme exist but doesnt appear in browser
- add_action in static class [closed]
- Changing page URL and connect newsletter to MailChip
- WordPress user account activation
- Dynamic admin submenu
- Center and hide overflow of WP toolbar custom links
- How to remove admin main menu name repetition
- External Script Using WP – Hooks / Actions Not Working?
- Custom Permalink Plugin and Current Page/Ancestor in Menus
- Submit custom form from post content and execute in plugin
- wp-custom-menu filter removes the current_page_item class
- Inject HTML meta tag inside wordpress tag using add_shortcode
- add_action does not call the function
- How to get post ID with hooks publish_post, new_to_publish, etc
- How to use my menu PHP code as sidebar?
- add_action in a custom plugin
- register_activation_hook in oop approach
- Redirect to another page using contact form 7? [closed]
- What is @Action in WordPress?
- Problem with removing plugin action
- edit_user_profile and show_user_profile are not firing inside a class
- Add action to fire when a published post is updated
- do add_action on condition
- Is there a way to figure out which action/filter invoked a function?
- get gravity form ID from backend/wordpress admin
- How to pass variables to a function argument using add_action [duplicate]
- _prime_post_caches in wordpress
- How to trace SUBMIT button
- How passing values to construct function with Actions?
- Remove_action from plugin with a Class
- add_action into another add_action not working
- publish_post action doesn’t work
- Run a plugin just ‘once’ per page reload
- Using add_action before add_filter on a plugin?
- a weird attribute on every html tag
- Submit Form data to another page via Ajax (WordPress Way)
- the_post hook is not firing for me
- Why do plugins often ask to add in to templates?
- Does using `add_action( ‘init’…` cause performance issues?
- do_action Nested List
- Create a post builder skin in a plugin
- remove_action not removing add_action from constructor
- Plugin Development – Functions or Hooks?
- Hide a Menu Item on Login
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Basic function call on init failing
- How to create Admin Notice from Plugin with argument? [duplicate]
- PHP script from functions php is loaded via admin-ajax to div…and the result is 0, not the desired content
- Hook for page Request?
- Editing wp-config.php
- Are there action hooks for comments?
- Progmatically adding menu links to the default (Top) or Footer menu
- New bulk action to resend welcome emails
- WooCommerce: after install hook
- $pages = get_pages(‘child_of=’.$post->ID); Why arguments are concatenated?
- How to remove a class function from a plugin by using remove_action()?
- Advanced WordPress plugin activation detection
- Trying to add_action in a loop
- how to execute some code after a post is published in WordPress [duplicate]
- How to remove products-links after the product title using remove_action
- Changing location of “About me” section
- Need to revert to an older version of wordpress
- Dequeue, Unregister, Remove Action – Not Working on Plugin
- Add action to custom Function
- WordPress Custom Menu Admin helper plugin
- Action on WordPress Install
- How can I add a fixed vertical menu to my site? [closed]
- wp_ajax action responds with 0
- 2 wordpress site same database
- Custom CSS not being added by plugin
- Retrieve options set through a plugin
- override function from my plugin [closed]
- Hook on creating a menu entry?
- How to use add_action for multiple instances of the same class
- What hook can I use to modify custom post data before it is displayed on the page?
- How to hook into action/filter call
- Dropdown menu on click change
- navigation among single posts
- Running a function with args in add_action()
- How do i specify a url to which to redirect the user after he logs out from facebook?
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- Edit post image attributes on fly?
- Button and Countdown overlapping mobile menu
- Displaying page content from plugin, inside exising empty WP page
- Hook from plugin doesn’t fire up from external PHP script
- Slideout submenu in mobile
- Display posts by alphabetical order
- update_option_{$option} not working (do function after options are saved)
- Mobile Menu and Mobile Sidebar missing
- WP Forms not displaying,becomming an fatal error
- Callback hooked to post_updated firing on new posts as well
- Why do actions with class and public method don’t fire __construct()
- The function called on the wp head hook becomes null