Completed
Push — master ( d5bcae...0ae8a5 )
by Naveen
30s queued 12s
created
src/wordlift/post-excerpt/class-post-excerpt-rest-controller.php 2 patches
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -18,210 +18,210 @@
 block discarded – undo
18 18
 
19 19
 class Post_Excerpt_Rest_Controller {
20 20
 
21
-	const POST_EXCERPT_NAMESPACE = 'post-excerpt';
22
-	/**
23
-	 * Key for storing the meta data for the wordlift post excerpt.
24
-	 */
25
-	const POST_EXCERPT_META_KEY = '_wl_post_excerpt_meta';
26
-
27
-	/**
28
-	 * Url for getting the post excerpt data from wordlift api.
29
-	 */
30
-	const WORDLIFT_POST_EXCERPT_ENDPOINT = '/summarize';
31
-
32
-	/**
33
-	 * Wordlift returns excerpt in response using this key..
34
-	 */
35
-	const WORDLIFT_POST_EXCERPT_RESPONSE_KEY = 'summary';
36
-
37
-	public static function register_routes() {
38
-		add_action( 'rest_api_init', 'Wordlift\Post_Excerpt\Post_Excerpt_Rest_Controller::register_route_callback' );
39
-	}
40
-
41
-	/**
42
-	 * Determines whether we need to get the excerpt from wordlift api,
43
-	 * or just use the one we already obtained by generating the hash and comparing it
44
-	 * with the previous one.
45
-	 *
46
-	 * @param $request WP_REST_Request $request {@link WP_REST_Request instance}.
47
-	 *
48
-	 * @return array Post excerpt data.
49
-	 */
50
-	public static function get_post_excerpt( $request ) {
51
-		$data      = $request->get_params();
52
-		$post_id   = $data['post_id'];
53
-		$post_body = strip_shortcodes( $data['post_body'] );
54
-		/**
55
-		 * @param $post_body string The post content sent from wordpress editor.
56
-		 * @param $post_id int The post id.
57
-		 *
58
-		 * @since 3.33.5
59
-		 * Allow post content sent to excerpt api to be filtered.
60
-		 */
61
-		$post_body       = apply_filters( 'wl_post_excerpt_post_content', $post_body, $post_id );
62
-		$current_hash    = md5( $post_body );
63
-		$server_response = self::get_post_excerpt_conditionally( $post_id, $post_body, $current_hash );
64
-		if ( empty( $server_response ) || ! array_key_exists( 'post_excerpt', $server_response ) ) {
65
-			return array(
66
-				'status'  => 'error',
67
-				'message' => __( 'Unable to contact WordLift API', 'wordlift' )
68
-			);
69
-		} else {
70
-			return array(
71
-				'status'       => 'success',
72
-				'post_excerpt' => $server_response['post_excerpt'],
73
-				'from_cache'   => $server_response['from_cache'],
74
-				'message'      => __( 'Excerpt successfully generated.', 'wordlift' )
75
-			);
76
-		}
77
-
78
-	}
79
-
80
-	/**
81
-	 * This function determines whether to get the excerpt from the server or from the meta cache.
82
-	 *
83
-	 * @param $post_id int The Post id.
84
-	 * @param $post_body string The post content
85
-	 * @param $current_hash string md5 hash of the current post body.
86
-	 *
87
-	 * @return array|bool|null
88
-	 */
89
-	public static function get_post_excerpt_conditionally( $post_id, $post_body, $current_hash ) {
90
-		$previous_data   = get_post_meta( $post_id, self::POST_EXCERPT_META_KEY, true );
91
-		$server_response = null;
92
-		if ( $previous_data === "" ) {
93
-			// There is no data in meta, so just fetch the data from remote server.
94
-			$server_response = self::get_post_excerpt_from_remote_server( $post_id, $post_body );
95
-		} else {
96
-			// If there is data in meta, get the previous hash and compare.
97
-			$previous_hash = $previous_data['post_body_hash'];
98
-
99
-			if ( $current_hash === $previous_hash ) {
100
-				// then return the previous value.
101
-				$server_response = array(
102
-					'post_excerpt' => $previous_data['post_excerpt'],
103
-					'from_cache'   => true
104
-				);
105
-			} else {
106
-				// send the request to external API and then send the response.
107
-				$server_response = self::get_post_excerpt_from_remote_server( $post_id, $post_body );
108
-			}
109
-		}
110
-
111
-		return $server_response;
112
-	}
113
-
114
-	/**
115
-	 * Sends the remote request to the wordlift API and saves the response in meta for
116
-	 * future use.
117
-	 *
118
-	 * @param $post_id int Post id which the post excerpt belongs to
119
-	 * @param $post_body string Total text content of the post body.
120
-	 *
121
-	 * @return array|bool
122
-	 */
123
-	public static function get_post_excerpt_from_remote_server( $post_id, $post_body ) {
124
-		// The configuration is constant for now, it might be changing in future.
125
-		$configuration = array(
126
-			'ratio'      => 0.0005,
127
-			'min_length' => 60
128
-		);
129
-		// Construct the url with the configuration
130
-		$endpoint    = add_query_arg( $configuration, self::WORDLIFT_POST_EXCERPT_ENDPOINT );
131
-		$api_service = Default_Api_Service::get_instance();
132
-		$response    = $api_service->request(
133
-			'POST',
134
-			$endpoint,
135
-			array( 'Content-Type' => 'text/plain' ),
136
-			$post_body,
137
-			null,
138
-			null,
139
-			array( 'data_format' => 'body' )
140
-		);
141
-
142
-		return self::save_response_to_meta_on_success( $post_id, $post_body, $response );
143
-	}
144
-
145
-	/**
146
-	 * Save the post excerpt to meta if the response is successful.
147
-	 *
148
-	 * @param $post_id int The post id
149
-	 * @param $post_body string Full text content of the post.
150
-	 * @param $response Response instance
151
-	 *
152
-	 * @return array|bool
153
-	 */
154
-	public static function save_response_to_meta_on_success( $post_id, $post_body, $response ) {
155
-		// If body exists then decode the body.
156
-		$body = json_decode( $response->get_body(), true );
157
-		if ( empty( $body ) || ! array_key_exists( self::WORDLIFT_POST_EXCERPT_RESPONSE_KEY, $body ) ) {
158
-			// Bail out if we get an incorrect response
159
-			return false;
160
-		} else {
161
-			$post_excerpt = (string) $body[ self::WORDLIFT_POST_EXCERPT_RESPONSE_KEY ];
162
-			// Save it to meta.
163
-			self::save_post_excerpt_in_meta( $post_id, $post_excerpt, $post_body );
164
-
165
-			return array(
166
-				'post_excerpt' => $post_excerpt,
167
-				'from_cache'   => false
168
-			);
169
-		}
170
-	}
171
-
172
-	/**
173
-	 * Saves the excerpt in the post meta.
174
-	 *
175
-	 * @param $post_id int Post id which the post excerpt belongs to
176
-	 * @param $post_excerpt string Post excerpt returned by the server
177
-	 * @param $post_body string Total text content of the post body.
178
-	 *
179
-	 * @return void
180
-	 */
181
-	public static function save_post_excerpt_in_meta( $post_id, $post_excerpt, $post_body ) {
182
-		// hash the post body and save it.
183
-		$data = array(
184
-			'post_body_hash' => md5( $post_body ),
185
-			'post_excerpt'   => $post_excerpt
186
-		);
187
-		update_post_meta( $post_id, self::POST_EXCERPT_META_KEY, $data );
188
-	}
189
-
190
-	/**
191
-	 * This call back is invoked by the Rest api action.
192
-	 */
193
-	public static function register_route_callback() {
194
-		/** @var  $post_id_validation_settings array Settings used to validate post id */
195
-		$post_id_validation_settings   = array(
196
-			'required'          => true,
197
-			'validate_callback' => function ( $param, $request, $key ) {
198
-				return is_numeric( $param );
199
-			}
200
-		);
201
-		$post_body_validation_settings = array(
202
-			'required'          => true,
203
-			'validate_callback' => function ( $param, $request, $key ) {
204
-				return is_string( $param );
205
-			}
206
-		);
207
-		/**
208
-		 * Rest route for getting the excerpt from wordlift api.
209
-		 */
210
-		register_rest_route(
211
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
212
-			'/' . self::POST_EXCERPT_NAMESPACE . '/(?P<post_id>\d+)',
213
-			array(
214
-				'methods'             => \WP_REST_Server::CREATABLE,
215
-				'callback'            => 'Wordlift\Post_Excerpt\Post_Excerpt_Rest_Controller::get_post_excerpt',
216
-				'permission_callback' => function () {
217
-					return current_user_can( 'publish_posts' );
218
-				},
219
-				'args'                => array(
220
-					'post_id'   => $post_id_validation_settings,
221
-					'post_body' => $post_body_validation_settings
222
-				)
223
-			)
224
-		);
225
-	}
21
+    const POST_EXCERPT_NAMESPACE = 'post-excerpt';
22
+    /**
23
+     * Key for storing the meta data for the wordlift post excerpt.
24
+     */
25
+    const POST_EXCERPT_META_KEY = '_wl_post_excerpt_meta';
26
+
27
+    /**
28
+     * Url for getting the post excerpt data from wordlift api.
29
+     */
30
+    const WORDLIFT_POST_EXCERPT_ENDPOINT = '/summarize';
31
+
32
+    /**
33
+     * Wordlift returns excerpt in response using this key..
34
+     */
35
+    const WORDLIFT_POST_EXCERPT_RESPONSE_KEY = 'summary';
36
+
37
+    public static function register_routes() {
38
+        add_action( 'rest_api_init', 'Wordlift\Post_Excerpt\Post_Excerpt_Rest_Controller::register_route_callback' );
39
+    }
40
+
41
+    /**
42
+     * Determines whether we need to get the excerpt from wordlift api,
43
+     * or just use the one we already obtained by generating the hash and comparing it
44
+     * with the previous one.
45
+     *
46
+     * @param $request WP_REST_Request $request {@link WP_REST_Request instance}.
47
+     *
48
+     * @return array Post excerpt data.
49
+     */
50
+    public static function get_post_excerpt( $request ) {
51
+        $data      = $request->get_params();
52
+        $post_id   = $data['post_id'];
53
+        $post_body = strip_shortcodes( $data['post_body'] );
54
+        /**
55
+         * @param $post_body string The post content sent from wordpress editor.
56
+         * @param $post_id int The post id.
57
+         *
58
+         * @since 3.33.5
59
+         * Allow post content sent to excerpt api to be filtered.
60
+         */
61
+        $post_body       = apply_filters( 'wl_post_excerpt_post_content', $post_body, $post_id );
62
+        $current_hash    = md5( $post_body );
63
+        $server_response = self::get_post_excerpt_conditionally( $post_id, $post_body, $current_hash );
64
+        if ( empty( $server_response ) || ! array_key_exists( 'post_excerpt', $server_response ) ) {
65
+            return array(
66
+                'status'  => 'error',
67
+                'message' => __( 'Unable to contact WordLift API', 'wordlift' )
68
+            );
69
+        } else {
70
+            return array(
71
+                'status'       => 'success',
72
+                'post_excerpt' => $server_response['post_excerpt'],
73
+                'from_cache'   => $server_response['from_cache'],
74
+                'message'      => __( 'Excerpt successfully generated.', 'wordlift' )
75
+            );
76
+        }
77
+
78
+    }
79
+
80
+    /**
81
+     * This function determines whether to get the excerpt from the server or from the meta cache.
82
+     *
83
+     * @param $post_id int The Post id.
84
+     * @param $post_body string The post content
85
+     * @param $current_hash string md5 hash of the current post body.
86
+     *
87
+     * @return array|bool|null
88
+     */
89
+    public static function get_post_excerpt_conditionally( $post_id, $post_body, $current_hash ) {
90
+        $previous_data   = get_post_meta( $post_id, self::POST_EXCERPT_META_KEY, true );
91
+        $server_response = null;
92
+        if ( $previous_data === "" ) {
93
+            // There is no data in meta, so just fetch the data from remote server.
94
+            $server_response = self::get_post_excerpt_from_remote_server( $post_id, $post_body );
95
+        } else {
96
+            // If there is data in meta, get the previous hash and compare.
97
+            $previous_hash = $previous_data['post_body_hash'];
98
+
99
+            if ( $current_hash === $previous_hash ) {
100
+                // then return the previous value.
101
+                $server_response = array(
102
+                    'post_excerpt' => $previous_data['post_excerpt'],
103
+                    'from_cache'   => true
104
+                );
105
+            } else {
106
+                // send the request to external API and then send the response.
107
+                $server_response = self::get_post_excerpt_from_remote_server( $post_id, $post_body );
108
+            }
109
+        }
110
+
111
+        return $server_response;
112
+    }
113
+
114
+    /**
115
+     * Sends the remote request to the wordlift API and saves the response in meta for
116
+     * future use.
117
+     *
118
+     * @param $post_id int Post id which the post excerpt belongs to
119
+     * @param $post_body string Total text content of the post body.
120
+     *
121
+     * @return array|bool
122
+     */
123
+    public static function get_post_excerpt_from_remote_server( $post_id, $post_body ) {
124
+        // The configuration is constant for now, it might be changing in future.
125
+        $configuration = array(
126
+            'ratio'      => 0.0005,
127
+            'min_length' => 60
128
+        );
129
+        // Construct the url with the configuration
130
+        $endpoint    = add_query_arg( $configuration, self::WORDLIFT_POST_EXCERPT_ENDPOINT );
131
+        $api_service = Default_Api_Service::get_instance();
132
+        $response    = $api_service->request(
133
+            'POST',
134
+            $endpoint,
135
+            array( 'Content-Type' => 'text/plain' ),
136
+            $post_body,
137
+            null,
138
+            null,
139
+            array( 'data_format' => 'body' )
140
+        );
141
+
142
+        return self::save_response_to_meta_on_success( $post_id, $post_body, $response );
143
+    }
144
+
145
+    /**
146
+     * Save the post excerpt to meta if the response is successful.
147
+     *
148
+     * @param $post_id int The post id
149
+     * @param $post_body string Full text content of the post.
150
+     * @param $response Response instance
151
+     *
152
+     * @return array|bool
153
+     */
154
+    public static function save_response_to_meta_on_success( $post_id, $post_body, $response ) {
155
+        // If body exists then decode the body.
156
+        $body = json_decode( $response->get_body(), true );
157
+        if ( empty( $body ) || ! array_key_exists( self::WORDLIFT_POST_EXCERPT_RESPONSE_KEY, $body ) ) {
158
+            // Bail out if we get an incorrect response
159
+            return false;
160
+        } else {
161
+            $post_excerpt = (string) $body[ self::WORDLIFT_POST_EXCERPT_RESPONSE_KEY ];
162
+            // Save it to meta.
163
+            self::save_post_excerpt_in_meta( $post_id, $post_excerpt, $post_body );
164
+
165
+            return array(
166
+                'post_excerpt' => $post_excerpt,
167
+                'from_cache'   => false
168
+            );
169
+        }
170
+    }
171
+
172
+    /**
173
+     * Saves the excerpt in the post meta.
174
+     *
175
+     * @param $post_id int Post id which the post excerpt belongs to
176
+     * @param $post_excerpt string Post excerpt returned by the server
177
+     * @param $post_body string Total text content of the post body.
178
+     *
179
+     * @return void
180
+     */
181
+    public static function save_post_excerpt_in_meta( $post_id, $post_excerpt, $post_body ) {
182
+        // hash the post body and save it.
183
+        $data = array(
184
+            'post_body_hash' => md5( $post_body ),
185
+            'post_excerpt'   => $post_excerpt
186
+        );
187
+        update_post_meta( $post_id, self::POST_EXCERPT_META_KEY, $data );
188
+    }
189
+
190
+    /**
191
+     * This call back is invoked by the Rest api action.
192
+     */
193
+    public static function register_route_callback() {
194
+        /** @var  $post_id_validation_settings array Settings used to validate post id */
195
+        $post_id_validation_settings   = array(
196
+            'required'          => true,
197
+            'validate_callback' => function ( $param, $request, $key ) {
198
+                return is_numeric( $param );
199
+            }
200
+        );
201
+        $post_body_validation_settings = array(
202
+            'required'          => true,
203
+            'validate_callback' => function ( $param, $request, $key ) {
204
+                return is_string( $param );
205
+            }
206
+        );
207
+        /**
208
+         * Rest route for getting the excerpt from wordlift api.
209
+         */
210
+        register_rest_route(
211
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
212
+            '/' . self::POST_EXCERPT_NAMESPACE . '/(?P<post_id>\d+)',
213
+            array(
214
+                'methods'             => \WP_REST_Server::CREATABLE,
215
+                'callback'            => 'Wordlift\Post_Excerpt\Post_Excerpt_Rest_Controller::get_post_excerpt',
216
+                'permission_callback' => function () {
217
+                    return current_user_can( 'publish_posts' );
218
+                },
219
+                'args'                => array(
220
+                    'post_id'   => $post_id_validation_settings,
221
+                    'post_body' => $post_body_validation_settings
222
+                )
223
+            )
224
+        );
225
+    }
226 226
 
227 227
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	const WORDLIFT_POST_EXCERPT_RESPONSE_KEY = 'summary';
36 36
 
37 37
 	public static function register_routes() {
38
-		add_action( 'rest_api_init', 'Wordlift\Post_Excerpt\Post_Excerpt_Rest_Controller::register_route_callback' );
38
+		add_action('rest_api_init', 'Wordlift\Post_Excerpt\Post_Excerpt_Rest_Controller::register_route_callback');
39 39
 	}
40 40
 
41 41
 	/**
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 *
48 48
 	 * @return array Post excerpt data.
49 49
 	 */
50
-	public static function get_post_excerpt( $request ) {
50
+	public static function get_post_excerpt($request) {
51 51
 		$data      = $request->get_params();
52 52
 		$post_id   = $data['post_id'];
53
-		$post_body = strip_shortcodes( $data['post_body'] );
53
+		$post_body = strip_shortcodes($data['post_body']);
54 54
 		/**
55 55
 		 * @param $post_body string The post content sent from wordpress editor.
56 56
 		 * @param $post_id int The post id.
@@ -58,20 +58,20 @@  discard block
 block discarded – undo
58 58
 		 * @since 3.33.5
59 59
 		 * Allow post content sent to excerpt api to be filtered.
60 60
 		 */
61
-		$post_body       = apply_filters( 'wl_post_excerpt_post_content', $post_body, $post_id );
62
-		$current_hash    = md5( $post_body );
63
-		$server_response = self::get_post_excerpt_conditionally( $post_id, $post_body, $current_hash );
64
-		if ( empty( $server_response ) || ! array_key_exists( 'post_excerpt', $server_response ) ) {
61
+		$post_body       = apply_filters('wl_post_excerpt_post_content', $post_body, $post_id);
62
+		$current_hash    = md5($post_body);
63
+		$server_response = self::get_post_excerpt_conditionally($post_id, $post_body, $current_hash);
64
+		if (empty($server_response) || ! array_key_exists('post_excerpt', $server_response)) {
65 65
 			return array(
66 66
 				'status'  => 'error',
67
-				'message' => __( 'Unable to contact WordLift API', 'wordlift' )
67
+				'message' => __('Unable to contact WordLift API', 'wordlift')
68 68
 			);
69 69
 		} else {
70 70
 			return array(
71 71
 				'status'       => 'success',
72 72
 				'post_excerpt' => $server_response['post_excerpt'],
73 73
 				'from_cache'   => $server_response['from_cache'],
74
-				'message'      => __( 'Excerpt successfully generated.', 'wordlift' )
74
+				'message'      => __('Excerpt successfully generated.', 'wordlift')
75 75
 			);
76 76
 		}
77 77
 
@@ -86,17 +86,17 @@  discard block
 block discarded – undo
86 86
 	 *
87 87
 	 * @return array|bool|null
88 88
 	 */
89
-	public static function get_post_excerpt_conditionally( $post_id, $post_body, $current_hash ) {
90
-		$previous_data   = get_post_meta( $post_id, self::POST_EXCERPT_META_KEY, true );
89
+	public static function get_post_excerpt_conditionally($post_id, $post_body, $current_hash) {
90
+		$previous_data   = get_post_meta($post_id, self::POST_EXCERPT_META_KEY, true);
91 91
 		$server_response = null;
92
-		if ( $previous_data === "" ) {
92
+		if ($previous_data === "") {
93 93
 			// There is no data in meta, so just fetch the data from remote server.
94
-			$server_response = self::get_post_excerpt_from_remote_server( $post_id, $post_body );
94
+			$server_response = self::get_post_excerpt_from_remote_server($post_id, $post_body);
95 95
 		} else {
96 96
 			// If there is data in meta, get the previous hash and compare.
97 97
 			$previous_hash = $previous_data['post_body_hash'];
98 98
 
99
-			if ( $current_hash === $previous_hash ) {
99
+			if ($current_hash === $previous_hash) {
100 100
 				// then return the previous value.
101 101
 				$server_response = array(
102 102
 					'post_excerpt' => $previous_data['post_excerpt'],
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 				);
105 105
 			} else {
106 106
 				// send the request to external API and then send the response.
107
-				$server_response = self::get_post_excerpt_from_remote_server( $post_id, $post_body );
107
+				$server_response = self::get_post_excerpt_from_remote_server($post_id, $post_body);
108 108
 			}
109 109
 		}
110 110
 
@@ -120,26 +120,26 @@  discard block
 block discarded – undo
120 120
 	 *
121 121
 	 * @return array|bool
122 122
 	 */
123
-	public static function get_post_excerpt_from_remote_server( $post_id, $post_body ) {
123
+	public static function get_post_excerpt_from_remote_server($post_id, $post_body) {
124 124
 		// The configuration is constant for now, it might be changing in future.
125 125
 		$configuration = array(
126 126
 			'ratio'      => 0.0005,
127 127
 			'min_length' => 60
128 128
 		);
129 129
 		// Construct the url with the configuration
130
-		$endpoint    = add_query_arg( $configuration, self::WORDLIFT_POST_EXCERPT_ENDPOINT );
130
+		$endpoint    = add_query_arg($configuration, self::WORDLIFT_POST_EXCERPT_ENDPOINT);
131 131
 		$api_service = Default_Api_Service::get_instance();
132 132
 		$response    = $api_service->request(
133 133
 			'POST',
134 134
 			$endpoint,
135
-			array( 'Content-Type' => 'text/plain' ),
135
+			array('Content-Type' => 'text/plain'),
136 136
 			$post_body,
137 137
 			null,
138 138
 			null,
139
-			array( 'data_format' => 'body' )
139
+			array('data_format' => 'body')
140 140
 		);
141 141
 
142
-		return self::save_response_to_meta_on_success( $post_id, $post_body, $response );
142
+		return self::save_response_to_meta_on_success($post_id, $post_body, $response);
143 143
 	}
144 144
 
145 145
 	/**
@@ -151,16 +151,16 @@  discard block
 block discarded – undo
151 151
 	 *
152 152
 	 * @return array|bool
153 153
 	 */
154
-	public static function save_response_to_meta_on_success( $post_id, $post_body, $response ) {
154
+	public static function save_response_to_meta_on_success($post_id, $post_body, $response) {
155 155
 		// If body exists then decode the body.
156
-		$body = json_decode( $response->get_body(), true );
157
-		if ( empty( $body ) || ! array_key_exists( self::WORDLIFT_POST_EXCERPT_RESPONSE_KEY, $body ) ) {
156
+		$body = json_decode($response->get_body(), true);
157
+		if (empty($body) || ! array_key_exists(self::WORDLIFT_POST_EXCERPT_RESPONSE_KEY, $body)) {
158 158
 			// Bail out if we get an incorrect response
159 159
 			return false;
160 160
 		} else {
161
-			$post_excerpt = (string) $body[ self::WORDLIFT_POST_EXCERPT_RESPONSE_KEY ];
161
+			$post_excerpt = (string) $body[self::WORDLIFT_POST_EXCERPT_RESPONSE_KEY];
162 162
 			// Save it to meta.
163
-			self::save_post_excerpt_in_meta( $post_id, $post_excerpt, $post_body );
163
+			self::save_post_excerpt_in_meta($post_id, $post_excerpt, $post_body);
164 164
 
165 165
 			return array(
166 166
 				'post_excerpt' => $post_excerpt,
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 	 *
179 179
 	 * @return void
180 180
 	 */
181
-	public static function save_post_excerpt_in_meta( $post_id, $post_excerpt, $post_body ) {
181
+	public static function save_post_excerpt_in_meta($post_id, $post_excerpt, $post_body) {
182 182
 		// hash the post body and save it.
183 183
 		$data = array(
184
-			'post_body_hash' => md5( $post_body ),
184
+			'post_body_hash' => md5($post_body),
185 185
 			'post_excerpt'   => $post_excerpt
186 186
 		);
187
-		update_post_meta( $post_id, self::POST_EXCERPT_META_KEY, $data );
187
+		update_post_meta($post_id, self::POST_EXCERPT_META_KEY, $data);
188 188
 	}
189 189
 
190 190
 	/**
@@ -192,16 +192,16 @@  discard block
 block discarded – undo
192 192
 	 */
193 193
 	public static function register_route_callback() {
194 194
 		/** @var  $post_id_validation_settings array Settings used to validate post id */
195
-		$post_id_validation_settings   = array(
195
+		$post_id_validation_settings = array(
196 196
 			'required'          => true,
197
-			'validate_callback' => function ( $param, $request, $key ) {
198
-				return is_numeric( $param );
197
+			'validate_callback' => function($param, $request, $key) {
198
+				return is_numeric($param);
199 199
 			}
200 200
 		);
201 201
 		$post_body_validation_settings = array(
202 202
 			'required'          => true,
203
-			'validate_callback' => function ( $param, $request, $key ) {
204
-				return is_string( $param );
203
+			'validate_callback' => function($param, $request, $key) {
204
+				return is_string($param);
205 205
 			}
206 206
 		);
207 207
 		/**
@@ -209,12 +209,12 @@  discard block
 block discarded – undo
209 209
 		 */
210 210
 		register_rest_route(
211 211
 			WL_REST_ROUTE_DEFAULT_NAMESPACE,
212
-			'/' . self::POST_EXCERPT_NAMESPACE . '/(?P<post_id>\d+)',
212
+			'/'.self::POST_EXCERPT_NAMESPACE.'/(?P<post_id>\d+)',
213 213
 			array(
214 214
 				'methods'             => \WP_REST_Server::CREATABLE,
215 215
 				'callback'            => 'Wordlift\Post_Excerpt\Post_Excerpt_Rest_Controller::get_post_excerpt',
216
-				'permission_callback' => function () {
217
-					return current_user_can( 'publish_posts' );
216
+				'permission_callback' => function() {
217
+					return current_user_can('publish_posts');
218 218
 				},
219 219
 				'args'                => array(
220 220
 					'post_id'   => $post_id_validation_settings,
Please login to merge, or discard this patch.