ACF Content Analysis for Yoast SEO - Version 1.0

Version Description

Download this release

Release Info

Developer ViktorFroberg
Plugin Icon 128x128 ACF Content Analysis for Yoast SEO
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (4) hide show
  1. README.md +16 -0
  2. readme.txt +40 -0
  3. yoast-seo-acf-content-analysis.php +129 -0
  4. yoast-seo-plugin.js +64 -0
README.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ACF-Content Analysis for Yoast SEO
2
+ This plugin ensures that Yoast SEO analysize all ACF content including FlexiContent and Repeaters
3
+
4
+ ## Filters
5
+ `ysacf_exclude_fields`: exceclude acf fields from Yoast scoring.
6
+
7
+
8
+ Example: exceclude text-color field from Yoast scoring.
9
+
10
+ ```
11
+ add_filter('ysacf_exclude_fields', function(){
12
+ return array(
13
+ 'text_color',
14
+ );
15
+ });
16
+ ```
readme.txt ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === ACF-Content Analysis for Yoast SEO ===
2
+ Contributors: viktorfroberg, marol87,pekz0r, AngryCreative
3
+ Tags: Angry Creative, Yoast SEO, Yoast, SEO, ACF, Advanced Custom Fields
4
+ Requires at least: 4.0
5
+ Tested up to: 4.3.1
6
+ Stable tag: 1.0
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ This plugin ensures that Yoast SEO analysize all ACF content including FlexiContent and Repeaters.
11
+ Requires version 3.0 or later of Yoast SEO plugin.
12
+
13
+ == Description ==
14
+
15
+ This plugin ensures that Yoast SEO analysize all ACF content including FlexiContent and Repeaters.
16
+ Requires version 3.0 or later of Yoast SEO plugin.
17
+
18
+ = Filters =
19
+ `ysacf_exclude_fields`: exceclude acf fields from Yoast scoring. Should return array of field names.
20
+
21
+ Example: exceclude text-color field from Yoast scoring.
22
+
23
+ `
24
+ add_filter('ysacf_exclude_fields', function(){
25
+ return array(
26
+ 'text_color',
27
+ );
28
+ });
29
+ `
30
+
31
+
32
+ == Installation ==
33
+
34
+ 1. Download, unzip and upload the plugin folder to the `/wp-content/plugins/` directory
35
+ 2. Activate the plugin through the 'Plugins' menu in WordPress (activate for network if multisite)
36
+
37
+ == Changelog ==
38
+
39
+ = 1.0.0 =
40
+ * First public release
yoast-seo-acf-content-analysis.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: ACF-Content Analysis for Yoast SEO
4
+ Plugin URI: http://angrycreative.se
5
+ Description: This plugin ensures that Yoast SEO analysize all ACF content including FlexiContent and Repeaters
6
+ Version: 1.0
7
+ Author: ViktorFroberg, marol87, AngryCreative
8
+ Author URI: http://angrycreative.se
9
+ License: GPL
10
+ */
11
+
12
+
13
+ // If this file is called directly, abort.
14
+ if ( ! defined( 'WPINC' ) ) {
15
+ die;
16
+ }
17
+
18
+ define('AC_SEO_ACF_ANALYSIS_PLUGIN_SLUG', 'ac-yoast-seo-acf-content-analysis');
19
+ define('AC_SEO_ACF_ANALYSIS_PLUGIN_PATH', plugin_dir_path( __FILE__ ));
20
+ define('AC_SEO_ACF_ANALYSIS_PLUGIN_URL', plugins_url('', __FILE__).'/');
21
+ define('AC_SEO_ACF_ANALYSIS_PLUGIN_NAME', untrailingslashit(plugin_basename(__FILE__)));
22
+
23
+ class AC_Yoast_SEO_ACF_Content_Analysis
24
+ {
25
+ /**
26
+ * Plugin version, used for autoatic updates and for cache-busting of style and script file references.
27
+ *
28
+ * @since 0.1.0
29
+ * @var string
30
+ */
31
+ const VERSION = '1.0';
32
+ /**
33
+ * Unique identifier for the plugin.
34
+ * This value is used as the text domain when internationalizing strings of text. It should
35
+ * match the Text Domain file header in the main plugin file.
36
+ *
37
+ * @since 0.1.0
38
+ * @var string
39
+ */
40
+ public $plugin_slug = 'ysacf';
41
+
42
+
43
+ function __construct(){
44
+
45
+
46
+
47
+ add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
48
+ add_action( 'admin_print_scripts-post-new.php', array($this, 'enqueue_admin_scripts') , 999 );
49
+ add_action( 'admin_print_scripts-post.php', array($this, 'enqueue_admin_scripts'), 999 );
50
+ add_action( 'wp_ajax_' . $plugin_slug . '_get_fields', array($this, 'ajax_get_fields') );
51
+ }
52
+ function get_excluded_fields() {
53
+ return apply_filters( 'ysacf_exclude_fields', array() );
54
+ }
55
+ /**
56
+ * Filter what ACF Fields not to score
57
+ * @param field name array
58
+ */
59
+
60
+ function get_field_data($fields) {
61
+
62
+ $values = $this->get_values( $fields );
63
+ $data = '';
64
+
65
+ foreach($fields as $key =>$item) {
66
+
67
+ if(in_array($key, $this->get_excluded_fields()) ){
68
+ continue;
69
+ } else {
70
+ switch(gettype($item)) {
71
+ case 'string':
72
+ if (preg_match('/(\.jpg|\.png|\.bmp)$/', $item)) {
73
+ $data = $data.' <img src="'.$item .'">';
74
+ } else {
75
+ $data = $data.' '.$item;
76
+ }
77
+
78
+ break;
79
+ case 'array':
80
+ if($key == 'sizes') {
81
+ // put all images in img tags for scoring.
82
+ $data = $data.' <img src="'.$item['sizes']['thumbnail'];
83
+ } else {
84
+
85
+ $data = $data.' '.$this->get_field_data($item);
86
+ }
87
+
88
+ break;
89
+ }
90
+ }
91
+ }
92
+
93
+ return $data;
94
+ }
95
+
96
+ function get_values($array) {
97
+ $value_array = array_values($array);
98
+ return $value_array;
99
+ }
100
+
101
+ function ajax_get_fields() {
102
+ $pid = $_POST['postId'];
103
+ $fields = get_fields( $pid );
104
+
105
+ wp_send_json( $this->get_field_data( $fields ) );
106
+ }
107
+
108
+ /**
109
+ * Register and enqueue admin-specific JavaScript.
110
+ *
111
+ * @since 0.1.0
112
+ */
113
+ public function enqueue_admin_scripts() {
114
+ $pid = isset($_GET['post']) ? $_GET['post'] : $post->ID;
115
+ 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);
116
+
117
+ wp_localize_script($this->plugin_slug, 'yoast_acf_settings', array(
118
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
119
+ 'id' => $pid,
120
+ 'ajax_action' => $plugin_slug . '_get_fields'
121
+ ));
122
+
123
+ }
124
+
125
+
126
+ }
127
+
128
+ new AC_Yoast_SEO_ACF_Content_Analysis();
129
+
yoast-seo-plugin.js ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery( document ).ready( function($) {
2
+
3
+
4
+ var fieldData = "";
5
+ YoastSEO_ACF_Content_Analysis = function() {
6
+
7
+ YoastSEO.app.registerPlugin( 'ACF_Content_Analysis', {status: 'loading'} );
8
+
9
+ this.appendACFFields();
10
+
11
+
12
+ }
13
+
14
+ YoastSEO_ACF_Content_Analysis.prototype.appendACFFields = function( ) {
15
+
16
+ var $this = this;
17
+
18
+ $.ajax({
19
+ url: yoast_acf_settings.ajax_url,
20
+ type: 'POST',
21
+ dataType: 'JSON',
22
+ data: {
23
+ postId : yoast_acf_settings.id,
24
+ action: yoast_acf_settings.ajax_action
25
+ }
26
+ })
27
+ .done(function(acf_fields) {
28
+
29
+ $this.setFieldData(acf_fields);
30
+
31
+
32
+ })
33
+ .fail(function() {
34
+ console.log("error");
35
+ })
36
+ .always(function() {
37
+ console.log("complete");
38
+ });
39
+
40
+ };
41
+
42
+ YoastSEO_ACF_Content_Analysis.prototype.setFieldData = function( data ) {
43
+
44
+ YoastSEO.app.pluginReady( 'ACF_Content_Analysis' );
45
+ fieldData = data;
46
+ this.registerModification();
47
+
48
+ };
49
+
50
+ YoastSEO_ACF_Content_Analysis.prototype.getFieldData = function( data ) {
51
+
52
+ return data + ' ' + fieldData;
53
+
54
+ };
55
+
56
+ YoastSEO_ACF_Content_Analysis.prototype.registerModification = function( data ) {
57
+ YoastSEO.app.registerModification( 'content', this.getFieldData, 'ACF_Content_Analysis', 50 );
58
+
59
+ };
60
+
61
+
62
+
63
+ new YoastSEO_ACF_Content_Analysis();
64
+ });