; } $post_type = PROAdminHelper::get_current_post_type(); $is_woocommerce = Helper::is_woocommerce_active() && 'product' === $post_type; $is_edd = Helper::is_edd_active() && 'download' === $post_type; if ( ! $is_woocommerce && ! $is_edd ) { return $tests; } $exclude_tests = [ 'keywordInSubheadings' => true, 'linksHasExternals' => true, 'linksNotAllExternals' => true, 'linksHasInternal' => true, 'titleSentiment' => true, 'titleHasNumber' => true, 'contentHasTOC' => true, ]; $tests = array_diff_assoc( $tests, $exclude_tests ); $tests['hasProductSchema'] = true; if ( $is_woocommerce ) { $tests['isReviewEnabled'] = true; } return $tests; } /** * Update the values used in the Update SEO Score Database Tools. * * @since 3.0.81 * * @param array $values Values used in Content analysis. * @param string $post_id Post ID. */ public function seo_score_tool_values( $values, $post_id ) { $post_type = get_post_type( $post_id ); $is_woocommerce = Helper::is_woocommerce_active() && 'product' === $post_type; $is_edd = Helper::is_edd_active() && 'download' === $post_type; if ( ! $is_woocommerce && ! $is_edd ) { return $values; } $values['isProduct'] = true; $schemas = DB::get_schemas( $post_id ); if ( empty( $schemas ) && Helper::get_default_schema_type( $post_id ) ) { $schemas = [ [ '@type' => Helper::get_default_schema_type( $post_id ) ], ]; } $schemas = array_filter( $schemas, function ( $schema ) { return in_array( $schema['@type'], [ 'WooCommerceProduct', 'EDDProduct', 'Product' ], true ); } ); $values['schemas'] = $schemas; $values['content'] = $is_woocommerce ? $this->add_product_gallery_images( $post_id, $values['content'] ) : $values['content']; return $values; } /** * Enqueue script to analyze product data. * * @since 3.0.7 */ public function enqueue() { if ( ! Admin_Helper::is_post_edit() ) { return; } $post_type = PROAdminHelper::get_current_post_type(); $is_woocommerce = Helper::is_woocommerce_active() && 'product' === $post_type; $is_edd = Helper::is_edd_active() && 'download' === $post_type; if ( ! $is_woocommerce && ! $is_edd ) { return; } wp_enqueue_script( 'rank-math-gallery-analysis', RANK_MATH_PRO_URL . 'assets/admin/js/product-analysis.js', [ 'rank-math-editor' ], rank_math_pro()->version, true ); } /** * Whether to add the Keyword Intent. */ public function determine_search_intent() { return Helper::get_settings( 'general.determine_search_intent', true ); } /** * Pass Product gallery images to the Update SEO Score tool. * * @param int $post_id Post ID. * @param string $content Post content. * * @since 3.0.81 */ private function add_product_gallery_images( $post_id, $content ) { $product = wc_get_product( $post_id ); if ( empty( $product ) ) { return $content; } $attachment_ids = $product->get_gallery_image_ids(); if ( empty( $attachment_ids ) ) { return $content; } foreach ( $attachment_ids as $attachment_id ) { $content .= wp_get_attachment_image( $attachment_id ); } return $content; } /** * Get Trends icon element. * * @return string */ private function get_icon_svg() { return ' '; } }