Extension_WordPressSeo_Plugin_Admin.php
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace W3TC;
class Extension_WordPressSeo_Plugin_Admin {
function run() {
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_filter( 'w3tc_extension_plugin_links_wordpress-seo', array( $this, 'remove_settings' ) );
add_action( 'w3tc_activate_extension_wordpress-seo', array( $this, 'activate' ) );
add_action( 'w3tc_deactivate_extension_wordpress-seo', array( $this, 'deactivate' ) );
}
public function admin_init() {
$config = Dispatcher::config();
$groups = $config->get_array( 'mobile.rgroups' );
if ( Util_Environment::is_w3tc_edge( $config ) &&
isset( $groups['google'] ) &&
sizeof( $groups['google']['agents'] ) == 1 &&
$groups['google']['agents'][0] == 'googlebot' ) {
w3tc_delete_user_agent_group( 'google' );
}
}
/**
*
*
* @param unknown $links
* @return mixed
*/
public function remove_settings( $links ) {
array_pop( $links );
return $links;
}
/**
*
*
* @param unknown $extensions
* @param Config $config
* @return mixed
*/
static public function w3tc_extensions( $extensions, $config ) {
$message = array();
if ( !self::criteria_match() )
$message[] = 'Optimizes "Yoast SEO" plugin, which is not active';
$extensions['wordpress-seo'] = array (
'name' => 'Yoast SEO',
'author' => 'W3 EDGE',
'description' => __( 'Configures W3 Total Cache to comply with Yoast SEO requirements automatically.', 'w3-total-cache' ),
'author_uri' => 'https://www.w3-edge.com/',
'extension_uri' => 'https://www.w3-edge.com/',
'extension_id' => 'wordpress-seo',
'settings_exists' => true,
'version' => '0.1',
'enabled' => self::criteria_match(),
'requirements' => implode( ', ', $message ),
'path' => 'w3-total-cache/Extension_WordPressSeo_Plugin.php'
);
return $extensions;
}
/**
* called from outside, since can show notice even when extension is not active
*/
static public function w3tc_extensions_hooks( $hooks ) {
if ( !self::show_notice() )
return $hooks;
if ( !isset( $hooks['filters']['w3tc_notes'] ) )
$hooks['filters']['w3tc_notes'] = array();
$hooks['filters']['w3tc_notes'][] = 'w3tc_notes_wordpress_seo';
return $hooks;
}
static private function show_notice() {
$config = Dispatcher::config();
if ( $config->is_extension_active( 'wordpress-seo' ) )
return false;
if ( !self::criteria_match() )
return false;
$state = Dispatcher::config_state();
if ( $state->get_boolean( 'wordpress_seo.hide_note_suggest_activation' ) )
return false;
return true;
}
static public function w3tc_notes_wordpress_seo( $notes ) {
if ( !self::show_notice() )
return $notes;
$extension_id = 'wordpress-seo';
$notes[$extension_id] = sprintf(
__( 'Activating the <a href="%s">Yoast SEO</a> extension for W3 Total Cache may be helpful for your site. <a class="button" href="%s">Click here</a> to try it. %s',
'w3-total-cache' ),
Util_Ui::admin_url( 'admin.php?page=w3tc_extensions#' . $extension_id ),
Util_Ui::url( array( 'w3tc_extensions_activate' => $extension_id ) ),
Util_Ui::button_link(
__( 'Hide this message', 'w3-total-cache' ),
Util_Ui::url( array(
'w3tc_default_config_state' => 'y',
'key' => 'wordpress_seo.hide_note_suggest_activation',
'value' => 'true' ) ) ) );
return $notes;
}
static private function criteria_match() {
return defined( 'WPSEO_VERSION' );
}
public function activate() {
try {
$config = Dispatcher::config();
$config->set( 'pgcache.prime.enabled', true );
$config->set( 'pgcache.prime.sitemap', '/sitemap_index.xml' );
$config->save();
} catch ( \Exception $ex ) {}
}
public function deactivate() {
try {
$config = Dispatcher::config();
$config->set( 'pgcache.prime.enabled', false );
$config->save();
} catch ( \Exception $ex ) {}
}
}