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
- How to only hook on Single.php after content?
- Add section (add_settings_section) to a custom page (add_submenu_page)
- What is the ‘admin_action_’ . $_REQUEST[‘action’] hook used for?
- What’s the easiest way to duplicate an entire navigation menu?
- Autogenerate wordpress shortcodes using array?
- How to call “page specific menu items” in template [closed]
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- Is there a global action for when a plugin is uninstalled?
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- How to remove action from plugin?
- Does the ‘nav_menu_css_class’ filter accept 2 or 3 arguments?
- Very stubborn wp_register_script / add_action vs remove
- do_action and hook methods
- Is it possible to add an action to the currently running action?
- Is there an action that is called when a post is restored from the trash?
- Creating WordPress Plugin solely for Admin panel with dash menu and submenus
- Action on post publish
- How to add inline css/js inside a shortcode
- How to prevent action in ajax request, when in admin side?
- Multiple navigation menus to a location?
- Can I use a method from an existing plugin as an action hook?
- Making menu link open in new tab?
- What are the benefit in adding hook in the init() hook?
- Detect when any plugin is activated or deactivated
- Where to hook my plugin’s action
- Overwrite or Replace code in WP_Footer
- How to make a customize role and view a specific plugins base on that role?
- Any hook for pre-plugin-update -either bulk or single plugin update
- wordpress plugin is not activating from widget
- When to load auto-login code?
- How to get all of the activate_plugin action parameters?
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Delete mobile menu button [closed]
- Changing page URL and connect newsletter to MailChip
- WordPress user account activation
- Dynamic admin submenu
- External Script Using WP – Hooks / Actions Not Working?
- Custom Permalink Plugin and Current Page/Ancestor in Menus
- wp-custom-menu filter removes the current_page_item class
- add_action does not call the function
- add_action in a custom plugin
- Add action to fire when a published post is updated
- _prime_post_caches in wordpress
- Run a plugin just ‘once’ per page reload
- Using add_action before add_filter on a plugin?
- a weird attribute on every html tag
- remove_action not removing add_action from constructor
- PHP script from functions php is loaded via admin-ajax to div…and the result is 0, not the desired content
- Progmatically adding menu links to the default (Top) or Footer menu
- Advanced WordPress plugin activation detection
- 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
- WordPress Custom Menu Admin helper plugin
- How can I add a fixed vertical menu to my site? [closed]
- wp_ajax action responds with 0
- Custom CSS not being added by plugin
- How to use add_action for multiple instances of the same class
- How to hook into action/filter call
- Dropdown menu on click change
- How do i specify a url to which to redirect the user after he logs out from facebook?
- Edit post image attributes on fly?
- Why do actions with class and public method don’t fire __construct()
- Sharing varible between two add_actions
- WordPress site hamburger menu toggle not working
- How to remove default action from a plugin?
- Removing Plugin Action via Theme for Non-admins
- Scroll to ID broken in main menu
- Get post content inside plugin class method
- Ajax call to php function doesn’t work PHP code
- Frontend AJAX Request causes Error: ‘Call to undefined function add_action’
- Creating Admin Submenu Page via Class Method
- Help needed with woocommerce (wc stripe) filter
- Sub Categories in drop down menu
- Why doesn’t a form need an ‘action’ with a plugin that uses the post data?
- Run only on plug-in activation instead of wp_head
- Am I using an action hook correctly?
- WordPress menu and plugin installation problem
- plugins_loaded action is not working properly
- AJAX login without a plugin does not work. when add a action to function.php
- Remove action working on functions.php but not in a plugin. Why?
- How can I pass value to function in add_menu_page?
- Automatically add child pages to menu
- Remove action plugin
- How to add plugin activity in the menus?
- How change menu for each user in plugin?
- Filter for modifying image on upload
- Redirect url in plugin to somewhere else?
- OOP Plugin: Where should I place the action hooks in the class?
- How can I add different menus (different style menu) on each page?
- add query string to all pages after user logged in
- How wordpress plugin hooks works? [duplicate]
- Make a Custom template for a specific category in wordpress
- How can I create a navigation menu in the sidebar that can also act like a slider?
- Plugin: Custom menu item problem
- Is it possible to know which menus are owned by a plugin?
- Hook automatic_updates_complete to autoupdate plugin