proweb
5/30/2015 - 9:45 AM

WPSEO + ACF content analysis

WPSEO + ACF content analysis

<?php

add_filter( 'wpseo_pre_analysis_post_content', 'acf_wpseo_add_fields_to_analysis', 10, 2 );
function acf_wpseo_add_fields_to_analysis( $content, $post ) {

	$fields = get_fields( $post->ID );

	foreach ( $fields as $key => $field_value ) :

		$field_settings = get_field_object( $key, $post->ID );
		if ( isset( $field_settings['add_to_wpseo_analysis'] ) && true == $field_settings['add_to_wpseo_analysis'] ) :
			$content .= ' ' . $field_value;
		endif;

	endforeach;

	return $content;

}

add_action('acf/create_field_options', 'add_acf_field', 10, 1 );
function add_acf_field( $field ) {

	if ( ! isset( $field['add_to_wpseo_analysis'] ) ) $field['add_to_wpseo_analysis'] = 0;

	?><tr class="conditional-logic" data-field_name="<?php echo $field['key']; ?>">
		<td class="label"><label><?php _e("Use value in WPSEO analysis",'acf'); ?></label></td>
		<td><?php

			do_action('acf/create_field', array(
				'type'	=>	'radio',
				'name'	=>	'fields['.$field['key'].'][add_to_wpseo_analysis]',
				'value'	=>	$field['add_to_wpseo_analysis'],
				'choices'	=>	array(
					1	=>	__("Yes",'acf'),
					0	=>	__("No",'acf'),
				),
				'layout'	=>	'horizontal',
			));

		?></td>
	</tr><?php

}