'name' => $parts[1], ); } /** * Returns a template post from the database. * * @since 3.2 * * @param string $post_name Post name (slug). * @param string $theme_name Theme name (slug). * @param string $post_type Post type, either 'wp_template' or 'wp_template_part'. * @return WP_Post|null */ public static function query_template_post( $post_name, $theme_name, $post_type ) { $template_query = new WP_Query( array( 'post_name__in' => (array) $post_name, 'post_type' => $post_type, 'post_status' => array( 'auto-draft', 'draft', 'publish', 'trash' ), 'posts_per_page' => 1, 'no_found_rows' => true, 'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query array( 'taxonomy' => 'wp_theme', 'field' => 'name', 'terms' => $theme_name, ), ), ) ); if ( empty( $template_query->posts ) ) { return null; } return reset( $template_query->posts ); } /** * Tells if we're in the site editor. * * @since 3.2 * * @global string $pagenow * * @return bool */ public static function is_site_editor() { return isset( $GLOBALS['pagenow'] ) && 'site-editor.php' === $GLOBALS['pagenow']; } }