WPSEO_Import_RankMath::import_meta_robots()privateYoast 1.0

RankMath stores robots meta quite differently, so we have to parse it out.

Метод класса: WPSEO_Import_RankMath{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->import_meta_robots();

Код WPSEO_Import_RankMath::import_meta_robots() Yoast 23.6

private function import_meta_robots() {
	global $wpdb;
	$post_metas = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'rank_math_robots'" );
	foreach ( $post_metas as $post_meta ) {
		// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Reason: We can't control the form in which Rankmath sends the data.
		$robots_values = unserialize( $post_meta->meta_value );
		foreach ( [ 'noindex', 'nofollow' ] as $directive ) {
			$directive_key = array_search( $directive, $robots_values, true );
			if ( $directive_key !== false ) {
				update_post_meta( $post_meta->post_id, '_yoast_wpseo_meta-robots-' . $directive, 1 );
				unset( $robots_values[ $directive_key ] );
			}
		}
		if ( count( $robots_values ) > 0 ) {
			$value = implode( ',', $robots_values );
			update_post_meta( $post_meta->post_id, '_yoast_wpseo_meta-robots-adv', $value );
		}
	}
}