plugin_slug . '_get_fields', array($this, 'ajax_get_fields') );
$this->pagenow = $GLOBALS['pagenow'];
}
function get_excluded_fields() {
return apply_filters( 'ysacf_exclude_fields', array() );
}
/**
* Filter what ACF Fields not to score
* @param field name array
*/
function get_field_data($fields) {
$values = $this->get_values( $fields );
$data = '';
foreach($fields as $key =>$item) {
if(in_array($key, $this->get_excluded_fields()) ){
continue;
} else {
switch(gettype($item)) {
case 'string':
if (preg_match('/(\.jpg|\.png|\.bmp)$/', $item)) {
$data = $data.'
';
} else {
$data = $data.' '.$item;
}
break;
case 'array':
if($key === 'sizes') {
// put all images in img tags for scoring.
$data = $data.' ;
}
break;
}
}
}
return $data;
}
function get_values($array) {
$value_array = array_values($array);
return $value_array;
}
function ajax_get_fields() {
$pid = $_POST['postId'];
$fields = get_fields( $pid );
wp_send_json( $this->get_field_data( $fields ) );
}
/**
* Register and enqueue admin-specific JavaScript.
*
* @since 0.1.0
*/
public function enqueue_admin_scripts() {
if( in_array( $this->pagenow, $this->analysize_page_types ) ) {
// if this is a taxonomy, get the taxonomy id else get the post id
if($this->pagenow === 'edit-tags.php' ) {
$id = $_GET['taxonomy'] . '_' . $_GET['tag_ID'];
wp_enqueue_script($this->plugin_slug, AC_SEO_ACF_ANALYSIS_PLUGIN_URL . 'yoast-seo-plugin.js', array('jquery', 'yoast-seo', 'wp-seo-term-scraper'), self::VERSION);
} else {
global $post;
$id = $post->ID;
wp_enqueue_script($this->plugin_slug, AC_SEO_ACF_ANALYSIS_PLUGIN_URL . 'yoast-seo-plugin.js', array('jquery', 'yoast-seo', 'wp-seo-post-scraper'), self::VERSION);
}
wp_localize_script($this->plugin_slug, 'yoast_acf_settings', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'id' => $id,
'ajax_action' => $this->plugin_slug . '_get_fields'
));
}
}
}
new AC_Yoast_SEO_ACF_Content_Analysis();
)