in_array( 'noindex', $robots, true ), 'nofollow' => in_array( 'nofollow', $robots, true ), ); } /** * Reads Rank Math's Open Graph (Facebook) title for a post. * * @param int $post_id Post ID. * @return string */ public function get_og_title( int $post_id ): string { return (string) get_post_meta( $post_id, 'rank_math_facebook_title', true ); } /** * Reads Rank Math's Open Graph (Facebook) description for a post. * * @param int $post_id Post ID. * @return string */ public function get_og_description( int $post_id ): string { return (string) get_post_meta( $post_id, 'rank_math_facebook_description', true ); } /** * Reads Rank Math's primary focus keyword for a post. Rank Math stores * multiple comma-separated keywords; the first is the primary one. * * @param int $post_id Post ID. * @return string */ public function get_focus_keyword( int $post_id ): string { $keyword = (string) get_post_meta( $post_id, 'rank_math_focus_keyword', true ); $parts = array_filter( array_map( 'trim', explode( ',', $keyword ) ) ); return $parts ? reset( $parts ) : ''; } /** * Counts posts that have Rank Math title or description data set. * * @return int */ public function count_migratable_pages(): int { global $wpdb; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- {$wpdb->postmeta} is WP core's own table-name property, never user input; both meta_key values are passed through $wpdb->prepare(). Only runs when previewing/counting a migration from the admin UI, not a cacheable read path. $count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT post_id) FROM {$wpdb->postmeta} WHERE meta_key IN (%s, %s) AND meta_value != ''", 'rank_math_title', 'rank_math_description' ) ); // phpcs:enable return $count; } /** * Deactivates Rank Math if it's currently active. * * @return bool True if it was active and is now deactivated. */ public function deactivate_self(): bool { if ( ! function_exists( 'deactivate_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $plugin_file = $this->find_active_plugin_file( 'rank-math.php' ); if ( ! $plugin_file ) { return false; } deactivate_plugins( $plugin_file ); return ! is_plugin_active( $plugin_file ); } }