Creates a new instance by the post ID

@access public
@param array|int|WP_Post $postId
@return static
779023
public static function create($post)
    {
        // If numeric, create the post
        if (is_numeric($post)) {
            // Retrieve the transient
            $transientKey = sprintf('WPMVC\Models\Post(%d)', $post);
            $storedData = WP::getTransient($transientKey);
            // If the transient doesn't yet exist, query for it!
            if ($storedData === false) {
                // Retrieve the post object
                $post = WP::getPost(intval($post));
                // Store the transient
                WP::setTransient($transientKey, $post, static::$transientTimeout);
            } else {
                $post = $storedData;
            }
        } elseif (is_array($post)) {
            // Convert array into object
            $post = (object) $post;
        }
        return new static($post);
    }
76653
def load_post(wp_post_id):
    

    # wait a bit to give WordPress REST API a chance to catch up
    time.sleep(1)

    loader = WPAPILoader()
    post = loader.load_post(wp_post_id)

    if post:
        logger.info("Successfully loaded post wp_post_id=%s, pk=%s", wp_post_id, post.pk)
    else:
        logger.warning("Error loading post wp_post_id=%s", wp_post_id)
226555
public function save( $post_id ) 
    {
        /**
         * A note on security:
         * 
         * We need to verify this came from the our screen and with proper authorization,
         * because save_post can be triggered at other times. since metaboxes can 
         * be removed - by having a nonce field in only one metabox there is no 
         * guarantee the nonce will be there. By placing a nonce field in each 
         * metabox you can check if data from that metabox has been sent 
         * (and is actually from where you think it is) prior to processing any data.
         * @see http://wordpress.stackexchange.com/a/49460/25959
         */
        
        // Check if our nonce is set.
        if ( ! isset( $_POST[$this->nonce_name()] ) )
        {
            return $post_id;
        }

        // Verify that the nonce is valid.
        $nonce = filter_input( INPUT_POST, $this->nonce_name() );
        if ( ! wp_verify_nonce( $nonce, $this->action_name() ) )
        {
            return $post_id;
        }
        
        // Bail if this is an autosave (nothing has been submitted)
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
        {
            return $post_id;
        }
        
        // Check the user's permissions.
        $post_type = filter_input( INPUT_POST, 'post_type' );
        if( in_array( $post_type, $this->settings['post_types'] ) )
        {
            // NOTE: this might not work for custom post types, unless Amarkal
            // is used to register them (custom post types might have labels different 
            // than 'edit_{post_type}'
            $capability = 'edit_'.$post_type;
            if ( !current_user_can( $capability, $post_id ) )
            {
                return $post_id;
            }
        }
        else
        {
            return $post_id;
        }

        // OK, it is safe to process data.
        $old_instance = \get_post_meta( $post_id, $this->settings['id'], true );
        $new_instance = $this->form->updater->update( $old_instance === "" ? array() : $old_instance );
        \update_post_meta( $post_id, $this->settings['id'], $new_instance );
        
        // Callback
        $callable = $this->settings['callback'];
        if(is_callable( $callable ) )
        {
            $callable( $post_id, $new_instance );
        }
    }
160318
public function create($accountId, $containerId, TagManager_Tag $postBody, $optParams = array())
  {
    $params = array('accountId' => $accountId, 'containerId' => $containerId, 'postBody' => $postBody);
    $params = array_merge($params, $optParams);
    return $this->call('create', array($params), "TagManager_Tag");
  }
1096579
public function create($shortCodeSid) {
        $data = Values::of(array('ShortCodeSid' => $shortCodeSid, ));

        $payload = $this->version->create(
            'POST',
            $this->uri,
            array(),
            $data
        );

        return new ShortCodeInstance($this->version, $payload, $this->solution['serviceSid']);
    }
159702
public function postCreate(PostRequest $request)
    {
        $command = new CreatePostCommand($request->all());

        try 
        {
            $this->bus->execute($command);
        }
        catch(ValidationException $e)
        {
            return Redirect::to(\OogleeBConfig::get('config.post_routes.base_uri_admin').'/post/create')->withErrors($e->getErrors());

        }
        catch(\DomainException $e)
        {
            return Redirect::to(\OogleeBConfig::get('config.post_routes.base_uri_admin').'/post/create')->withErrors($e->getErrors());
        }

        return Redirect::to(\OogleeBConfig::get('config.post_routes.base_uri_admin').'/posts')->with(['message' => 'success!']);
    }
1357785
public function update($postId, $postArr)
    {

        if ( ! $postBeforeUpdate = $this->find($postId, ['id', 'post_status'])) {
            return false;
        }

        try {
            $post = $this->postRepository->update($postArr, $postId);
        } catch (\Exception $e) {
            return new EtherError($e);
        }

        if (isset($postArr[ 'post_status' ]) && $postArr[ 'post_status' ] != $post[ 'post_status' ]) {
            Plugin::do_action('post_status_changed', $postId, $postArr[ 'post_status' ],
                $postBeforeUpdate[ 'post_status' ]);
        }

        Cache::tags('post_' . $postId)->flush();

        return $post;
    }
392463
public function get($blogId, $pageId, $optParams = array()) {
      $params = array('blogId' => $blogId, 'pageId' => $pageId);
      $params = array_merge($params, $optParams);
      $data = $this->__call('get', array($params));
      if ($this->useObjects()) {
        return new Page($data);
      } else {
        return $data;
      }
    }
102035
public function save_post_metaboxes( $pid, $post ) {

		if ( ! isset( $_POST['pods_templates_metabox'] ) || ! isset( $_POST['pods_templates_metabox_prefix'] ) ) {
			return;
		}

		if ( ! wp_verify_nonce( $_POST['pods_templates_metabox'], plugin_basename( __FILE__ ) ) ) {
			return $post->ID;
		}
		if ( ! current_user_can( 'edit_post', $post->ID ) ) {
			return $post->ID;
		}
		if ( $post->post_type == 'revision' ) {
			return;
		}

		foreach ( $_POST['pods_templates_metabox_prefix'] as $prefix ) {
			if ( ! isset( $_POST[ $prefix ] ) ) {
				continue;
			}

			delete_post_meta( $post->ID, $prefix );
			add_post_meta( $post->ID, $prefix, $_POST[ $prefix ] );
		}
	}
967565
protected function updatePost( $post_id, $status ) {

		$post = get_post( $post_id, 'ARRAY_A' );
		if ( empty( $post ) ) {
			return;
		}

		global $wpdb;
		$menu_order = $wpdb->get_var(
			$wpdb->prepare(
				"SELECT MAX(menu_order) FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %d AND ID != %d ",
				$post['post_type'],
				$post['post_parent'],
				$post_id
			)
		);
		if ( $menu_order !== null ) {
			$post['menu_order'] = $menu_order + 1;
		}

		$post['post_status'] = $status;

		wp_update_post( $post );
	}
338390
public function redirectToPost($post_id)
    {
        $post_id = Container::get('hooks')->fire('model.topic.redirect_to_post', $post_id);

        $result['select'] = ['topic_id', 'posted'];

        $result = DB::forTable('posts')
                      ->select_many($result['select'])
                      ->where('id', $post_id);
        $result = Container::get('hooks')->fireDB('model.topic.redirect_to_post_query', $result);
        $result = $result->find_one();

        if (!$result) {
            throw new  RunBBException(__('Bad request'), 404);
        }

        $post['topic_id'] = $result['topic_id'];
        $posted = $result['posted'];

        // Determine on which page the post is located (depending on $forum_user['disp_posts'])
        $num_posts = DB::forTable('posts')
                        ->where('topic_id', $post['topic_id'])
                        ->where_lt('posted', $posted)
                        ->count('id');

        $num_posts = Container::get('hooks')->fire('model.topic.redirect_to_post_num', $num_posts);

        $post['get_p'] = ceil(($num_posts + 1) / User::get()->disp_posts);

        $post = Container::get('hooks')->fire('model.topic.redirect_to_post', $post);

        return $post;
    }
1261444
public function delete_post( $id ) {

		$post = get_post( $id );

		if ( empty( $post ) ) {
			return;
		}

		$id        = $post->ID;
		$post_type = $post->post_type;

		return $this->delete_object( 'post_type', $id, $post_type );
	}
1324394
public static function _delete_generated_if_image( $post_id ) {
		if ( wp_attachment_is_image($post_id) ) {
			$attachment = new Image($post_id);
			if ( $attachment->file_loc ) {
				ImageHelper::delete_generated_files($attachment->file_loc);
			}
		}
	}
1344796
function newComment($post_id, array $comment)
    {
        $params = array(1, $this->username, $this->password, $post_id, $comment);

        return $this->sendRequest('wp.newComment', $params);
    }
1206274
public static function getPostModules($postId)
    {

        //Declarations
        $modules = array();
        $retModules = array();

        //Get current post id
        $postId = self::pageForPostTypeTranscribe($postId);

        // Get enabled modules
        $available = \Modularity\ModuleManager::$available;
        $enabled = \Modularity\ModuleManager::$enabled;

        // Get modules structure
        $moduleIds = array();
        $moduleSidebars = null;

        if (is_numeric($postId)) {
            $moduleSidebars = get_post_meta($postId, 'modularity-modules', true);
        } else {
            $moduleSidebars = get_option('modularity_' . $postId . '_modules');
        }

        //Create array of visible modules
        if (!empty($moduleSidebars)) {
            foreach ($moduleSidebars as $sidebar) {
                foreach ($sidebar as $module) {
                    if (!isset($module['postid'])) {
                        continue;
                    }

                    $moduleIds[] = $module['postid'];
                }
            }
        }

        //Get allowed post statuses
        $postStatuses = array('publish');
        if (is_user_logged_in()) {
            $postStatuses[] = 'private';
        }

        // Get module posts
        $modulesPosts = get_posts(array(
            'posts_per_page' => -1,
            'post_type' => $enabled,
            'include' => $moduleIds,
            'post_status' => $postStatuses
        ));

        // Add module id's as keys in the array
        if (!empty($modulesPosts)) {
            foreach ($modulesPosts as $module) {
                $modules[$module->ID] = $module;
            }
        }

        // Create an strucural correct array with module post data
        if (!empty($moduleSidebars)) {
            foreach ($moduleSidebars as $key => $sidebar) {
                $retModules[$key] = array(
                    'modules' => array(),

                    // Todo: This will duplicate for every sidebar, move it to top level of array(?)
                    // Alternatively only fetch options for the current sidebar (not all like now)
                    'options' => get_post_meta($postId, 'modularity-sidebar-options', true)
                );

                $arrayIndex = 0;

                foreach ($sidebar as $moduleUid => $module) {
                    if (!isset($module['postid'])) {
                        continue;
                    }
                    $moduleId = $module['postid'];

                    if (!isset($modules[$moduleId])) {
                        continue;
                    }

                    $moduleObject = self::getModule($moduleId, $module);
                    if (!$moduleObject) {
                        continue;
                    }

                    $retModules[$key]['modules'][$arrayIndex] = $moduleObject;

                    $arrayIndex++;
                }
            }
        }

        return $retModules;
    }
858527
public function create($postArr)
    {
        $userId = null;
        if (Auth::check()) {
            $userId = Auth::user()->id;
        }

        $default = [
            'post_author'    => $userId,
            'post_content'   => '',
            'post_title'     => '',
            'post_excerpt'   => '',
            'post_status'    => 'draft',
            'post_type'      => 'post',
            'comment_status' => '',
            'post_parent'    => 0,
            'menu_order'     => 0,
        ];

        $postArr = array_unique(array_merge($default, $postArr));

        $postArr[ 'guid' ] = sha1(time());

        if (empty($postArr[ 'post_title' ])) {
            return new EtherError('Post title must be provided');
        }

        if (isset($postArr[ 'post_slug' ]) && ! empty($postArr[ 'post_slug' ])) {
            $postArr[ 'post_slug' ] = $this->postRepository->sluggable($postArr[ 'post_slug' ], 'post_slug');
        } else {
            $postArr[ 'post_slug' ] = $this->postRepository->sluggable($postArr[ 'post_title' ], 'post_slug');
        }
        try {
            $post = $this->postRepository->create($postArr);
        } catch (\Exception $e) {
            return new EtherError($e);
        }

        return $post;
    }
594885
public static function instance($postId, $title, $body, Author $author, array $comments)
    {
        $post = new self();

        $post->postId   = $postId;
        $post->title    = $title;
        $post->body     = $body;
        $post->author   = $author;
        $post->comments = $comments;

        return $post;
    }