/** * update post meta * * @since 0.4 * @access public * @uses get_post_status, update_post_meta * @param $post_id ID of the post * @return void */ public function save_post($post_id, $post = NULL) { // leave function if box was not available if (!isset($_POST['trasher_box'])) { return; } // We're only interested in published posts at this time $post_status = get_post_status($post_id); if ('publish' !== $post_status && 'draft' !== $post_status) { return; } // Avoid recursion: // wp_insert_post() invokes the save_post hook, so we have to make sure // the loop below is only entered once per save action. Therefore we save // the source_blog in a static class variable. If it is already set we // know the loop has already been entered and we can exit the save action. if (NULL === self::$source_blog) { self::$source_blog = get_current_blog_id(); } else { return; } // old key delete_post_meta($post_id, 'trash_the_other_posts'); $trash_the_other_posts = FALSE; // Should the other post also been trashed? if (isset($_POST['_trash_the_other_posts']) && 'on' == $_POST['_trash_the_other_posts']) { update_post_meta($post_id, '_trash_the_other_posts', '1'); $trash_the_other_posts = TRUE; } else { update_post_meta($post_id, '_trash_the_other_posts', '0'); } // Get linked posts $linked_posts = mlp_get_linked_elements($post_id); foreach ($linked_posts as $linked_blog => $linked_post) { switch_to_blog($linked_blog); delete_post_meta($linked_post, 'trash_the_other_posts'); // Should the other post also been trashed? if ($trash_the_other_posts) { update_post_meta($linked_post, '_trash_the_other_posts', '1'); } else { update_post_meta($linked_post, '_trash_the_other_posts', '0'); } restore_current_blog(); } }