← All changes
|
admin/rewrite-rules/class-rewrite-rules-abstract.php
+17
-8
3.2.7
→
4.1.2
View file →
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | -abstract class Rewrite_Rules_Abstract { | |
| 2 | +abstract class Quickwebp_Rewrite_Rules_Abstract { | |
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Name of the tag used as block delemiter. |
| 6 | 6 | */ |
| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | if ( is_wp_error( $result ) ) { |
| 16 | 16 | add_action( 'admin_notices', function() use ( $result ) { |
| 17 | 17 | ?> |
| 18 | 18 | <div class="notice notice-error"> |
| 19 | - <p><?php echo $result->get_error_message(); ?></p> | |
| 19 | + <p><?php echo esc_html( $result->get_error_message() ); ?></p> | |
| 20 | 20 | </div> |
| 21 | 21 | <?php |
| 22 | 22 | }); |
| 23 | 23 | } |
| @@ -35,9 +35,9 @@ | ||
| 35 | 35 | if ( is_wp_error( $result ) ) { |
| 36 | 36 | add_action( 'admin_notices', function() use ( $result ) { |
| 37 | 37 | ?> |
| 38 | 38 | <div class="notice notice-error"> |
| 39 | - <p><?php echo $result->get_error_message(); ?></p> | |
| 39 | + <p><?php echo esc_html( $result->get_error_message() ); ?></p> | |
| 40 | 40 | </div> |
| 41 | 41 | <?php |
| 42 | 42 | }); |
| 43 | 43 | } |
| @@ -98,9 +98,11 @@ | ||
| 98 | 98 | * |
| 99 | 99 | * Friend, each time an attempt is made to improve this method, and especially this part, please increment the following counter. |
| 100 | 100 | * Improvement attempts: 3. |
| 101 | 101 | */ |
| 102 | - $document_root = realpath( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ); // `realpath()` is needed for those cases where $_SERVER['DOCUMENT_ROOT'] is totally different from ABSPATH. | |
| 102 | + $document_root_raw = isset( $_SERVER['DOCUMENT_ROOT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ) : ''; | |
| 103 | + $document_root = realpath( $document_root_raw ); // `realpath()` is needed for those cases where $_SERVER['DOCUMENT_ROOT'] is totally different from ABSPATH. | |
| 104 | + $document_root = $document_root ? $document_root : ABSPATH; | |
| 103 | 105 | $document_root = trailingslashit( str_replace( '\\', '/', $document_root ) ); |
| 104 | 106 | $path_current_site = trim( str_replace( '\\', '/', PATH_CURRENT_SITE ), '/' ); |
| 105 | 107 | $root_path = trailingslashit( wp_normalize_path( $document_root . $path_current_site ) ); |
| 106 | 108 | |
| @@ -116,10 +118,12 @@ | ||
| 116 | 118 | $file_exists = file_exists( $file_path ); |
| 117 | 119 | if ( ! $file_exists ) { |
| 118 | 120 | $dir_name = dirname( $file_path ); |
| 119 | 121 | if ( ! file_exists( $dir_name ) ){ |
| 122 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_mkdir | |
| 120 | 123 | mkdir( $dir_name, 0755, true ); |
| 121 | 124 | } |
| 125 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_touch | |
| 122 | 126 | touch( $file_path ); |
| 123 | 127 | } |
| 124 | 128 | $writable = wp_is_writable( $file_path ); |
| 125 | 129 | |
| @@ -132,9 +136,10 @@ | ||
| 132 | 136 | if ( false === $contents ) { |
| 133 | 137 | return new \WP_Error( |
| 134 | 138 | 'not_read', |
| 135 | 139 | sprintf( |
| 136 | - __( 'The %s file could not be read.', QUICKWEBP_TEXT_DOMAIN ), | |
| 140 | + // translators: %s is a placeholder for the file path. | |
| 141 | + __( 'The %s file could not be read.', 'quickwebp' ), | |
| 137 | 142 | '<code>' . esc_html( $file_path ) . '</code>' |
| 138 | 143 | ) |
| 139 | 144 | ); |
| 140 | 145 | } |
| @@ -156,9 +161,10 @@ | ||
| 156 | 161 | |
| 157 | 162 | return new \WP_Error( |
| 158 | 163 | 'edition_failed', |
| 159 | 164 | sprintf( |
| 160 | - __( 'Could not write into the %s file.', QUICKWEBP_TEXT_DOMAIN ), | |
| 165 | + // translators: %s is a placeholder for the file path. | |
| 166 | + __( 'Could not write into the %s file.', 'quickwebp' ), | |
| 161 | 167 | '<code>' . esc_html( $file_path ) . '</code>' |
| 162 | 168 | ) |
| 163 | 169 | ); |
| 164 | 170 | } |
| @@ -167,8 +173,9 @@ | ||
| 167 | 173 | * Write contents to the file. |
| 168 | 174 | */ |
| 169 | 175 | protected function put_contents( $file, $contents, $mode = false ) { |
| 170 | 176 | |
| 177 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen | |
| 171 | 178 | $fp = @fopen( $file, 'wb' ); |
| 172 | 179 | |
| 173 | 180 | if ( ! $fp ) { |
| 174 | 181 | return false; |
| @@ -177,12 +184,14 @@ | ||
| 177 | 184 | mbstring_binary_safe_encoding(); |
| 178 | 185 | |
| 179 | 186 | $data_length = strlen( $contents ); |
| 180 | 187 | |
| 188 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite | |
| 181 | 189 | $bytes_written = fwrite( $fp, $contents ); |
| 182 | 190 | |
| 183 | 191 | reset_mbstring_encoding(); |
| 184 | 192 | |
| 193 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose | |
| 185 | 194 | fclose( $fp ); |
| 186 | 195 | |
| 187 | 196 | if ( $data_length !== $bytes_written ) { |
| 188 | 197 | return false; |
| @@ -188,10 +197,10 @@ | ||
| 188 | 197 | return false; |
| 189 | 198 | } |
| 190 | 199 | |
| 191 | 200 | $chmod_file = fileperms( ABSPATH . 'index.php' ) & 0777 | 0644; |
| 201 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_chmod | |
| 192 | 202 | chmod( $file, $chmod_file ); |
| 193 | 203 | |
| 194 | 204 | return true; |
| 195 | 205 | } |
| 196 | - | |
| 197 | -} | |
| 206 | +} | |