mtv\wp\models\Post::save PHP Метод

save() публичный Метод

public save ( )
    public function save()
    {
        $data = $this->attributes;
        if (!empty($data['blogid'])) {
            $blogid =& $data['blogid'];
            unset($data['blogid']);
        } else {
            $blogid = get_current_blog_id();
        }
        if (!empty($data['post_meta'])) {
            $meta =& $data['post_meta'];
            unset($data['post_meta']);
        }
        if (isset($data['post_format'])) {
            $post_format =& $data['post_format'];
            unset($data['post_format']);
        }
        if (!empty($data['id'])) {
            $data['ID'] =& $data['id'];
            unset($data['id']);
        }
        switch_to_blog($blogid);
        $postid = wp_insert_post($data, true);
        if (is_wp_error($postid)) {
            throw new WPException($postid);
        } else {
            if ($postid == 0) {
                throw new JsonableException(__("Couldn't update the post", 'mtv'));
            }
        }
        if (!empty($meta)) {
            foreach ($meta as $key => $val) {
                update_post_meta($postid, $key, $val);
            }
        }
        if (isset($post_format)) {
            $result = set_post_format($postid, $post_format);
            if (is_wp_error($result)) {
                throw new WPException($result);
            }
        }
        restore_current_blog();
        $this->id = $postid;
        # Invalidate cached data for this Post
        foreach ($this->cache_groups as $cache_group) {
            wp_cache_delete($this->id, $cache_group);
        }
        $this->fetch();
        // We refresh the post in case any filters changed the content
    }