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

Yoast / wordpress-seo / 56db0408fe2a0dbffe1c2c6cfad9b5c2f6941e34

14 Apr 2025 12:24PM UTC coverage: 52.454% (-2.1%) from 54.594%
56db0408fe2a0dbffe1c2c6cfad9b5c2f6941e34

Pull #22077

github

enricobattocchi
Adjust carryforward in Coveralls action
Pull Request #22077: Drop compatibility with PHP 7.2 and 7.3

7827 of 13877 branches covered (56.4%)

Branch coverage included in aggregate %.

29025 of 56379 relevant lines covered (51.48%)

42277.18 hits per line

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

67.57
/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_Collector;
10

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

16
        /**
17
         * The custom meta collector.
18
         *
19
         * @var Custom_Meta_Collector
20
         */
21
        private $custom_meta_collector;
22

23
        /**
24
         * The constructor.
25
         *
26
         * @param Custom_Meta_Collector $custom_meta_collector The custom meta collector.
27
         */
28
        public function __construct( Custom_Meta_Collector $custom_meta_collector ) {
2✔
29
                $this->custom_meta_collector = $custom_meta_collector;
2✔
30
        }
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 [
2✔
39
                        Admin_Conditional::class,
2✔
40
                        User_Can_Edit_Users_Conditional::class,
2✔
41
                        User_Edit_Conditional::class,
2✔
42
                ];
2✔
43
        }
44

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

54
                \add_action( 'personal_options_update', [ $this, 'process_user_option_update' ] );
2✔
55
                \add_action( 'edit_user_profile_update', [ $this, 'process_user_option_update' ] );
2✔
56
        }
57

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

68
                if ( ! \check_admin_referer( 'wpseo_user_profile_update', 'wpseo_nonce' ) ) {
14✔
69
                        return;
×
70
                }
71

72
                foreach ( $this->custom_meta_collector->get_custom_meta() as $meta ) {
14✔
73
                        if ( ! $meta->is_setting_enabled() ) {
14✔
74
                                continue;
4✔
75
                        }
76

77
                        $meta_field_id       = $meta->get_field_id();
10✔
78
                        $user_input_to_store = isset( $_POST[ $meta_field_id ] ) ? \sanitize_text_field( \wp_unslash( $_POST[ $meta_field_id ] ) ) : '';
10✔
79

80
                        if ( $meta->is_empty_allowed() || $user_input_to_store !== '' ) {
10✔
81
                                \update_user_meta( $user_id, $meta->get_key(), $user_input_to_store );
10✔
82
                                continue;
10✔
83
                        }
84

85
                        \delete_user_meta( $user_id, $meta->get_key() );
4✔
86
                }
87
        }
88

89
        /**
90
         * Adds the inputs needed for SEO values to the User Profile page.
91
         *
92
         * @param WP_User $user User instance to output for.
93
         *
94
         * @return void
95
         */
96
        public function user_profile( $user ) {
×
97
                \wp_nonce_field( 'wpseo_user_profile_update', 'wpseo_nonce' );
×
98

99
                /* translators: %1$s expands to Yoast SEO */
100
                $yoast_user_settings_header = \sprintf( \__( '%1$s settings', 'wordpress-seo' ), 'Yoast SEO' );
×
101

102
                echo '
×
103

104
                <div class="yoast yoast-settings">
105
                        
106
                        <h2 id="wordpress-seo">' . \esc_html( $yoast_user_settings_header ) . '</h2>';
×
107

108
                foreach ( $this->custom_meta_collector->get_sorted_custom_meta() as $meta ) {
×
109
                        if ( ! $meta->is_setting_enabled() ) {
×
110
                                continue;
×
111
                        }
112

113
                        $meta->render_field( $user->ID );
×
114
                }
115

116
                \do_action( 'wpseo_render_user_profile', $user );
×
117
                echo '</div>';
×
118
        }
119
}
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