publish_post called too early

Try this workaround of this issue without using publish_post hook (using save_post) add_action( ‘save_post’, ‘wpse228941_save_post’ ); function wpse228941_save_post( $post_id ) { if( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) return; if ( “publish” == get_post_status( $post_id ) && ! get_post_meta( $post_id, “se_228941_mailed”, 1 ) ) { do_action( “sm12_publish_post”, $post_id ); update_post_meta( $post_id, “se_228941_mailed”, time() ); } } add_action( … Read more

Redirect to page list when page published

I have the below code which works as expected if anyone else is looking for similar. add_action( ‘publish_page’, ‘redirect_user_page_list’, 10, 3 ); function redirect_user_page_list() { if( is_user_logged_in() ) { $user = wp_get_current_user(); $role = ( array ) $user->roles; if ( ‘role_slug’ == $role[0] ) { $url=”url to redirect to”; wp_redirect($url); exit; } } }

Set meta field to publish date + 2 weeks

Try this: add_action(‘publish_post’, ‘dp_expiry’); function dp_expiry( $data ) { /*adds 2 weeks onto the current date in unix epoch format*/ $dp_new_expiry_date = (strtotime( current_time( ‘mysql’ ) ) + 1209600); /*converts unix timstamp back to yyyy-mm-dd format like you required*/ $dp_new_expiry_date_conv = date(“Y-m-d”, $dp_new_expiry_date); update_post_meta( $data[‘post_id’], ‘postexpiry’, $dp_new_expiry_date_conv ); }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)