Completed
Push — develop ( 92fbf3...048bfe )
by David
02:47 queued 10s
created
src/wordlift/mappings/class-jsonld-converter.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -16,152 +16,152 @@
 block discarded – undo
16 16
  * @since 3.25.0
17 17
  */
18 18
 class Jsonld_Converter {
19
-	/**
20
-	 * Enumerations for the field types.
21
-	 * Enumerations for the field types.
22
-	 */
23
-	const FIELD_TYPE_TEXT_FIELD = 'text';
24
-	const FIELD_TYPE_CUSTOM_FIELD = 'custom_field';
25
-	const FIELD_TYPE_ACF = 'acf';
26
-	/**
27
-	 * The {@link Mappings_Validator} instance to test.
28
-	 *
29
-	 * @since  3.25.0
30
-	 * @access private
31
-	 * @var Mappings_Validator $validator The {@link Mappings_Validator} instance.
32
-	 */
33
-	private $validator;
34
-
35
-	/**
36
-	 * The {@link Mappings_Transform_Functions_Registry} instance.
37
-	 *
38
-	 * @since  3.25.0
39
-	 * @access private
40
-	 * @var Mappings_Transform_Functions_Registry $transform_functions_registry The {@link Mappings_Transform_Functions_Registry} instance.
41
-	 */
42
-	private $transform_functions_registry;
43
-
44
-	/**
45
-	 * Initialize all dependencies required.
46
-	 *
47
-	 * @param Mappings_Validator $validator A {@link Mappings_Validator} instance.
48
-	 * @param Mappings_Transform_Functions_Registry $transform_functions_registry
49
-	 */
50
-	public function __construct( $validator, $transform_functions_registry ) {
51
-
52
-		$this->validator                    = $validator;
53
-		$this->transform_functions_registry = $transform_functions_registry;
54
-
55
-		// Hook to refactor the JSON-LD.
56
-		add_filter( 'wl_post_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 11, 2 );
57
-		add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 11, 3 );
58
-
59
-	}
60
-
61
-	/**
62
-	 * Hook to `wl_post_jsonld_array` and `wl_entity_jsonld_array`.
63
-	 *
64
-	 * Receive the JSON-LD and the references in the array along with the post ID and transform them according to
65
-	 * the configuration.
66
-	 *
67
-	 * @param array $value {
68
-	 *      The array containing the JSON-LD and the references.
69
-	 *
70
-	 * @type array $jsonld The JSON-LD array.
71
-	 * @type int[] $references An array of post ID referenced by the JSON-LD (will be expanded by the converter).
72
-	 * }
73
-	 *
74
-	 * @param int $post_id The post ID.
75
-	 *
76
-	 * @return array An array with the updated JSON-LD and references.
77
-	 */
78
-	public function wl_post_jsonld_array( $value, $post_id ) {
79
-
80
-		$jsonld     = $value['jsonld'];
81
-		$references = $value['references'];
82
-
83
-		return array(
84
-			'jsonld'     => $this->wl_post_jsonld( $jsonld, $post_id, $references ),
85
-			'references' => $references,
86
-		);
87
-	}
88
-
89
-	/**
90
-	 * Returns JSON-LD data after applying transformation functions.
91
-	 *
92
-	 * @param array $jsonld The JSON-LD structure.
93
-	 * @param int $post_id The {@link WP_Post} id.
94
-	 * @param array $references An array of post references.
95
-	 *
96
-	 * @return array the new refactored array structure.
97
-	 * @since 3.25.0
98
-	 */
99
-	private function wl_post_jsonld( $jsonld, $post_id, &$references ) {
100
-
101
-		// @@todo I think there's an issue here with the Validator, because you're changing the instance state and the
102
-		// instance may be reused afterwards.
103
-
104
-		$properties = $this->validator->validate( $post_id );
105
-
106
-		foreach ( $properties as $property ) {
107
-			$transform_instance = $this->transform_functions_registry->get_transform_function( $property['transform_function'] );
108
-			$data               = $this->get_data_from_data_source( $post_id, $property );
109
-			if ( null !== $transform_instance ) {
110
-				$transform_data = $transform_instance->transform_data( $data, $jsonld, $references, $post_id );
111
-				if ( null !== $transform_data ) {
112
-					$jsonld[ $property['property_name'] ] = $this->make_single( $transform_data );
113
-				}
114
-			} else {
115
-				$jsonld[ $property['property_name'] ] = $this->make_single( $data );
116
-			}
117
-		}
118
-
119
-		return $jsonld;
120
-	}
121
-
122
-	/**
123
-	 * Returns data from data source.
124
-	 *
125
-	 * @param int $post_id Id of the post.
126
-	 * @param array $property_data The property data for the post_id.
127
-	 *
128
-	 * @return array Returns key, value array, if the value is not found, then it returns null.
129
-	 */
130
-	final public function get_data_from_data_source( $post_id, $property_data ) {
131
-		$value = $property_data['field_name'];
132
-
133
-		// Do 1 to 1 mapping and return result.
134
-		switch ( $property_data['field_type'] ) {
135
-			case self::FIELD_TYPE_ACF:
136
-				if ( ! function_exists( 'get_field' ) ) {
137
-					return array();
138
-				}
139
-
140
-				return get_field( $property_data['field_name'], $post_id );
141
-
142
-			case self::FIELD_TYPE_CUSTOM_FIELD:
143
-
144
-				return array_map( 'wp_strip_all_tags', get_post_meta( $post_id, $value ) );
145
-
146
-			default:
147
-				return $value;
148
-		}
149
-
150
-	}
151
-
152
-	private function make_single( $value ) {
153
-
154
-		$values = (array) $value;
155
-
156
-		if ( empty( $values ) ) {
157
-			return null;
158
-		}
159
-
160
-		if ( 1 === count( $values ) && 0 === key( $values ) ) {
161
-			return current( $values );
162
-		}
163
-
164
-		return $values;
165
-	}
19
+    /**
20
+     * Enumerations for the field types.
21
+     * Enumerations for the field types.
22
+     */
23
+    const FIELD_TYPE_TEXT_FIELD = 'text';
24
+    const FIELD_TYPE_CUSTOM_FIELD = 'custom_field';
25
+    const FIELD_TYPE_ACF = 'acf';
26
+    /**
27
+     * The {@link Mappings_Validator} instance to test.
28
+     *
29
+     * @since  3.25.0
30
+     * @access private
31
+     * @var Mappings_Validator $validator The {@link Mappings_Validator} instance.
32
+     */
33
+    private $validator;
34
+
35
+    /**
36
+     * The {@link Mappings_Transform_Functions_Registry} instance.
37
+     *
38
+     * @since  3.25.0
39
+     * @access private
40
+     * @var Mappings_Transform_Functions_Registry $transform_functions_registry The {@link Mappings_Transform_Functions_Registry} instance.
41
+     */
42
+    private $transform_functions_registry;
43
+
44
+    /**
45
+     * Initialize all dependencies required.
46
+     *
47
+     * @param Mappings_Validator $validator A {@link Mappings_Validator} instance.
48
+     * @param Mappings_Transform_Functions_Registry $transform_functions_registry
49
+     */
50
+    public function __construct( $validator, $transform_functions_registry ) {
51
+
52
+        $this->validator                    = $validator;
53
+        $this->transform_functions_registry = $transform_functions_registry;
54
+
55
+        // Hook to refactor the JSON-LD.
56
+        add_filter( 'wl_post_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 11, 2 );
57
+        add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 11, 3 );
58
+
59
+    }
60
+
61
+    /**
62
+     * Hook to `wl_post_jsonld_array` and `wl_entity_jsonld_array`.
63
+     *
64
+     * Receive the JSON-LD and the references in the array along with the post ID and transform them according to
65
+     * the configuration.
66
+     *
67
+     * @param array $value {
68
+     *      The array containing the JSON-LD and the references.
69
+     *
70
+     * @type array $jsonld The JSON-LD array.
71
+     * @type int[] $references An array of post ID referenced by the JSON-LD (will be expanded by the converter).
72
+     * }
73
+     *
74
+     * @param int $post_id The post ID.
75
+     *
76
+     * @return array An array with the updated JSON-LD and references.
77
+     */
78
+    public function wl_post_jsonld_array( $value, $post_id ) {
79
+
80
+        $jsonld     = $value['jsonld'];
81
+        $references = $value['references'];
82
+
83
+        return array(
84
+            'jsonld'     => $this->wl_post_jsonld( $jsonld, $post_id, $references ),
85
+            'references' => $references,
86
+        );
87
+    }
88
+
89
+    /**
90
+     * Returns JSON-LD data after applying transformation functions.
91
+     *
92
+     * @param array $jsonld The JSON-LD structure.
93
+     * @param int $post_id The {@link WP_Post} id.
94
+     * @param array $references An array of post references.
95
+     *
96
+     * @return array the new refactored array structure.
97
+     * @since 3.25.0
98
+     */
99
+    private function wl_post_jsonld( $jsonld, $post_id, &$references ) {
100
+
101
+        // @@todo I think there's an issue here with the Validator, because you're changing the instance state and the
102
+        // instance may be reused afterwards.
103
+
104
+        $properties = $this->validator->validate( $post_id );
105
+
106
+        foreach ( $properties as $property ) {
107
+            $transform_instance = $this->transform_functions_registry->get_transform_function( $property['transform_function'] );
108
+            $data               = $this->get_data_from_data_source( $post_id, $property );
109
+            if ( null !== $transform_instance ) {
110
+                $transform_data = $transform_instance->transform_data( $data, $jsonld, $references, $post_id );
111
+                if ( null !== $transform_data ) {
112
+                    $jsonld[ $property['property_name'] ] = $this->make_single( $transform_data );
113
+                }
114
+            } else {
115
+                $jsonld[ $property['property_name'] ] = $this->make_single( $data );
116
+            }
117
+        }
118
+
119
+        return $jsonld;
120
+    }
121
+
122
+    /**
123
+     * Returns data from data source.
124
+     *
125
+     * @param int $post_id Id of the post.
126
+     * @param array $property_data The property data for the post_id.
127
+     *
128
+     * @return array Returns key, value array, if the value is not found, then it returns null.
129
+     */
130
+    final public function get_data_from_data_source( $post_id, $property_data ) {
131
+        $value = $property_data['field_name'];
132
+
133
+        // Do 1 to 1 mapping and return result.
134
+        switch ( $property_data['field_type'] ) {
135
+            case self::FIELD_TYPE_ACF:
136
+                if ( ! function_exists( 'get_field' ) ) {
137
+                    return array();
138
+                }
139
+
140
+                return get_field( $property_data['field_name'], $post_id );
141
+
142
+            case self::FIELD_TYPE_CUSTOM_FIELD:
143
+
144
+                return array_map( 'wp_strip_all_tags', get_post_meta( $post_id, $value ) );
145
+
146
+            default:
147
+                return $value;
148
+        }
149
+
150
+    }
151
+
152
+    private function make_single( $value ) {
153
+
154
+        $values = (array) $value;
155
+
156
+        if ( empty( $values ) ) {
157
+            return null;
158
+        }
159
+
160
+        if ( 1 === count( $values ) && 0 === key( $values ) ) {
161
+            return current( $values );
162
+        }
163
+
164
+        return $values;
165
+    }
166 166
 
167 167
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 	 * @param Mappings_Validator $validator A {@link Mappings_Validator} instance.
48 48
 	 * @param Mappings_Transform_Functions_Registry $transform_functions_registry
49 49
 	 */
50
-	public function __construct( $validator, $transform_functions_registry ) {
50
+	public function __construct($validator, $transform_functions_registry) {
51 51
 
52 52
 		$this->validator                    = $validator;
53 53
 		$this->transform_functions_registry = $transform_functions_registry;
54 54
 
55 55
 		// Hook to refactor the JSON-LD.
56
-		add_filter( 'wl_post_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 11, 2 );
57
-		add_filter( 'wl_entity_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 11, 3 );
56
+		add_filter('wl_post_jsonld_array', array($this, 'wl_post_jsonld_array'), 11, 2);
57
+		add_filter('wl_entity_jsonld_array', array($this, 'wl_post_jsonld_array'), 11, 3);
58 58
 
59 59
 	}
60 60
 
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return array An array with the updated JSON-LD and references.
77 77
 	 */
78
-	public function wl_post_jsonld_array( $value, $post_id ) {
78
+	public function wl_post_jsonld_array($value, $post_id) {
79 79
 
80 80
 		$jsonld     = $value['jsonld'];
81 81
 		$references = $value['references'];
82 82
 
83 83
 		return array(
84
-			'jsonld'     => $this->wl_post_jsonld( $jsonld, $post_id, $references ),
84
+			'jsonld'     => $this->wl_post_jsonld($jsonld, $post_id, $references),
85 85
 			'references' => $references,
86 86
 		);
87 87
 	}
@@ -96,23 +96,23 @@  discard block
 block discarded – undo
96 96
 	 * @return array the new refactored array structure.
97 97
 	 * @since 3.25.0
98 98
 	 */
99
-	private function wl_post_jsonld( $jsonld, $post_id, &$references ) {
99
+	private function wl_post_jsonld($jsonld, $post_id, &$references) {
100 100
 
101 101
 		// @@todo I think there's an issue here with the Validator, because you're changing the instance state and the
102 102
 		// instance may be reused afterwards.
103 103
 
104
-		$properties = $this->validator->validate( $post_id );
104
+		$properties = $this->validator->validate($post_id);
105 105
 
106
-		foreach ( $properties as $property ) {
107
-			$transform_instance = $this->transform_functions_registry->get_transform_function( $property['transform_function'] );
108
-			$data               = $this->get_data_from_data_source( $post_id, $property );
109
-			if ( null !== $transform_instance ) {
110
-				$transform_data = $transform_instance->transform_data( $data, $jsonld, $references, $post_id );
111
-				if ( null !== $transform_data ) {
112
-					$jsonld[ $property['property_name'] ] = $this->make_single( $transform_data );
106
+		foreach ($properties as $property) {
107
+			$transform_instance = $this->transform_functions_registry->get_transform_function($property['transform_function']);
108
+			$data               = $this->get_data_from_data_source($post_id, $property);
109
+			if (null !== $transform_instance) {
110
+				$transform_data = $transform_instance->transform_data($data, $jsonld, $references, $post_id);
111
+				if (null !== $transform_data) {
112
+					$jsonld[$property['property_name']] = $this->make_single($transform_data);
113 113
 				}
114 114
 			} else {
115
-				$jsonld[ $property['property_name'] ] = $this->make_single( $data );
115
+				$jsonld[$property['property_name']] = $this->make_single($data);
116 116
 			}
117 117
 		}
118 118
 
@@ -127,21 +127,21 @@  discard block
 block discarded – undo
127 127
 	 *
128 128
 	 * @return array Returns key, value array, if the value is not found, then it returns null.
129 129
 	 */
130
-	final public function get_data_from_data_source( $post_id, $property_data ) {
130
+	final public function get_data_from_data_source($post_id, $property_data) {
131 131
 		$value = $property_data['field_name'];
132 132
 
133 133
 		// Do 1 to 1 mapping and return result.
134
-		switch ( $property_data['field_type'] ) {
134
+		switch ($property_data['field_type']) {
135 135
 			case self::FIELD_TYPE_ACF:
136
-				if ( ! function_exists( 'get_field' ) ) {
136
+				if ( ! function_exists('get_field')) {
137 137
 					return array();
138 138
 				}
139 139
 
140
-				return get_field( $property_data['field_name'], $post_id );
140
+				return get_field($property_data['field_name'], $post_id);
141 141
 
142 142
 			case self::FIELD_TYPE_CUSTOM_FIELD:
143 143
 
144
-				return array_map( 'wp_strip_all_tags', get_post_meta( $post_id, $value ) );
144
+				return array_map('wp_strip_all_tags', get_post_meta($post_id, $value));
145 145
 
146 146
 			default:
147 147
 				return $value;
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
 
150 150
 	}
151 151
 
152
-	private function make_single( $value ) {
152
+	private function make_single($value) {
153 153
 
154 154
 		$values = (array) $value;
155 155
 
156
-		if ( empty( $values ) ) {
156
+		if (empty($values)) {
157 157
 			return null;
158 158
 		}
159 159
 
160
-		if ( 1 === count( $values ) && 0 === key( $values ) ) {
161
-			return current( $values );
160
+		if (1 === count($values) && 0 === key($values)) {
161
+			return current($values);
162 162
 		}
163 163
 
164 164
 		return $values;
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-endpoint.php 2 patches
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -21,138 +21,138 @@
 block discarded – undo
21 21
  */
22 22
 class Jsonld_Endpoint {
23 23
 
24
-	/**
25
-	 * The {@link Wordlift_Jsonld_Service} instance.
26
-	 *
27
-	 * @var Wordlift_Jsonld_Service The {@link Wordlift_Jsonld_Service} instance.
28
-	 */
29
-	private $jsonld_service;
30
-	/**
31
-	 * @var \Wordlift_Entity_Uri_Service
32
-	 */
33
-	private $entity_uri_service;
34
-
35
-	/**
36
-	 * Jsonld_Endpoint constructor.
37
-	 *
38
-	 * @param \Wordlift_Jsonld_Service $jsonld_service
39
-	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service
40
-	 */
41
-	public function __construct( $jsonld_service, $entity_uri_service ) {
42
-
43
-		$this->jsonld_service     = $jsonld_service;
44
-		$this->entity_uri_service = $entity_uri_service;
45
-
46
-		// PHP 5.3 compatibility.
47
-		$that = $this;
48
-		add_action( 'rest_api_init', function () use ( $that ) {
49
-			register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/(?P<id>\d+)', array(
50
-				'methods'  => 'GET',
51
-				'callback' => array( $that, 'jsonld_using_post_id' ),
52
-				'args'     => array(
53
-					'id' => array(
54
-						'validate_callback' => function ( $param, $request, $key ) {
55
-							return is_numeric( $param );
56
-						},
57
-						'sanitize_callback' => 'absint',
58
-					),
59
-				)
60
-			) );
61
-
62
-			register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/(?P<post_type>.*)/(?P<post_name>.*)', array(
63
-				'methods'  => 'GET',
64
-				'callback' => array( $that, 'jsonld_using_get_page_by_path' ),
65
-			) );
66
-
67
-			register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/http/(?P<item_id>.*)', array(
68
-				'methods'  => 'GET',
69
-				'callback' => array( $that, 'jsonld_using_item_id' ),
70
-			) );
71
-		} );
72
-
73
-	}
74
-
75
-	/**
76
-	 * Callback for the JSON-LD request.
77
-	 *
78
-	 * @param array $request {
79
-	 *  The request array.
80
-	 *
81
-	 * @type int $id The post id.
82
-	 * }
83
-	 *
84
-	 * @return WP_REST_Response
85
-	 * @throws \Exception
86
-	 */
87
-	public function jsonld_using_post_id( $request ) {
88
-
89
-		$post_id     = $request['id'];
90
-		$is_homepage = ( 0 === $post_id );
91
-
92
-		// Send the generated JSON-LD.
93
-		$data     = $this->jsonld_service->get_jsonld( $is_homepage, $post_id );
94
-		$response = new WP_REST_Response( $data );
95
-
96
-		$cache_in_seconds = 86400;
97
-		$date_timezone    = new DateTimeZone( 'GMT' );
98
-		$date_now         = new DateTime( 'now', $date_timezone );
99
-		$date_interval    = new DateInterval( "PT{$cache_in_seconds}S" );
100
-		$expires          = $date_now->add( $date_interval )->format( 'D, j M Y H:i:s T' );
101
-
102
-		$response->set_headers( array(
103
-			'Content-Type'  => 'application/ld+json; charset=' . get_option( 'blog_charset' ),
104
-			'Cache-Control' => "max-age=$cache_in_seconds",
105
-			'Expires'       => $expires
106
-		) );
107
-
108
-		return $response;
109
-	}
110
-
111
-	/**
112
-	 * Provide a JSON-LD given the itemId.
113
-	 *
114
-	 * @param array $request {
115
-	 *  The request array.
116
-	 *
117
-	 * @type string $item_id The entity item id.
118
-	 * }
119
-	 *
120
-	 * @return WP_REST_Response
121
-	 * @throws \Exception
122
-	 */
123
-	public function jsonld_using_item_id( $request ) {
124
-
125
-		$item_id = 'http://' . $request['item_id'];
126
-		$post    = $this->entity_uri_service->get_entity( $item_id );
127
-
128
-		if ( ! is_a( $post, 'WP_Post' ) ) {
129
-			return new WP_REST_Response( esc_html( "$item_id not found." ), 404, array( 'Content-Type' => 'text/html' ) );
130
-		}
131
-
132
-		return $this->jsonld_using_post_id( array( 'id' => $post->ID, ) );
133
-	}
134
-
135
-	public function jsonld_using_get_page_by_path( $request ) {
136
-
137
-		$post_name = $request['post_name'];
138
-		$post_type = $request['post_type'];
139
-
140
-		global $wpdb;
141
-
142
-		$sql     = "
24
+    /**
25
+     * The {@link Wordlift_Jsonld_Service} instance.
26
+     *
27
+     * @var Wordlift_Jsonld_Service The {@link Wordlift_Jsonld_Service} instance.
28
+     */
29
+    private $jsonld_service;
30
+    /**
31
+     * @var \Wordlift_Entity_Uri_Service
32
+     */
33
+    private $entity_uri_service;
34
+
35
+    /**
36
+     * Jsonld_Endpoint constructor.
37
+     *
38
+     * @param \Wordlift_Jsonld_Service $jsonld_service
39
+     * @param \Wordlift_Entity_Uri_Service $entity_uri_service
40
+     */
41
+    public function __construct( $jsonld_service, $entity_uri_service ) {
42
+
43
+        $this->jsonld_service     = $jsonld_service;
44
+        $this->entity_uri_service = $entity_uri_service;
45
+
46
+        // PHP 5.3 compatibility.
47
+        $that = $this;
48
+        add_action( 'rest_api_init', function () use ( $that ) {
49
+            register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/(?P<id>\d+)', array(
50
+                'methods'  => 'GET',
51
+                'callback' => array( $that, 'jsonld_using_post_id' ),
52
+                'args'     => array(
53
+                    'id' => array(
54
+                        'validate_callback' => function ( $param, $request, $key ) {
55
+                            return is_numeric( $param );
56
+                        },
57
+                        'sanitize_callback' => 'absint',
58
+                    ),
59
+                )
60
+            ) );
61
+
62
+            register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/(?P<post_type>.*)/(?P<post_name>.*)', array(
63
+                'methods'  => 'GET',
64
+                'callback' => array( $that, 'jsonld_using_get_page_by_path' ),
65
+            ) );
66
+
67
+            register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/http/(?P<item_id>.*)', array(
68
+                'methods'  => 'GET',
69
+                'callback' => array( $that, 'jsonld_using_item_id' ),
70
+            ) );
71
+        } );
72
+
73
+    }
74
+
75
+    /**
76
+     * Callback for the JSON-LD request.
77
+     *
78
+     * @param array $request {
79
+     *  The request array.
80
+     *
81
+     * @type int $id The post id.
82
+     * }
83
+     *
84
+     * @return WP_REST_Response
85
+     * @throws \Exception
86
+     */
87
+    public function jsonld_using_post_id( $request ) {
88
+
89
+        $post_id     = $request['id'];
90
+        $is_homepage = ( 0 === $post_id );
91
+
92
+        // Send the generated JSON-LD.
93
+        $data     = $this->jsonld_service->get_jsonld( $is_homepage, $post_id );
94
+        $response = new WP_REST_Response( $data );
95
+
96
+        $cache_in_seconds = 86400;
97
+        $date_timezone    = new DateTimeZone( 'GMT' );
98
+        $date_now         = new DateTime( 'now', $date_timezone );
99
+        $date_interval    = new DateInterval( "PT{$cache_in_seconds}S" );
100
+        $expires          = $date_now->add( $date_interval )->format( 'D, j M Y H:i:s T' );
101
+
102
+        $response->set_headers( array(
103
+            'Content-Type'  => 'application/ld+json; charset=' . get_option( 'blog_charset' ),
104
+            'Cache-Control' => "max-age=$cache_in_seconds",
105
+            'Expires'       => $expires
106
+        ) );
107
+
108
+        return $response;
109
+    }
110
+
111
+    /**
112
+     * Provide a JSON-LD given the itemId.
113
+     *
114
+     * @param array $request {
115
+     *  The request array.
116
+     *
117
+     * @type string $item_id The entity item id.
118
+     * }
119
+     *
120
+     * @return WP_REST_Response
121
+     * @throws \Exception
122
+     */
123
+    public function jsonld_using_item_id( $request ) {
124
+
125
+        $item_id = 'http://' . $request['item_id'];
126
+        $post    = $this->entity_uri_service->get_entity( $item_id );
127
+
128
+        if ( ! is_a( $post, 'WP_Post' ) ) {
129
+            return new WP_REST_Response( esc_html( "$item_id not found." ), 404, array( 'Content-Type' => 'text/html' ) );
130
+        }
131
+
132
+        return $this->jsonld_using_post_id( array( 'id' => $post->ID, ) );
133
+    }
134
+
135
+    public function jsonld_using_get_page_by_path( $request ) {
136
+
137
+        $post_name = $request['post_name'];
138
+        $post_type = $request['post_type'];
139
+
140
+        global $wpdb;
141
+
142
+        $sql     = "
143 143
 			SELECT ID
144 144
 			FROM $wpdb->posts
145 145
 			WHERE post_name = %s
146 146
 			 AND post_type = %s
147 147
 		";
148 148
 
149
-		$post_id = $wpdb->get_var( $wpdb->prepare( $sql, $post_name, $post_type ) );
149
+        $post_id = $wpdb->get_var( $wpdb->prepare( $sql, $post_name, $post_type ) );
150 150
 
151
-		if ( is_null( $post_id ) ) {
152
-			return new WP_REST_Response( esc_html( "$post_name of type $post_type not found." ), 404, array( 'Content-Type' => 'text/html' ) );
153
-		}
151
+        if ( is_null( $post_id ) ) {
152
+            return new WP_REST_Response( esc_html( "$post_name of type $post_type not found." ), 404, array( 'Content-Type' => 'text/html' ) );
153
+        }
154 154
 
155
-		return $this->jsonld_using_post_id( array( 'id' => $post_id, ) );
156
-	}
155
+        return $this->jsonld_using_post_id( array( 'id' => $post_id, ) );
156
+    }
157 157
 
158 158
 }
159 159
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -38,36 +38,36 @@  discard block
 block discarded – undo
38 38
 	 * @param \Wordlift_Jsonld_Service $jsonld_service
39 39
 	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service
40 40
 	 */
41
-	public function __construct( $jsonld_service, $entity_uri_service ) {
41
+	public function __construct($jsonld_service, $entity_uri_service) {
42 42
 
43 43
 		$this->jsonld_service     = $jsonld_service;
44 44
 		$this->entity_uri_service = $entity_uri_service;
45 45
 
46 46
 		// PHP 5.3 compatibility.
47 47
 		$that = $this;
48
-		add_action( 'rest_api_init', function () use ( $that ) {
49
-			register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/(?P<id>\d+)', array(
48
+		add_action('rest_api_init', function() use ($that) {
49
+			register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/(?P<id>\d+)', array(
50 50
 				'methods'  => 'GET',
51
-				'callback' => array( $that, 'jsonld_using_post_id' ),
51
+				'callback' => array($that, 'jsonld_using_post_id'),
52 52
 				'args'     => array(
53 53
 					'id' => array(
54
-						'validate_callback' => function ( $param, $request, $key ) {
55
-							return is_numeric( $param );
54
+						'validate_callback' => function($param, $request, $key) {
55
+							return is_numeric($param);
56 56
 						},
57 57
 						'sanitize_callback' => 'absint',
58 58
 					),
59 59
 				)
60
-			) );
60
+			));
61 61
 
62
-			register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/(?P<post_type>.*)/(?P<post_name>.*)', array(
62
+			register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/(?P<post_type>.*)/(?P<post_name>.*)', array(
63 63
 				'methods'  => 'GET',
64
-				'callback' => array( $that, 'jsonld_using_get_page_by_path' ),
65
-			) );
64
+				'callback' => array($that, 'jsonld_using_get_page_by_path'),
65
+			));
66 66
 
67
-			register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/http/(?P<item_id>.*)', array(
67
+			register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/jsonld/http/(?P<item_id>.*)', array(
68 68
 				'methods'  => 'GET',
69
-				'callback' => array( $that, 'jsonld_using_item_id' ),
70
-			) );
69
+				'callback' => array($that, 'jsonld_using_item_id'),
70
+			));
71 71
 		} );
72 72
 
73 73
 	}
@@ -84,26 +84,26 @@  discard block
 block discarded – undo
84 84
 	 * @return WP_REST_Response
85 85
 	 * @throws \Exception
86 86
 	 */
87
-	public function jsonld_using_post_id( $request ) {
87
+	public function jsonld_using_post_id($request) {
88 88
 
89 89
 		$post_id     = $request['id'];
90
-		$is_homepage = ( 0 === $post_id );
90
+		$is_homepage = (0 === $post_id);
91 91
 
92 92
 		// Send the generated JSON-LD.
93
-		$data     = $this->jsonld_service->get_jsonld( $is_homepage, $post_id );
94
-		$response = new WP_REST_Response( $data );
93
+		$data     = $this->jsonld_service->get_jsonld($is_homepage, $post_id);
94
+		$response = new WP_REST_Response($data);
95 95
 
96 96
 		$cache_in_seconds = 86400;
97
-		$date_timezone    = new DateTimeZone( 'GMT' );
98
-		$date_now         = new DateTime( 'now', $date_timezone );
99
-		$date_interval    = new DateInterval( "PT{$cache_in_seconds}S" );
100
-		$expires          = $date_now->add( $date_interval )->format( 'D, j M Y H:i:s T' );
97
+		$date_timezone    = new DateTimeZone('GMT');
98
+		$date_now         = new DateTime('now', $date_timezone);
99
+		$date_interval    = new DateInterval("PT{$cache_in_seconds}S");
100
+		$expires          = $date_now->add($date_interval)->format('D, j M Y H:i:s T');
101 101
 
102
-		$response->set_headers( array(
103
-			'Content-Type'  => 'application/ld+json; charset=' . get_option( 'blog_charset' ),
102
+		$response->set_headers(array(
103
+			'Content-Type'  => 'application/ld+json; charset='.get_option('blog_charset'),
104 104
 			'Cache-Control' => "max-age=$cache_in_seconds",
105 105
 			'Expires'       => $expires
106
-		) );
106
+		));
107 107
 
108 108
 		return $response;
109 109
 	}
@@ -120,39 +120,39 @@  discard block
 block discarded – undo
120 120
 	 * @return WP_REST_Response
121 121
 	 * @throws \Exception
122 122
 	 */
123
-	public function jsonld_using_item_id( $request ) {
123
+	public function jsonld_using_item_id($request) {
124 124
 
125
-		$item_id = 'http://' . $request['item_id'];
126
-		$post    = $this->entity_uri_service->get_entity( $item_id );
125
+		$item_id = 'http://'.$request['item_id'];
126
+		$post    = $this->entity_uri_service->get_entity($item_id);
127 127
 
128
-		if ( ! is_a( $post, 'WP_Post' ) ) {
129
-			return new WP_REST_Response( esc_html( "$item_id not found." ), 404, array( 'Content-Type' => 'text/html' ) );
128
+		if ( ! is_a($post, 'WP_Post')) {
129
+			return new WP_REST_Response(esc_html("$item_id not found."), 404, array('Content-Type' => 'text/html'));
130 130
 		}
131 131
 
132
-		return $this->jsonld_using_post_id( array( 'id' => $post->ID, ) );
132
+		return $this->jsonld_using_post_id(array('id' => $post->ID,));
133 133
 	}
134 134
 
135
-	public function jsonld_using_get_page_by_path( $request ) {
135
+	public function jsonld_using_get_page_by_path($request) {
136 136
 
137 137
 		$post_name = $request['post_name'];
138 138
 		$post_type = $request['post_type'];
139 139
 
140 140
 		global $wpdb;
141 141
 
142
-		$sql     = "
142
+		$sql = "
143 143
 			SELECT ID
144 144
 			FROM $wpdb->posts
145 145
 			WHERE post_name = %s
146 146
 			 AND post_type = %s
147 147
 		";
148 148
 
149
-		$post_id = $wpdb->get_var( $wpdb->prepare( $sql, $post_name, $post_type ) );
149
+		$post_id = $wpdb->get_var($wpdb->prepare($sql, $post_name, $post_type));
150 150
 
151
-		if ( is_null( $post_id ) ) {
152
-			return new WP_REST_Response( esc_html( "$post_name of type $post_type not found." ), 404, array( 'Content-Type' => 'text/html' ) );
151
+		if (is_null($post_id)) {
152
+			return new WP_REST_Response(esc_html("$post_name of type $post_type not found."), 404, array('Content-Type' => 'text/html'));
153 153
 		}
154 154
 
155
-		return $this->jsonld_using_post_id( array( 'id' => $post_id, ) );
155
+		return $this->jsonld_using_post_id(array('id' => $post_id,));
156 156
 	}
157 157
 
158 158
 }
159 159
\ No newline at end of file
Please login to merge, or discard this patch.
src/install/class-wordlift-install-3-25-0.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -60,54 +60,54 @@  discard block
 block discarded – undo
60 60
  * @subpackage Wordlift/install
61 61
  */
62 62
 class Wordlift_Install_3_25_0 extends Wordlift_Install {
63
-	/**
64
-	 * @inheritdoc
65
-	 */
66
-	protected static $version = '3.25.2.20200317.1';
67
-
68
-	/**
69
-	 * Reference to global $wpdb instance.
70
-	 *
71
-	 * @var $wpdb
72
-	 * */
73
-	private $wpdb;
74
-
75
-	/** Constructor for 3_25_0 installer. */
76
-	public function __construct() {
77
-		global $wpdb;
78
-		$this->wpdb = $wpdb;
79
-	}
80
-
81
-	/**
82
-	 * @inheritdoc
83
-	 */
84
-	public function install() {
85
-		$this->create_mappings_table();
86
-		$this->create_rule_group_table();
87
-		$this->create_rule_table();
88
-		$this->create_property_table();
89
-	}
90
-
91
-	/**
92
-	 * Install mappings table.
93
-	 *
94
-	 * +----------------+--------------+------+-----+---------+----------------+
95
-	 * | Field          | Type         | Null | Key | Default | Extra          |
96
-	 * +----------------+--------------+------+-----+---------+----------------+
97
-	 * | mapping_id     | int(11)      | NO   | PRI | NULL    | auto_increment |
98
-	 * | mapping_title  | varchar(255) | NO   |     | NULL    |                |
99
-	 * | mapping_status | varchar(255) | NO   |     | active  |                |
100
-	 * +----------------+--------------+------+-----+---------+----------------+
101
-	 *
102
-	 * @return void
103
-	 * @since 3.25.0
104
-	 *
105
-	 */
106
-	public function create_mappings_table() {
107
-		$table_name      = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME;
108
-		$charset_collate = $this->wpdb->get_charset_collate();
109
-		// @@todo: is necessary to prefix the column names with `mapping_` ? we're the mappings table already.
110
-		$sql = <<<EOF
63
+    /**
64
+     * @inheritdoc
65
+     */
66
+    protected static $version = '3.25.2.20200317.1';
67
+
68
+    /**
69
+     * Reference to global $wpdb instance.
70
+     *
71
+     * @var $wpdb
72
+     * */
73
+    private $wpdb;
74
+
75
+    /** Constructor for 3_25_0 installer. */
76
+    public function __construct() {
77
+        global $wpdb;
78
+        $this->wpdb = $wpdb;
79
+    }
80
+
81
+    /**
82
+     * @inheritdoc
83
+     */
84
+    public function install() {
85
+        $this->create_mappings_table();
86
+        $this->create_rule_group_table();
87
+        $this->create_rule_table();
88
+        $this->create_property_table();
89
+    }
90
+
91
+    /**
92
+     * Install mappings table.
93
+     *
94
+     * +----------------+--------------+------+-----+---------+----------------+
95
+     * | Field          | Type         | Null | Key | Default | Extra          |
96
+     * +----------------+--------------+------+-----+---------+----------------+
97
+     * | mapping_id     | int(11)      | NO   | PRI | NULL    | auto_increment |
98
+     * | mapping_title  | varchar(255) | NO   |     | NULL    |                |
99
+     * | mapping_status | varchar(255) | NO   |     | active  |                |
100
+     * +----------------+--------------+------+-----+---------+----------------+
101
+     *
102
+     * @return void
103
+     * @since 3.25.0
104
+     *
105
+     */
106
+    public function create_mappings_table() {
107
+        $table_name      = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME;
108
+        $charset_collate = $this->wpdb->get_charset_collate();
109
+        // @@todo: is necessary to prefix the column names with `mapping_` ? we're the mappings table already.
110
+        $sql = <<<EOF
111 111
         CREATE TABLE $table_name (
112 112
 			mapping_id INT(11) NOT NULL AUTO_INCREMENT, 
113 113
 			mapping_title VARCHAR(255) NOT NULL,
@@ -115,33 +115,33 @@  discard block
 block discarded – undo
115 115
 			PRIMARY KEY  (mapping_id)
116 116
         ) $charset_collate;
117 117
 EOF;
118
-		// Execute the query for mappings table.
119
-		dbDelta( $sql );
120
-	}
121
-
122
-
123
-	/**
124
-	 * Install rule table
125
-	 *
126
-	 * +------------------+--------------+------+-----+---------+----------------+
127
-	 * | Field            | Type         | Null | Key | Default | Extra          |
128
-	 * +------------------+--------------+------+-----+---------+----------------+
129
-	 * | rule_id          | int(11)      | NO   | PRI | NULL    | auto_increment |
130
-	 * | rule_field_one   | varchar(255) | NO   |     | NULL    |                |
131
-	 * | rule_logic_field | varchar(255) | NO   |     | NULL    |                |
132
-	 * | rule_field_two   | varchar(255) | NO   |     | NULL    |                |
133
-	 * | rule_group_id    | int(11)      | NO   | MUL | NULL    |                |
134
-	 * +------------------+--------------+------+-----+---------+----------------+
135
-	 *
136
-	 * @return void
137
-	 * @since 3.25.0
138
-	 */
139
-	public function create_rule_table() {
140
-		$table_name            = $this->wpdb->prefix . WL_RULE_TABLE_NAME;
141
-		$rule_group_table_name = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME;
142
-		$charset_collate       = $this->wpdb->get_charset_collate();
143
-		// @@todo: is necessary to prefix the column names with `rule_` ? we're the rules table already.
144
-		$sql = <<<EOF
118
+        // Execute the query for mappings table.
119
+        dbDelta( $sql );
120
+    }
121
+
122
+
123
+    /**
124
+     * Install rule table
125
+     *
126
+     * +------------------+--------------+------+-----+---------+----------------+
127
+     * | Field            | Type         | Null | Key | Default | Extra          |
128
+     * +------------------+--------------+------+-----+---------+----------------+
129
+     * | rule_id          | int(11)      | NO   | PRI | NULL    | auto_increment |
130
+     * | rule_field_one   | varchar(255) | NO   |     | NULL    |                |
131
+     * | rule_logic_field | varchar(255) | NO   |     | NULL    |                |
132
+     * | rule_field_two   | varchar(255) | NO   |     | NULL    |                |
133
+     * | rule_group_id    | int(11)      | NO   | MUL | NULL    |                |
134
+     * +------------------+--------------+------+-----+---------+----------------+
135
+     *
136
+     * @return void
137
+     * @since 3.25.0
138
+     */
139
+    public function create_rule_table() {
140
+        $table_name            = $this->wpdb->prefix . WL_RULE_TABLE_NAME;
141
+        $rule_group_table_name = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME;
142
+        $charset_collate       = $this->wpdb->get_charset_collate();
143
+        // @@todo: is necessary to prefix the column names with `rule_` ? we're the rules table already.
144
+        $sql = <<<EOF
145 145
         CREATE TABLE IF NOT EXISTS $table_name (
146 146
 				rule_id INT(11) NOT NULL AUTO_INCREMENT,
147 147
 				rule_field_one VARCHAR(255) NOT NULL,
@@ -153,31 +153,31 @@  discard block
 block discarded – undo
153 153
 				PRIMARY KEY  (rule_id)
154 154
         ) $charset_collate;
155 155
 EOF;
156
-		// Execute the query for mappings table.
157
-		$this->wpdb->query( $sql );
158
-	}
159
-
160
-	/**
161
-	 * Install rule group table, should run after creating mapping and
162
-	 * rule table due to foreign key reference.
163
-	 *
164
-	 * +---------------+---------+------+-----+---------+----------------+
165
-	 * | Field         | Type    | Null | Key | Default | Extra          |
166
-	 * +---------------+---------+------+-----+---------+----------------+
167
-	 * | rule_group_id | int(11) | NO   | PRI | NULL    | auto_increment |
168
-	 * | mapping_id    | int(11) | NO   | MUL | NULL    |                |
169
-	 * +---------------+---------+------+-----+---------+----------------+
170
-	 *
171
-	 * @return void
172
-	 * @since 3.25.0
173
-	 */
174
-	public function create_rule_group_table() {
175
-		$table_name      = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME;
176
-		$charset_collate = $this->wpdb->get_charset_collate();
177
-
178
-		$mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME;
179
-		// @@todo is this table actually needed? I am not understanding what it does.
180
-		$sql = <<<EOF
156
+        // Execute the query for mappings table.
157
+        $this->wpdb->query( $sql );
158
+    }
159
+
160
+    /**
161
+     * Install rule group table, should run after creating mapping and
162
+     * rule table due to foreign key reference.
163
+     *
164
+     * +---------------+---------+------+-----+---------+----------------+
165
+     * | Field         | Type    | Null | Key | Default | Extra          |
166
+     * +---------------+---------+------+-----+---------+----------------+
167
+     * | rule_group_id | int(11) | NO   | PRI | NULL    | auto_increment |
168
+     * | mapping_id    | int(11) | NO   | MUL | NULL    |                |
169
+     * +---------------+---------+------+-----+---------+----------------+
170
+     *
171
+     * @return void
172
+     * @since 3.25.0
173
+     */
174
+    public function create_rule_group_table() {
175
+        $table_name      = $this->wpdb->prefix . WL_RULE_GROUP_TABLE_NAME;
176
+        $charset_collate = $this->wpdb->get_charset_collate();
177
+
178
+        $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME;
179
+        // @@todo is this table actually needed? I am not understanding what it does.
180
+        $sql = <<<EOF
181 181
         CREATE TABLE IF NOT EXISTS $table_name (
182 182
                 rule_group_id INT(11) NOT NULL AUTO_INCREMENT,
183 183
                 mapping_id INT(11) NOT NULL,
@@ -186,38 +186,38 @@  discard block
 block discarded – undo
186 186
                 ON DELETE CASCADE
187 187
         ) $charset_collate;
188 188
 EOF;
189
-		// Execute the query for rule group table, we cant use db delta
190
-		// due to lack of support for foreign keys.
191
-		$this->wpdb->query( $sql );
192
-	}
193
-
194
-
195
-	/**
196
-	 * Install property table, should run after mapping table due to
197
-	 * foreign key reference.
198
-	 *
199
-	 * +--------------------+--------------+------+-----+---------+----------------+
200
-	 * | Field              | Type         | Null | Key | Default | Extra          |
201
-	 * +--------------------+--------------+------+-----+---------+----------------+
202
-	 * | property_id        | int(11)      | NO   | PRI | NULL    | auto_increment |
203
-	 * | mapping_id         | int(11)      | NO   | MUL | NULL    |                |
204
-	 * | property_name      | varchar(255) | NO   |     | NULL    |                |
205
-	 * | field_type         | varchar(255) | NO   |     | NULL    |                |
206
-	 * | field_name         | varchar(255) | NO   |     | NULL    |                |
207
-	 * | transform_function | varchar(255) | NO   |     | NULL    |                |
208
-	 * | property_status    | varchar(255) | NO   |     | active  |                |
209
-	 * +--------------------+--------------+------+-----+---------+----------------+
210
-	 *
211
-	 * @return void
212
-	 * @since 3.25.0
213
-	 */
214
-	public function create_property_table() {
215
-		$table_name      = $this->wpdb->prefix . WL_PROPERTY_TABLE_NAME;
216
-		$charset_collate = $this->wpdb->get_charset_collate();
217
-
218
-		$mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME;
219
-		// @@todo do you we need the `property_` prefix? this is the property table anyway.
220
-		$sql = <<<EOF
189
+        // Execute the query for rule group table, we cant use db delta
190
+        // due to lack of support for foreign keys.
191
+        $this->wpdb->query( $sql );
192
+    }
193
+
194
+
195
+    /**
196
+     * Install property table, should run after mapping table due to
197
+     * foreign key reference.
198
+     *
199
+     * +--------------------+--------------+------+-----+---------+----------------+
200
+     * | Field              | Type         | Null | Key | Default | Extra          |
201
+     * +--------------------+--------------+------+-----+---------+----------------+
202
+     * | property_id        | int(11)      | NO   | PRI | NULL    | auto_increment |
203
+     * | mapping_id         | int(11)      | NO   | MUL | NULL    |                |
204
+     * | property_name      | varchar(255) | NO   |     | NULL    |                |
205
+     * | field_type         | varchar(255) | NO   |     | NULL    |                |
206
+     * | field_name         | varchar(255) | NO   |     | NULL    |                |
207
+     * | transform_function | varchar(255) | NO   |     | NULL    |                |
208
+     * | property_status    | varchar(255) | NO   |     | active  |                |
209
+     * +--------------------+--------------+------+-----+---------+----------------+
210
+     *
211
+     * @return void
212
+     * @since 3.25.0
213
+     */
214
+    public function create_property_table() {
215
+        $table_name      = $this->wpdb->prefix . WL_PROPERTY_TABLE_NAME;
216
+        $charset_collate = $this->wpdb->get_charset_collate();
217
+
218
+        $mapping_table_name = $this->wpdb->prefix . WL_MAPPING_TABLE_NAME;
219
+        // @@todo do you we need the `property_` prefix? this is the property table anyway.
220
+        $sql = <<<EOF
221 221
         CREATE TABLE IF NOT EXISTS $table_name (
222 222
                 property_id INT(11) NOT NULL AUTO_INCREMENT,
223 223
                 mapping_id INT(11) NOT NULL,
@@ -231,18 +231,18 @@  discard block
 block discarded – undo
231 231
                 ON DELETE CASCADE
232 232
         ) $charset_collate;
233 233
 EOF;
234
-		// Execute the query for property table, we cant use db delta
235
-		// due to lack of support for foreign keys.
236
-		$this->wpdb->query( $sql );
237
-	}
238
-
239
-	public static function drop_tables() {
240
-		global $wpdb;
241
-
242
-		$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . WL_PROPERTY_TABLE_NAME );
243
-		$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . WL_RULE_TABLE_NAME );
244
-		$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . WL_RULE_GROUP_TABLE_NAME );
245
-		$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . WL_MAPPING_TABLE_NAME );
246
-	}
234
+        // Execute the query for property table, we cant use db delta
235
+        // due to lack of support for foreign keys.
236
+        $this->wpdb->query( $sql );
237
+    }
238
+
239
+    public static function drop_tables() {
240
+        global $wpdb;
241
+
242
+        $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . WL_PROPERTY_TABLE_NAME );
243
+        $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . WL_RULE_TABLE_NAME );
244
+        $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . WL_RULE_GROUP_TABLE_NAME );
245
+        $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . WL_MAPPING_TABLE_NAME );
246
+    }
247 247
 
248 248
 }
Please login to merge, or discard this patch.