| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | * Holds the nonce action. |
| 17 | 17 | * |
| 18 | 18 | * @var string |
| 19 | 19 | */ |
| 20 | - const NONCE_ACTION = 'wpseo_export'; | |
| 20 | + public const NONCE_ACTION = 'wpseo_export'; | |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Holds the export data. |
| 24 | 24 | * |
| @@ -34,8 +34,10 @@ | ||
| 34 | 34 | public $success; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Handles the export request. |
| 38 | + * | |
| 39 | + * @return void | |
| 38 | 40 | */ |
| 39 | 41 | public function export() { |
| 40 | 42 | check_admin_referer( self::NONCE_ACTION ); |
| 41 | 43 | $this->export_settings(); |
| @@ -43,8 +45,10 @@ | ||
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | /** |
| 46 | 48 | * Outputs the export. |
| 49 | + * | |
| 50 | + * @return void | |
| 47 | 51 | */ |
| 48 | 52 | public function output() { |
| 49 | 53 | if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) { |
| 50 | 54 | esc_html_e( 'You do not have the required rights to export settings.', 'wordpress-seo' ); |
| @@ -55,14 +59,14 @@ | ||
| 55 | 59 | printf( |
| 56 | 60 | /* translators: %1$s expands to Import settings */ |
| 57 | 61 | esc_html__( |
| 58 | 62 | 'Copy all these settings to another site\'s %1$s tab and click "%1$s" there.', |
| 59 | - 'wordpress-seo' | |
| 63 | + 'wordpress-seo', | |
| 60 | 64 | ), |
| 61 | 65 | esc_html__( |
| 62 | 66 | 'Import settings', |
| 63 | - 'wordpress-seo' | |
| 64 | - ) | |
| 67 | + 'wordpress-seo', | |
| 68 | + ), | |
| 65 | 69 | ); |
| 66 | 70 | echo '</p>'; |
| 67 | 71 | /* translators: %1$s expands to Yoast SEO */ |
| 68 | 72 | echo '<label for="wpseo-settings-export" class="yoast-inline-label">' . sprintf( __( 'Your %1$s settings:', 'wordpress-seo' ), 'Yoast SEO' ) . '</label><br />'; |
| @@ -70,8 +74,10 @@ | ||
| 70 | 74 | } |
| 71 | 75 | |
| 72 | 76 | /** |
| 73 | 77 | * Exports the current site's WP SEO settings. |
| 78 | + * | |
| 79 | + * @return void | |
| 74 | 80 | */ |
| 75 | 81 | private function export_settings() { |
| 76 | 82 | $this->export_header(); |
| 77 | 83 | |
| @@ -81,8 +87,10 @@ | ||
| 81 | 87 | } |
| 82 | 88 | |
| 83 | 89 | /** |
| 84 | 90 | * Writes the header of the export. |
| 91 | + * | |
| 92 | + * @return void | |
| 85 | 93 | */ |
| 86 | 94 | private function export_header() { |
| 87 | 95 | $header = sprintf( |
| 88 | 96 | /* translators: %1$s expands to Yoast SEO, %2$s expands to Yoast.com */ |
| @@ -87,9 +95,9 @@ | ||
| 87 | 95 | $header = sprintf( |
| 88 | 96 | /* translators: %1$s expands to Yoast SEO, %2$s expands to Yoast.com */ |
| 89 | 97 | esc_html__( 'These are settings for the %1$s plugin by %2$s', 'wordpress-seo' ), |
| 90 | 98 | 'Yoast SEO', |
| 91 | - 'Yoast.com' | |
| 99 | + 'Yoast.com', | |
| 92 | 100 | ); |
| 93 | 101 | $this->write_line( '; ' . $header ); |
| 94 | 102 | } |
| 95 | 103 | |
| @@ -97,8 +105,10 @@ | ||
| 97 | 105 | * Writes a line to the export. |
| 98 | 106 | * |
| 99 | 107 | * @param string $line Line string. |
| 100 | 108 | * @param bool $newline_first Boolean flag whether to prepend with new line. |
| 109 | + * | |
| 110 | + * @return void | |
| 101 | 111 | */ |
| 102 | 112 | private function write_line( $line, $newline_first = false ) { |
| 103 | 113 | if ( $newline_first ) { |
| 104 | 114 | $this->export .= PHP_EOL; |
| @@ -109,8 +119,10 @@ | ||
| 109 | 119 | /** |
| 110 | 120 | * Writes an entire option group to the export. |
| 111 | 121 | * |
| 112 | 122 | * @param string $opt_group Option group name. |
| 123 | + * | |
| 124 | + * @return void | |
| 113 | 125 | */ |
| 114 | 126 | private function write_opt_group( $opt_group ) { |
| 115 | 127 | |
| 116 | 128 | $this->write_line( '[' . $opt_group . ']', true ); |
| @@ -124,9 +136,10 @@ | ||
| 124 | 136 | foreach ( $options as $key => $elem ) { |
| 125 | 137 | if ( is_array( $elem ) ) { |
| 126 | 138 | $count = count( $elem ); |
| 127 | 139 | for ( $i = 0; $i < $count; $i++ ) { |
| 128 | - $this->write_setting( $key . '[]', $elem[ $i ] ); | |
| 140 | + $elem_check = ( $elem[ $i ] ?? null ); | |
| 141 | + $this->write_setting( $key . '[]', $elem_check ); | |
| 129 | 142 | } |
| 130 | 143 | } |
| 131 | 144 | else { |
| 132 | 145 | $this->write_setting( $key, $elem ); |
| @@ -138,8 +151,10 @@ | ||
| 138 | 151 | * Writes a settings line to the export. |
| 139 | 152 | * |
| 140 | 153 | * @param string $key Key string. |
| 141 | 154 | * @param string $val Value string. |
| 155 | + * | |
| 156 | + * @return void | |
| 142 | 157 | */ |
| 143 | 158 | private function write_setting( $key, $val ) { |
| 144 | 159 | if ( is_string( $val ) ) { |
| 145 | 160 | $val = '"' . $val . '"'; |