/** * Print a notice about the current page being an index page. * * Unlike WordPress for the Posts page, it will not disabled the editor. * * @since 1.2.1 Rejigged check to handle deprecated index pages. * @since 1.1.0 Added missing static keyword * @since 1.0.0 * * @param WP_Post $post The post in question. */ public static function add_index_notice(\WP_Post $post) { // Abort if not a page or not an index page if ($post->post_type != 'page' || !($post_type = Registry::is_index_page($post->ID)) || !post_type_exists($post_type)) { return; } // Get the plural labe to use $label = strtolower(get_post_type_object($post_type)->label); echo '<div class="notice notice-warning inline"><p>' . sprintf(__('You are currently editing the page that shows your latest %s.', 'index-pages'), $label) . ' <em>' . __('Your current theme may not display the content you write here.', 'index-pages') . '</em>' . '</p></div>'; }
/** * Check if the path requested matches an assigned index page. * * Also checks for date and pagination parameters. * * @since 1.2.0 Added check to make sure post type currently exists. * @since 1.0.0 * * @param WP $wp The WP request object. */ public static function handle_request(\WP $wp) { $qv =& $wp->query_vars; // Abort if a pagename wasn't matched at all if (!isset($qv['pagename'])) { return; } // Build a RegExp to capture a page with date/paged arguments $pattern = '(.+?)' . '(?:/([0-9]{4})' . '(?:/([0-9]{2})' . '(?:/([0-9]{2}))?' . ')?' . ')?' . '(?:/page/([0-9]+))?' . '/?$'; // Proceed if the pattern checks out if (preg_match("#{$pattern}#", $wp->request, $matches)) { // Get the page using match 1 (pagename) $page = get_page_by_path($matches[1]); // Abort if no page is found if (is_null($page)) { return; } // Get the post type, and validate that it exists if (($post_type = Registry::is_index_page($page->ID)) && post_type_exists($post_type)) { // Modify the request into a post type archive instead $qv['post_type'] = $post_type; list(, , $qv['year'], $qv['monthnum'], $qv['day'], $qv['paged']) = array_pad($matches, 6, null); // Make sure these are unset unset($qv['pagename']); unset($qv['page']); unset($qv['name']); } } }