コード例 #1
0
ファイル: api.php プロジェクト: Garth619/wines-by-jennifer
 /**
 		@brief		Rebroadcasts a parent post to its existing children.
 		@details	Optionally adds children on new blogs.
 		@param		int		$post_id	The ID of the post to rebroadcast.
 		@param		array	$new_blogs	Optional array of blog IDs to which to add new children.
 		@since		2015-06-24 18:44:46
 	**/
 public function update_children($post_id, $new_blogs = [])
 {
     $bcd = \threewp_broadcast\broadcasting_data::make($post_id);
     foreach ($this->_get_post_children($post_id) as $blog_id) {
         $bcd->broadcast_to($blog_id);
     }
     foreach ($new_blogs as $blog_id) {
         $bcd->broadcast_to($blog_id);
     }
     apply_filters('threewp_broadcast_broadcast_post', $bcd);
     return $bcd;
 }
コード例 #2
0
 public function save_post($post_id)
 {
     // We must be on the source blog.
     if (ms_is_switched()) {
         $this->debug('Blog is switched. Not broadcasting.');
         return;
     }
     // Loop check.
     if ($this->is_broadcasting()) {
         $this->debug('Already broadcasting.');
         return;
     }
     // We must handle this post type.
     $post = get_post($post_id);
     $action = new actions\get_post_types();
     $action->execute();
     if (!in_array($post->post_type, $action->post_types)) {
         return $this->debug('We do not care about the %s post type.', $post->post_type);
     }
     // No post?
     if (count($_POST) < 1) {
         return $this->debug('No _POST available. Not broadcasting.');
     }
     // Does this post_id match up with the one in the post?
     $_post_id = $_POST['ID'];
     if (isset($_post_id)) {
         if ($_post_id != $post_id) {
             return $this->debug('Post ID %s does not match up with ID in POST %s.', $post_id, $_post_id);
         }
     }
     // Is this post a child?
     $broadcast_data = $this->get_post_broadcast_data(get_current_blog_id(), $post_id);
     if ($broadcast_data->get_linked_parent() !== false) {
         return $this->debug('Post is a child. Not broadcasting.');
     }
     // No permission.
     if (!static::user_has_roles($this->get_site_option('role_broadcast'))) {
         return $this->debug('User does not have permission to use Broadcast. Not broadcasting.');
     }
     // Save the user's last settings.
     if (isset($_POST['broadcast'])) {
         $this->save_last_used_settings($this->user_id(), $_POST['broadcast']);
     }
     $this->debug('We are currently on blog %s (%s).', get_bloginfo('blogname'), get_current_blog_id());
     $broadcasting_data = new broadcasting_data(['parent_post_id' => $post_id]);
     $this->debug('Preparing the broadcasting data.');
     // This is to fetch the selected blogs from the meta box.
     $action = new actions\prepare_broadcasting_data();
     $action->broadcasting_data = $broadcasting_data;
     $action->execute();
     $this->debug('Broadcasting data prepared.');
     if ($broadcasting_data->has_blogs()) {
         $this->filters('threewp_broadcast_broadcast_post', $broadcasting_data);
     } else {
         $this->debug('No blogs are selected. Not broadcasting.');
     }
 }