Preventing frontpage to be deleted/moved to trash

I want to prevent my frontpage to be deleted/moved to trash using this: add_action( ‘wp_trash_post’, ‘tcb_page_delete_check’ ); add_action( ‘before_delete_post’, ‘tcb_page_delete_check’ ); function tcb_page_delete_check( $post_id ){ $frontpage = get_option( ‘page_on_front’); $blogpage = get_option(‘page_for_posts’); if( $post_id === $frontpage || $post_id === $blogpage ) { wp_redirect(admin_url(‘edit.php?post_type=page’)); exit; } } The problem is that option(‘page_on_front’)’s ID get’s changed from … Read more

What’s the best way to split admin-only functionality in the theme’s functions.php file?

I am customising a WordPress admin area and so far so good with a number of add_filter and add_action calls in my theme’s functions.php file. But I’m a bit worried because all this code will be executed on all pages, not just the admin area. I therefore went ahead with the below approach: if (is_admin()) … Read more

How To Get User Data in Callback Function for pre_user_nicename?

Whenever I update a user profile in the dashboard, the user nice-name gets changed in the database: Every time, a “-2” is added. I tried to reset the nicename (based loosely on this thread) by hooking into edit_user_profile_update and personal_options_update, but that seems to be to early, the value does not change: add_action( ‘personal_options_update’, ‘my_reset_nicename_function’ … Read more

Add my own function to existing WooCommerce hook

I’m trying to customise my WooCommerce child theme with parent theme Storefront. The parent theme creates single product template (content-single.php) like this: /** * @hooked storefront_post_header – 10 * @hooked storefront_post_meta – 20 * @hooked storefront_post_content – 30 */ do_action( ‘storefront_single_post’ ); and these functions are hooked to build out the page (/inc/structure/hooks.php): add_action( ‘storefront_single_post’, … Read more

WP 4.4.1 allow empty comments via add_action ‘pre_comment_on_post’

got a question about allowing empty comments with worpdress v.4.4.1 to achieve this i use the action ‘pre_comment_on_post’. in WP 4.3.1 i could do this easily: if (isset($_POST[‘comment’]) && $_POST[‘comment’] == “”) { $_POST[‘comment’] = “dummy content”; } the dummy content would be filtered out later via another add_filter call … in wp 4.3.1 in … Read more

How to get Custom Post ID by adding filter to child theme’s function

How to get Custom Post ID by adding code to child theme’s function. The following code works fine for the regular post, but can’t figure out for the custom post types. add_filter( ‘manage_posts_columns’, ‘revealid_add_id_column’, 5 ); add_action( ‘manage_posts_custom_column’, ‘revealid_id_column_content’, 5, 2 ); function revealid_add_id_column( $columns ) { $columns[‘revealid_id’] = ‘ID’; return $columns; } function revealid_id_column_content( … Read more