if ( ! defined( 'AUTOSAVE_INTERVAL' ) ) {
// Change 10 to the number of minutes you want to use.
define( 'AUTOSAVE_INTERVAL', 10 * MINUTE_IN_SECONDS );
}
Remove dashboard welcome panel
add_action(
'admin_init',
function () {
remove_action( 'welcome_panel', 'wp_welcome_panel' );
}
);
Change “Howdy” text in the admin bar
function snipjar_change_howdy( $wp_admin_bar ) {
// Edit the line below to set what you want the admin bar to display intead of "Howdy,".
$new_howdy = 'Welcome,';
$my_account = $wp_admin_bar->get_node( 'my-account' );
$wp_admin_bar->add_node(
array(
'id' => 'my-account',
'title' => str_replace( 'Howdy,', $new_howdy, $my_account->title ),
)
);
}
add_filter( 'admin_bar_menu', 'snipjar_change_howdy', 25 );
Change admin panel footer text
add_filter(
'admin_footer_text',
function ( $footer_text ) {
$footer_text = 'Brought to you by by <a href="https://www.snipjar.com" target="_blank" rel="noopener">Snipjar</a>';
return $footer_text;
}
);
Limit the number of post revisions
add_filter( 'wp_revisions_to_keep', function( $limit ) {
return 10;
} );
Set a minimum word count for posts
function wpcode_snippet_publish_min_words( $post_id, $post ) {
$word_count = 100;
if ( str_word_count( $post->post_content ) < $word_count ) {
wp_die(
sprintf(
// Translators: placeholder adds the minimum number of words.
esc_html__( 'The post content is below the minimum word count. Your post needs to have at least %d words to be published.' ),
absint( $word_count )
)
);
}
}
add_action( 'publish_post', 'wpcode_snippet_publish_min_words', 9, 2 );
Disable attachment pages
add_action(
'template_redirect',
function () {
global $post;
if ( ! is_attachment() || ! isset( $post->post_parent ) || ! is_numeric( $post->post_parent ) ) {
return;
}
// Does the attachment have a parent post?
// If the post is trashed, fallback to redirect to homepage.
if ( 0 !== $post->post_parent && 'trash' !== get_post_status( $post->post_parent ) ) {
// Redirect to the attachment parent.
wp_safe_redirect( get_permalink( $post->post_parent ), 301 );
} else {
// For attachment without a parent redirect to homepage.
wp_safe_redirect( get_bloginfo( 'wpurl' ), 302 );
}
exit;
},
1
);
Disable WordPress REST API
add_filter(
'rest_authentication_errors',
function ( $access ) {
return new WP_Error(
'rest_disabled',
__( 'The WordPress REST API has been disabled.' ),
array(
'status' => rest_authorization_required_code(),
)
);
}
);
Completely disable comments for all post types, in the admin and the frontend
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_safe_redirect(admin_url());
exit;
}
// Remove comments metabox from dashboard
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
// Disable support for comments and trackbacks in post types
foreach (get_post_types() as $post_type) {
if (post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
});
// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);
// Remove comments page in menu
add_action('admin_menu', function () {
remove_menu_page('edit-comments.php');
});
// Remove comments links from admin bar
add_action('admin_bar_menu', function () {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}, 0);
Disable XML-RPC
add_filter( 'xmlrpc_enabled', '__return_false' );
Disable automatic updates emails
add_filter( 'auto_core_update_send_email', '__return_false' );
add_filter( 'auto_plugin_update_send_email', '__return_false' );
add_filter( 'auto_theme_update_send_email', '__return_false' );
Disable WordPress Admin Bar for all users
add_filter( 'show_admin_bar', '__return_false' );