Preventing frontpage to be deleted/moved to trash

There are two problems with your code snippet: 1) Comparison The first problem is in this line: if( $post_id === $frontpage || $post_id === $blogpage ) { where you’re strictly comparing int with string. Notice that === comparison will only return TRUE if both variables are of the same type and have the same value. … Read more

Delete user from frontend

Taken directly form the wp_delete_user documentation: if(is_user_logged_in() && !empty($_GET[‘DeleteMyAccount’])) { add_action(‘init’, ‘remove_logged_in_user’); } function remove_logged_in_user() { require_once(ABSPATH.’wp-admin/includes/user.php’ ); $current_user = wp_get_current_user(); wp_delete_user( $current_user->ID ); } Things to note: Your code didn’t check if the user was logged in or not by the time you’re printing the remove user link, the init action has already happened … Read more

How To Get User Data in Callback Function for pre_user_nicename?

If anyone should be faced with this problem, check if you have defined a callback function to set the user_login on pre_user_login. This filter is applied inside the wp_insert_user()-function and produced a same username again. Therefore the nicename was changed by adding a “-2”. So, my problem was that I reset the user_logins again and … Read more

Add my own function to existing WooCommerce hook

storefront_single_post hook pertains only to single posts and not products although products are considered posts of type ‘product’ This is the hook you need: add_action( ‘woocommerce_single_product_summary’, ‘storefront_post_header_categories’, 6 ); function storefront_post_header_categories() { echo “code to display categories here”; } You will find it in plugins/woocommerce/content-single-product.php: /** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title – 5 … Read more

Delete database tables on theme uninstall?

Yes, you can accomplish it by WP default functionality. Let me explain it. 1. While switch theme: There is a switch_theme action that runs right after the theme is switched. switch_theme is triggered when the blog’s theme is changed. Specifically, it fires after the theme has been switched but before the next request. Theme developers … Read more