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

Yoast / wordpress-seo / 0a98291f4f7ebedbb53c98815f22c6822361b572

11 Apr 2024 07:13AM UTC coverage: 47.435%. First build
0a98291f4f7ebedbb53c98815f22c6822361b572

Pull #21307

github

leonidasmi
Merge branch 'trunk' into feature/21044-stop-empty-usermeta
Pull Request #21307: Stop storing empty usermeta used by sitemaps

189 of 201 new or added lines in 26 files covered. (94.03%)

15034 of 31694 relevant lines covered (47.43%)

3.54 hits per line

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

96.0
/src/user-meta/user-interface/custom-meta-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\User_Meta\User_Interface;
4

5
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
6
use Yoast\WP\SEO\Conditionals\User_Can_Edit_Users_Conditional;
7
use Yoast\WP\SEO\Conditionals\User_Edit_Conditional;
8
use Yoast\WP\SEO\Integrations\Integration_Interface;
9
use Yoast\WP\SEO\User_Meta\Application\Custom_Meta_Repository;
10

11
/**
12
 * Handles custom meta for users.
13
 */
14
class Custom_Meta_Integration implements Integration_Interface {
15

16
        /**
17
         * The custom meta repository.
18
         *
19
         * @var Custom_Meta_Repository $custom_meta_repository The custom meta repository.
20
         */
21
        private $custom_meta_repository;
22

23
        /**
24
         * The constructor.
25
         *
26
         * @param Custom_Meta_Repository $custom_meta_repository The custom meta repository.
27
         */
28
        public function __construct( Custom_Meta_Repository $custom_meta_repository ) {
2✔
29
                $this->custom_meta_repository = $custom_meta_repository;
2✔
30
        }
1✔
31

32
        /**
33
         * Retrieves the conditionals for the integration.
34
         *
35
         * @return array<Yoast\WP\SEO\Conditionals> The conditionals.
36
         */
37
        public static function get_conditionals() {
2✔
38
                return [
1✔
39
                        Admin_Conditional::class,
2✔
40
                        User_Can_Edit_Users_Conditional::class,
1✔
41
                        User_Edit_Conditional::class,
1✔
42
                ];
1✔
43
        }
44

45
        /**
46
         * Registers action hook.
47
         *
48
         * @return void
49
         */
50
        public function register_hooks(): void {
2✔
51
                \add_action( 'personal_options_update', [ $this, 'process_user_option_update' ] );
2✔
52
                \add_action( 'edit_user_profile_update', [ $this, 'process_user_option_update' ] );
2✔
53
        }
1✔
54

55
        /**
56
         * Updates the user metas that (might) have been set on the user profile page.
57
         *
58
         * @param int $user_id User ID of the updated user.
59
         *
60
         * @return void
61
         */
62
        public function process_user_option_update( $user_id ) {
6✔
63
                \update_user_meta( $user_id, '_yoast_wpseo_profile_updated', \time() );
6✔
64

65
                if ( ! \check_admin_referer( 'wpseo_user_profile_update', 'wpseo_nonce' ) ) {
6✔
NEW
66
                        return;
×
67
                }
68

69
                foreach ( $this->custom_meta_repository->get_custom_meta() as $meta ) {
6✔
70
                        $meta_field_id = $meta->get_field_id();
6✔
71

72
                        $user_input_to_store = isset( $_POST[ $meta_field_id ] ) ? \sanitize_text_field( \wp_unslash( $_POST[ $meta_field_id ] ) ) : '';
6✔
73
                        if ( $meta->is_empty_allowed() || $user_input_to_store !== '' ) {
6✔
74
                                \update_user_meta( $user_id, $meta->get_key(), $user_input_to_store );
6✔
75
                                continue;
6✔
76
                        }
77

78
                        \delete_user_meta( $user_id, $meta->get_key() );
2✔
79
                }
80
        }
3✔
81
}
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