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

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

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

0.0
/inc/class-upgrade-history.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Internal
6
 */
7

8
/**
9
 * This class handles storing the current options for future reference.
10
 *
11
 * This should only be used during an upgrade routine.
12
 */
13
class WPSEO_Upgrade_History {
14

15
        /**
16
         * Option to use to store/retrieve data from.
17
         *
18
         * @var string
19
         */
20
        protected $option_name = 'wpseo_upgrade_history';
21

22
        /**
23
         * WPSEO_Upgrade_History constructor.
24
         *
25
         * @param string|null $option_name Optional. Custom option to use to store/retrieve history from.
26
         */
UNCOV
27
        public function __construct( $option_name = null ) {
×
UNCOV
28
                if ( $option_name !== null ) {
×
UNCOV
29
                        $this->option_name = $option_name;
×
30
                }
31
        }
32

33
        /**
34
         * Retrieves the content of the history items currently stored.
35
         *
36
         * @return array<array<string>> The contents of the history option.
37
         */
UNCOV
38
        public function get() {
×
UNCOV
39
                $data = get_option( $this->get_option_name(), [] );
×
UNCOV
40
                if ( ! is_array( $data ) ) {
×
41
                        return [];
×
42
                }
43

UNCOV
44
                return $data;
×
45
        }
46

47
        /**
48
         * Adds a new history entry in the storage.
49
         *
50
         * @param string        $old_version  The version we are upgrading from.
51
         * @param string        $new_version  The version we are upgrading to.
52
         * @param array<string> $option_names The options that need to be stored.
53
         *
54
         * @return void
55
         */
UNCOV
56
        public function add( $old_version, $new_version, array $option_names ) {
×
UNCOV
57
                $option_data = [];
×
UNCOV
58
                if ( $option_names !== [] ) {
×
UNCOV
59
                        $option_data = $this->get_options_data( $option_names );
×
60
                }
61

62
                // Retrieve current history.
UNCOV
63
                $data = $this->get();
×
64

65
                // Add new entry.
UNCOV
66
                $data[ time() ] = [
×
UNCOV
67
                        'options'     => $option_data,
×
UNCOV
68
                        'old_version' => $old_version,
×
UNCOV
69
                        'new_version' => $new_version,
×
UNCOV
70
                ];
×
71

72
                // Store the data.
UNCOV
73
                $this->set( $data );
×
74
        }
75

76
        /**
77
         * Retrieves the data for the specified option names from the database.
78
         *
79
         * @param array<string> $option_names The option names to retrieve.
80
         *
81
         * @return array<int|string|bool|float,array<string|int|bool|float>> The retrieved data.
82
         */
UNCOV
83
        protected function get_options_data( array $option_names ) {
×
UNCOV
84
                $wpdb = $this->get_wpdb();
×
85

UNCOV
86
                $results = $wpdb->get_results(
×
UNCOV
87
                        $wpdb->prepare(
×
UNCOV
88
                                '
×
UNCOV
89
                                SELECT %i, %i FROM ' . $wpdb->options . ' WHERE
×
UNCOV
90
                                %i IN ( ' . implode( ',', array_fill( 0, count( $option_names ), '%s' ) ) . ' )
×
UNCOV
91
                                ',
×
UNCOV
92
                                array_merge( [ 'option_value', 'option_name', 'option_name' ], $option_names )
×
UNCOV
93
                        ),
×
UNCOV
94
                        ARRAY_A
×
UNCOV
95
                );
×
96

UNCOV
97
                $data = [];
×
UNCOV
98
                foreach ( $results as $result ) {
×
UNCOV
99
                        $data[ $result['option_name'] ] = maybe_unserialize( $result['option_value'] );
×
100
                }
101

UNCOV
102
                return $data;
×
103
        }
104

105
        /**
106
         * Stores the new history state.
107
         *
108
         * @param array<array<string>> $data The data to store.
109
         *
110
         * @return void
111
         */
UNCOV
112
        protected function set( array $data ) {
×
113
                // This should not be autoloaded!
UNCOV
114
                update_option( $this->get_option_name(), $data, false );
×
115
        }
116

117
        /**
118
         * Retrieves the WPDB object.
119
         *
120
         * @return wpdb The WPDB object to use.
121
         */
122
        protected function get_wpdb() {
×
123
                global $wpdb;
×
124

125
                return $wpdb;
×
126
        }
127

128
        /**
129
         * Retrieves the option name to store the history in.
130
         *
131
         * @return string The option name to store the history in.
132
         */
133
        protected function get_option_name() {
×
134
                return $this->option_name;
×
135
        }
136
}
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