Integration: Yoast SEO & qTranslate-X - Version 1.1

Version Description

  • Enhancement: multilingual sitemaps, require qTranslate-X 3.4.5: Issue #1.
  • Enhancement: moved to the new integration way using i18n-config.json file. You have to deactivate/activate plugin when updating. Normal WP update would be sufficient, but if you simply override the files, then you will miss the plugin integaration configuration.
  • Enhancement: A few more fields are made multilingual.
  • Fix: "Page Analysis" is disabled unlesss Single Language Editor Mode is in use. "Page Analysis" is not currently integrated in any other Editor Mode.
Download this release

Release Info

Developer johnclause
Plugin Icon wp plugin Integration: Yoast SEO & qTranslate-X
Version 1.1
Comparing to
See all releases

Code changes from version 1.0.2 to 1.1

Files changed (5) hide show
  1. i18n-config.json +45 -0
  2. qwpseo-admin.php +103 -21
  3. qwpseo-front.php +290 -2
  4. readme.txt +30 -4
  5. wordpress-seo-qtranslate-x.php +13 -3
i18n-config.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"vendor":{"plugins/wp-seo-qtranslate-x":"1.0"},
2
+ "admin-config":{
3
+ "post":{
4
+ "pages":{"post.php":"", "post-new.php":""},
5
+ "forms":{
6
+ "post":{
7
+ "fields":{
8
+ "yoast_wpseo_title":{},
9
+ "yoast_wpseo_focuskw":{},
10
+ "yoast_wpseo_metadesc":{"encode":"{"},
11
+ "yoast_wpseo_metakeywords":{},
12
+ "wpseosnippet_title":{"encode":"display"}
13
+ }
14
+ }
15
+ }
16
+ }
17
+ ,
18
+ "edit-tag":{
19
+ "pages":{"edit-tags.php":"action=edit"},
20
+ "forms":{
21
+ "edittag":{
22
+ "fields":{
23
+ "wpseo_title":{},
24
+ "wpseo_desc":{},
25
+ "wpseo_metakey":{},
26
+ "wpseo_canonical":{}
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ ,
33
+ "front-config":{
34
+ "all-pages":{
35
+ "filters":{
36
+ "text":{
37
+ "wpseo_title":"20",
38
+ "wpseo_meta":"20",
39
+ "wpseo_metadesc":"20",
40
+ "wpseo_replacements":"20"
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
qwpseo-admin.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
  if(!defined('ABSPATH'))exit;
3
 
 
4
  add_filter('qtranslate_load_admin_page_config','qwpseo_add_admin_page_config');//obsolete
5
  //add_filter('i18n_admin_config','qwpseo_add_admin_page_config');// should be used instead
6
  function qwpseo_add_admin_page_config($page_configs)
@@ -13,56 +14,137 @@ function qwpseo_add_admin_page_config($page_configs)
13
  $page_config['forms'] = array();
14
 
15
  $f = array();
16
- $f['form'] = array( 'id' => 'post' );//identify the form which input fields described below belong to
17
-
18
  $f['fields'] = array();
19
  $fields = &$f['fields']; // shorthand
20
 
21
- $fields[] = array( 'id' => 'yoast_wpseo_title' );
22
- $fields[] = array( 'id' => 'yoast_wpseo_focuskw' );
23
- $fields[] = array( 'id' => 'yoast_wpseo_metadesc', 'encode' => '{' );
24
- $fields[] = array( 'id' => 'wpseosnippet_title', 'encode' => 'display' );
 
25
 
26
- $page_config['forms'][] = $f;
27
  $page_configs[] = $page_config;
28
  }
29
 
30
  {
31
  $page_config = array();
32
  $page_config['pages'] = array( 'edit-tags.php' => 'action=edit' );
33
- //$page_config['anchors'] = array( 'titlediv' );
34
 
35
  $page_config['forms'] = array();
36
 
37
  $f = array();
38
- $f['form'] = array( 'id' => 'edittag' );//identify the form which input fields described below belong to
39
-
40
  $f['fields'] = array();
41
  $fields = &$f['fields']; // shorthand
42
 
43
- $fields[] = array( 'id' => 'wpseo_title' );
44
- $fields[] = array( 'id' => 'wpseo_desc' );
45
- $fields[] = array( 'id' => 'wpseo_canonical' );
 
46
 
47
- $page_config['forms'][] = $f;
48
  $page_configs[] = $page_config;
49
  }
50
 
51
  return $page_configs;
52
  }
 
53
 
54
  function qwpseo_admin_filters()
55
  {
56
- global $pagenow;
57
- if($pagenow != 'edit.php') return;
58
- //if( strpos($_SERVER['QUERY_STRING'],'post_type=post')===FALSE && strpos($_SERVER['QUERY_STRING'],'post_type=page')===FALSE) return;
59
- add_filter( 'wpseo_title', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage');
60
- add_filter( 'wpseo_meta', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage');
61
- add_filter( 'wpseo_metadesc', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage');
62
- //focus keywords are still not translated
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
  qwpseo_admin_filters();
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  /*
67
  function qwpseo_manage_custom_column($column)
68
  {
1
  <?php
2
  if(!defined('ABSPATH'))exit;
3
 
4
+ /* moved to i18n-config.xml
5
  add_filter('qtranslate_load_admin_page_config','qwpseo_add_admin_page_config');//obsolete
6
  //add_filter('i18n_admin_config','qwpseo_add_admin_page_config');// should be used instead
7
  function qwpseo_add_admin_page_config($page_configs)
14
  $page_config['forms'] = array();
15
 
16
  $f = array();
 
 
17
  $f['fields'] = array();
18
  $fields = &$f['fields']; // shorthand
19
 
20
+ $fields['yoast_wpseo_title'] = array();
21
+ $fields['yoast_wpseo_focuskw'] = array();
22
+ $fields['yoast_wpseo_metadesc'] = array('encode' => '{' );
23
+ $fields['yoast_wpseo_metakeywords'] = array();
24
+ $fields['wpseosnippet_title'] = array('encode' => 'display' );
25
 
26
+ $page_config['forms']['post'] = $f;
27
  $page_configs[] = $page_config;
28
  }
29
 
30
  {
31
  $page_config = array();
32
  $page_config['pages'] = array( 'edit-tags.php' => 'action=edit' );
 
33
 
34
  $page_config['forms'] = array();
35
 
36
  $f = array();
 
 
37
  $f['fields'] = array();
38
  $fields = &$f['fields']; // shorthand
39
 
40
+ $fields['wpseo_title'] = array();
41
+ $fields['wpseo_desc'] = array();
42
+ $fields['wpseo_metakey'] = array();
43
+ $fields['wpseo_canonical'] = array();
44
 
45
+ $page_config['forms']['edittag'] = $f;
46
  $page_configs[] = $page_config;
47
  }
48
 
49
  return $page_configs;
50
  }
51
+ */
52
 
53
  function qwpseo_admin_filters()
54
  {
55
+ global $pagenow, $q_config;
56
+ switch($pagenow){
57
+ case 'edit.php':
58
+ add_filter( 'wpseo_title', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage');
59
+ add_filter( 'wpseo_meta', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage');
60
+ add_filter( 'wpseo_metadesc', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage');
61
+ break;
62
+ case 'post.php':
63
+ case 'post-new.php':
64
+ if($q_config['editor_mode'] == QTX_EDITOR_MODE_SINGLGE){
65
+ add_filter( 'get_post_metadata', 'qwpseo_get_post_metadata', 5, 4);
66
+ //add_filter( 'option_blogname', 'qtranxf_useCurrentLanguageIfNotFoundShowEmpty');
67
+ }
68
+
69
+ //to prevent the effect of 'strip_tags' in function 'retrieve_sitename' in '/wp-content/plugins/wordpress-seo/inc/class-wpseo-replace-vars.php'
70
+ add_filter( 'option_blogname', 'qwpseo_encode_swirly');
71
+ add_filter( 'option_blogdescription', 'qwpseo_encode_swirly');
72
+
73
+ //to make "Page Analysis" work in Single Language Mode
74
+ add_filter( 'wpseo_pre_analysis_post_content', 'qtranxf_useCurrentLanguageIfNotFoundShowEmpty');
75
+ break;
76
+ }
77
  }
78
  qwpseo_admin_filters();
79
 
80
+ function qwpseo_get_post_metadata($original_value, $object_id, $meta_key = '', $single = false)
81
+ {
82
+ global $q_config;
83
+ if(empty($meta_key)){
84
+ //very ugly hack
85
+ $trace = debug_backtrace();
86
+ //qtranxf_dbg_log('qwpseo_get_post_metadata: $trace: ',$trace);
87
+ //qtranxf_dbg_log('qwpseo_get_post_metadata: $trace[6][args][0]: ',$trace[6]['args'][0]);
88
+ //qtranxf_dbg_log('qwpseo_get_post_metadata: $trace[7][function]: ',$trace[7]['function']);
89
+ if( isset($trace[7]['function']) && $trace[7]['function'] === 'calculate_results' &&
90
+ isset($trace[6]['args'][0]) && $trace[6]['args'][0] === 'focuskw'
91
+ ){
92
+ //qtranxf_dbg_log('qwpseo_get_post_metadata: $object_id: ',$object_id);
93
+ //qtranxf_dbg_log('qwpseo_get_post_metadata: $single: ',$single);
94
+ $key = WPSEO_Meta::$meta_prefix . 'focuskw';
95
+ $focuskw = get_metadata('post',$object_id,$key,true);
96
+ //qtranxf_dbg_log('qwpseo_get_post_metadata: $focuskw: ',$focuskw);
97
+ $focuskw = qtranxf_use_language($q_config['language'],$focuskw);
98
+ return array( $key => array($focuskw));
99
+ }
100
+ }
101
+ return $original_value;
102
+ }
103
+
104
+ /**
105
+ * adds single-language sitemap links to the Yoast configuration page for XML Sitemaps.
106
+ */
107
+ function qwpseo_xmlsitemaps_config()
108
+ {
109
+ global $q_config;
110
+ $options = get_option( 'wpseo_xml' );
111
+ //qtranxf_dbg_log('qwpseo_xmlsitemaps_config: $options: ',$options);
112
+ if(empty($options['enablexmlsitemap'])) return;
113
+ printf(__('%sNotes from %s'.PHP_EOL), '<h3>', 'qTranslate&#8209;X</h3>');
114
+ echo '<p>'.PHP_EOL;
115
+ echo __('In addition to main XML Sitemap, you may also view sitemaps for each individual language:').PHP_EOL;
116
+ echo '<ul>'.PHP_EOL;
117
+ $sitemap_index_url = qtranxf_convertURL(get_option('home').'/sitemap_index.xml', $q_config['default_language'], true);
118
+ $url = home_url('i18n-index-sitemap.xml');
119
+ $rb = '';
120
+ foreach($q_config['enabled_languages'] as $lang){
121
+ $href = qtranxf_convertURL($url,$lang,true,true);
122
+ $u = $q_config['default_language'] == $lang ? qtranxf_convertURL($url,$lang,true,false) : $href;
123
+ echo '<li>'.$q_config['language_name'][$lang].' ('.$lang.', '.$q_config['locale'][$lang].'): <a href="'.$href.'" target="_blank">'.$u.'</a></li>'.PHP_EOL;
124
+ $rb .= 'Sitemap: '.$u.PHP_EOL;
125
+ }
126
+ echo '</ul><br />'.PHP_EOL;
127
+ printf(__('It is advisable to append the site\'s "%s" with the list of index sitemaps separated by language'),'/robots.txt');
128
+ $nmaps = count($q_config['enabled_languages'])+1;
129
+ echo '<br /><textarea class="widefat" rows="'.$nmaps.'" name="robots-sitemaps" readonly="readonly">'.$rb.'</textarea>'.PHP_EOL;
130
+ //echo '<pre>'.$rb.'</pre>'.PHP_EOL;
131
+ echo '<br />or with this single entry of flat multilingual index sitemap<br /><textarea class="widefat" rows="2" name="robots-sitemap" readonly="readonly">Sitemap: '.$sitemap_index_url.'</textarea>'.PHP_EOL;
132
+ echo '<br />Do not combine two sets together, since they both equally cover all languages in all pages as defined by Yoast configuration.';
133
+ echo '</p>'.PHP_EOL;
134
+ }
135
+ add_action( 'wpseo_xmlsitemaps_config', 'qwpseo_xmlsitemaps_config' );
136
+
137
+ /**
138
+ * Change encoding of $value to swirly breckets, '{'.
139
+ * @since 1.1
140
+ */
141
+ function qwpseo_encode_swirly($value)
142
+ {
143
+ //qtranxf_dbg_log('qwpseo_encode_swirly: $value: ',$value);
144
+ $value = preg_replace('#\[:([a-z]{2}|)\]#i','{:$1}',$value);
145
+ return $value;
146
+ }
147
+
148
  /*
149
  function qwpseo_manage_custom_column($column)
150
  {
qwpseo-front.php CHANGED
@@ -1,12 +1,16 @@
1
  <?php
2
  if(!defined('ABSPATH'))exit;
3
 
 
4
  function qwpseo_add_filters_front() {
5
  $use_filters = array(
 
 
 
6
  'wpseo_title' => 20,
7
  'wpseo_meta' => 20,
8
  'wpseo_metadesc' => 20,
9
- 'wpseo_replacements' => 20,
10
  );
11
 
12
  foreach ( $use_filters as $name => $priority ) {
@@ -14,5 +18,289 @@ function qwpseo_add_filters_front() {
14
  }
15
  }
16
  qwpseo_add_filters_front();
 
17
 
18
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  if(!defined('ABSPATH'))exit;
3
 
4
+ /* moved to i18n-config.json
5
  function qwpseo_add_filters_front() {
6
  $use_filters = array(
7
+ //'wpseo_opengraph_title' => 20,//comes already translated
8
+ //'wpseo_metakey' => 20, //deprecated
9
+ //'wpseo_metakeywords' => 20,//comes already translated
10
  'wpseo_title' => 20,
11
  'wpseo_meta' => 20,
12
  'wpseo_metadesc' => 20,
13
+ 'wpseo_replacements' => 20
14
  );
15
 
16
  foreach ( $use_filters as $name => $priority ) {
18
  }
19
  }
20
  qwpseo_add_filters_front();
21
+ */
22
 
23
+ // sitemaps handling
24
+ /**
25
+ * Remove duplicated images and translates image attributes.
26
+ * @since 1.0.3
27
+ */
28
+ function qwpseo_sitemap_urlimages( $images, $id )
29
+ {
30
+ global $q_config;
31
+ $lang = $q_config['language'];
32
+ //qtranxf_dbg_log('qwpseo_sitemap_urlimages('.$id.'): $images: ',$images);
33
+ $srcs = array();
34
+ foreach($images as $k => $image){
35
+ $src = $image['src'];
36
+ if(isset($srcs[$src])){
37
+ unset($images[$k]);
38
+ }else{
39
+ $srcs[$src] = $image;
40
+ foreach($image as $p => $txt){
41
+ if($p == 'src') continue;
42
+ $images[$k][$p] = qtranxf_use($lang,$txt,false,true);
43
+ }
44
+ }
45
+ }
46
+ return $images;
47
+ }
48
+ add_filter( 'wpseo_sitemap_urlimages', 'qwpseo_sitemap_urlimages', 999, 2);
49
+
50
+ /**
51
+ * Generate top level index for hierarchical sitemaps.
52
+ * @since 1.0.3
53
+ *
54
+ function qwpseo_sitemap_index( $sm )
55
+ {
56
+ global $q_config, $wpseo_sitemaps;
57
+ if(isset($q_config['sitemap-type'])) return '';
58
+ //qtranxf_dbg_log('qwpseo_sitemap_index: $wpseo_sitemaps: ', $wpseo_sitemaps);
59
+ ob_start();
60
+ $wpseo_sitemaps->output();
61
+ $content = ob_get_contents();
62
+ ob_end_clean();
63
+ //qtranxf_dbg_log('qwpseo_sitemap_index: $content: ', $content);
64
+ $matches;
65
+ $lastmod = '';
66
+ $p = 0;
67
+ $sitemaps = array();
68
+ while(($p = strpos($content,'<sitemap>',$p))!==false){
69
+ if(($e = strpos($content,'</sitemap>',$p)) !== false){
70
+ $len = $e - $p + strlen('</sitemap>');
71
+ $s = substr($content, $p, $len);
72
+ //qtranxf_dbg_log('qwpseo_sitemap_index: $s: ', $s);
73
+ $p += $len;
74
+ $sitemaps[] = $s;
75
+ if(preg_match('!<lastmod>\\s*([^\\s<]+)\\s*</lastmod>!s',$s,$matches)){
76
+ if(empty($lastmod) || strcmp($lastmod,$matches[1])<0) $lastmod = $matches[1];
77
+ }
78
+ }else{
79
+ $p += strlen('<sitemap>');
80
+ }
81
+ }
82
+ if(preg_match('/<sitemapindex[^>]*>/',$content,$matches))
83
+ $sm = $matches[0];
84
+ else
85
+ $sm = '';
86
+ //qtranxf_dbg_log('qwpseo_sitemap_index: $sitemapindex: ', $sm);
87
+ $wpseo_sitemaps->set_sitemap($sm);
88
+ $url = home_url('i18n-index-sitemap.xml');
89
+ $sm = '';
90
+ foreach($q_config['enabled_languages'] as $lang){
91
+ $sm .= '<sitemap>'.PHP_EOL;
92
+ $sm .= '<loc>'.esc_url(qtranxf_convertURL($url,$lang,true,true)).'</loc>'.PHP_EOL;
93
+ if(!empty($lastmod)) $sm .= '<lastmod>'.$lastmod.'</lastmod>'.PHP_EOL;
94
+ $sm .= '</sitemap>'.PHP_EOL;
95
+ }
96
+ //qtranxf_dbg_log('qwpseo_sitemap_index: $sm: ', $sm);
97
+ return $sm;
98
+ } //*/
99
+
100
+ /*
101
+ * Adds other language sitemaps to the sitemap_index.xml
102
+ * @since 1.0.3
103
+ */
104
+ function qwpseo_sitemap_index( $sm )
105
+ {
106
+ global $q_config, $wpseo_sitemaps;
107
+ if(isset($q_config['sitemap-type'])){
108
+ return;
109
+ }
110
+ //qtranxf_dbg_log('qwpseo_sitemap_index: $wpseo_sitemaps: ', $wpseo_sitemaps);
111
+ ob_start();
112
+ $wpseo_sitemaps->output();
113
+ $content = ob_get_contents();
114
+ ob_end_clean();
115
+ //qtranxf_dbg_log('qwpseo_sitemap_index: $content: ', $content);
116
+ $p = 0;
117
+ $sitemaps = array();
118
+ while(($p = strpos($content,'<sitemap>',$p))!==false){
119
+ if(($e = strpos($content,'</sitemap>',$p)) !== false){
120
+ $len = $e - $p + strlen('</sitemap>');
121
+ $s = substr($content, $p, $len);
122
+ //qtranxf_dbg_log('qwpseo_sitemap_index: $s: ', $s);
123
+ $p += $len;
124
+ $sitemaps[] = $s;
125
+ }else{
126
+ $p += strlen('<sitemap>');
127
+ }
128
+ }
129
+ $sm = '';
130
+ foreach($q_config['enabled_languages'] as $lang){
131
+ //if($lang == $q_config['default_language']) continue;
132
+ if($lang == $q_config['language']) continue;
133
+ //$sm .= preg_replace('!<loc>(.*)/([^/]+)</loc>!','<loc>$1/'.$lang.'-$2</loc>',$s);
134
+ foreach($sitemaps as $s){
135
+ if(preg_match('!<loc>([^<]+)</loc>!',$s,$matches)){
136
+ $loc = $matches[1];
137
+ $sm .= preg_replace('!<loc>([^<]+)</loc>!','<loc>'.qtranxf_convertURL($loc,$lang).'</loc>',$s);
138
+ }
139
+ }
140
+ }
141
+ //qtranxf_dbg_log('qwpseo_sitemap_index: $sm: ', $sm);
142
+ return $sm;
143
+ }
144
+ add_filter( 'wpseo_sitemap_index', 'qwpseo_sitemap_index');
145
+
146
+ /**
147
+ * Translates $p->post_content to make image lookup work correctly later.
148
+ */
149
+ function qwpseo_enable_xml_sitemap_post_url( $loc, $p ){
150
+ global $q_config;
151
+ $lang = $q_config['language'];
152
+ //qtranxf_dbg_log('qwpseo_enable_xml_sitemap_post_url: $sm: ', $p);
153
+ $p->post_content = qtranxf_use_language($lang,$p->post_content,false,true);
154
+ return $loc;
155
+ }
156
+ add_filter( 'wpseo_xml_sitemap_post_url', 'qwpseo_enable_xml_sitemap_post_url', 5, 2);
157
+
158
+ /**
159
+ * Has to be disabled for now, unless we ask Yoast to add a filter to alter cache key name depending on active language.
160
+ * @since 1.0.3
161
+ */
162
+ function qwpseo_enable_xml_sitemap_transient_caching( $caching ){ return false; }
163
+ add_filter( 'wpseo_enable_xml_sitemap_transient_caching', 'qwpseo_enable_xml_sitemap_transient_caching' );
164
+
165
+ /**
166
+ *
167
+ * @since 1.0.3
168
+ */
169
+ function qwpseo_build_sitemap_post_type( $type )
170
+ {
171
+ //qtranxf_dbg_log('qwpseo_build_sitemap_post_type: $type: ', $type);
172
+ switch($type){
173
+ case 'i18n-index':
174
+ global $q_config;
175
+ //root map for single language
176
+ $q_config['sitemap-type'] = $type;
177
+ return '1';
178
+ //case '1': return $type;
179
+ }
180
+ return $type;
181
+ }
182
+ add_filter( 'wpseo_build_sitemap_post_type', 'qwpseo_build_sitemap_post_type', 5);
183
+
184
+ /**
185
+ * Change XLS stylesheet URL.
186
+ * @since 1.1
187
+ */
188
+ function qwpseo_stylesheet_url( $stylesheet )
189
+ {
190
+ if(isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'],'sitemap_index.xml') !== false){
191
+ $pefix = 'index-';
192
+ }elseif(isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'],'i18n-index-sitemap') !== false){
193
+ $pefix = 'qtx-';
194
+ }else{
195
+ $pefix = 'qwp-';
196
+ }
197
+ $stylesheet = str_replace('main-', $pefix, $stylesheet);
198
+ return $stylesheet;
199
+ }
200
+ add_filter('wpseo_stylesheet_url', 'qwpseo_stylesheet_url');
201
+
202
+ function qwpseo_xsl_heading($buffer)
203
+ {
204
+ $buffer = str_replace(', this is an XML Sitemap', ' and <a href="https://wordpress.org/plugins/wp-seo-qtranslate-x/">qTranslate&#8209;X</a><xsl:text> </xsl:text><a href="https://qtranslatexteam.wordpress.com/about/">Team</a>, this is an XML Sitemap', $buffer);
205
+ $buffer = str_replace('</a> <a ', '</a><xsl:text> </xsl:text><a ', $buffer);
206
+ return $buffer;
207
+ }
208
+
209
+ function qwpseo_xsl_language($buffer)
210
+ {
211
+ global $q_config;
212
+ $lang = $q_config['language'];
213
+ $buffer = str_replace(', this is an XML Sitemap', ', this is an XML Sitemap of "'.$q_config['language_name'][$lang].'" content', $buffer);
214
+ return $buffer;
215
+ }
216
+
217
+ function qwpseo_xsl_callback_idx($buffer)
218
+ {
219
+ $buffer = str_replace(', this is an XML Sitemap', ', this is an XML Sitemap of multilingual content', $buffer);
220
+ return qwpseo_xsl_heading($buffer);
221
+ }
222
+
223
+ function qwpseo_xsl_callback_qwp($buffer)
224
+ {
225
+ $buffer = qwpseo_xsl_language($buffer);
226
+ return qwpseo_xsl_heading($buffer);
227
+ }
228
+
229
+ function qwpseo_xsl_callback_qtx($buffer)
230
+ {
231
+ $buffer = str_replace('sitemap_index.xml', 'i18n-index-sitemap.xml', $buffer);
232
+ $buffer = qwpseo_xsl_language($buffer);
233
+ return qwpseo_xsl_heading($buffer);
234
+ }
235
+
236
+ /**
237
+ * Output 'qwpseo-sitemap.xsl' based on the output of function 'xsl_output' in /wp-content/plugins/wordpress-seo/inc/class-sitemaps.php.
238
+ * @since 1.1
239
+ */
240
+ function qwpseo_xsl_i18n($callback)
241
+ {
242
+ global $wpseo_sitemaps;
243
+ ob_start($callback);
244
+ $wpseo_sitemaps->xsl_output('main');
245
+ ob_end_flush();
246
+ }
247
+
248
+ function qwpseo_xsl_idx($callback){ qwpseo_xsl_i18n('qwpseo_xsl_callback_idx'); }
249
+ add_action('wpseo_xsl_index', 'qwpseo_xsl_idx', 20);
250
+
251
+ function qwpseo_xsl_qwp($callback){ qwpseo_xsl_i18n('qwpseo_xsl_callback_qwp'); }
252
+ add_action('wpseo_xsl_qwp', 'qwpseo_xsl_qwp', 20);
253
+
254
+ function qwpseo_xsl_qtx($callback){ qwpseo_xsl_i18n('qwpseo_xsl_callback_qtx'); }
255
+ add_action('wpseo_xsl_qtx', 'qwpseo_xsl_qtx', 20);
256
+
257
+ /*
258
+ function qwpseo_register_xsl_i18n()
259
+ {
260
+ //qtranxf_dbg_log('qwpseo_register_xsl_i18n:');
261
+ //qtranxf_dbg_log('qwpseo_register_xsl_i18n: $_SERVER[HTTP_REFERER]: ', $_SERVER['HTTP_REFERER']);
262
+ global $wpseo_sitemaps;
263
+ $wpseo_sitemaps->register_xsl('i18n','qwpseo_xsl_i18n',true);
264
+ }
265
+ //add_action('init', 'qwpseo_register_xsl_i18n', 30);
266
+
267
+ $wpseo_sitemaps->set_stylesheet('');
268
+
269
+ function qwpseo_sitemap_entry( $url, $post_type, $p )
270
+ {
271
+ //qtranxf_dbg_log('qwpseo_sitemap_entry: $post_type: '.$post_type.'; $url: ', $url);
272
+ global $q_config;
273
+ //qtranxf_dbg_log('qwpseo_sitemap_entry: $p: ', $p);
274
+ $urls = array();
275
+ foreach($q_config['enabled_languages'] as $lang){
276
+ $urls[$lang] = $url;
277
+ $urls[$lang]['loc'] = qtranxf_convertURL($url['loc'],$lang);
278
+ if(isset($url['images'])){
279
+ foreach($url['images'] as $k => $img){
280
+ foreach($img as $p => $txt){
281
+ if($p == 'src') continue;
282
+ $urls[$lang]['images'][$k][$p] = qtranxf_use($lang,$txt,false,true);
283
+ }
284
+ }
285
+ }
286
+ }
287
+ //qtranxf_dbg_log('qwpseo_sitemap_entry: $urls: ', $urls);
288
+ $url['urls'] = $urls;
289
+ return $url;
290
+ }
291
+ //add_filter( 'wpseo_sitemap_entry', 'qwpseo_sitemap_entry', 999, 3 );
292
+
293
+ function qwpseo_test_filter( $arg )
294
+ {
295
+ //qtranxf_dbg_log('qwpseo_test_filter: $arg: ', $arg);
296
+ return $arg;
297
+ }
298
+ add_filter( 'wpseo_opengraph_title', 'qwpseo_test_filter');
299
+ add_filter( 'wpseo_metakeywords', 'qwpseo_test_filter');
300
+ add_filter( 'wpseo_title', 'qwpseo_test_filter');
301
+ add_filter( 'wpseo_meta', 'qwpseo_test_filter');
302
+ add_filter( 'wpseo_metadesc', 'qwpseo_test_filter');
303
+ add_filter( 'wpseo_replacements', 'qwpseo_test_filter');
304
+
305
+ // "js-exec":{"wp-seo-post-exec":{"src":"./js/post-exec.min.js"}}
306
+ */
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: johnclause
4
  Tags: multilingual, language, bilingual, i18n, l10n, multilanguage, translation, Yoast SEO
5
  Requires at least: 4.0
6
  Tested up to: 4.4
7
- Stable tag: 1.0.2
8
  License: GPLv3 or later
9
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QEXEK3HX8AR6U
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -15,14 +15,18 @@ Enables multilingual framework for plugin "Yoast SEO".
15
 
16
  Enables [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/) multilingual framework for plugin [Yoast SEO](https://wordpress.org/plugins/wordpress-seo/).
17
 
18
- At least version 3.4 of [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/) is required.
19
 
20
  This plugin is currently a work in progress, please review the [Known Issues](https://wordpress.org/plugins/wp-seo-qtranslate-x/other_notes/) and report the features, which did not work for you.
21
 
 
 
22
  == Installation ==
23
 
24
  Standard, as any other normal plugin hosted at WordPress.
25
 
 
 
26
  == Screenshots ==
27
 
28
  Plugin does not have any configuration options, and no screenshots needed.
@@ -33,12 +37,32 @@ Plugin does not have any configuration options, and no screenshots needed.
33
 
34
  Plugin does not have any configuration options, simply activate it and it will enable the translation of relevant fields for Yoast SEO back- and front-end.
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  == Upgrade Notice ==
37
 
38
- No need for Upgrade Notice.
39
 
40
  == Changelog ==
41
 
 
 
 
 
 
 
42
  = 1.0.2 =
43
  * Improvement: encoding of `yoast_wpseo_metadesc` and `yoast_wpseo_focuskw` is changed to '{' to deal with imperfections of Yoast java script.
44
 
@@ -50,5 +74,7 @@ No need for Upgrade Notice.
50
 
51
  == Known Issues ==
52
 
53
- * Yoast SEO Page Analysis does not work correctly.
 
54
  * [Resolved in plugin version 1.0.2 under qTranslate-X 3.4.4] Field 'Meta description' is not coming back correctly after saving. In some configurations it works though. The nature of conflict is not yet known. You would need to keep this field empty, if you are affected.
 
4
  Tags: multilingual, language, bilingual, i18n, l10n, multilanguage, translation, Yoast SEO
5
  Requires at least: 4.0
6
  Tested up to: 4.4
7
+ Stable tag: 1.1
8
  License: GPLv3 or later
9
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QEXEK3HX8AR6U
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
15
 
16
  Enables [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/) multilingual framework for plugin [Yoast SEO](https://wordpress.org/plugins/wordpress-seo/).
17
 
18
+ At least version 3.4.5 of [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/) is required.
19
 
20
  This plugin is currently a work in progress, please review the [Known Issues](https://wordpress.org/plugins/wp-seo-qtranslate-x/other_notes/) and report the features, which did not work for you.
21
 
22
+ The biggest issue is that "Page Analysis" has not yet been fully integarated, and it is disabled unless Single Language Editor Mode is in use, which can be set on "Advanced" tab of "Languages" configuration page: `/wp-admin/options-general.php?page=qtranslate-x#advanced`. If you have time and resources, please feel free to submit pool request to the plugin [repository at GitHub](https://github.com/qTranslate-Team/wp-seo-qtranslate-x/pulls) with the implementation of "Page Analysis" for other editor modes. However, it may not be possible without asking Yoast to put a few additional filters within ["Yoast SEO" plugin code](https://github.com/Yoast/wordpress-seo).
23
+
24
  == Installation ==
25
 
26
  Standard, as any other normal plugin hosted at WordPress.
27
 
28
+ Remeber to set "URL Modification Mode" in qTranslate-X configuration page `/wp-admin/options-general.php?page=qtranslate-x#general` to any mode other then "Query Mode", since "Query Mode" does not make much sense for SEO.
29
+
30
  == Screenshots ==
31
 
32
  Plugin does not have any configuration options, and no screenshots needed.
37
 
38
  Plugin does not have any configuration options, simply activate it and it will enable the translation of relevant fields for Yoast SEO back- and front-end.
39
 
40
+ = Why "Page Analysis" are disabled? =
41
+
42
+ Yoast SEO "Page Analysis" is not yet integrated and is mostly disabled to prevent confusions. It is only experimentally enabled in Single Language Editor Mode, which can be set on "Advanced" tab of "Languages" configuration page, `/wp-admin/options-general.php?page=qtranslate-x#advanced`.
43
+
44
+ If you have time and resources, please feel free to submit pool request to the plugin [repository at GitHub](https://github.com/qTranslate-Team/wp-seo-qtranslate-x/pulls) with the implementation of "Page Analysis" for other editor modes. Unfortunately, it may not be possible without asking Yoast to put a few additional filters within "Yoast SEO" plugin code.
45
+
46
+ = Sitemaps suddenly stopped working showing 404 page? =
47
+
48
+ Most likely you deactivated "Yoast SEO" plugin and then activated it again. When XML Sitemaps are enabled on Yoast "XML Sitemaps" configuration page `/wp-admin/admin.php?page=wpseo_xml` and Yoast plugin is deactivated, it clears rewrite rules needed for sitemap to function. On next activation of Yoast plugin, sitemaps no longer function until their functionality is deactivated and then activated again on Yoast configuration page "XML Sitemaps".
49
+
50
+ = Something does not work right, is it me? =
51
+
52
+ Please, review section "[Known Issues](https://wordpress.org/plugins/wp-seo-qtranslate-x/other_notes/)".
53
+
54
  == Upgrade Notice ==
55
 
56
+ No need for an Upgrade Notice.
57
 
58
  == Changelog ==
59
 
60
+ = 1.1 =
61
+ * Enhancement: multilingual sitemaps, require qTranslate-X 3.4.5: [Issue #1](https://github.com/qTranslate-Team/wp-seo-qtranslate-x/issues/1).
62
+ * Enhancement: moved to the new [integration](https://qtranslatexteam.wordpress.com/integration/) way using i18n-config.json file. You have to deactivate/activate plugin when updating. Normal WP update would be sufficient, but if you simply override the files, then you will miss the plugin integaration configuration.
63
+ * Enhancement: A few more fields are made multilingual.
64
+ * Fix: "Page Analysis" is disabled unlesss Single Language Editor Mode is in use. "Page Analysis" is not currently integrated in any other Editor Mode.
65
+
66
  = 1.0.2 =
67
  * Improvement: encoding of `yoast_wpseo_metadesc` and `yoast_wpseo_focuskw` is changed to '{' to deal with imperfections of Yoast java script.
68
 
74
 
75
  == Known Issues ==
76
 
77
+ * Yoast SEO "Page Analysis" is not yet integrated and is mostly disabled to prevent confusions. It is only experimentally enabled in Single Language Editor Mode, which can be set on "Advanced" tab of "Languages" configuration page, `/wp-admin/options-general.php?page=qtranslate-x#advanced`. If you have time and resources, please feel free to submit pool request to the plugin [repository at GitHub](https://github.com/qTranslate-Team/wp-seo-qtranslate-x/pulls) with the implementation of "Page Analysis" for other editor modes. Unfortunately, it may not be possible without asking Yoast to put a few additional filters within "Yoast SEO" plugin code.
78
+ * [plugin Yoast SEO issue] When XML Sitemaps are enabled on Yoast configuration page `/wp-admin/admin.php?page=wpseo_xml` and Yoast plugin is deactivated, it clears rewrite rules needed for sitemap to function. On next activation of Yoast plugin, sitemaps no longer function until their functionality is deactivated and then activated again on Yoast configuration page "XML Sitemaps".
79
  * [Resolved in plugin version 1.0.2 under qTranslate-X 3.4.4] Field 'Meta description' is not coming back correctly after saving. In some configurations it works though. The nature of conflict is not yet known. You would need to keep this field empty, if you are affected.
80
+ * [not really an issue] Sitemaps do not work quite right in Query URL Modification Mode. Query Mode is not supposed to be used for SEO.
wordpress-seo-qtranslate-x.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Yoast SEO & qTranslate-X
4
  * Plugin URI: https://wordpress.org/plugins/wp-seo-qtranslate-x/
5
  * Description: Enables multilingual framework for plugin "Yoast SEO".
6
- * Version: 1.0.2
7
  * Author: qTranslate Team
8
  * Author URI: http://qtranslatexteam.wordpress.com/about
9
  * License: GPL2
@@ -14,16 +14,26 @@
14
  */
15
  if(!defined('ABSPATH'))exit;
16
 
17
- define('QWPSEO_VERSION','1.0.2');
18
 
19
  function qwpseo_init_language($url_info)
20
  {
 
21
  if($url_info['doing_front_end']) {
 
22
  require_once(dirname(__FILE__)."/qwpseo-front.php");
23
  }else{
 
 
 
 
24
  require_once(dirname(__FILE__)."/qwpseo-admin.php");
25
  }
26
  }
27
  add_action('qtranslate_init_language','qwpseo_init_language');
28
 
29
- ?>
 
 
 
 
3
  * Plugin Name: Yoast SEO & qTranslate-X
4
  * Plugin URI: https://wordpress.org/plugins/wp-seo-qtranslate-x/
5
  * Description: Enables multilingual framework for plugin "Yoast SEO".
6
+ * Version: 1.1
7
  * Author: qTranslate Team
8
  * Author URI: http://qtranslatexteam.wordpress.com/about
9
  * License: GPL2
14
  */
15
  if(!defined('ABSPATH'))exit;
16
 
17
+ define('QWPSEO_VERSION','1.1');
18
 
19
  function qwpseo_init_language($url_info)
20
  {
21
+ global $q_config;
22
  if($url_info['doing_front_end']) {
23
+ add_filter( 'wpseo_use_page_analysis', 'qwpseo_no_page_analysis' );
24
  require_once(dirname(__FILE__)."/qwpseo-front.php");
25
  }else{
26
+ if($q_config['editor_mode'] != QTX_EDITOR_MODE_SINGLGE){
27
+ //Disable "Page Analysis" unless Single Language Editor Mode is in use.
28
+ add_filter( 'wpseo_use_page_analysis', 'qwpseo_no_page_analysis' );
29
+ }
30
  require_once(dirname(__FILE__)."/qwpseo-admin.php");
31
  }
32
  }
33
  add_action('qtranslate_init_language','qwpseo_init_language');
34
 
35
+ /**
36
+ * Disable "Page Analysis".
37
+ */
38
+ function qwpseo_no_page_analysis($a){ return false; }
39
+ //add_filter( 'wpseo_use_page_analysis', 'qwpseo_no_page_analysis' );