| Conditions | 4 |
| Paths | 1 |
| Total Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | public function __construct() { |
||
| 14 | |||
| 15 | $no_index_flag = self::YOAST_POST_NO_INDEX_FLAG; |
||
| 16 | |||
| 17 | add_action( 'wp_insert_post', function ( $post_id, $post, $update ) use ( $no_index_flag ) { |
||
| 18 | |||
| 19 | $post_type = get_post_type( $post_id ); |
||
| 20 | |||
| 21 | if ( $post_type !== \Wordlift_Entity_Service::TYPE_NAME ) { |
||
| 22 | // Dont set this flag for any other post types. |
||
| 23 | return; |
||
| 24 | } |
||
| 25 | |||
| 26 | // We need to set this flag only on entity creation. |
||
| 27 | if ( ! $update ) { |
||
| 28 | update_post_meta( $post_id, $no_index_flag, 1 ); |
||
| 29 | } |
||
| 30 | |||
| 31 | }, PHP_INT_MAX, 3 ); |
||
| 32 | |||
| 33 | |||
| 34 | add_action( 'post_updated', function ( $post_id ) use ( $no_index_flag ) { |
||
| 35 | if ( get_post_type( $post_id ) !== \Wordlift_Entity_Service::TYPE_NAME ) { |
||
| 36 | return; |
||
| 37 | } |
||
| 38 | // if the post is updated, remove this flag |
||
| 39 | delete_post_meta( $post_id, $no_index_flag ); |
||
| 40 | }, PHP_INT_MAX ); |
||
| 41 | |||
| 42 | } |
||
| 43 | |||
| 46 |