remove all submenus from plugin

Not without touching the global $submenu directly (which I wouldn’t recommend – using only purposefully exposed APIs provides, in general, better stability). However, if you wanted a function to remove all submenus: /** * Removes all submenus of given menu item * * @param string $menu_slug The slug of the parent menu to remove submenus … Read more

WordPress plugin development OOP style

Change ma_admin_options_init() to: public function ma_admin_options_init(){ register_setting(‘ma_admin_styler’, ‘ma_admin_styler’, array( $this,’ma_admin_styler_validate’)); add_settings_section(‘main_section’, ”, array( $this,’section_text_default’), ‘ma_admin_styler’); add_settings_field(‘error_font_color’, ‘Error Font Color’, array( $this,’ma_error_font_color’), ‘ma_admin_styler’, ‘main_section’); } The fourth parameter of add_settings_section() and add_settings_field() is $page and that needs to match the page ID set in add_options_page().

I18n not working in plugin

The problem I was encountering was a result of not realizing that the 3rd parameter for load_plugin_textdomain should be a relative path to the language directory from WP_PLUGIN_DIR. Since plugin_dir_path returns an absolute path, things broke. Changing the hooked function as follows solved the problem: add_action(‘plugins_loaded’, array(‘PluginName’, ‘loadTextDomain’)); class PluginName { public static function loadTextDomain() … Read more

Is there an admin hook that will let me read GET variable before it’s too late to set the header Location

You can check the $current_screen on the current_screen action, and redirect after checking some GET conditions: function wpd_current_screen( $current_screen ) { if ( ‘toplevel_page_your_menu_item_id’ == $current_screen->base ) { // check some condition and wp_redirect( admin_url() ); exit; } } add_action( ‘current_screen’, ‘wpd_current_screen’ );

A question about add_action()

The emailer::send is the function callback for a publish_post action hook. This action hook accepts only one parameter which is the post ID and it is passed by WordPress. When you define an action hook, you set what parameters are passed to the callback functions. For example: $arg_1 = “The aregument value”; do_action( ‘my_custom_action’, $arg_1 … Read more

How can I modify admin bar only if my plugin is loaded

You need to remember screen id of your page and check current screen id before adding new menu item: add_action( ‘admin_menu’, ‘my_plugin_menu’ ); function my_plugin_menu() { global $my_swell_plugin_page; $my_swell_plugin_page = add_menu_page( ‘My Swell Plugin’, ‘My Swell Plugin’, ‘edit_posts’, ‘blah’, ‘generate_main_page’ ); } function generate_main_page() { //We are definitely in our plugins page now – let’s … Read more

Jquery was not found on this server

The proper way to include jquery in your plugin is /** * Proper way to enqueue scripts and styles */ function theme_name_scripts() { wp_enqueue_script( ‘script-name’, get_template_directory_uri() . ‘/js/example.js’, array(), ‘1.0.0’, true ); } add_action( ‘wp_enqueue_scripts’, ‘theme_name_scripts’ );