PluginProbe
Redirection / 5.2
Redirection v5.2
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
← All changes | modules/apache.php +27 -5 4.05.2 View file →
@@ -30,9 +30,9 @@
30 30 protected function flush_module() {
31 31 include_once dirname( dirname( __FILE__ ) ) . '/models/htaccess.php';
32 32
33 33 if ( empty( $this->location ) ) {
34 - return;
34 + return false;
35 35 }
36 36
37 37 $items = Red_Item::get_all_for_module( $this->get_id() );
38 38
@@ -48,16 +48,38 @@
48 48
49 49 return $htaccess->save( $this->location );
50 50 }
51 51
52 + public function can_save( $location ) {
53 + $location = $this->sanitize_location( $location );
54 +
55 + if ( @fopen( $location, 'a' ) === false ) {
56 + $error = error_get_last();
57 + return new WP_Error( 'redirect', isset( $error['message'] ) ? $error['message'] : 'Unknown error' );
58 + }
59 +
60 + return true;
61 + }
62 +
63 + private function sanitize_location( $location ) {
64 + $location = str_replace( '.htaccess', '', $location );
65 + $location = rtrim( $location, '/' ) . '/.htaccess';
66 + return rtrim( dirname( $location ), '/' ) . '/.htaccess';
67 + }
68 +
52 69 public function update( array $data ) {
53 70 include_once dirname( dirname( __FILE__ ) ) . '/models/htaccess.php';
54 71
55 - $save = array(
56 - 'location' => isset( $data['location'] ) ? trim( $data['location'] ) : '',
57 - );
72 + $new_location = isset( $data['location'] ) ? $data['location'] : '';
73 + if ( strlen( $new_location ) > 0 ) {
74 + $new_location = $this->sanitize_location( trim( $data['location'] ) );
75 + }
58 76
59 - if ( ! empty( $this->location ) && $save['location'] !== $this->location ) {
77 + $save = [
78 + 'location' => $new_location,
79 + ];
80 +
81 + if ( ! empty( $this->location ) && $save['location'] !== $this->location && $save['location'] !== '' ) {
60 82 // Location has moved. Remove from old location
61 83 $htaccess = new Red_Htaccess();
62 84 $htaccess->save( $this->location, '' );
63 85 }