Skip to Content
Menu

plugin_force_settings()

Force certain plugin settings for better experience.

PHP April 26, 2017

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Additional Notes

This function used to override many plugins’ settings, but is down to just Yoast SEO now. It may grow or shrink as plugin annoyances come and go.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Optimization.php on line 819.

    1 Hook

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    "pre_nebula_plugin_force_settings"
    Need a new filter hook? Request one here.

    Actions
    This function has no action hooks available. Request one?

    PHP
            public function plugin_force_settings(){
                $override = apply_filters('pre_nebula_plugin_force_settings', null);
                if ( isset($override) ){return;}
    
                //Wordpress SEO (Yoast)
                if ( is_plugin_active('wordpress-seo/wp-seo.php') ){
                    remove_submenu_page('wpseo_dashboard', 'wpseo_files'); //Remove the ability to edit files.
                    $wpseo = get_option('wpseo');
                    $wpseo['ignore_meta_description_warning'] = true; //Disable the meta description warning.
                    $wpseo['ignore_tour'] = true; //Disable the tour.
                    $wpseo['theme_description_found'] = false; //Not working because this keeps getting checked/tested at many various times in the plugin.
                    $wpseo['theme_has_description'] = false; //Not working because this keeps getting checked/tested at many various times in the plugin.
                    update_option('wpseo', $wpseo);
    
                    //Disable update notifications
                    if ( class_exists('Yoast_Notification_Center') ){
                        remove_action('admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications'));
                        remove_action('all_admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications'));
                    }
                }
            }
    

    Override

    To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

    PHP
    add_filter('pre_nebula_plugin_force_settings', 'my_custom_plugin_force_settings'); 
    function my_custom_plugin_force_settings(){ 
        //Write your own code here
    
        return true; //Return true to prevent the original function from running afterwords
    }

    You can completely disable this PHP function with a single line actions:

    PHP
     add_filter('pre_nebula_plugin_force_settings', '__return_false');