Which code snippets would be the most useful

Please let me know which code snippets for which plugins would be of the most use?

3 Likes

Hi, any chance you could share a snippet code to rearrange the order of Mainwp menu? Thanks

So change the menu item order in the MainWP dashboard site.

1 Like

Yes this could be useful, as well as adding new menu item with custom link snippet.
thanks

1 Like

At the moment Iā€™m looking for code snippets to add to a custom mu-plugin, that will be installed on all the sites I manage for clients. So Iā€™m looking for snippets regarding security, updates, monitoring hosting environment etc.

Iā€™m already blocking the admin email check and have removed the automatic updater options. Iā€™ll continue my search.

These would be good ones to add to the mu-plugin.

add_filter( 'wp_lazy_loading_enabled', '__return_false' );
add_filter( 'wp_sitemaps_enabled', '__return_false' );
add_filter( 'plugins_auto_update_enabled', '__return_false' );
add_filter( 'themes_auto_update_enabled', '__return_false' );
add_filter( 'auto_plugin_update_send_email', '__return_false' );
add_filter( 'auto_theme_update_send_email', '__return_false' );
1 Like

Using a mu-plugin is a great idea. I would also add:

// Disable the site health dashboard widget
add_action(ā€˜wp_dashboard_setupā€™, ā€˜remove_site_health_dashboard_widgetā€™);
function remove_site_health_dashboard_widget()
{
remove_meta_box(ā€˜dashboard_site_healthā€™, ā€˜dashboardā€™, ā€˜normalā€™);
}

// Disable the URL field from the WordPress comment form on your child site.
add_filter(ā€˜comment_form_field_urlā€™, ā€˜__return_falseā€™);`

// Disable checking of admin email
add_filter( ā€˜admin_email_check_intervalā€™, ā€˜__return_falseā€™ );

1 Like

Yep those are some handy code snippets as well.

@sebastian-moran - You mentioned a mu-plugin but how you set up one from MainWP and push it to the child?
Do you create your own plugin and then push it to all sites and edit the function when needed?

@wpexpert Iā€™ve created one and uploaded it to all my clients with the File Uploader Extension to /wp-content/mu-plugins/. That makes it much easier (and faster when managing many sites) to add these code snippets to a new child.

2 Likes

Thanks, @josklever. We have more than 95 sites, do you have ever encountered any conflicts with other plugins?

Conflicts between other plugins and what? The mu-plugin? I only use it for snippets, that can be used on all (240) sites, like disabling the ā€œauto update settingsā€ from WP 5.5.

For more specific snippets you can create separate plugins and push them only to sites in a certain group.

2 Likes

Must-use plugins get loaded before plugins are loaded in WordPress.

1 Like

I didnā€™t know that! Thanks so less chance to have a conflict with a plugin thenā€¦

1 Like