@@ -24,29 +24,29 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function wl_transition_post_status( $new_status, $old_status, $post ) { |
| 26 | 26 | |
| 27 | - // transition from *published* to any other status: delete the post. |
|
| 28 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 29 | - // Delete the post from the triple store. |
|
| 30 | - rl_delete_post( $post ); |
|
| 31 | - |
|
| 32 | - // Remove all relation instances for the current post from `wl_relation_instances`. |
|
| 33 | - wl_core_delete_relation_instances( $post->ID ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Everytime when post is published, even when post status changed from publish to publish |
|
| 38 | - * we have to publish the linked entities, this is needed because when you have p1 post linked to |
|
| 39 | - * e1 and saved as draft, p1 and e1 will be saved as draft. Then you create p2, add some content and publish it. |
|
| 40 | - * After publishing, it if you link e1 to the post p2 and save, the entity e1 won't be published. To prevent this |
|
| 41 | - * upon every save we need to publish the entities which are linked. |
|
| 42 | - */ |
|
| 43 | - if ( 'publish' === $new_status |
|
| 44 | - && apply_filters( 'wl_feature__enable__entity-auto-publish', true ) ) { |
|
| 45 | - |
|
| 46 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 47 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 48 | - } |
|
| 49 | - } |
|
| 27 | + // transition from *published* to any other status: delete the post. |
|
| 28 | + if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 29 | + // Delete the post from the triple store. |
|
| 30 | + rl_delete_post( $post ); |
|
| 31 | + |
|
| 32 | + // Remove all relation instances for the current post from `wl_relation_instances`. |
|
| 33 | + wl_core_delete_relation_instances( $post->ID ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Everytime when post is published, even when post status changed from publish to publish |
|
| 38 | + * we have to publish the linked entities, this is needed because when you have p1 post linked to |
|
| 39 | + * e1 and saved as draft, p1 and e1 will be saved as draft. Then you create p2, add some content and publish it. |
|
| 40 | + * After publishing, it if you link e1 to the post p2 and save, the entity e1 won't be published. To prevent this |
|
| 41 | + * upon every save we need to publish the entities which are linked. |
|
| 42 | + */ |
|
| 43 | + if ( 'publish' === $new_status |
|
| 44 | + && apply_filters( 'wl_feature__enable__entity-auto-publish', true ) ) { |
|
| 45 | + |
|
| 46 | + foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 47 | + wl_update_post_status( $entity_id, 'publish' ); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // hook save events. |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | function rl_delete_post( $post ) { |
| 62 | 62 | |
| 63 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 63 | + $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 64 | 64 | |
| 65 | - // Remove the post. |
|
| 66 | - do_action( 'wl_legacy_linked_data__remove', $post_id ); |
|
| 65 | + // Remove the post. |
|
| 66 | + do_action( 'wl_legacy_linked_data__remove', $post_id ); |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
@@ -75,35 +75,35 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | function wl_update_post_status( $post_id, $status ) { |
| 77 | 77 | |
| 78 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 78 | + wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 79 | 79 | |
| 80 | - global $wpdb; |
|
| 80 | + global $wpdb; |
|
| 81 | 81 | |
| 82 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 82 | + if ( ! $post = get_post( $post_id ) ) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - if ( $status === $post->post_status ) { |
|
| 87 | - return; |
|
| 88 | - } |
|
| 86 | + if ( $status === $post->post_status ) { |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - wl_write_log( "wl_update_post_status, old and new post status do not match [ post ID :: $post_id ][ new status :: $status ][ old status :: $post->post_status ]." ); |
|
| 90 | + wl_write_log( "wl_update_post_status, old and new post status do not match [ post ID :: $post_id ][ new status :: $status ][ old status :: $post->post_status ]." ); |
|
| 91 | 91 | |
| 92 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 92 | + $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 93 | 93 | |
| 94 | - clean_post_cache( $post->ID ); |
|
| 94 | + clean_post_cache( $post->ID ); |
|
| 95 | 95 | |
| 96 | - $old_status = $post->post_status; |
|
| 97 | - $post->post_status = $status; |
|
| 96 | + $old_status = $post->post_status; |
|
| 97 | + $post->post_status = $status; |
|
| 98 | 98 | |
| 99 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 99 | + wp_transition_post_status( $status, $old_status, $post ); |
|
| 100 | 100 | |
| 101 | - /** This action is documented in wp-includes/post.php */ |
|
| 102 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 103 | - /** This action is documented in wp-includes/post.php */ |
|
| 104 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 105 | - /** This action is documented in wp-includes/post.php */ |
|
| 106 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 107 | - /** This action is documented in wp-includes/post.php */ |
|
| 108 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 101 | + /** This action is documented in wp-includes/post.php */ |
|
| 102 | + do_action( 'edit_post', $post->ID, $post ); |
|
| 103 | + /** This action is documented in wp-includes/post.php */ |
|
| 104 | + do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 105 | + /** This action is documented in wp-includes/post.php */ |
|
| 106 | + do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 107 | + /** This action is documented in wp-includes/post.php */ |
|
| 108 | + do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 109 | 109 | } |
@@ -22,15 +22,15 @@ discard block |
||
| 22 | 22 | * @param string $old_status The old post status |
| 23 | 23 | * @param array $post An array with the post data |
| 24 | 24 | */ |
| 25 | -function wl_transition_post_status( $new_status, $old_status, $post ) { |
|
| 25 | +function wl_transition_post_status($new_status, $old_status, $post) { |
|
| 26 | 26 | |
| 27 | 27 | // transition from *published* to any other status: delete the post. |
| 28 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 28 | + if ('publish' === $old_status && 'publish' !== $new_status) { |
|
| 29 | 29 | // Delete the post from the triple store. |
| 30 | - rl_delete_post( $post ); |
|
| 30 | + rl_delete_post($post); |
|
| 31 | 31 | |
| 32 | 32 | // Remove all relation instances for the current post from `wl_relation_instances`. |
| 33 | - wl_core_delete_relation_instances( $post->ID ); |
|
| 33 | + wl_core_delete_relation_instances($post->ID); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -40,17 +40,17 @@ discard block |
||
| 40 | 40 | * After publishing, it if you link e1 to the post p2 and save, the entity e1 won't be published. To prevent this |
| 41 | 41 | * upon every save we need to publish the entities which are linked. |
| 42 | 42 | */ |
| 43 | - if ( 'publish' === $new_status |
|
| 44 | - && apply_filters( 'wl_feature__enable__entity-auto-publish', true ) ) { |
|
| 43 | + if ('publish' === $new_status |
|
| 44 | + && apply_filters('wl_feature__enable__entity-auto-publish', true)) { |
|
| 45 | 45 | |
| 46 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 47 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 46 | + foreach (wl_core_get_related_entity_ids($post->ID) as $entity_id) { |
|
| 47 | + wl_update_post_status($entity_id, 'publish'); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // hook save events. |
| 53 | -add_action( 'transition_post_status', 'wl_transition_post_status', 10, 3 ); |
|
| 53 | +add_action('transition_post_status', 'wl_transition_post_status', 10, 3); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @param array|int $post An array of post data |
| 60 | 60 | */ |
| 61 | -function rl_delete_post( $post ) { |
|
| 61 | +function rl_delete_post($post) { |
|
| 62 | 62 | |
| 63 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 63 | + $post_id = (is_numeric($post) ? $post : $post->ID); |
|
| 64 | 64 | |
| 65 | 65 | // Remove the post. |
| 66 | - do_action( 'wl_legacy_linked_data__remove', $post_id ); |
|
| 66 | + do_action('wl_legacy_linked_data__remove', $post_id); |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
@@ -73,37 +73,37 @@ discard block |
||
| 73 | 73 | * @param int $post_id The post ID |
| 74 | 74 | * @param string $status The new status |
| 75 | 75 | */ |
| 76 | -function wl_update_post_status( $post_id, $status ) { |
|
| 76 | +function wl_update_post_status($post_id, $status) { |
|
| 77 | 77 | |
| 78 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 78 | + wl_write_log("wl_update_post_status [ post ID :: $post_id ][ status :: $status ]"); |
|
| 79 | 79 | |
| 80 | 80 | global $wpdb; |
| 81 | 81 | |
| 82 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 82 | + if ( ! $post = get_post($post_id)) { |
|
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ( $status === $post->post_status ) { |
|
| 86 | + if ($status === $post->post_status) { |
|
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - wl_write_log( "wl_update_post_status, old and new post status do not match [ post ID :: $post_id ][ new status :: $status ][ old status :: $post->post_status ]." ); |
|
| 90 | + wl_write_log("wl_update_post_status, old and new post status do not match [ post ID :: $post_id ][ new status :: $status ][ old status :: $post->post_status ]."); |
|
| 91 | 91 | |
| 92 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 92 | + $wpdb->update($wpdb->posts, array('post_status' => $status), array('ID' => $post->ID)); |
|
| 93 | 93 | |
| 94 | - clean_post_cache( $post->ID ); |
|
| 94 | + clean_post_cache($post->ID); |
|
| 95 | 95 | |
| 96 | 96 | $old_status = $post->post_status; |
| 97 | 97 | $post->post_status = $status; |
| 98 | 98 | |
| 99 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 99 | + wp_transition_post_status($status, $old_status, $post); |
|
| 100 | 100 | |
| 101 | 101 | /** This action is documented in wp-includes/post.php */ |
| 102 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 102 | + do_action('edit_post', $post->ID, $post); |
|
| 103 | 103 | /** This action is documented in wp-includes/post.php */ |
| 104 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 104 | + do_action("save_post_{$post->post_type}", $post->ID, $post, true); |
|
| 105 | 105 | /** This action is documented in wp-includes/post.php */ |
| 106 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 106 | + do_action('wl_linked_data_save_post', $post->ID); |
|
| 107 | 107 | /** This action is documented in wp-includes/post.php */ |
| 108 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 108 | + do_action('wp_insert_post', $post->ID, $post, true); |
|
| 109 | 109 | } |