@@ -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; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | $meta = apply_filters( 'wogh_pre_import_meta', $post->get_meta(), $post ); |
| 156 | 156 | |
| 157 | - update_post_meta( $post_id, '_wogh_sha', $meta['_wogh_sha'] ); |
|
| 157 | + update_post_meta( $post_id, '_wogh_sha', $meta['_wogh_sha'] ); |
|
| 158 | 158 | |
| 159 | 159 | // unset( $meta['tags'] ); |
| 160 | 160 | // unset( $meta['categories'] ); |
@@ -185,65 +185,65 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | // update tags |
| 187 | 187 | if ( ! empty( $meta['tags'] ) ) { |
| 188 | - $args['tags_input'] = $meta['tags']; |
|
| 188 | + $args['tags_input'] = $meta['tags']; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | // update categories |
| 192 | 192 | if ( ! empty( $meta['categories'] ) ) { |
| 193 | - $categories = $meta['categories']; |
|
| 194 | - if ( ! is_array( $categories ) ) { |
|
| 195 | - $categories = array( $categories ); |
|
| 196 | - } |
|
| 197 | - $terms = get_terms( array( |
|
| 198 | - 'taxonomy' => 'category', |
|
| 199 | - 'fields' => 'id=>name', |
|
| 200 | - 'hide_empty' => 0, |
|
| 201 | - 'name' => $categories |
|
| 202 | - ) |
|
| 203 | - ); |
|
| 204 | - $map = array(); |
|
| 205 | - foreach ( $categories as $name ) { |
|
| 206 | - $map[$name] = 1; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - $ids = array(); |
|
| 210 | - if ( ! empty( $terms ) ) { |
|
| 211 | - foreach ( $terms as $id => $name ) { |
|
| 212 | - $ids[] = $id; |
|
| 213 | - unset( $map[$name] ); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // create new terms |
|
| 218 | - if ( ! empty( $map ) ) { |
|
| 219 | - foreach ( $map as $name => $value ) { |
|
| 220 | - $term = wp_insert_term( $name, 'category', array( 'parent' => 0 ) ); |
|
| 221 | - // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
|
| 222 | - $ids[] = $term['term_id']; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $args['post_category'] = $ids; |
|
| 193 | + $categories = $meta['categories']; |
|
| 194 | + if ( ! is_array( $categories ) ) { |
|
| 195 | + $categories = array( $categories ); |
|
| 196 | + } |
|
| 197 | + $terms = get_terms( array( |
|
| 198 | + 'taxonomy' => 'category', |
|
| 199 | + 'fields' => 'id=>name', |
|
| 200 | + 'hide_empty' => 0, |
|
| 201 | + 'name' => $categories |
|
| 202 | + ) |
|
| 203 | + ); |
|
| 204 | + $map = array(); |
|
| 205 | + foreach ( $categories as $name ) { |
|
| 206 | + $map[$name] = 1; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + $ids = array(); |
|
| 210 | + if ( ! empty( $terms ) ) { |
|
| 211 | + foreach ( $terms as $id => $name ) { |
|
| 212 | + $ids[] = $id; |
|
| 213 | + unset( $map[$name] ); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // create new terms |
|
| 218 | + if ( ! empty( $map ) ) { |
|
| 219 | + foreach ( $map as $name => $value ) { |
|
| 220 | + $term = wp_insert_term( $name, 'category', array( 'parent' => 0 ) ); |
|
| 221 | + // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
|
| 222 | + $ids[] = $term['term_id']; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $args['post_category'] = $ids; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | return $args; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - private function get_post_id_by_filename( $filename, $pattern ) { |
|
| 233 | - preg_match( $pattern , $filename, $matches ); |
|
| 234 | - $title = $matches[4]; |
|
| 232 | + private function get_post_id_by_filename( $filename, $pattern ) { |
|
| 233 | + preg_match( $pattern , $filename, $matches ); |
|
| 234 | + $title = $matches[4]; |
|
| 235 | 235 | |
| 236 | - $query = new WP_Query( array( |
|
| 237 | - 'name' => $title, |
|
| 238 | - 'posts_per_page' => 1, |
|
| 239 | - 'post_type' => $this->get_whitelisted_post_types(), |
|
| 240 | - 'fields' => 'ids', |
|
| 241 | - ) ); |
|
| 236 | + $query = new WP_Query( array( |
|
| 237 | + 'name' => $title, |
|
| 238 | + 'posts_per_page' => 1, |
|
| 239 | + 'post_type' => $this->get_whitelisted_post_types(), |
|
| 240 | + 'fields' => 'ids', |
|
| 241 | + ) ); |
|
| 242 | 242 | |
| 243 | - $post_id = $query->get_posts(); |
|
| 244 | - $post_id = array_pop( $post_id ); |
|
| 245 | - return $post_id; |
|
| 246 | - } |
|
| 243 | + $post_id = $query->get_posts(); |
|
| 244 | + $post_id = array_pop( $post_id ); |
|
| 245 | + return $post_id; |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | 248 | /** |
| 249 | 249 | * Deletes a post from the database based on its GitHub path. |
@@ -270,11 +270,11 @@ discard block |
||
| 270 | 270 | $directory = $parts ? array_shift( $parts ) : ''; |
| 271 | 271 | |
| 272 | 272 | if ( false !== strpos( $directory, 'post' ) ) { |
| 273 | - $post_id = get_post_id_by_filename( $filename, '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/' ); |
|
| 273 | + $post_id = get_post_id_by_filename( $filename, '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/' ); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | if ( ! $post_id ) { |
| 277 | - $post_id = get_post_id_by_filename( $filename, '/(.*)\.md/' ); |
|
| 277 | + $post_id = get_post_id_by_filename( $filename, '/(.*)\.md/' ); |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
@@ -419,12 +419,12 @@ discard block |
||
| 419 | 419 | if ( ! empty( $display_name ) ) { |
| 420 | 420 | $search_string = esc_attr( $display_name ); |
| 421 | 421 | $query = new WP_User_Query( array( |
| 422 | - 'search' => "{$search_string}", |
|
| 423 | - 'search_columns' => array( |
|
| 424 | - 'display_name', |
|
| 425 | - 'user_nicename', |
|
| 426 | - 'user_login', |
|
| 427 | - ) |
|
| 422 | + 'search' => "{$search_string}", |
|
| 423 | + 'search_columns' => array( |
|
| 424 | + 'display_name', |
|
| 425 | + 'user_nicename', |
|
| 426 | + 'user_login', |
|
| 427 | + ) |
|
| 428 | 428 | ) ); |
| 429 | 429 | $users = $query->get_results(); |
| 430 | 430 | $user = empty($users) ? false : $users[0]; |