@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | /** |
| 43 | 43 | * Queries the database for all of the supported posts. |
| 44 | 44 | * |
| 45 | - * @param bool $force |
|
| 46 | - * |
|
| 47 | - * @return Writing_On_GitHub_Post[]|WP_Error |
|
| 48 | - */ |
|
| 45 | + * @param bool $force |
|
| 46 | + * |
|
| 47 | + * @return Writing_On_GitHub_Post[]|WP_Error |
|
| 48 | + */ |
|
| 49 | 49 | public function fetch_all_supported( $force = false ) { |
| 50 | 50 | $args = array( |
| 51 | 51 | 'post_type' => $this->get_whitelisted_post_types(), |
@@ -187,45 +187,45 @@ discard block |
||
| 187 | 187 | |
| 188 | 188 | // update tags |
| 189 | 189 | if ( isset( $meta['tags'] ) && $meta['tags'] ) { |
| 190 | - $args['tags_input'] = $meta['tags']; |
|
| 190 | + $args['tags_input'] = $meta['tags']; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // update categories |
| 194 | 194 | if ( isset( $meta['categories'] ) && $meta['categories'] ) { |
| 195 | - $categories = $meta['categories']; |
|
| 196 | - if (!is_array($categories)) { |
|
| 197 | - $categories = array($categories); |
|
| 198 | - } |
|
| 199 | - $terms = get_terms(array( |
|
| 200 | - 'taxonomy' => 'category', |
|
| 201 | - 'fields' => 'id=>name', |
|
| 202 | - 'hide_empty' => 0, |
|
| 203 | - 'name' => $categories |
|
| 204 | - ) |
|
| 205 | - ); |
|
| 206 | - $map = array(); |
|
| 207 | - foreach ($categories as $name) { |
|
| 208 | - $map[$name] = 1; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $ids = array(); |
|
| 212 | - if (!empty($terms)) { |
|
| 213 | - foreach ($terms as $id => $name) { |
|
| 214 | - $ids[] = $id; |
|
| 215 | - unset($map[$name]); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // create new terms |
|
| 220 | - if (!empty($map)) { |
|
| 221 | - foreach ($map as $name => $value) { |
|
| 222 | - $term = wp_insert_term($name, 'category', array('parent' => 0)); |
|
| 223 | - // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
|
| 224 | - $ids[] = $term['term_id']; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $args['post_category'] = $ids; |
|
| 195 | + $categories = $meta['categories']; |
|
| 196 | + if (!is_array($categories)) { |
|
| 197 | + $categories = array($categories); |
|
| 198 | + } |
|
| 199 | + $terms = get_terms(array( |
|
| 200 | + 'taxonomy' => 'category', |
|
| 201 | + 'fields' => 'id=>name', |
|
| 202 | + 'hide_empty' => 0, |
|
| 203 | + 'name' => $categories |
|
| 204 | + ) |
|
| 205 | + ); |
|
| 206 | + $map = array(); |
|
| 207 | + foreach ($categories as $name) { |
|
| 208 | + $map[$name] = 1; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $ids = array(); |
|
| 212 | + if (!empty($terms)) { |
|
| 213 | + foreach ($terms as $id => $name) { |
|
| 214 | + $ids[] = $id; |
|
| 215 | + unset($map[$name]); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // create new terms |
|
| 220 | + if (!empty($map)) { |
|
| 221 | + foreach ($map as $name => $value) { |
|
| 222 | + $term = wp_insert_term($name, 'category', array('parent' => 0)); |
|
| 223 | + // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
|
| 224 | + $ids[] = $term['term_id']; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $args['post_category'] = $ids; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | return $args; |
@@ -427,12 +427,12 @@ discard block |
||
| 427 | 427 | if ( ! empty( $display_name ) ) { |
| 428 | 428 | $search_string = esc_attr( $display_name ); |
| 429 | 429 | $query = new WP_User_Query( array( |
| 430 | - 'search' => "{$search_string}", |
|
| 431 | - 'search_columns' => array( |
|
| 432 | - 'display_name', |
|
| 433 | - 'user_nicename', |
|
| 434 | - 'user_login', |
|
| 435 | - ) |
|
| 430 | + 'search' => "{$search_string}", |
|
| 431 | + 'search_columns' => array( |
|
| 432 | + 'display_name', |
|
| 433 | + 'user_nicename', |
|
| 434 | + 'user_login', |
|
| 435 | + ) |
|
| 436 | 436 | ) ); |
| 437 | 437 | $users = $query->get_results(); |
| 438 | 438 | $user = empty($users) ? false : $users[0]; |
@@ -21,21 +21,21 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @var array |
| 23 | 23 | */ |
| 24 | - protected $whitelisted_post_types = array( 'post', 'page' ); |
|
| 24 | + protected $whitelisted_post_types = array('post', 'page'); |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Currently whitelisted post statuses. |
| 28 | 28 | * |
| 29 | 29 | * @var array |
| 30 | 30 | */ |
| 31 | - protected $whitelisted_post_statuses = array( 'publish' ); |
|
| 31 | + protected $whitelisted_post_statuses = array('publish'); |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Instantiates a new Database object. |
| 35 | 35 | * |
| 36 | 36 | * @param Writing_On_GitHub $app Application container. |
| 37 | 37 | */ |
| 38 | - public function __construct( Writing_On_GitHub $app ) { |
|
| 38 | + public function __construct(Writing_On_GitHub $app) { |
|
| 39 | 39 | $this->app = $app; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -46,32 +46,32 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return Writing_On_GitHub_Post[]|WP_Error |
| 48 | 48 | */ |
| 49 | - public function fetch_all_supported( $force = false ) { |
|
| 50 | - $args = array( |
|
| 49 | + public function fetch_all_supported($force = false) { |
|
| 50 | + $args = array( |
|
| 51 | 51 | 'post_type' => $this->get_whitelisted_post_types(), |
| 52 | 52 | 'post_status' => $this->get_whitelisted_post_statuses(), |
| 53 | 53 | 'nopaging' => true, |
| 54 | 54 | 'fields' => 'ids', |
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | - $query = new WP_Query( apply_filters( 'wogh_pre_fetch_all_supported', $args ) ); |
|
| 57 | + $query = new WP_Query(apply_filters('wogh_pre_fetch_all_supported', $args)); |
|
| 58 | 58 | |
| 59 | 59 | $post_ids = $query->get_posts(); |
| 60 | 60 | |
| 61 | - if ( ! $post_ids ) { |
|
| 61 | + if ( ! $post_ids) { |
|
| 62 | 62 | return new WP_Error( |
| 63 | 63 | 'no_results', |
| 64 | - __( 'Querying for supported posts returned no results.', 'writing-on-github' ) |
|
| 64 | + __('Querying for supported posts returned no results.', 'writing-on-github') |
|
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $results = array(); |
| 69 | - foreach ( $post_ids as $post_id ) { |
|
| 69 | + foreach ($post_ids as $post_id) { |
|
| 70 | 70 | // Do not export posts that have already been exported |
| 71 | - if ( $force || ! get_post_meta( $post_id, '_wogh_sha', true ) || |
|
| 72 | - ! get_post_meta( $post_id, '_wogh_github_path', true ) ) { |
|
| 71 | + if ($force || ! get_post_meta($post_id, '_wogh_sha', true) || |
|
| 72 | + ! get_post_meta($post_id, '_wogh_github_path', true)) { |
|
| 73 | 73 | |
| 74 | - $results[] = new Writing_On_GitHub_Post( $post_id, $this->app->api() ); |
|
| 74 | + $results[] = new Writing_On_GitHub_Post($post_id, $this->app->api()); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
@@ -85,10 +85,10 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @return WP_Error|Writing_On_GitHub_Post |
| 87 | 87 | */ |
| 88 | - public function fetch_by_id( $post_id ) { |
|
| 89 | - $post = new Writing_On_GitHub_Post( $post_id, $this->app->api() ); |
|
| 88 | + public function fetch_by_id($post_id) { |
|
| 89 | + $post = new Writing_On_GitHub_Post($post_id, $this->app->api()); |
|
| 90 | 90 | |
| 91 | - if ( ! $this->is_post_supported( $post ) ) { |
|
| 91 | + if ( ! $this->is_post_supported($post)) { |
|
| 92 | 92 | return new WP_Error( |
| 93 | 93 | 'unsupported_post', |
| 94 | 94 | sprintf( |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return string|WP_Error |
| 114 | 114 | */ |
| 115 | - public function save_posts( array $posts ) { |
|
| 115 | + public function save_posts(array $posts) { |
|
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * Whether an error has occurred. |
@@ -121,20 +121,19 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | $error = false; |
| 123 | 123 | |
| 124 | - foreach ( $posts as $post ) { |
|
| 125 | - $args = apply_filters( 'wogh_pre_import_args', $this->post_args( $post ), $post ); |
|
| 124 | + foreach ($posts as $post) { |
|
| 125 | + $args = apply_filters('wogh_pre_import_args', $this->post_args($post), $post); |
|
| 126 | 126 | |
| 127 | - remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); |
|
| 127 | + remove_filter('content_save_pre', 'wp_filter_post_kses'); |
|
| 128 | 128 | $post_id = $post->is_new() ? |
| 129 | - wp_insert_post( $args, true ) : |
|
| 130 | - wp_update_post( $args, true ); |
|
| 131 | - add_filter( 'content_save_pre', 'wp_filter_post_kses' ); |
|
| 129 | + wp_insert_post($args, true) : wp_update_post($args, true); |
|
| 130 | + add_filter('content_save_pre', 'wp_filter_post_kses'); |
|
| 132 | 131 | |
| 133 | - if ( is_wp_error( $post_id ) ) { |
|
| 134 | - if ( ! $error ) { |
|
| 132 | + if (is_wp_error($post_id)) { |
|
| 133 | + if ( ! $error) { |
|
| 135 | 134 | $error = $post_id; |
| 136 | 135 | } else { |
| 137 | - $error->add( $post_id->get_error_code(), $post_id->get_error_message() ); |
|
| 136 | + $error->add($post_id->get_error_code(), $post_id->get_error_message()); |
|
| 138 | 137 | } |
| 139 | 138 | |
| 140 | 139 | // Abort saving if updating the post fails. |
@@ -143,20 +142,20 @@ discard block |
||
| 143 | 142 | |
| 144 | 143 | // $this->set_revision_author( $post_id, $user_id ); |
| 145 | 144 | |
| 146 | - if ( $post->is_new() ) { |
|
| 145 | + if ($post->is_new()) { |
|
| 147 | 146 | $author = false; |
| 148 | 147 | $meta = $post->get_meta(); |
| 149 | - if ( ! empty( $meta ) && ! empty( $meta['author'] ) ) { |
|
| 148 | + if ( ! empty($meta) && ! empty($meta['author'])) { |
|
| 150 | 149 | $author = $meta['author']; |
| 151 | 150 | } |
| 152 | - $user = $this->fetch_commit_user( $author ); |
|
| 153 | - $user_id = ! is_wp_error( $user ) ? $user->ID : 0; |
|
| 154 | - $this->set_post_author( $post_id, $user_id ); |
|
| 151 | + $user = $this->fetch_commit_user($author); |
|
| 152 | + $user_id = ! is_wp_error($user) ? $user->ID : 0; |
|
| 153 | + $this->set_post_author($post_id, $user_id); |
|
| 155 | 154 | } |
| 156 | 155 | |
| 157 | - $post->set_post( get_post( $post_id ) ); |
|
| 156 | + $post->set_post(get_post($post_id)); |
|
| 158 | 157 | |
| 159 | - $meta = apply_filters( 'wogh_pre_import_meta', $post->get_meta(), $post ); |
|
| 158 | + $meta = apply_filters('wogh_pre_import_meta', $post->get_meta(), $post); |
|
| 160 | 159 | |
| 161 | 160 | // unset( $meta['tags'] ); |
| 162 | 161 | // unset( $meta['categories'] ); |
@@ -171,14 +170,14 @@ discard block |
||
| 171 | 170 | // } |
| 172 | 171 | } |
| 173 | 172 | |
| 174 | - if ( $error ) { |
|
| 173 | + if ($error) { |
|
| 175 | 174 | return $error; |
| 176 | 175 | } |
| 177 | 176 | |
| 178 | - return __( 'Successfully saved posts.', 'writing-on-github' ); |
|
| 177 | + return __('Successfully saved posts.', 'writing-on-github'); |
|
| 179 | 178 | } |
| 180 | 179 | |
| 181 | - protected function post_args( $post ) { |
|
| 180 | + protected function post_args($post) { |
|
| 182 | 181 | $args = $post->get_args(); |
| 183 | 182 | $meta = $post->get_meta(); |
| 184 | 183 | |
@@ -186,14 +185,14 @@ discard block |
||
| 186 | 185 | $args['post_content'] = addslashes($args['post_content']); |
| 187 | 186 | |
| 188 | 187 | // update tags |
| 189 | - if ( isset( $meta['tags'] ) && $meta['tags'] ) { |
|
| 188 | + if (isset($meta['tags']) && $meta['tags']) { |
|
| 190 | 189 | $args['tags_input'] = $meta['tags']; |
| 191 | 190 | } |
| 192 | 191 | |
| 193 | 192 | // update categories |
| 194 | - if ( isset( $meta['categories'] ) && $meta['categories'] ) { |
|
| 193 | + if (isset($meta['categories']) && $meta['categories']) { |
|
| 195 | 194 | $categories = $meta['categories']; |
| 196 | - if (!is_array($categories)) { |
|
| 195 | + if ( ! is_array($categories)) { |
|
| 197 | 196 | $categories = array($categories); |
| 198 | 197 | } |
| 199 | 198 | $terms = get_terms(array( |
@@ -209,7 +208,7 @@ discard block |
||
| 209 | 208 | } |
| 210 | 209 | |
| 211 | 210 | $ids = array(); |
| 212 | - if (!empty($terms)) { |
|
| 211 | + if ( ! empty($terms)) { |
|
| 213 | 212 | foreach ($terms as $id => $name) { |
| 214 | 213 | $ids[] = $id; |
| 215 | 214 | unset($map[$name]); |
@@ -217,7 +216,7 @@ discard block |
||
| 217 | 216 | } |
| 218 | 217 | |
| 219 | 218 | // create new terms |
| 220 | - if (!empty($map)) { |
|
| 219 | + if ( ! empty($map)) { |
|
| 221 | 220 | foreach ($map as $name => $value) { |
| 222 | 221 | $term = wp_insert_term($name, 'category', array('parent' => 0)); |
| 223 | 222 | // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
@@ -238,77 +237,77 @@ discard block |
||
| 238 | 237 | * |
| 239 | 238 | * @return string|WP_Error |
| 240 | 239 | */ |
| 241 | - public function delete_post_by_path( $path ) { |
|
| 242 | - $query = new WP_Query( array( |
|
| 240 | + public function delete_post_by_path($path) { |
|
| 241 | + $query = new WP_Query(array( |
|
| 243 | 242 | 'meta_key' => '_wogh_github_path', |
| 244 | 243 | 'meta_value' => $path, |
| 245 | 244 | 'meta_compare' => '=', |
| 246 | 245 | 'posts_per_page' => 1, |
| 247 | 246 | 'fields' => 'ids', |
| 248 | - ) ); |
|
| 247 | + )); |
|
| 249 | 248 | |
| 250 | 249 | $post_id = $query->get_posts(); |
| 251 | - $post_id = array_pop( $post_id ); |
|
| 250 | + $post_id = array_pop($post_id); |
|
| 252 | 251 | |
| 253 | - if ( ! $post_id ) { |
|
| 254 | - $parts = explode( '/', $path ); |
|
| 255 | - $filename = array_pop( $parts ); |
|
| 256 | - $directory = $parts ? array_shift( $parts ) : ''; |
|
| 252 | + if ( ! $post_id) { |
|
| 253 | + $parts = explode('/', $path); |
|
| 254 | + $filename = array_pop($parts); |
|
| 255 | + $directory = $parts ? array_shift($parts) : ''; |
|
| 257 | 256 | |
| 258 | - if ( false !== strpos( $directory, 'post' ) ) { |
|
| 259 | - preg_match( '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/', $filename, $matches ); |
|
| 257 | + if (false !== strpos($directory, 'post')) { |
|
| 258 | + preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/', $filename, $matches); |
|
| 260 | 259 | $title = $matches[4]; |
| 261 | 260 | |
| 262 | - $query = new WP_Query( array( |
|
| 261 | + $query = new WP_Query(array( |
|
| 263 | 262 | 'name' => $title, |
| 264 | 263 | 'posts_per_page' => 1, |
| 265 | 264 | 'post_type' => $this->get_whitelisted_post_types(), |
| 266 | 265 | 'fields' => 'ids', |
| 267 | - ) ); |
|
| 266 | + )); |
|
| 268 | 267 | |
| 269 | 268 | $post_id = $query->get_posts(); |
| 270 | - $post_id = array_pop( $post_id ); |
|
| 269 | + $post_id = array_pop($post_id); |
|
| 271 | 270 | } |
| 272 | 271 | |
| 273 | - if ( ! $post_id ) { |
|
| 274 | - preg_match( '/(.*)\.md/', $filename, $matches ); |
|
| 272 | + if ( ! $post_id) { |
|
| 273 | + preg_match('/(.*)\.md/', $filename, $matches); |
|
| 275 | 274 | $title = $matches[1]; |
| 276 | 275 | |
| 277 | - $query = new WP_Query( array( |
|
| 276 | + $query = new WP_Query(array( |
|
| 278 | 277 | 'name' => $title, |
| 279 | 278 | 'posts_per_page' => 1, |
| 280 | 279 | 'post_type' => $this->get_whitelisted_post_types(), |
| 281 | 280 | 'fields' => 'ids', |
| 282 | - ) ); |
|
| 281 | + )); |
|
| 283 | 282 | |
| 284 | 283 | $post_id = $query->get_posts(); |
| 285 | - $post_id = array_pop( $post_id ); |
|
| 284 | + $post_id = array_pop($post_id); |
|
| 286 | 285 | } |
| 287 | 286 | } |
| 288 | 287 | |
| 289 | - if ( ! $post_id ) { |
|
| 288 | + if ( ! $post_id) { |
|
| 290 | 289 | return new WP_Error( |
| 291 | 290 | 'path_not_found', |
| 292 | 291 | sprintf( |
| 293 | - __( 'Post not found for path %s.', 'writing-on-github' ), |
|
| 292 | + __('Post not found for path %s.', 'writing-on-github'), |
|
| 294 | 293 | $path |
| 295 | 294 | ) |
| 296 | 295 | ); |
| 297 | 296 | } |
| 298 | 297 | |
| 299 | - $result = wp_delete_post( $post_id ); |
|
| 298 | + $result = wp_delete_post($post_id); |
|
| 300 | 299 | |
| 301 | 300 | // If deleting fails... |
| 302 | - if ( false === $result ) { |
|
| 303 | - $post = get_post( $post_id ); |
|
| 301 | + if (false === $result) { |
|
| 302 | + $post = get_post($post_id); |
|
| 304 | 303 | |
| 305 | 304 | // ...and the post both exists and isn't in the trash... |
| 306 | - if ( $post && 'trash' !== $post->post_status ) { |
|
| 305 | + if ($post && 'trash' !== $post->post_status) { |
|
| 307 | 306 | // ... then something went wrong. |
| 308 | 307 | return new WP_Error( |
| 309 | 308 | 'db_error', |
| 310 | 309 | sprintf( |
| 311 | - __( 'Failed to delete post ID %d.', 'writing-on-github' ), |
|
| 310 | + __('Failed to delete post ID %d.', 'writing-on-github'), |
|
| 312 | 311 | $post_id |
| 313 | 312 | ) |
| 314 | 313 | ); |
@@ -316,25 +315,25 @@ discard block |
||
| 316 | 315 | } |
| 317 | 316 | |
| 318 | 317 | return sprintf( |
| 319 | - __( 'Successfully deleted post ID %d.', 'writing-on-github' ), |
|
| 318 | + __('Successfully deleted post ID %d.', 'writing-on-github'), |
|
| 320 | 319 | $post_id |
| 321 | 320 | ); |
| 322 | 321 | } |
| 323 | 322 | |
| 324 | - public function delete_post( $post_id ) { |
|
| 325 | - $result = wp_delete_post( $post_id ); |
|
| 323 | + public function delete_post($post_id) { |
|
| 324 | + $result = wp_delete_post($post_id); |
|
| 326 | 325 | |
| 327 | 326 | // If deleting fails... |
| 328 | - if ( false === $result ) { |
|
| 329 | - $post = get_post( $post_id ); |
|
| 327 | + if (false === $result) { |
|
| 328 | + $post = get_post($post_id); |
|
| 330 | 329 | |
| 331 | 330 | // ...and the post both exists and isn't in the trash... |
| 332 | - if ( $post && 'trash' !== $post->post_status ) { |
|
| 331 | + if ($post && 'trash' !== $post->post_status) { |
|
| 333 | 332 | // ... then something went wrong. |
| 334 | 333 | return new WP_Error( |
| 335 | 334 | 'db_error', |
| 336 | 335 | sprintf( |
| 337 | - __( 'Failed to delete post ID %d.', 'writing-on-github' ), |
|
| 336 | + __('Failed to delete post ID %d.', 'writing-on-github'), |
|
| 338 | 337 | $post_id |
| 339 | 338 | ) |
| 340 | 339 | ); |
@@ -342,7 +341,7 @@ discard block |
||
| 342 | 341 | } |
| 343 | 342 | |
| 344 | 343 | return sprintf( |
| 345 | - __( 'Successfully deleted post ID %d.', 'writing-on-github' ), |
|
| 344 | + __('Successfully deleted post ID %d.', 'writing-on-github'), |
|
| 346 | 345 | $post_id |
| 347 | 346 | ); |
| 348 | 347 | } |
@@ -353,7 +352,7 @@ discard block |
||
| 353 | 352 | * @return array |
| 354 | 353 | */ |
| 355 | 354 | protected function get_whitelisted_post_types() { |
| 356 | - return apply_filters( 'wogh_whitelisted_post_types', $this->whitelisted_post_types ); |
|
| 355 | + return apply_filters('wogh_whitelisted_post_types', $this->whitelisted_post_types); |
|
| 357 | 356 | } |
| 358 | 357 | |
| 359 | 358 | /** |
@@ -362,7 +361,7 @@ discard block |
||
| 362 | 361 | * @return array |
| 363 | 362 | */ |
| 364 | 363 | protected function get_whitelisted_post_statuses() { |
| 365 | - return apply_filters( 'wogh_whitelisted_post_statuses', $this->whitelisted_post_statuses ); |
|
| 364 | + return apply_filters('wogh_whitelisted_post_statuses', $this->whitelisted_post_statuses); |
|
| 366 | 365 | } |
| 367 | 366 | |
| 368 | 367 | /** |
@@ -372,12 +371,12 @@ discard block |
||
| 372 | 371 | * |
| 373 | 372 | * @return string Whitelist formatted for query |
| 374 | 373 | */ |
| 375 | - protected function format_for_query( $whitelist ) { |
|
| 376 | - foreach ( $whitelist as $key => $value ) { |
|
| 377 | - $whitelist[ $key ] = "'$value'"; |
|
| 374 | + protected function format_for_query($whitelist) { |
|
| 375 | + foreach ($whitelist as $key => $value) { |
|
| 376 | + $whitelist[$key] = "'$value'"; |
|
| 378 | 377 | } |
| 379 | 378 | |
| 380 | - return implode( ', ', $whitelist ); |
|
| 379 | + return implode(', ', $whitelist); |
|
| 381 | 380 | } |
| 382 | 381 | |
| 383 | 382 | /** |
@@ -388,25 +387,25 @@ discard block |
||
| 388 | 387 | * |
| 389 | 388 | * @return boolean True if supported, false if not. |
| 390 | 389 | */ |
| 391 | - protected function is_post_supported( Writing_On_GitHub_Post $post ) { |
|
| 392 | - if ( wp_is_post_revision( $post->id ) ) { |
|
| 390 | + protected function is_post_supported(Writing_On_GitHub_Post $post) { |
|
| 391 | + if (wp_is_post_revision($post->id)) { |
|
| 393 | 392 | return false; |
| 394 | 393 | } |
| 395 | 394 | |
| 396 | 395 | // We need to allow trashed posts to be queried, but they are not whitelisted for export. |
| 397 | - if ( ! in_array( $post->status(), $this->get_whitelisted_post_statuses() ) && 'trash' !== $post->status() ) { |
|
| 396 | + if ( ! in_array($post->status(), $this->get_whitelisted_post_statuses()) && 'trash' !== $post->status()) { |
|
| 398 | 397 | return false; |
| 399 | 398 | } |
| 400 | 399 | |
| 401 | - if ( ! in_array( $post->type(), $this->get_whitelisted_post_types() ) ) { |
|
| 400 | + if ( ! in_array($post->type(), $this->get_whitelisted_post_types())) { |
|
| 402 | 401 | return false; |
| 403 | 402 | } |
| 404 | 403 | |
| 405 | - if ( $post->has_password() ) { |
|
| 404 | + if ($post->has_password()) { |
|
| 406 | 405 | return false; |
| 407 | 406 | } |
| 408 | 407 | |
| 409 | - return apply_filters( 'wogh_is_post_supported', true, $post ); |
|
| 408 | + return apply_filters('wogh_is_post_supported', true, $post); |
|
| 410 | 409 | } |
| 411 | 410 | |
| 412 | 411 | /** |
@@ -419,35 +418,35 @@ discard block |
||
| 419 | 418 | * |
| 420 | 419 | * @return WP_Error|WP_User |
| 421 | 420 | */ |
| 422 | - protected function fetch_commit_user( $display_name ) { |
|
| 421 | + protected function fetch_commit_user($display_name) { |
|
| 423 | 422 | // If we can't find a user and a default hasn't been set, |
| 424 | 423 | // we're just going to set the revision author to 0. |
| 425 | 424 | $user = false; |
| 426 | 425 | |
| 427 | - if ( ! empty( $display_name ) ) { |
|
| 428 | - $search_string = esc_attr( $display_name ); |
|
| 429 | - $query = new WP_User_Query( array( |
|
| 426 | + if ( ! empty($display_name)) { |
|
| 427 | + $search_string = esc_attr($display_name); |
|
| 428 | + $query = new WP_User_Query(array( |
|
| 430 | 429 | 'search' => "{$search_string}", |
| 431 | 430 | 'search_columns' => array( |
| 432 | 431 | 'display_name', |
| 433 | 432 | 'user_nicename', |
| 434 | 433 | 'user_login', |
| 435 | 434 | ) |
| 436 | - ) ); |
|
| 435 | + )); |
|
| 437 | 436 | $users = $query->get_results(); |
| 438 | 437 | $user = empty($users) ? false : $users[0]; |
| 439 | 438 | } |
| 440 | 439 | |
| 441 | - if ( ! $user ) { |
|
| 440 | + if ( ! $user) { |
|
| 442 | 441 | // Use the default user. |
| 443 | - $user = get_user_by( 'id', (int) get_option( 'wogh_default_user' ) ); |
|
| 442 | + $user = get_user_by('id', (int) get_option('wogh_default_user')); |
|
| 444 | 443 | } |
| 445 | 444 | |
| 446 | - if ( ! $user ) { |
|
| 445 | + if ( ! $user) { |
|
| 447 | 446 | return new WP_Error( |
| 448 | 447 | 'user_not_found', |
| 449 | 448 | sprintf( |
| 450 | - __( 'Commit user not found for email %s', 'writing-on-github' ), |
|
| 449 | + __('Commit user not found for email %s', 'writing-on-github'), |
|
| 451 | 450 | |
| 452 | 451 | ) |
| 453 | 452 | ); |
@@ -465,28 +464,28 @@ discard block |
||
| 465 | 464 | * |
| 466 | 465 | * @return string|WP_Error |
| 467 | 466 | */ |
| 468 | - protected function set_revision_author( $post_id, $user_id ) { |
|
| 469 | - $revision = wp_get_post_revisions( $post_id ); |
|
| 467 | + protected function set_revision_author($post_id, $user_id) { |
|
| 468 | + $revision = wp_get_post_revisions($post_id); |
|
| 470 | 469 | |
| 471 | - if ( ! $revision ) { |
|
| 472 | - $new_revision = wp_save_post_revision( $post_id ); |
|
| 470 | + if ( ! $revision) { |
|
| 471 | + $new_revision = wp_save_post_revision($post_id); |
|
| 473 | 472 | |
| 474 | - if ( ! $new_revision || is_wp_error( $new_revision ) ) { |
|
| 475 | - return new WP_Error( 'db_error', 'There was a problem saving a new revision.' ); |
|
| 473 | + if ( ! $new_revision || is_wp_error($new_revision)) { |
|
| 474 | + return new WP_Error('db_error', 'There was a problem saving a new revision.'); |
|
| 476 | 475 | } |
| 477 | 476 | |
| 478 | 477 | // `wp_save_post_revision` returns the ID, whereas `get_post_revision` returns the whole object |
| 479 | 478 | // in order to be consistent, let's make sure we have the whole object before continuing. |
| 480 | - $revision = get_post( $new_revision ); |
|
| 479 | + $revision = get_post($new_revision); |
|
| 481 | 480 | |
| 482 | - if ( ! $revision ) { |
|
| 483 | - return new WP_Error( 'db_error', 'There was a problem retrieving the newly recreated revision.' ); |
|
| 481 | + if ( ! $revision) { |
|
| 482 | + return new WP_Error('db_error', 'There was a problem retrieving the newly recreated revision.'); |
|
| 484 | 483 | } |
| 485 | 484 | } else { |
| 486 | - $revision = array_shift( $revision ); |
|
| 485 | + $revision = array_shift($revision); |
|
| 487 | 486 | } |
| 488 | 487 | |
| 489 | - return $this->set_post_author( $revision->ID, $user_id ); |
|
| 488 | + return $this->set_post_author($revision->ID, $user_id); |
|
| 490 | 489 | } |
| 491 | 490 | |
| 492 | 491 | /** |
@@ -499,7 +498,7 @@ discard block |
||
| 499 | 498 | * |
| 500 | 499 | * @return string|WP_Error |
| 501 | 500 | */ |
| 502 | - protected function set_post_author( $post_id, $user_id ) { |
|
| 501 | + protected function set_post_author($post_id, $user_id) { |
|
| 503 | 502 | global $wpdb; |
| 504 | 503 | |
| 505 | 504 | $result = $wpdb->update( |
@@ -510,25 +509,25 @@ discard block |
||
| 510 | 509 | array( |
| 511 | 510 | 'ID' => (int) $post_id, |
| 512 | 511 | ), |
| 513 | - array( '%d' ), |
|
| 514 | - array( '%d' ) |
|
| 512 | + array('%d'), |
|
| 513 | + array('%d') |
|
| 515 | 514 | ); |
| 516 | 515 | |
| 517 | - if ( false === $result ) { |
|
| 518 | - return new WP_Error( 'db_error', $wpdb->last_error ); |
|
| 516 | + if (false === $result) { |
|
| 517 | + return new WP_Error('db_error', $wpdb->last_error); |
|
| 519 | 518 | } |
| 520 | 519 | |
| 521 | - if ( 0 === $result ) { |
|
| 520 | + if (0 === $result) { |
|
| 522 | 521 | return sprintf( |
| 523 | - __( 'No change for post ID %d.', 'writing-on-github' ), |
|
| 522 | + __('No change for post ID %d.', 'writing-on-github'), |
|
| 524 | 523 | $post_id |
| 525 | 524 | ); |
| 526 | 525 | } |
| 527 | 526 | |
| 528 | - clean_post_cache( $post_id ); |
|
| 527 | + clean_post_cache($post_id); |
|
| 529 | 528 | |
| 530 | 529 | return sprintf( |
| 531 | - __( 'Successfully updated post ID %d.', 'writing-on-github' ), |
|
| 530 | + __('Successfully updated post ID %d.', 'writing-on-github'), |
|
| 532 | 531 | $post_id |
| 533 | 532 | ); |
| 534 | 533 | } |
@@ -541,7 +540,7 @@ discard block |
||
| 541 | 540 | * |
| 542 | 541 | * @return bool|int |
| 543 | 542 | */ |
| 544 | - public function set_post_sha( $post, $sha ) { |
|
| 545 | - return update_post_meta( $post->id, '_wogh_sha', $sha ); |
|
| 543 | + public function set_post_sha($post, $sha) { |
|
| 544 | + return update_post_meta($post->id, '_wogh_sha', $sha); |
|
| 546 | 545 | } |
| 547 | 546 | } |