Removes nested shortcodes
@param  WP_Post $post
@return WP_Post
506294
public function filterNestedModuleShortocde($post)
    {
        if (is_admin()) {
            return $post;
        }

        if (substr($post->post_type, 0, 4) != 'mod-') {
            return $post;
        }

        $post->post_content = preg_replace('/\[modularity(.*)\]/', '', $post->post_content);
        return $post;
    }
1164201
public static function get_all_post_meta( $post ) {
		$tags = [
			[ 'name' => 'description',			'content' => self::get_post_meta_description( $post ) ],
			[ 'property' => 'og:locale',		'content' => get_locale() ],
			[ 'property' => 'og:type',			'content' => 'article' ],
			[ 'property' => 'og:title',			'content' => self::get_post_og_title( $post ) ],
			[ 'property' => 'og:description',	'content' => self::get_post_og_description( $post ) ],
			[ 'property' => 'og:url',			'content' => get_permalink( $post->ID ) ],
			[ 'property' => 'og:site_name',		'content' => get_bloginfo( 'title' ) ],
			[ 'property' => 'og:updated_time',	'content' => get_post_modified_time( 'c', true, $post ) ],
			[ 'name' => 'twitter:card',			'content' => self::get_twitter_card_type() ],
			[ 'name' => 'twitter:title',		'content' => self::get_post_twitter_title( $post ) ],
			[ 'name' => 'twitter:description',	'content' => self::get_post_twitter_description( $post ) ],
		];

		$og_image = self::get_post_og_image( $post );
		$twitter_image = self::get_post_twitter_image( $post );

		if ( ! empty( $og_image ) ) {
			$og_image_size = getimagesize( $og_image );

			$tags = array_merge( $tags, [
				[ 'property' => 'og:image',			'content' => $og_image ],
				[ 'property' => 'og:image:width',	'content' => $og_image_size[0] ],
				[ 'property' => 'og:image:height',	'content' => $og_image_size[1] ],
			] );
		}

		if ( ! empty( $twitter_image ) ) {
			$twitter_image_size = getimagesize( $twitter_image );

			$tags = array_merge( $tags, [
				[ 'name' => 'twitter:image',		'content' => $twitter_image ],
				[ 'name' => 'twitter:image:width',	'content' => $twitter_image_size[0] ],
				[ 'name' => 'twitter:image:height',	'content' => $twitter_image_size[1] ],
			] );
		}

		$tags = array_merge( $tags, Site::webmaster_tools() );

		return [
			'title' => self::get_post_meta_title( $post ),
			'tags' => $tags,
		];
	}
298775
public function purgeTreeMenuTransientForAncestors($postId)
    {
        // Get page ancestors
        $ancestors = get_post_ancestors($postId);
        $ancestors[] = $postId;

        // Remove front page from ancestors array
        $ancestors = array_reverse($ancestors);

        if ($ancestors[0] == get_option('page_on_front')) {
            unset($ancestors[0]);
        }

        $ancestors = array_values($ancestors);

        // Delete transient for page ancestors
        foreach ($ancestors as $postId) {
            $children = get_children(array(
                'post_parent' => $postId,
                'numberofposts' => -1,
                'post_type' => 'page',
            ));

            foreach ($children as $child) {
                delete_transient('main_menu_' . $child->ID);
                delete_transient('mobile_menu_' . $child->ID);
                delete_transient('sidebar_menu_' . $child->ID);

                delete_transient('main_menu_' . $child->ID . '_loggedin');
                delete_transient('mobile_menu_' . $child->ID . '_loggedin');
                delete_transient('sidebar_menu_' . $child->ID . '_loggedin');
            }
        }
    }
929219
public function delete(Post $post)
    {
        $this->authorize(PostsPolicy::PERMISSION_DELETE);

        try {
            $post->trashed() ? $post->forceDelete() : $post->delete();

            return $this->jsonResponseSuccess([
                'message' => $this->transNotification('deleted', ['title' => $post->title], $post->toArray())
            ]);
        }
        catch(\Exception $e) {
            return $this->jsonResponseError(['message' => $e->getMessage()], 500);
        }
    }
666711
protected function checkInternalShortcodes( $post_id, $html ) {
		// Glossary
		if ( has_shortcode( $html, \Pressbooks\Shortcodes\Glossary\Glossary::SHORTCODE ) ) {
			$this->postsWithGlossaryShortcodesToFix[] = $post_id;
		}
		// Attachments
		if ( has_shortcode( $html, \Pressbooks\Shortcodes\Attributions\Attachments::SHORTCODE ) ) {
			$this->postsWithAttachmentsShortcodesToFix[] = $post_id;
		}
		// TODO
		//  H5P not supported in WXR imports
	}
457002
public function deserialize($data, Post $post = null, array $options = [])
    {
        if (empty($post)) {
            $post = new Post();
        }

        if (!in_array(Options::REFRESH_UUID, $options)) {
            $this->sipe('id', 'setUuid', $data, $post);
        }

        if (isset($data['title'])) {
            $post->setTitle($data['title']);
        }
        if (isset($data['content'])) {
            $post->setContent($data['content']);
        }
        if (isset($data['creationDate'])) {
            $post->setCreationDate(DateNormalizer::denormalize($data['creationDate']));
        }
        if (isset($data['publicationDate'])) {
            $post->setPublicationDate(DateNormalizer::denormalize($data['publicationDate']));
        }
        if (isset($data['modificationDate'])) {
            $post->setModificationDate(DateNormalizer::denormalize($data['modificationDate']));
        }
        if (isset($data['viewCounter'])) {
            $post->setViewCounter($data['viewCounter']);
        }
        if (isset($data['user'])) {
            $user = isset($data['user']['id']) ? $this->userRepo->findOneBy(['id' => $data['user']['id']]) : null;
            $post->setAuthor($user);
        }
        if (isset($data['tags'])) {
            $this->deserializeTags($post, $data['tags']);
        }
        if (isset($data['published']) && true === $data['published']) {
            $post->publish();
        }
        if (isset($data['commentModerationMode'])) {
            $post->setCommentModerationMode($data['commentModerationMode']);
        }

        return $post;
    }
654700
public function removePost(ForumThreadPost $post)
    {
        if ($this->posts->contains($post) === true) {
            $post->setThread(null);
            $this->posts->removeElement($post);
        }

        return $this;
    }
555626
private function get_modules_content( \WP_Post $post ) : string {
		$flexible_content = $this->_flexible_content[ $post->ID ] ?? null;

		if ( empty( $flexible_content ) ) {
			$layouts = $this->get_current_post_layouts( $post );

			foreach ( $layouts as $layout ) {

				if ( ! isset( $layout['acf_fc_layout'] ) || empty( $layout['acf_fc_layout'] ) ) {
					continue;
				}

				ob_start();
				$this->render_module_template( $layout['acf_fc_layout'], $layout );
				$flexible_content .= ob_get_clean();
			}

			/*
			 * Store the flexible content to reuse it if `the_content` is
			 * runned more than once.
			 */
			$this->_flexible_content[ $post->ID ] = $flexible_content;
		}

		return (string) $flexible_content;
	}
580041
public function postTerms(Post $post)
    {
        $adaptees = wp_get_post_terms($post->id, $this->getSlug());

        return $this->plugger
            ->setModel($this)
            ->setAdapter(Term::class)
            ->plugIn($adaptees)
            ->getConnected();
    }
745153
public function formFields($fields, $post)
    {
        // Bail if its not edit attachment page
        if (!isset($_GET['post']) || $post->post_type !== 'attachment') {
            return $fields;
        }

        add_thickbox();
        wp_enqueue_media();
        $uploadDir = wp_upload_dir();

        $mime =  mime_content_type($uploadDir['basedir'] . '/' . get_post_meta(get_the_id(), '_wp_attached_file', true));

        // Media replace button
        $html = '<button type="button" class="button-secondary button-large" data-action="media-replacer-replace" data-mime="' . $mime . '" data-edit-link="' . get_edit_post_link($post->ID) . '">' . __('Replace media', 'media-replacer') . '</button>
                 <input type="hidden" name="media-replacer-replace-with">';

        // Revision button
        $revisions = get_post_meta($post->ID, self::$revisionMetaKey, true);
        if (!is_array($revisions)) {
            $revisions = array();
        }

        $revisions = array_reverse($revisions, true);

        if (count($revisions) > 0) {
            $html .= '<a href="#TB_inline?width=600&height=550&inlineId=media-replace-revisions-thickbox-' . $post->ID . '" class="thickbox button-secondary button-large" data-action="media-replacer-revisions" data-edit-link="' . get_edit_post_link($post->ID) . '">' . __('Media revisions', 'media-replacer') . '</a>';
            $html .= '<div id="media-replace-revisions-thickbox-' . $post->ID . '" style="display:none;"><ul class="media-replace-revisions">';
        }

        foreach ($revisions as $time => $path) {
            if (!file_exists($path)) {
                continue;
            }

            $url = str_replace($uploadDir['basedir'], $uploadDir['baseurl'], $path);

            $date = mysql2date('Y-m-d H:i', date('Y-m-d H:i:s', $time));
            $html .= '<li data-restore="' . $path . '">';

            if (explode('/', mime_content_type($path))[0] === 'image') {
                $html .= '<div class="media-replace-revision-thumb" style="background-image:url(' . $url . ')"></div>';
            }

            $html .= '<time>' . $date . '</time>';
            $html .= '</li>';
        }

        if (count($revisions)) {
            $html .= '</ul>
                <div class="media-replace-revision-footer">
                    <button type="button" class="button button-large" data-action="media-replace-close-thickbox">' . __('Cancel') . '</button>
                    <button type="button" class="button button-large button-primary" data-action="media-replace-close-thickbox">' . __('Ok') . '</button>
                </div>
            </div><input type="hidden" name="media-replace-restore">';
        }

        $fields['media_replacer'] = array(
            'label' => '',
            'input' => 'html',
            'html' => $html
        );

        return $fields;
    }
365388
public static function get_post_twitter_description( $post ) {
		$description = get_post_meta( $post->ID, '_yoast_wpseo_twitter-description', true );

		if ( empty( $description ) ) {
			$description = self::get_post_meta_description( $post );
		}

		return $description;
	}
1207900
def from_shortcode(cls, context: InstaloaderContext, shortcode: str):
        """"""
        # pylint:disable=protected-access
        post = cls(context, {'shortcode': shortcode})
        post._node = post._full_metadata
        return post
1243695
static function deletePost( $pid ) {

		if ( false === Book::isBook() || wp_is_post_revision( $pid ) || 'auto-draft' === get_post_status( $pid ) ) {
			return false;
		}

		/** @var $wpdb \wpdb */
		global $wpdb;

		// remove chapter/part/front matter
		// decrement order of everything with a higher order, and if chapter, only within that part

		$post_to_delete = get_post( $pid );
		$order = $post_to_delete->menu_order;
		$type = $post_to_delete->post_type;
		$parent = $post_to_delete->post_parent;

		if ( 'chapter' === $type ) {
			$success = $wpdb->query(
				$wpdb->prepare(
					"UPDATE {$wpdb->posts} SET menu_order = menu_order - 1 WHERE menu_order > %d AND post_type = %s AND post_parent = %d ",
					$order,
					$type,
					$parent
				)
			);
		} else {
			$success = $wpdb->query(
				$wpdb->prepare(
					"UPDATE {$wpdb->posts} SET menu_order = menu_order - 1 WHERE menu_order > %d AND post_type = %s ",
					$order,
					$type
				)
			);
		}

		clean_post_cache( $post_to_delete );

		if ( 'part' === $type ) {

			// We're setting two things here - the new post_parent (to the first part)
			// And the new menu order for the chapters that were in the part being deleted.

			$new_parent_id = $wpdb->get_var(
				$wpdb->prepare(
					"SELECT ID FROM {$wpdb->posts} WHERE post_type = 'part' AND post_status = 'publish' AND NOT ID = %d ORDER BY menu_order LIMIT 1 ",
					$pid
				)
			);

			if ( $new_parent_id ) {
				$existing_numposts = $wpdb->get_var(
					$wpdb->prepare(
						"SELECT COUNT(1) AS numposts FROM {$wpdb->posts} WHERE post_type = 'chapter' AND post_parent = %d ",
						$new_parent_id
					)
				);
				$success = $wpdb->query(
					$wpdb->prepare(
						"UPDATE {$wpdb->posts} SET post_parent = %d, menu_order = menu_order + %d WHERE post_parent = %d AND post_type = 'chapter' ",
						$new_parent_id,
						$existing_numposts,
						$pid
					)
				);
			} else {
				$success = $wpdb->query(
					$wpdb->prepare(
						"UPDATE {$wpdb->posts} SET post_status = 'trash' WHERE post_parent = %d AND post_type = 'chapter' ",
						$pid
					)
				);
			}

			wp_cache_flush();
		}

		static::deleteBookObjectCache();

		return $success ? true : false;
	}
743889
public function clean_wp_head()
    {
        global $wp_widget_factory;

        $this->remove_action('wp_head', 'feed_links_extra', 3);
        
        // Remove emojis.
        $this->remove_emojis();

        // Remove next/previous links.
        $this->remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
        
        // Remove oembed.
        $this->remove_action('wp_head', 'wp_oembed_add_discovery_links');
        $this->remove_action('wp_head', 'wp_oembed_add_host_js');

        // Generic fixes.
        $this->remove_action('wp_head', 'rsd_link');
        $this->remove_action('wp_head', 'wlwmanifest_link');
        $this->remove_action('wp_head', 'wp_generator');
        $this->remove_action('wp_head', 'wp_shortlink_wp_head', 10);
        $this->remove_action('wp_head', 'rest_output_link_wp_head', 10);
        
        if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
            $this->remove_action('wp_head', [$wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style']);
        }

        add_filter('use_default_gallery_style', '__return_false');
    }
515921
public function elasticPressPreIndex($post)
    {
        $rendered = $this->getRenderedPostModules($post);

        if (is_array($post)) {
            $post['post_content'] .= $rendered;
        } else {
            $post->post_content .= $rendered;
        }

        return $post;
    }
1077119
public function convertPostContent($post) {
		$content = $post->Content;
		
		$lines = explode("\n", $content);
		
		$newContent = array();
		$title = '';
		$converted = false;
		
		// store the converted items
		$convertedLinks = array();
		
		foreach ($lines as $line) {
			$url = trim($line);
			if (strlen($url) && $this->isWebpage($url)) {
				$convertedContent = $this->convertUrl($url);
				if ($convertedContent) {
					$converted = true;
					$line = 'CONVERTEDCONTENT:' . count($convertedLinks);
					$convertedLinks[] = $convertedContent;
					$title = strlen($convertedContent['Title']) ? $convertedContent['Title'] : '';
				}
			} 
			$newContent[] = $line;
		}

		$newContent = implode("\n", $newContent);
		$newContent = RestrictedMarkdown::create($newContent)->parse();
		
		// replace the converted bits
		$newContent = preg_replace_callback('/CONVERTEDCONTENT:(\d+)/is', function ($bit) use ($convertedLinks) {
			return isset($convertedLinks[$bit[1]]) ? $convertedLinks[$bit[1]]['Content'] : '';
		}, $newContent);
		
		if ($converted) {
			$post->IsOembed = true;
			$post->OriginalContent = $post->Content;
			$post->Content = $newContent;
			$post->Title = $title;
		}

		return $post;
	}
184611
public function removePostPostType()
    {
        global $wp_post_types;

        if (isset($wp_post_types['post'])) {
            if (function_exists('get_field') && get_field('disable_default_blog_post_type', 'option')) {
                add_action('admin_menu', function () {
                    remove_menu_page('edit.php');
                });

                add_action('wp_before_admin_bar_render', function () {
                    global $wp_admin_bar;
                    $wp_admin_bar->remove_menu('new-post');
                });
            }
        }

        if (isset($wp_post_types['page'])) {
            if (function_exists('get_field') && get_field('disable_default_page_post_type', 'option')) {
                add_action('admin_menu', function () {
                    remove_menu_page('edit.php?post_type=page');
                });

                add_action('wp_before_admin_bar_render', function () {
                    global $wp_admin_bar;
                    $wp_admin_bar->remove_menu('new-page');
                });
            }
        }

        return null;
    }