wordproof-integration-toggle.php
4.65 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
namespace Yoast\WP\SEO\Integrations\Third_Party;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Helpers\Wordproof_Helper;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast_Feature_Toggle;
/**
* Class WordProofIntegrationToggle.
*
* @package Yoast\WP\SEO\Integrations\Third_Party
*/
class Wordproof_Integration_Toggle implements Integration_Interface {
/**
* The WordProof helper instance.
*
* @var Wordproof_Helper
*/
protected $wordproof;
/**
* The WordProof integration toggle constructor.
*
* @param Wordproof_Helper $wordproof The WordProof helper instance.
*/
public function __construct( Wordproof_Helper $wordproof ) {
$this->wordproof = $wordproof;
}
/**
* Returns the conditionals based in which this loadable should be active.
*
* @return array
*/
public static function get_conditionals() {
return [ Admin_Conditional::class ];
}
/**
* Initializes the integration.
*
* This is the place to register hooks and filters.
*
* @return void
*/
public function register_hooks() {
/**
* Called by Yoast_Integration_Toggles to add extra toggles to the ones defined there.
*/
\add_filter( 'wpseo_integration_toggles', [ $this, 'add_integration_toggle' ] );
/**
* Update the default wordproof_integration_active depending if the integration is disabled or not.
*/
\add_filter( 'wpseo_option_wpseo_defaults', [ $this, 'default_values' ] );
/**
* Add extra text after the network integration toggle if the toggle is disabled.
*/
\add_action( 'Yoast\WP\SEO\admin_network_integration_after', [ $this, 'after_network_integration_toggle' ] );
}
/**
* Adds the WordProof integration toggle to the array.
*
* @param array $integration_toggles The integration toggles array.
*
* @return array The updated integration toggles array.
*/
public function add_integration_toggle( $integration_toggles ) {
if ( \is_array( $integration_toggles ) ) {
$integration_toggles[] = (object) [
/* translators: %s expands to WordProof */
'name' => \sprintf( \__( '%s integration', 'wordpress-seo' ), 'WordProof' ),
'setting' => 'wordproof_integration_active',
'label' => \sprintf(
/* translators: %s expands to WordProof */
\__( '%1$s can be used to timestamp your privacy page.', 'wordpress-seo' ),
'WordProof'
),
/* translators: %s expands to WordProof */
'read_more_label' => \sprintf( \__( 'Read more about how %s works.', 'wordpress-seo' ), 'WordProof ' ),
'read_more_url' => 'https://yoa.st/wordproof-integration',
'order' => 16,
'disabled' => $this->wordproof->integration_is_disabled(),
'new' => true,
];
}
return $integration_toggles;
}
/**
* Set the default WordProof integration option value depending if the integration is disabled or not.
*
* @param array $defaults Array containing default wpseo options.
*
* @return array
*/
public function default_values( $defaults ) {
if ( $this->wordproof->integration_is_disabled() ) {
$defaults['wordproof_integration_active'] = false;
}
return $defaults;
}
/**
* Add an explainer when the integration toggle is disabled.
*
* @deprecated 20.3
* @codeCoverageIgnore
*
* @param Yoast_Feature_Toggle $integration The integration toggle class.
*/
public function after_integration_toggle( $integration ) {
\_deprecated_function( __METHOD__, 'Yoast SEO 20.3' );
if ( $integration->setting === 'wordproof_integration_active' ) {
if ( $integration->disabled ) {
$conditional = $this->wordproof->integration_is_disabled( true );
if ( $conditional === 'Non_Multisite_Conditional' ) {
echo '<p>' . \sprintf(
/* translators: %s expands to WordProof */
\esc_html__( 'Currently, the %s integration is not available for multisites.', 'wordpress-seo' ),
'WordProof'
) . '</p>';
}
if ( $conditional === 'Wordproof_Plugin_Inactive_Conditional' ) {
echo '<p>' . \esc_html__( 'The WordProof Timestamp plugin needs to be disabled before you can activate this integration.', 'wordpress-seo' ) . '</p>';
}
}
}
}
/**
* Add an explainer when the network integration toggle is disabled.
*
* @param Yoast_Feature_Toggle $integration The integration toggle class.
*/
public function after_network_integration_toggle( $integration ) {
if ( $integration->setting === 'wordproof_integration_active' ) {
if ( $integration->disabled ) {
echo '<p>' . \sprintf(
/* translators: %s expands to WordProof */
\esc_html__( 'Currently, the %s integration is not available for multisites.', 'wordpress-seo' ),
'WordProof'
) . '</p>';
}
}
}
}