WP Hook Before a post is created

There’s a hook save_post, docs here: https://developer.wordpress.org/reference/hooks/save_post/ which will allow you to run some code after the post is saved. Example from there: function add_user_after_post_save( $post_id ) { // add a user? // move the post to the user? } add_action( ‘save_post’, ‘add_user_after_post_save’ ); Not sure why you’d need to call the hook immediately before … Read more

Notify the user by e-mail after the creation of a post

There’s wp_schedule_single_event: $in_ten_minutes = time() + 10 * 60; $post_id = get_the_ID(); wp_schedule_single_event( $in_ten_minutes, ‘notify_post_event’, array( $post_id ) ); or similar – I’ve no idea if it’s just the post ID you need, or whether get_the_ID() is the right way to find it when you’re handling this action. Depending on where the button is and … Read more

Display all categories including sub categories under a list ul

Do you know how recursive functions are working? Here is an example: function get_categories_list( $parent ) { $args = array( ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => false, ‘parent’ => $parent ); $current_level_categories = get_terms( $args ); $result=””; if ( $current_level_categories ) { foreach ( $current_level_categories as $cat ) { if ( $cat->name == ‘Uncategorized’ ) continue; … Read more

Display a custom name when the user has no name settle in his account

Use PHP ternary comparsion operator to check if get_user_meta() function returns blank or non-blank result: function colaborador_nome($atts) { if (is_user_logged_in() && !is_feed()) { return ‘&nbsp;’. (get_user_meta( get_current_user_id(), ‘first_name’, true ) ?: “Hi >No Name<, please settle your name in your account.”); } } add_shortcode(‘colaborador_nome’, ‘colaborador_nome’);