> */ private static function builders(): array { return array( array( 'slug' => 'elementor', 'label' => 'Elementor', 'meta_key' => '_elementor_edit_mode', 'meta_is' => 'builder', 'stored_in' => 'post meta _elementor_data (JSON)', 'writes' => self::WRITES_IGNORED, 'active_if' => array( 'class' => '\\Elementor\\Plugin' ), ), array( 'slug' => 'bricks', 'label' => 'Bricks', 'meta_key' => '_bricks_editor_mode', 'meta_is' => 'bricks', 'stored_in' => 'post meta _bricks_page_content_2 (serialized)', 'writes' => self::WRITES_IGNORED, 'active_if' => array( 'const' => 'BRICKS_VERSION' ), ), array( 'slug' => 'divi', 'label' => 'Divi', 'meta_key' => '_et_pb_use_builder', 'meta_is' => 'on', 'stored_in' => 'post_content as [et_pb_*] shortcodes', 'writes' => self::WRITES_DESTRUCTIVE, 'active_if' => array( 'const' => 'ET_BUILDER_VERSION' ), ), array( 'slug' => 'beaver-builder', 'label' => 'Beaver Builder', 'meta_key' => '_fl_builder_enabled', 'meta_is' => '', 'stored_in' => 'post meta _fl_builder_data (serialized)', 'writes' => self::WRITES_IGNORED, 'active_if' => array( 'class' => 'FLBuilderLoader' ), ), array( 'slug' => 'oxygen', 'label' => 'Oxygen', 'meta_key' => 'ct_builder_shortcodes', 'meta_is' => '', 'stored_in' => 'post meta ct_builder_shortcodes', 'writes' => self::WRITES_IGNORED, 'active_if' => array( 'const' => 'CT_VERSION' ), ), array( 'slug' => 'breakdance', 'label' => 'Breakdance', 'meta_key' => '_breakdance_data', 'meta_is' => '', 'stored_in' => 'post meta _breakdance_data (JSON)', 'writes' => self::WRITES_IGNORED, 'active_if' => array( 'const' => '__BREAKDANCE_VERSION' ), ), array( 'slug' => 'zion-builder', 'label' => 'Zion Builder', 'meta_key' => '_zionbuilder_page_elements', 'meta_is' => '', 'stored_in' => 'post meta _zionbuilder_page_elements (JSON)', 'writes' => self::WRITES_IGNORED, 'active_if' => array( 'const' => 'ZIONBUILDER_VERSION' ), ), array( 'slug' => 'seedprod', 'label' => 'SeedProd', 'meta_key' => '_seedprod_page', 'meta_is' => '', 'stored_in' => 'post meta _seedprod_page (JSON)', 'writes' => self::WRITES_IGNORED, 'active_if' => array( 'const' => 'SEEDPROD_VERSION' ), ), array( 'slug' => 'siteorigin', 'label' => 'SiteOrigin Page Builder', 'meta_key' => 'panels_data', 'meta_is' => '', 'stored_in' => 'post meta panels_data (serialized)', 'writes' => self::WRITES_IGNORED, 'active_if' => array( 'const' => 'SITEORIGIN_PANELS_VERSION' ), ), array( 'slug' => 'fusion', 'label' => 'Avada / Fusion Builder', 'meta_key' => 'fusion_builder_status', 'meta_is' => 'active', 'stored_in' => 'post_content as [fusion_*] shortcodes', 'writes' => self::WRITES_DESTRUCTIVE, 'active_if' => array( 'const' => 'FUSION_BUILDER_VERSION' ), ), ); } /** * Builders identified by a marker in post_content rather than an ownership flag. * * Weaker evidence than a meta flag, so these run only after every flagged builder has been * ruled out — and before the block check, because their markup is not block markup. * * @since 0.0.34 * @return array> */ private static function content_markers(): array { return array( array( 'slug' => 'wpbakery', 'label' => 'WPBakery Page Builder', 'marker' => '[vc_row', 'stored_in' => 'post_content as [vc_*] shortcodes', 'writes' => self::WRITES_DESTRUCTIVE, 'active_if' => array( 'const' => 'WPB_VC_VERSION' ), ), array( 'slug' => 'divi', 'label' => 'Divi', 'marker' => '[et_pb_section', 'stored_in' => 'post_content as [et_pb_*] shortcodes', 'writes' => self::WRITES_DESTRUCTIVE, 'active_if' => array( 'const' => 'ET_BUILDER_VERSION' ), ), array( 'slug' => 'fusion', 'label' => 'Avada / Fusion Builder', 'marker' => '[fusion_builder_container', 'stored_in' => 'post_content as [fusion_*] shortcodes', 'writes' => self::WRITES_DESTRUCTIVE, 'active_if' => array( 'const' => 'FUSION_BUILDER_VERSION' ), ), ); } /** * Classify one post. * * @since 0.0.34 * @param int $post_id Post ID. * @return array|null Null when the post does not exist. */ public static function detect( int $post_id ): ?array { $post = get_post( $post_id ); if ( ! $post instanceof WP_Post ) { return null; } $signals = array(); foreach ( self::builders() as $builder ) { $api = self::ask_builder( (string) $builder['slug'], $post_id ); if ( is_bool( $api ) ) { // The builder answered for itself. Trust it over the meta key and stop. if ( ! $api ) { continue; } $signals[] = self::signal( $builder['slug'] . ' API', 'true', 'builder confirmed ownership' ); return self::result( $post, $builder, $signals ); } $value = get_post_meta( $post_id, $builder['meta_key'], true ); if ( ! self::flag_matches( $value, (string) $builder['meta_is'] ) ) { continue; } $signals[] = self::signal( $builder['meta_key'], $value, 'post meta' ); return self::result( $post, $builder, $signals ); } foreach ( self::content_markers() as $builder ) { if ( false === strpos( (string) $post->post_content, (string) $builder['marker'] ) ) { continue; } $signals[] = self::signal( 'post_content', $builder['marker'], 'content marker' ); return self::result( $post, $builder, $signals ); } return self::result( $post, self::core_editor( $post, $signals ), $signals ); } /** * Let a builder answer for itself, when it exposes a public way to. * * Prefer the builder's own API over reading its meta key: the meta key is an implementation * detail the builder may change, and its API will change with it. The meta fallback still has * to exist, though — a post stays owned by a builder after the plugin is deactivated, which is * exactly the case where the answer matters most and the API is unreachable. * * Elementor's `Db::is_built_with_elementor()` is deprecated as of 3.2.0 in favour of the * document; only the document form is used here. * * @since 0.0.34 * @param string $slug Builder slug. * @param int $post_id Post ID. * @return bool|null Null when the builder cannot be asked. */ private static function ask_builder( string $slug, int $post_id ): ?bool { if ( 'elementor' !== $slug || ! class_exists( '\\Elementor\\Plugin' ) ) { return null; } $plugin = \Elementor\Plugin::$instance; if ( ! isset( $plugin->documents ) ) { return null; } // Returns false — not null — for an unknown or unsupported post. $document = $plugin->documents->get( $post_id ); if ( ! $document || ! method_exists( $document, 'is_built_with_elementor' ) ) { return null; } return (bool) $document->is_built_with_elementor(); } /** * Whether a stored flag counts as ownership. * * `$expected` of '' means any truthy value, which is how the builders that store data rather * than a mode string signal ownership. * * @since 0.0.34 * @param mixed $value Stored meta value. * @param string $expected Required value, or '' for any truthy one. * @return bool */ private static function flag_matches( $value, string $expected ): bool { if ( '' !== $expected ) { return is_scalar( $value ) && (string) $value === $expected; } if ( is_array( $value ) ) { return array() !== $value; } return is_scalar( $value ) && '' !== (string) $value && '0' !== (string) $value; } /** * Classify a post no builder claimed: block editor, classic, or empty. * * `has_blocks()` is a substring test for `