plugin_slug . '_get_fields', array($this, 'ajax_get_fields') ); if(isset($GLOBALS['pagenow'])) { $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) { $data = ''; if(!empty($fields)) { foreach($fields as $key =>$item) { if(in_array((string)$key, $this->get_excluded_fields()) ){ continue; } else { switch(gettype($item)) { case 'string': $data = $data.' '.$item; break; case 'array': if(isset($item['sizes']['thumbnail'])) { // put all images in img tags for scoring. $alt = ''; if(isset($item['alt'])) { $alt = $item['alt']; } $title = ''; if(isset($item['title'])) { $title = $item['title']; } $data = $data.' ' . $alt .''; } else { $data = $data.' '.$this->get_field_data($item); } break; } } } } return $data; } function ajax_get_fields() { $pid = filter_input(INPUT_POST, 'postId', FILTER_SANITIZE_STRING); $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 === 'term.php' || $this->pagenow === 'edit-tags.php') { $id = filter_input(INPUT_GET, 'taxonomy', FILTER_SANITIZE_STRING) . '_' . filter_input(INPUT_GET, 'tag_ID', FILTER_SANITIZE_NUMBER_INT); } else { global $post; $id = $post->ID; } wp_enqueue_script($this->plugin_slug, AC_SEO_ACF_ANALYSIS_PLUGIN_URL . 'yoast-seo-plugin.js', array('jquery'), 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' )); } } } add_action( 'plugins_loaded', 'init_ysacf' ); function init_ysacf() { new AC_Yoast_SEO_ACF_Content_Analysis(); }