• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 6638054992

25 Oct 2023 08:55AM UTC coverage: 49.106%. First build
6638054992

Pull #20653

github

vraja-pro
Merge remote-tracking branch 'origin/feature/upgrade-react-and-tests' into feature/upgrade-react-and-tests
Pull Request #20653: Feature/upgrade react and tests

64 of 157 new or added lines in 34 files covered. (40.76%)

13135 of 26748 relevant lines covered (49.11%)

3.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/integrations/third-party/wordproof.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations\Third_Party;
4

5
use WPSEO_Admin_Asset;
6
use WPSEO_Admin_Asset_Manager;
7
use Yoast\WP\SEO\Conditionals\Non_Multisite_Conditional;
8
use Yoast\WP\SEO\Conditionals\Third_Party\Wordproof_Integration_Active_Conditional;
9
use Yoast\WP\SEO\Conditionals\Third_Party\Wordproof_Plugin_Inactive_Conditional;
10
use Yoast\WP\SEO\Config\Wordproof_App_Config;
11
use Yoast\WP\SEO\Config\Wordproof_Translations;
12
use Yoast\WP\SEO\Helpers\Wordproof_Helper;
13
use Yoast\WP\SEO\Integrations\Integration_Interface;
14
use YoastSEO_Vendor\WordProof\SDK\Helpers\CertificateHelper;
15
use YoastSEO_Vendor\WordProof\SDK\Helpers\PostMetaHelper;
16
use YoastSEO_Vendor\WordProof\SDK\WordPressSDK;
17

18
/**
19
 * Class WordProof
20
 *
21
 * @package Yoast\WP\SEO\Integrations\Third_Party
22
 */
23
class Wordproof implements Integration_Interface {
24

25
        /**
26
         * The Yoast meta key used to save if a post shiould be timestamped.
27
         *
28
         * @var string
29
         */
30
        protected $post_meta_key = '_yoast_wpseo_wordproof_timestamp';
31

32
        /**
33
         * The WordProof helper instance.
34
         *
35
         * @var Wordproof_Helper
36
         */
37
        protected $wordproof;
38

39
        /**
40
         * Asset manager instance.
41
         *
42
         * @var WPSEO_Admin_Asset_Manager
43
         */
44
        protected $asset_manager;
45

46
        /**
47
         * The WordProof integration constructor.
48
         *
49
         * @param Wordproof_Helper          $wordproof     The WordProof helper instance.
50
         * @param WPSEO_Admin_Asset_Manager $asset_manager The WPSEO admin asset manager instance.
51
         */
52
        public function __construct( Wordproof_Helper $wordproof, WPSEO_Admin_Asset_Manager $asset_manager = null ) {
53
                if ( ! $asset_manager ) {
×
54
                        $asset_manager = new WPSEO_Admin_Asset_Manager();
×
55
                }
56

57
                $this->asset_manager = $asset_manager;
×
58
                $this->wordproof     = $wordproof;
×
59
        }
60

61
        /**
62
         * Returns the conditionals based in which this loadable should be active.
63
         *
64
         * @return array
65
         */
66
        public static function get_conditionals() {
67
                return [
68
                        Wordproof_Plugin_Inactive_Conditional::class,
×
69
                        Non_Multisite_Conditional::class,
70
                        Wordproof_Integration_Active_Conditional::class,
71
                ];
72
        }
73

74
        /**
75
         * Initializes the integration.
76
         *
77
         * This is the place to register hooks and filters.
78
         *
79
         * @return void
80
         */
81
        public function register_hooks() {
82
                /**
83
                 * Used to initialize the WordProof WordPress SDK.
84
                 */
85
                \add_action( 'init', [ $this, 'sdk_setup' ], 11 );
×
86

87
                /**
88
                 * Enqueue the wordproof assets.
89
                 */
90
                \add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_assets' ], 10, 0 );
×
91

NEW
92
                if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '6.3', '>=' ) ) {
×
NEW
93
                        \add_action(
×
NEW
94
                                'wp_enqueue_scripts',
×
95
                                function() {
NEW
96
                                        \wp_script_add_data( WPSEO_Admin_Asset_Manager::PREFIX . 'wordproof-uikit', 'strategy', 'async' );
×
NEW
97
                                },
×
NEW
98
                                11,
×
99
                                0
100
                        );
101
                }
102
                else {
NEW
103
                        \add_filter( 'script_loader_tag', [ $this, 'add_async_to_script' ], 10, 3 );
×
104
                }
105

106
                /**
107
                 * Removes the post meta timestamp key for the old privacy page.
108
                 */
109
                \add_action( 'update_option_wp_page_for_privacy_policy', [ $this, 'disable_timestamp_for_previous_legal_page' ], 10, 2 );
×
110

111
                /**
112
                 * Removes the post meta timestamp key for the old terms and conditions page.
113
                 */
114
                \add_action( 'update_option_woocommerce_terms_page_id', [ $this, 'disable_timestamp_for_previous_legal_page' ], 10, 2 );
×
115

116
                /**
117
                 * Called by the WordProof WordPress SDK to determine if the post should be timestamped.
118
                 */
119
                \add_filter( 'wordproof_timestamp_post_meta_key_overrides', [ $this, 'add_post_meta_key' ] );
×
120

121
                /**
122
                 * Called by the WordProof WordPress SDK to determine if the post should be automatically timestamped.
123
                 */
124
                \add_filter( 'wordproof_timestamp_post_types', [ $this, 'wordproof_timestamp_post_types' ] );
×
125

126
                /**
127
                 * Called by the WordProof WordPress SDK to determine if the certificate should be shown.
128
                 */
129
                \add_filter( 'wordproof_timestamp_show_certificate', [ $this, 'show_certificate' ], 10, 2 );
×
130

131
                /**
132
                 * Called by WPSEO_Meta to add extra meta fields to the ones defined there.
133
                 */
134
                \add_filter( 'add_extra_wpseo_meta_fields', [ $this, 'add_meta_field' ] );
×
135
        }
136

137
        /**
138
         * Initializes the WordProof WordPress SDK.
139
         */
140
        public function sdk_setup() {
141

142
                $config       = new Wordproof_App_Config();
×
143
                $translations = new Wordproof_Translations();
×
144

145
                WordPressSDK::getInstance( $config, $translations )
×
146
                        ->certificate()
×
147
                        ->initialize();
×
148
        }
149

150
        /**
151
         * Removes the WordProof timestamp post meta if a legal page is changed.
152
         *
153
         * @param int $old_post_id The old post id.
154
         * @param int $new_post_id The new post id.
155
         */
156
        public function disable_timestamp_for_previous_legal_page( $old_post_id, $new_post_id ) {
157

158
                if ( $old_post_id !== $new_post_id ) {
×
159
                        \delete_post_meta( $old_post_id, '_yoast_wpseo_wordproof_timestamp' );
×
160
                }
161
        }
162

163
        /**
164
         * Return the Yoast post meta key for the SDK to determine if the post should be timestamped.
165
         *
166
         * @param array $meta_keys The array containing meta keys that should be used.
167
         * @return array
168
         */
169
        public function add_post_meta_key( $meta_keys ) {
170
                return [ $this->post_meta_key ];
×
171
        }
172

173
        /**
174
         * Return an empty array to disable automatically timestamping selected post types.
175
         *
176
         * @param array $post_types The array containing post types that should be automatically timestamped.
177
         * @return array
178
         */
179
        public function wordproof_timestamp_post_types( $post_types ) {
180
                return [];
×
181
        }
182

183
        /**
184
         * This filters hides the certificate if the Yoast post meta key is not set to true.
185
         *
186
         * @param bool    $value If the certificate should be shown.
187
         * @param WP_Post $post  The post object of the post for which to determine the certificate should be shown.
188
         * @return bool|null
189
         */
190
        public function show_certificate( $value, $post ) {
191
                if ( ! $value ) {
×
192
                        return $value;
×
193
                }
194

195
                if ( ! $this->wordproof->integration_is_active() ) {
×
196
                        return false;
×
197
                }
198

199
                return \boolval( PostMetaHelper::get( $post->ID, $this->post_meta_key ) );
×
200
        }
201

202
        /**
203
         * Adds the WordProof integration toggle to the array.
204
         *
205
         * @param array $fields The currently registered meta fields.
206
         *
207
         * @return array A new array with meta fields.
208
         */
209
        public function add_meta_field( $fields ) {
210
                $fields['advanced']['wordproof_timestamp'] = [
×
211
                        'type'          => 'hidden',
212
                        'title'         => '',
213
                        'default_value' => '',
214
                        'description'   => '0',
215
                ];
216

217
                return $fields;
×
218
        }
219

220
        /**
221
         * Enqueue the uikit script.
222
         *
223
         * @return void
224
         */
225
        public function enqueue_assets() {
226
                if ( CertificateHelper::show() ) {
×
227
                        $flat_version = $this->asset_manager->flatten_version( \WPSEO_VERSION );
×
228

229
                        /**
230
                         * We are using the Admin asset manager to register and enqueue a file served for all visitors,
231
                         * authenticated and unauthenticated users.
232
                         */
233
                        $script = new WPSEO_Admin_Asset(
×
234
                                [
235
                                        'name'    => 'wordproof-uikit',
×
236
                                        'src'     => 'wordproof-uikit.js',
×
237
                                        'version' => $flat_version,
×
238
                                ]
239
                        );
240

241
                        $this->asset_manager->register_script( $script );
×
242
                        $this->asset_manager->enqueue_script( 'wordproof-uikit' );
×
243
                }
244
        }
245

246
        /**
247
         * Adds async to the wordproof-uikit script.
248
         *
249
         * @param string $tag    The script tag for the enqueued script.
250
         * @param string $handle The script's registered handle.
251
         * @param string $src    The script's source URL.
252
         *
253
         * @return string The script's tag.
254
         *
255
         * @phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
256
         */
257
        public function add_async_to_script( $tag, $handle, $src ) {
258
                if ( $handle !== WPSEO_Admin_Asset_Manager::PREFIX . 'wordproof-uikit' ) {
×
259
                        return $tag;
×
260
                }
261

262
                return "<script src={$src} async></script>";
×
263
        }
264
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc