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

Yoast / wordpress-seo / 5066322038

pending completion
5066322038

push

github

GitHub
Merge pull request #20316 from Yoast/JRF/ghactions-run-more-selectively

2550 of 29012 relevant lines covered (8.79%)

0.32 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

92
                /**
93
                 * Add async to the wordproof scripts.
94
                 */
95
                \add_filter( 'script_loader_tag', [ $this, 'add_async_to_script' ], 10, 3 );
×
96

97
                /**
98
                 * Removes the post meta timestamp key for the old privacy page.
99
                 */
100
                \add_action( 'update_option_wp_page_for_privacy_policy', [ $this, 'disable_timestamp_for_previous_legal_page' ], 10, 2 );
×
101

102
                /**
103
                 * Removes the post meta timestamp key for the old terms and conditions page.
104
                 */
105
                \add_action( 'update_option_woocommerce_terms_page_id', [ $this, 'disable_timestamp_for_previous_legal_page' ], 10, 2 );
×
106

107
                /**
108
                 * Called by the WordProof WordPress SDK to determine if the post should be timestamped.
109
                 */
110
                \add_filter( 'wordproof_timestamp_post_meta_key_overrides', [ $this, 'add_post_meta_key' ] );
×
111

112
                /**
113
                 * Called by the WordProof WordPress SDK to determine if the post should be automatically timestamped.
114
                 */
115
                \add_filter( 'wordproof_timestamp_post_types', [ $this, 'wordproof_timestamp_post_types' ] );
×
116

117
                /**
118
                 * Called by the WordProof WordPress SDK to determine if the certificate should be shown.
119
                 */
120
                \add_filter( 'wordproof_timestamp_show_certificate', [ $this, 'show_certificate' ], 10, 2 );
×
121

122
                /**
123
                 * Called by WPSEO_Meta to add extra meta fields to the ones defined there.
124
                 */
125
                \add_filter( 'add_extra_wpseo_meta_fields', [ $this, 'add_meta_field' ] );
×
126
        }
127

128
        /**
129
         * Initializes the WordProof WordPress SDK.
130
         */
131
        public function sdk_setup() {
132

133
                $config       = new Wordproof_App_Config();
×
134
                $translations = new Wordproof_Translations();
×
135

136
                WordPressSDK::getInstance( $config, $translations )
×
137
                        ->certificate()
×
138
                        ->initialize();
×
139
        }
140

141
        /**
142
         * Removes the WordProof timestamp post meta if a legal page is changed.
143
         *
144
         * @param int $old_post_id The old post id.
145
         * @param int $new_post_id The new post id.
146
         */
147
        public function disable_timestamp_for_previous_legal_page( $old_post_id, $new_post_id ) {
148

149
                if ( $old_post_id !== $new_post_id ) {
×
150
                        \delete_post_meta( $old_post_id, '_yoast_wpseo_wordproof_timestamp' );
×
151
                }
152
        }
153

154
        /**
155
         * Return the Yoast post meta key for the SDK to determine if the post should be timestamped.
156
         *
157
         * @param array $meta_keys The array containing meta keys that should be used.
158
         * @return array
159
         */
160
        public function add_post_meta_key( $meta_keys ) {
161
                return [ $this->post_meta_key ];
×
162
        }
163

164
        /**
165
         * Return an empty array to disable automatically timestamping selected post types.
166
         *
167
         * @param array $post_types The array containing post types that should be automatically timestamped.
168
         * @return array
169
         */
170
        public function wordproof_timestamp_post_types( $post_types ) {
171
                return [];
×
172
        }
173

174
        /**
175
         * This filters hides the certificate if the Yoast post meta key is not set to true.
176
         *
177
         * @param bool    $value If the certificate should be shown.
178
         * @param WP_Post $post  The post object of the post for which to determine the certificate should be shown.
179
         * @return bool|null
180
         */
181
        public function show_certificate( $value, $post ) {
182
                if ( ! $value ) {
×
183
                        return $value;
×
184
                }
185

186
                if ( ! $this->wordproof->integration_is_active() ) {
×
187
                        return false;
×
188
                }
189

190
                return \boolval( PostMetaHelper::get( $post->ID, $this->post_meta_key ) );
×
191
        }
192

193
        /**
194
         * Adds the WordProof integration toggle to the array.
195
         *
196
         * @param array $fields The currently registered meta fields.
197
         *
198
         * @return array A new array with meta fields.
199
         */
200
        public function add_meta_field( $fields ) {
201
                $fields['advanced']['wordproof_timestamp'] = [
×
202
                        'type'          => 'hidden',
×
203
                        'title'         => '',
×
204
                        'default_value' => '',
×
205
                        'description'   => '0',
×
206
                ];
×
207

208
                return $fields;
×
209
        }
210

211
        /**
212
         * Enqueue the uikit script.
213
         *
214
         * @return void
215
         */
216
        public function enqueue_assets() {
217
                if ( CertificateHelper::show() ) {
×
218
                        $flat_version = $this->asset_manager->flatten_version( \WPSEO_VERSION );
×
219

220
                        /**
221
                         * We are using the Admin asset manager to register and enqueue a file served for all visitors,
222
                         * authenticated and unauthenticated users.
223
                         */
224
                        $script = new WPSEO_Admin_Asset(
×
225
                                [
×
226
                                        'name'    => 'wordproof-uikit',
×
227
                                        'src'     => 'wordproof-uikit.js',
×
228
                                        'version' => $flat_version,
×
229
                                ]
×
230
                        );
×
231

232
                        $this->asset_manager->register_script( $script );
×
233
                        $this->asset_manager->enqueue_script( 'wordproof-uikit' );
×
234
                }
235
        }
236

237
        /**
238
         * Adds async to the wordproof-uikit script.
239
         *
240
         * @param string $tag    The script tag for the enqueued script.
241
         * @param string $handle The script's registered handle.
242
         * @param string $src    The script's source URL.
243
         *
244
         * @return string The script's tag.
245
         *
246
         * @phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
247
         */
248
        public function add_async_to_script( $tag, $handle, $src ) {
249
                if ( $handle !== WPSEO_Admin_Asset_Manager::PREFIX . 'wordproof-uikit' ) {
×
250
                        return $tag;
×
251
                }
252

253
                return "<script src={$src} async></script>";
×
254
        }
255
}
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

© 2026 Coveralls, Inc