PluginProbe
Redirection / 2.7
Redirection v2.7
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 | fileio/json.php +18 -30 4.22.7 View file →
@@ -3,14 +3,16 @@
3 3 class Red_Json_File extends Red_FileIO {
4 4 public function force_download() {
5 5 parent::force_download();
6 6
7 + $filename = 'redirection-'.date_i18n( get_option( 'date_format' ) ).'.json';
8 +
7 9 header( 'Content-Type: application/json' );
8 - header( 'Content-Disposition: attachment; filename="' . $this->export_filename( 'json' ) . '"' );
10 + header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
9 11 }
10 12
11 13 public function get_data( array $items, array $groups ) {
12 - $version = red_get_plugin_data( dirname( dirname( __FILE__ ) ) . '/redirection.php' );
14 + $version = get_plugin_data( dirname( dirname( __FILE__ ) ).'/redirection.php' );
13 15
14 16 $items = array(
15 17 'plugin' => array(
16 18 'version' => trim( $version['Version'] ),
@@ -21,16 +23,14 @@
21 23 return $item->to_json();
22 24 }, $items ),
23 25 );
24 26
25 - return wp_json_encode( $items, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) . PHP_EOL;
27 + return json_encode( $items, JSON_PRETTY_PRINT ).PHP_EOL;
26 28 }
27 29
28 30 public function load( $group, $filename, $data ) {
29 - global $wpdb;
30 -
31 31 $count = 0;
32 - $json = @json_decode( $data, true );
32 + $json = @json_decode( $data );
33 33 if ( $json === false ) {
34 34 return 0;
35 35 }
36 36
@@ -37,14 +37,14 @@
37 37 // Import groups
38 38 $groups = array();
39 39 $group_map = array();
40 40
41 - if ( isset( $json['groups'] ) ) {
42 - foreach ( $json['groups'] as $group ) {
43 - $old_group_id = $group['id'];
44 - unset( $group['id'] );
41 + if ( isset( $json->groups ) ) {
42 + foreach ( $json->groups as $group ) {
43 + $old_group_id = $group->id;
44 + unset( $group->id );
45 45
46 - $group = Red_Group::create( $group['name'], $group['module_id'], $group['enabled'] ? true : false );
46 + $group = Red_Group::create( $group->name, $group->module_id );
47 47 if ( $group ) {
48 48 $group_map[ $old_group_id ] = $group->get_id();
49 49 }
50 50 }
@@ -49,32 +49,20 @@
49 49 }
50 50 }
51 51 }
52 52
53 - unset( $json['groups'] );
54 -
55 53 // Import redirects
56 - if ( isset( $json['redirects'] ) ) {
57 - foreach ( $json['redirects'] as $pos => $redirect ) {
58 - unset( $redirect['id'] );
54 + if ( isset( $json->redirects ) ) {
55 + foreach ( $json->redirects as $redirect ) {
56 + unset( $redirect->id );
59 57
60 - if ( ! isset( $group_map[ $redirect['group_id'] ] ) ) {
61 - $new_group = Red_Group::create( 'Group', 1 );
62 - $group_map[ $redirect['group_id'] ] = $new_group->get_id();
58 + if ( ! isset( $group_map[ $redirect->group_id ] ) ) {
59 + $group_map[ $redirect->group_id ] = Red_Group::create( 'Group', 1 );
63 60 }
64 61
65 - if ( $redirect['match_type'] === 'url' && isset( $redirect['action_data'] ) && ! is_array( $redirect['action_data'] ) ) {
66 - $redirect['action_data'] = array( 'url' => $redirect['action_data'] );
67 - }
68 -
69 - $redirect['group_id'] = $group_map[ $redirect['group_id'] ];
70 - Red_Item::create( $redirect );
62 + $redirect->group_id = $group_map[ $redirect->group_id ];
63 + $redirect = Red_Item::create( (array)$redirect );
71 64 $count++;
72 -
73 - // Helps reduce memory usage
74 - unset( $json['redirects'][ $pos ] );
75 - $wpdb->queries = array();
76 - $wpdb->num_queries = 0;
77 65 }
78 66 }
79 67
80 68 return $count;