@@ -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(), |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /* @var Writing_On_GitHub_Post[] $results */ |
|
| 68 | + /* @var Writing_On_GitHub_Post[] $results */ |
|
| 69 | 69 | $results = array(); |
| 70 | 70 | foreach ( $post_ids as $post_id ) { |
| 71 | 71 | // Do not export posts that have already been exported |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | add_filter( 'content_save_pre', 'wp_filter_post_kses' ); |
| 133 | 133 | |
| 134 | 134 | if ( is_wp_error( $post_id ) ) { |
| 135 | - /* @var WP_Error $post_id */ |
|
| 136 | - $error = wogh_append_error( $error, $post_id ); |
|
| 135 | + /* @var WP_Error $post_id */ |
|
| 136 | + $error = wogh_append_error( $error, $post_id ); |
|
| 137 | 137 | |
| 138 | 138 | // Abort saving if updating the post fails. |
| 139 | 139 | continue; |
@@ -183,65 +183,65 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | // update tags |
| 185 | 185 | if ( ! empty( $meta['tags'] ) ) { |
| 186 | - $args['tags_input'] = $meta['tags']; |
|
| 186 | + $args['tags_input'] = $meta['tags']; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // update categories |
| 190 | 190 | if ( ! empty( $meta['categories'] ) ) { |
| 191 | - $categories = $meta['categories']; |
|
| 192 | - if ( ! is_array( $categories ) ) { |
|
| 193 | - $categories = array( $categories ); |
|
| 194 | - } |
|
| 195 | - $terms = get_terms( array( |
|
| 196 | - 'taxonomy' => 'category', |
|
| 197 | - 'fields' => 'id=>name', |
|
| 198 | - 'hide_empty' => 0, |
|
| 199 | - 'name' => $categories |
|
| 200 | - ) |
|
| 201 | - ); |
|
| 202 | - $map = array(); |
|
| 203 | - foreach ( $categories as $name ) { |
|
| 204 | - $map[$name] = 1; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $ids = array(); |
|
| 208 | - if ( ! empty( $terms ) ) { |
|
| 209 | - foreach ( $terms as $id => $name ) { |
|
| 210 | - $ids[] = $id; |
|
| 211 | - unset( $map[$name] ); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // create new terms |
|
| 216 | - if ( ! empty( $map ) ) { |
|
| 217 | - foreach ( $map as $name => $value ) { |
|
| 218 | - $term = wp_insert_term( $name, 'category', array( 'parent' => 0 ) ); |
|
| 219 | - // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
|
| 220 | - $ids[] = $term['term_id']; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $args['post_category'] = $ids; |
|
| 191 | + $categories = $meta['categories']; |
|
| 192 | + if ( ! is_array( $categories ) ) { |
|
| 193 | + $categories = array( $categories ); |
|
| 194 | + } |
|
| 195 | + $terms = get_terms( array( |
|
| 196 | + 'taxonomy' => 'category', |
|
| 197 | + 'fields' => 'id=>name', |
|
| 198 | + 'hide_empty' => 0, |
|
| 199 | + 'name' => $categories |
|
| 200 | + ) |
|
| 201 | + ); |
|
| 202 | + $map = array(); |
|
| 203 | + foreach ( $categories as $name ) { |
|
| 204 | + $map[$name] = 1; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $ids = array(); |
|
| 208 | + if ( ! empty( $terms ) ) { |
|
| 209 | + foreach ( $terms as $id => $name ) { |
|
| 210 | + $ids[] = $id; |
|
| 211 | + unset( $map[$name] ); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // create new terms |
|
| 216 | + if ( ! empty( $map ) ) { |
|
| 217 | + foreach ( $map as $name => $value ) { |
|
| 218 | + $term = wp_insert_term( $name, 'category', array( 'parent' => 0 ) ); |
|
| 219 | + // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
|
| 220 | + $ids[] = $term['term_id']; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $args['post_category'] = $ids; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | return $args; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - private function get_post_id_by_filename( $filename, $pattern ) { |
|
| 231 | - preg_match( $pattern , $filename, $matches ); |
|
| 232 | - $title = $matches[4]; |
|
| 230 | + private function get_post_id_by_filename( $filename, $pattern ) { |
|
| 231 | + preg_match( $pattern , $filename, $matches ); |
|
| 232 | + $title = $matches[4]; |
|
| 233 | 233 | |
| 234 | - $query = new WP_Query( array( |
|
| 235 | - 'name' => $title, |
|
| 236 | - 'posts_per_page' => 1, |
|
| 237 | - 'post_type' => $this->get_whitelisted_post_types(), |
|
| 238 | - 'fields' => 'ids', |
|
| 239 | - ) ); |
|
| 234 | + $query = new WP_Query( array( |
|
| 235 | + 'name' => $title, |
|
| 236 | + 'posts_per_page' => 1, |
|
| 237 | + 'post_type' => $this->get_whitelisted_post_types(), |
|
| 238 | + 'fields' => 'ids', |
|
| 239 | + ) ); |
|
| 240 | 240 | |
| 241 | - $post_id = $query->get_posts(); |
|
| 242 | - $post_id = array_pop( $post_id ); |
|
| 243 | - return $post_id; |
|
| 244 | - } |
|
| 241 | + $post_id = $query->get_posts(); |
|
| 242 | + $post_id = array_pop( $post_id ); |
|
| 243 | + return $post_id; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | 247 | * Deletes a post from the database based on its GitHub path. |
@@ -268,11 +268,11 @@ discard block |
||
| 268 | 268 | $directory = $parts ? array_shift( $parts ) : ''; |
| 269 | 269 | |
| 270 | 270 | if ( false !== strpos( $directory, 'post' ) ) { |
| 271 | - $post_id = get_post_id_by_filename( $filename, '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/' ); |
|
| 271 | + $post_id = get_post_id_by_filename( $filename, '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/' ); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | if ( ! $post_id ) { |
| 275 | - $post_id = get_post_id_by_filename( $filename, '/(.*)\.md/' ); |
|
| 275 | + $post_id = get_post_id_by_filename( $filename, '/(.*)\.md/' ); |
|
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | |
@@ -417,12 +417,12 @@ discard block |
||
| 417 | 417 | if ( ! empty( $display_name ) ) { |
| 418 | 418 | $search_string = esc_attr( $display_name ); |
| 419 | 419 | $query = new WP_User_Query( array( |
| 420 | - 'search' => "{$search_string}", |
|
| 421 | - 'search_columns' => array( |
|
| 422 | - 'display_name', |
|
| 423 | - 'user_nicename', |
|
| 424 | - 'user_login', |
|
| 425 | - ) |
|
| 420 | + 'search' => "{$search_string}", |
|
| 421 | + 'search_columns' => array( |
|
| 422 | + 'display_name', |
|
| 423 | + 'user_nicename', |
|
| 424 | + 'user_login', |
|
| 425 | + ) |
|
| 426 | 426 | ) ); |
| 427 | 427 | $users = $query->get_results(); |
| 428 | 428 | $user = empty($users) ? false : $users[0]; |