@@ -26,23 +26,23 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function wl_transition_post_status( $new_status, $old_status, $post ) { |
| 28 | 28 | |
| 29 | - // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
|
| 30 | - |
|
| 31 | - // transition from *published* to any other status: delete the post. |
|
| 32 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 33 | - // Remove all relation instances for the current post from `wl_relation_instances`. |
|
| 34 | - wl_core_delete_relation_instances( $post->ID ); |
|
| 35 | - |
|
| 36 | - // Delete the post from the triple store. |
|
| 37 | - rl_delete_post( $post ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // when a post is published, then all the referenced entities must be published. |
|
| 41 | - if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 42 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 43 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 44 | - } |
|
| 45 | - } |
|
| 29 | + // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
|
| 30 | + |
|
| 31 | + // transition from *published* to any other status: delete the post. |
|
| 32 | + if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 33 | + // Remove all relation instances for the current post from `wl_relation_instances`. |
|
| 34 | + wl_core_delete_relation_instances( $post->ID ); |
|
| 35 | + |
|
| 36 | + // Delete the post from the triple store. |
|
| 37 | + rl_delete_post( $post ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // when a post is published, then all the referenced entities must be published. |
|
| 41 | + if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 42 | + foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 43 | + wl_update_post_status( $entity_id, 'publish' ); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // hook save events. |
@@ -56,25 +56,25 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function rl_delete_post( $post ) { |
| 58 | 58 | |
| 59 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 59 | + $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 60 | 60 | |
| 61 | - // hide all entities that are not referenced by any published post. |
|
| 62 | - foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 61 | + // hide all entities that are not referenced by any published post. |
|
| 62 | + foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 63 | 63 | |
| 64 | - // check if there is at least one referencing post published. |
|
| 65 | - $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 66 | - $post = get_post( $item ); |
|
| 64 | + // check if there is at least one referencing post published. |
|
| 65 | + $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 66 | + $post = get_post( $item ); |
|
| 67 | 67 | |
| 68 | - return ( $carry || ( 'publish' === $post->post_status ) ); |
|
| 69 | - } ); |
|
| 70 | - // set the entity to draft if no referencing posts are published. |
|
| 71 | - if ( ! $is_published ) { |
|
| 72 | - wl_update_post_status( $entity_id, 'draft' ); |
|
| 73 | - } |
|
| 74 | - } |
|
| 68 | + return ( $carry || ( 'publish' === $post->post_status ) ); |
|
| 69 | + } ); |
|
| 70 | + // set the entity to draft if no referencing posts are published. |
|
| 71 | + if ( ! $is_published ) { |
|
| 72 | + wl_update_post_status( $entity_id, 'draft' ); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // Remove the post. |
|
| 77 | - Wordlift_Linked_Data_Service::get_instance()->remove( $post_id ); |
|
| 76 | + // Remove the post. |
|
| 77 | + Wordlift_Linked_Data_Service::get_instance()->remove( $post_id ); |
|
| 78 | 78 | |
| 79 | 79 | } |
| 80 | 80 | |
@@ -86,33 +86,33 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function wl_update_post_status( $post_id, $status ) { |
| 88 | 88 | |
| 89 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 89 | + wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 90 | 90 | |
| 91 | - global $wpdb; |
|
| 91 | + global $wpdb; |
|
| 92 | 92 | |
| 93 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 93 | + if ( ! $post = get_post( $post_id ) ) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - if ( $status === $post->post_status ) { |
|
| 98 | - return; |
|
| 99 | - } |
|
| 97 | + if ( $status === $post->post_status ) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 101 | + $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 102 | 102 | |
| 103 | - clean_post_cache( $post->ID ); |
|
| 103 | + clean_post_cache( $post->ID ); |
|
| 104 | 104 | |
| 105 | - $old_status = $post->post_status; |
|
| 106 | - $post->post_status = $status; |
|
| 105 | + $old_status = $post->post_status; |
|
| 106 | + $post->post_status = $status; |
|
| 107 | 107 | |
| 108 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 108 | + wp_transition_post_status( $status, $old_status, $post ); |
|
| 109 | 109 | |
| 110 | - /** This action is documented in wp-includes/post.php */ |
|
| 111 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 112 | - /** This action is documented in wp-includes/post.php */ |
|
| 113 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 114 | - /** This action is documented in wp-includes/post.php */ |
|
| 115 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 116 | - /** This action is documented in wp-includes/post.php */ |
|
| 117 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 110 | + /** This action is documented in wp-includes/post.php */ |
|
| 111 | + do_action( 'edit_post', $post->ID, $post ); |
|
| 112 | + /** This action is documented in wp-includes/post.php */ |
|
| 113 | + do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 114 | + /** This action is documented in wp-includes/post.php */ |
|
| 115 | + do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 116 | + /** This action is documented in wp-includes/post.php */ |
|
| 117 | + do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 118 | 118 | } |
@@ -24,29 +24,29 @@ discard block |
||
| 24 | 24 | * @param string $old_status The old post status |
| 25 | 25 | * @param array $post An array with the post data |
| 26 | 26 | */ |
| 27 | -function wl_transition_post_status( $new_status, $old_status, $post ) { |
|
| 27 | +function wl_transition_post_status($new_status, $old_status, $post) { |
|
| 28 | 28 | |
| 29 | 29 | // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
| 30 | 30 | |
| 31 | 31 | // transition from *published* to any other status: delete the post. |
| 32 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 32 | + if ('publish' === $old_status && 'publish' !== $new_status) { |
|
| 33 | 33 | // Remove all relation instances for the current post from `wl_relation_instances`. |
| 34 | - wl_core_delete_relation_instances( $post->ID ); |
|
| 34 | + wl_core_delete_relation_instances($post->ID); |
|
| 35 | 35 | |
| 36 | 36 | // Delete the post from the triple store. |
| 37 | - rl_delete_post( $post ); |
|
| 37 | + rl_delete_post($post); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // when a post is published, then all the referenced entities must be published. |
| 41 | - if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 42 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 43 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 41 | + if ('publish' !== $old_status && 'publish' === $new_status) { |
|
| 42 | + foreach (wl_core_get_related_entity_ids($post->ID) as $entity_id) { |
|
| 43 | + wl_update_post_status($entity_id, 'publish'); |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // hook save events. |
| 49 | -add_action( 'transition_post_status', 'wl_transition_post_status', 10, 3 ); |
|
| 49 | +add_action('transition_post_status', 'wl_transition_post_status', 10, 3); |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -54,27 +54,27 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @param array|int $post An array of post data |
| 56 | 56 | */ |
| 57 | -function rl_delete_post( $post ) { |
|
| 57 | +function rl_delete_post($post) { |
|
| 58 | 58 | |
| 59 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 59 | + $post_id = (is_numeric($post) ? $post : $post->ID); |
|
| 60 | 60 | |
| 61 | 61 | // hide all entities that are not referenced by any published post. |
| 62 | - foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 62 | + foreach (wl_core_get_related_entity_ids($post_id) as $entity_id) { |
|
| 63 | 63 | |
| 64 | 64 | // check if there is at least one referencing post published. |
| 65 | - $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 66 | - $post = get_post( $item ); |
|
| 65 | + $is_published = array_reduce(wl_core_get_related_post_ids($entity_id), function($carry, $item) { |
|
| 66 | + $post = get_post($item); |
|
| 67 | 67 | |
| 68 | - return ( $carry || ( 'publish' === $post->post_status ) ); |
|
| 68 | + return ($carry || ('publish' === $post->post_status)); |
|
| 69 | 69 | } ); |
| 70 | 70 | // set the entity to draft if no referencing posts are published. |
| 71 | - if ( ! $is_published ) { |
|
| 72 | - wl_update_post_status( $entity_id, 'draft' ); |
|
| 71 | + if ( ! $is_published) { |
|
| 72 | + wl_update_post_status($entity_id, 'draft'); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // Remove the post. |
| 77 | - Wordlift_Linked_Data_Service::get_instance()->remove( $post_id ); |
|
| 77 | + Wordlift_Linked_Data_Service::get_instance()->remove($post_id); |
|
| 78 | 78 | |
| 79 | 79 | } |
| 80 | 80 | |
@@ -84,35 +84,35 @@ discard block |
||
| 84 | 84 | * @param int $post_id The post ID |
| 85 | 85 | * @param string $status The new status |
| 86 | 86 | */ |
| 87 | -function wl_update_post_status( $post_id, $status ) { |
|
| 87 | +function wl_update_post_status($post_id, $status) { |
|
| 88 | 88 | |
| 89 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 89 | + wl_write_log("wl_update_post_status [ post ID :: $post_id ][ status :: $status ]"); |
|
| 90 | 90 | |
| 91 | 91 | global $wpdb; |
| 92 | 92 | |
| 93 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 93 | + if ( ! $post = get_post($post_id)) { |
|
| 94 | 94 | return; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if ( $status === $post->post_status ) { |
|
| 97 | + if ($status === $post->post_status) { |
|
| 98 | 98 | return; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 101 | + $wpdb->update($wpdb->posts, array('post_status' => $status), array('ID' => $post->ID)); |
|
| 102 | 102 | |
| 103 | - clean_post_cache( $post->ID ); |
|
| 103 | + clean_post_cache($post->ID); |
|
| 104 | 104 | |
| 105 | 105 | $old_status = $post->post_status; |
| 106 | 106 | $post->post_status = $status; |
| 107 | 107 | |
| 108 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 108 | + wp_transition_post_status($status, $old_status, $post); |
|
| 109 | 109 | |
| 110 | 110 | /** This action is documented in wp-includes/post.php */ |
| 111 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 111 | + do_action('edit_post', $post->ID, $post); |
|
| 112 | 112 | /** This action is documented in wp-includes/post.php */ |
| 113 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 113 | + do_action("save_post_{$post->post_type}", $post->ID, $post, true); |
|
| 114 | 114 | /** This action is documented in wp-includes/post.php */ |
| 115 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 115 | + do_action('wl_linked_data_save_post', $post->ID); |
|
| 116 | 116 | /** This action is documented in wp-includes/post.php */ |
| 117 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 117 | + do_action('wp_insert_post', $post->ID, $post, true); |
|
| 118 | 118 | } |