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

Yoast / wordpress-seo / 6987097851

25 Nov 2023 04:49AM UTC coverage: 49.206% (-0.1%) from 49.302%
6987097851

push

github

web-flow
Merge pull request #20878 from Yoast/JRF/ghactions-minor-tweak

GH Actions: update a few links in inline comments

15305 of 31104 relevant lines covered (49.21%)

4.03 hits per line

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

0.0
/admin/class-export.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Export
6
 */
7

8
/**
9
 * Class WPSEO_Export.
10
 *
11
 * Class with functionality to export the WP SEO settings.
12
 */
13
class WPSEO_Export {
14

15
        /**
16
         * Holds the nonce action.
17
         *
18
         * @var string
19
         */
20
        const NONCE_ACTION = 'wpseo_export';
21

22
        /**
23
         * Holds the export data.
24
         *
25
         * @var string
26
         */
27
        private $export = '';
28

29
        /**
30
         * Holds whether the export was a success.
31
         *
32
         * @var bool
33
         */
34
        public $success;
35

36
        /**
37
         * Handles the export request.
38
         */
39
        public function export() {
×
40
                check_admin_referer( self::NONCE_ACTION );
×
41
                $this->export_settings();
×
42
                $this->output();
×
43
        }
44

45
        /**
46
         * Outputs the export.
47
         */
48
        public function output() {
×
49
                if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
×
50
                        esc_html_e( 'You do not have the required rights to export settings.', 'wordpress-seo' );
×
51
                        return;
×
52
                }
53

54
                echo '<p id="wpseo-settings-export-desc">';
×
55
                printf(
×
56
                        /* translators: %1$s expands to Import settings */
57
                        esc_html__(
×
58
                                'Copy all these settings to another site\'s %1$s tab and click "%1$s" there.',
×
59
                                'wordpress-seo'
×
60
                        ),
×
61
                        esc_html__(
×
62
                                'Import settings',
×
63
                                'wordpress-seo'
×
64
                        )
×
65
                );
×
66
                echo '</p>';
×
67
                /* translators: %1$s expands to Yoast SEO */
68
                echo '<label for="wpseo-settings-export" class="yoast-inline-label">' . sprintf( __( 'Your %1$s settings:', 'wordpress-seo' ), 'Yoast SEO' ) . '</label><br />';
×
69
                echo '<textarea id="wpseo-settings-export" rows="20" cols="100" aria-describedby="wpseo-settings-export-desc">' . esc_textarea( $this->export ) . '</textarea>';
×
70
        }
71

72
        /**
73
         * Exports the current site's WP SEO settings.
74
         */
75
        private function export_settings() {
×
76
                $this->export_header();
×
77

78
                foreach ( WPSEO_Options::get_option_names() as $opt_group ) {
×
79
                        $this->write_opt_group( $opt_group );
×
80
                }
81
        }
82

83
        /**
84
         * Writes the header of the export.
85
         */
86
        private function export_header() {
×
87
                $header = sprintf(
×
88
                        /* translators: %1$s expands to Yoast SEO, %2$s expands to Yoast.com */
89
                        esc_html__( 'These are settings for the %1$s plugin by %2$s', 'wordpress-seo' ),
×
90
                        'Yoast SEO',
×
91
                        'Yoast.com'
×
92
                );
×
93
                $this->write_line( '; ' . $header );
×
94
        }
95

96
        /**
97
         * Writes a line to the export.
98
         *
99
         * @param string $line          Line string.
100
         * @param bool   $newline_first Boolean flag whether to prepend with new line.
101
         */
102
        private function write_line( $line, $newline_first = false ) {
×
103
                if ( $newline_first ) {
×
104
                        $this->export .= PHP_EOL;
×
105
                }
106
                $this->export .= $line . PHP_EOL;
×
107
        }
108

109
        /**
110
         * Writes an entire option group to the export.
111
         *
112
         * @param string $opt_group Option group name.
113
         */
114
        private function write_opt_group( $opt_group ) {
×
115

116
                $this->write_line( '[' . $opt_group . ']', true );
×
117

118
                $options = get_option( $opt_group );
×
119

120
                if ( ! is_array( $options ) ) {
×
121
                        return;
×
122
                }
123

124
                foreach ( $options as $key => $elem ) {
×
125
                        if ( is_array( $elem ) ) {
×
126
                                $count = count( $elem );
×
127
                                for ( $i = 0; $i < $count; $i++ ) {
×
128
                                        $elem_check = isset( $elem[ $i ] ) ? $elem[ $i ] : null;
×
129
                                        $this->write_setting( $key . '[]', $elem_check );
×
130
                                }
131
                        }
132
                        else {
133
                                $this->write_setting( $key, $elem );
×
134
                        }
135
                }
136
        }
137

138
        /**
139
         * Writes a settings line to the export.
140
         *
141
         * @param string $key Key string.
142
         * @param string $val Value string.
143
         */
144
        private function write_setting( $key, $val ) {
×
145
                if ( is_string( $val ) ) {
×
146
                        $val = '"' . $val . '"';
×
147
                }
148
                $this->write_line( $key . ' = ' . $val );
×
149
        }
150
}
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