PluginProbe ʕ •ᴥ•ʔ
SiteSEO – SEO Simplified / 1.3.6
SiteSEO – SEO Simplified v1.3.6
trunk 1.1.5 1.1.6 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9
siteseo / main / advanced.php
siteseo / main Last commit date
metaboxes 5 months ago settings 3 months ago admin.php 5 months ago advanced.php 6 months ago ajax.php 5 months ago columns.php 9 months ago generatesitemap.php 5 months ago googleanalytics.php 9 months ago imageseo.php 8 months ago import.php 5 months ago install.php 8 months ago instantindexing.php 5 months ago primarycategory.php 9 months ago socialmetas.php 5 months ago tableofcontent.php 1 year ago titlesmetas.php 5 months ago
advanced.php
253 lines
1 <?php
2 /*
3 * SITESEO
4 * https://siteseo.io
5 * (c) SiteSEO Team
6 */
7
8 namespace SiteSEO;
9
10 if(!defined('ABSPATH')){
11 die('HACKING ATTEMPT!');
12 }
13
14 class Advanced{
15
16 static function tags(){
17 global $siteseo;
18
19 if(empty($siteseo->setting_enabled['toggle-advanced'])){
20 return; // toggle disable
21 }
22 // meta tags
23 if(!empty($siteseo->advanced_settings['advanced_google'])){
24 echo '<meta name="google-site-verification" content="'.esc_attr($siteseo->advanced_settings['advanced_google']).'" />' . "\n";
25 }
26
27 if(!empty($siteseo->advanced_settings['advanced_bing'])){
28 echo '<meta name="msvalidate.01" content="'.esc_attr($siteseo->advanced_settings['advanced_bing']).'" />' . "\n";
29 }
30
31 if(!empty($siteseo->advanced_settings['advanced_pinterest'])){
32 echo '<meta name="p:domain_verify" content="'.esc_attr($siteseo->advanced_settings['advanced_pinterest']).'" />';
33 }
34
35 if(!empty($siteseo->advanced_settings['advanced_yandex'])){
36 echo '<meta name="yandex-verification" content="'.esc_attr($siteseo->advanced_settings['advanced_yandex']).'" />';
37 }
38
39 if(!empty($siteseo->advanced_settings['advanced_wp_rsd'])){
40 remove_action('wp_head', 'rsd_link');
41 }
42
43 }
44
45 static function remove_links(){
46 global $siteseo;
47
48 if(empty($siteseo->setting_enabled['toggle-advanced'])){
49 return; // toggle disable
50 }
51
52 if(!empty($siteseo->advanced_settings['advanced_wp_rsd'])){
53 remove_action('wp_head', 'rsd_link');
54 }
55
56 if(!empty($siteseo->advanced_settings['advanced_wp_wlw'])){
57 remove_action('wp_head', 'wlwmanifest_link');
58 }
59
60 if(!empty($siteseo->advanced_settings['advanced_wp_shortlink'])){
61 remove_action('wp_head', 'wp_shortlink_wp_head');
62 }
63
64 if(!empty($siteseo->advanced_settings['advanced_wp_generator'])){
65 remove_action('wp_head', 'wp_generator');
66 }
67
68 if(!empty($siteseo->advanced_settings['advanced_comments_form_link'])){
69 add_filter('comment_form_default_fields', '\SiteSEO\Advanced::remove_comment_url_field');
70 }
71
72 if(!empty($siteseo->advanced_settings['advanced_comments_author_url'])){
73 add_filter('get_comment_author_link', '\SiteSEO\Advanced::remove_author_link_if_profile_url');
74 }
75
76 if(!empty($siteseo->advanced_settings['advanced_hentry'])){
77 add_filter('post_class', '\SiteSEO\Advanced::remove_hentry_post_class');
78 }
79
80 if(!empty($siteseo->advanced_settings['advanced_noreferrer'])){
81 add_filter('the_content', '\SiteSEO\Advanced::remove_noreferrer_from_post_content');
82 }
83
84 if(!empty($siteseo->advanced_settings['advanced_tax_desc_editor'])){
85 add_action('edit_term', '\SiteSEO\Advanced::add_wp_editor_to_taxonomy_description', 10, 2);
86 }
87
88 if(!empty($siteseo->advanced_settings['advanced_category_url'])){
89 add_action('init', '\SiteSEO\Advanced::remove_category_base', 111);
90 add_action('template_redirect', '\SiteSEO\Advanced::redirect_category');
91 }
92 }
93
94 static function add_wp_editor_to_taxonomy_description($tag, $tt_id = 0){
95
96 if('edit' !== get_current_screen()->base || 'edit-tags' !== get_current_screen()->id){
97 return;
98 }
99
100 if(isset($tag->description)){
101 $editor_settings = array(
102 'textarea_name' => 'description',
103 'textarea_rows' => 10,
104 'editor_class' => 'wp-editor-area',
105 'media_buttons' => true,
106 'tinymce' => true,
107 'quicktags' => true,
108 );
109
110 wp_editor($tag->description, 'description', $editor_settings);
111 }
112 }
113
114 static function remove_noreferrer_from_post_content($content){
115 $content = preg_replace('/(<a\s+[^>]*rel=["\'][^"\']*?)(\s*\bnoreferrer\b\s*)([^"\']*["\'][^>]*>)/i', '$1$3', $content);
116 return $content;
117 }
118
119 static function remove_hentry_post_class($classes){
120 $classes = array_diff($classes, array('hentry'));
121 return $classes;
122 }
123
124 static function remove_comment_url_field($fields){
125 if(isset($fields['url'])){
126 unset($fields['url']);
127 }
128
129 return $fields;
130 }
131
132 static function remove_author_link_if_profile_url($comment_author_link = '', $comment_author = '', $comment_id = 0){
133 if(empty($comment_id)){
134 return $comment_author;
135 }
136
137 $comment = get_comment($comment_id);
138
139 if(empty($comment) || !is_object($comment)){
140 return $comment_author;
141 }
142
143 $user_id = $comment->user_id;
144
145 if(!empty($user_id)){
146 $user_website = get_the_author_meta('user_url', $user_id);
147
148 if($user_website){
149 return get_comment_author($comment_id);
150 }
151 }
152
153 return $comment_author;
154 }
155
156 static function remove_category_base(){
157
158 $categories = get_categories(array('hide_empty' => false));
159 $category_slugs = wp_list_pluck($categories, 'slug');
160
161 if(empty($category_slugs)){
162 return;
163 }
164
165 $category_pattern = '(' . implode('|', $category_slugs) .')';
166
167 add_rewrite_rule(
168 '^'.$category_pattern.'/?$',
169 'index.php?category_name=$matches[1]',
170 'top'
171 );
172
173 // Add rule for handle pagination
174 add_rewrite_rule(
175 '^'.$category_pattern.'/page/([0-9]+)/?$',
176 'index.php?category_name=$matches[1]&paged=$matches[2]',
177 'top'
178 );
179 }
180
181 static function redirect_category(){
182 if(is_category() && !is_admin()){
183 $category = get_query_var('category_name');
184 $category_base = get_option('category_base');
185 $base_to_check = !empty($category_base) ? $category_base : 'category';
186
187 if(!empty($category) && strpos(sanitize_url($_SERVER['REQUEST_URI']), '/'.$base_to_check.'/') !== false){
188 wp_safe_redirect(home_url('/' . $category . '/'), 301);
189 exit;
190 }
191 }
192 }
193
194 static function remove_wc_category_base(){
195 global $siteseo;
196
197 if(empty($siteseo->advanced_settings['advanced_product_cat_url']) || empty($siteseo->setting_enabled['toggle-advanced'])){
198 return;
199 }
200
201 if(!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))){
202 return;
203 }
204
205 add_filter('term_link', '\SiteSEO\Advanced::remove_category_base_woo', 10, 3);
206 add_filter('request', '\SiteSEO\Advanced::category_url_request');
207 add_action('created_product_cat', 'flush_rewrite_rules');
208 add_action('delete_product_cat', 'flush_rewrite_rules');
209 add_action('edited_product_cat', 'flush_rewrite_rules');
210 add_action('parse_request', '\SiteSEO\Advanced::old_category_url_request');
211
212 }
213
214 static function remove_category_base_woo($termlink, $term, $taxonomy){
215 if($taxonomy === 'product_cat'){
216 $category_base = '/product-category/';
217 return str_replace($category_base, '/', $termlink);
218 }
219
220 return $termlink;
221 }
222
223 static function category_url_request($query_vars){
224 if(!isset($query_vars['product_cat']) && isset($query_vars['pagename'])){
225 $pagename = $query_vars['pagename'];
226 $term = get_term_by('slug', $pagename, 'product_cat');
227
228 if($term){
229 $query_vars['product_cat'] = $term->slug;
230 unset($query_vars['pagename']);
231 }
232 }
233
234 return $query_vars;
235 }
236
237 static function old_category_url_request($wp){
238
239 if(!isset($wp->query_vars['pagename'])){
240 return;
241 }
242
243 $pagename = $wp->query_vars['pagename'];
244 $term = get_term_by('slug', $pagename, 'product_cat');
245
246 if($term){
247 $wp->query_vars['product_cat'] = $term->slug;
248 unset($wp->query_vars['pagename']);
249 }
250
251 }
252 }
253