' . print_r($data, 1) . ''; } if (!$data){ $output.= "\n\n"; } if ($die){ wp_die(wp_kses_post($output)); // debug output only } else { if (Helper::$doDebug !== 'silent'){ //echo $output; error_log($output . "\n\n"); } //Helper::$debugOutput.= $output; } } } public static function isBlockAdminPage($id = null){ global $pagenow; $postId = null; $isBlockAdmin = false; //$regular = $pagenow === 'post.php'; if (!is_admin()){ return false; } if ($pagenow === 'post-new.php'){ $postId = -1; $isBlockAdmin = true; } elseif ($pagenow === 'post.php' && isset($_GET['post'])){ $postId = intval($_GET["post"]); $isBlockAdmin = true; } elseif ($pagenow === 'site-editor.php'){ if (isset($_GET['postId'])){ $postId = sanitize_text_field(wp_unslash($_GET["postId"])); } else { $postId = Helper::homePageData()['id']; } $isBlockAdmin = true; } return $isBlockAdmin && ($id === 'global' || $id == $postId); } // get the template file WordPress is loading e.g. page, single, single-with-sidebar // this is duplicate code of method with same name in Common class, which may not be present public static function getCurrentTemplateSlug(){ return !empty(Logic::$cache['settings']['currentTemplate']) ? Logic::$cache['settings']['currentTemplate'] : ''; } // determine what type of FSE page we're editing public static function getFSEType($postType, $categoryType){ return $postType === 'wp_block' || $categoryType === 'pattern' ? 'wp_pattern' : $postType; } // determine what type of FSE page we're editing public static function getTemplateFromPostId($postId, $post){ if (Common::$live_template !== false){ $currentTemplate = Common::$live_template; //echo 'Retrieved from Common::$live_template: ' . $currentTemplate . '
'; } else { $currentTemplate = get_post_meta($postId, '_wp_page_template', true); //echo 'Retrieved from get_post_meta: ' . $currentTemplate . '
'; } if (!$currentTemplate){ $currentTemplate = $post ? ($post->post_type === 'post' ? 'single' : $post->post_type) : 'page'; } return $currentTemplate; } // if it's a front page fallback on the FSE admin page public static function isFrontOrFallback($orDirectView = true){ global $pagenow; $fse = $pagenow === 'site-editor.php'; $regular = $pagenow === 'post.php'; $post = isset($_GET["post"]) ? intval($_GET["post"]) : null; $postId = isset($_GET["postId"]) ? sanitize_text_field(wp_unslash($_GET["postId"])) : null; $homePage = Helper::homePageData(); $fseFallback = $fse && $postId === null; $fseDirect = $fse && $postId === $homePage['id']; // The request ID is cast above, so normalize the option value before the strict comparison too. $regularDirect = $regular && $post === (int) $homePage['id']; $frontDirect = !is_admin() && ( is_front_page() || ( $homePage['id'] > 0 && is_page($homePage['id']) ) ); return $fseFallback || ($orDirectView && ($fseDirect || $regularDirect || $frontDirect)); } public static function getMicroRoot($wp_content_dir, $wp_content_url){ global $blog_id; if (is_multisite()) { $filename = $wp_content_dir . "/blogs.dir/"; if (file_exists($filename)){ if ($blog_id == '1') { $dir = $wp_content_dir . '/blogs.dir/micro-themes/'; $url = $wp_content_url . '/blogs.dir/micro-themes/'; } else { $dir = $wp_content_dir . '/blogs.dir/' . $blog_id . '/micro-themes/'; $url = $wp_content_url . '/blogs.dir/' . $blog_id . '/micro-themes/'; } } else { if ($blog_id == '1') { $dir = $wp_content_dir . '/uploads/sites/micro-themes/'; $url = $wp_content_url . '/uploads/sites/micro-themes/'; } else { $dir = $wp_content_dir . '/uploads/sites/' . $blog_id . '/micro-themes/'; $url = $wp_content_url . '/uploads/sites/' . $blog_id . '/micro-themes/'; } } } else { $dir = $wp_content_dir . '/micro-themes/'; $url = $wp_content_url . '/micro-themes/'; } return array( 'dir' => $dir, 'url' => $url, ); } public static function getTemplateMap($themeSlug = '', &$cache = array()){ $themeSlug = $themeSlug ?: get_stylesheet(); // return cache if available if (isset($cache['templateMap'][$themeSlug])){ return $cache['templateMap'][$themeSlug]; } // else read the file $map = null; $dir = Helper::getMicroRoot(wp_normalize_path(WP_CONTENT_DIR), content_url())['dir']; $templateMapFile = $dir . 'mt/cache/themes/'.$themeSlug.'/'.Helper::templateMapName().'.json'; if (file_exists($templateMapFile)){ $mapString = file_get_contents($templateMapFile); if ($mapString){ $map = json_decode($mapString, true); } } // cache to save reading the file again $cache['templateMap'][$themeSlug] = $map; return $map; } public static function isLiveContentTest(){ return isset($_POST['live_post_content']); } public static function getFSEPermalink($permalink){ $themeSlug = get_stylesheet(); // Get parameters in case we are in the FSE view extract(Helper::extractUrlParams($themeSlug)); if ($postType === 'page' && $postId !== null){ $permalink = get_permalink($postId); } return $permalink; } public static function extractUrlParams($themeSlug){ $postType = isset($_GET["postType"]) ? sanitize_key(wp_unslash($_GET["postType"])) : null; $postId = isset($_GET['postId']) ? Helper::removeRedundantThemePrefix( Helper::maybeMakeNumber(sanitize_text_field(wp_unslash($_GET["postId"]))), $themeSlug ) : null; $categoryType = isset($_GET["categoryType"]) ? sanitize_key(wp_unslash($_GET["categoryType"])) : null; $fseType = Helper::getFSEType($postType, $categoryType); return array( 'postType' => $postType, 'postId' => $postId, 'categoryType' => $categoryType, 'fseType' => $fseType, ); } public static function templateMapName(){ return Helper::isLiveContentTest() ? 'template-map-live' : 'template-map'; } public static function extractSyncedPatterns($content){ $pattern = '/