| @@ 344-388 (lines=45) @@ | ||
| 341 | $media_id_string = join( ',', array_filter( array_map( 'absint', $media_results['media_ids'] ) ) ); |
|
| 342 | } |
|
| 343 | ||
| 344 | if ( $new ) { |
|
| 345 | if ( isset( $input['content'] ) && ! has_shortcode( $input['content'], 'gallery' ) && ( $has_media || $has_media_by_url ) ) { |
|
| 346 | switch ( ( $has_media + $has_media_by_url ) ) { |
|
| 347 | case 0 : |
|
| 348 | // No images - do nothing. |
|
| 349 | break; |
|
| 350 | case 1 : |
|
| 351 | // 1 image - make it big |
|
| 352 | $insert['post_content'] = $input['content'] = sprintf( |
|
| 353 | "[gallery size=full ids='%s' columns=1]\n\n", |
|
| 354 | $media_id_string |
|
| 355 | ) . $input['content']; |
|
| 356 | break; |
|
| 357 | default : |
|
| 358 | // Several images - 3 column gallery |
|
| 359 | $insert['post_content'] = $input['content'] = sprintf( |
|
| 360 | "[gallery ids='%s']\n\n", |
|
| 361 | $media_id_string |
|
| 362 | ) . $input['content']; |
|
| 363 | break; |
|
| 364 | } |
|
| 365 | } |
|
| 366 | ||
| 367 | $post_id = wp_insert_post( add_magic_quotes( $insert ), true ); |
|
| 368 | } else { |
|
| 369 | $insert['ID'] = $post->ID; |
|
| 370 | ||
| 371 | // wp_update_post ignores date unless edit_date is set |
|
| 372 | // See: http://codex.wordpress.org/Function_Reference/wp_update_post#Scheduling_posts |
|
| 373 | // See: https://core.trac.wordpress.org/browser/tags/3.9.2/src/wp-includes/post.php#L3302 |
|
| 374 | if ( isset( $input['date_gmt'] ) || isset( $input['date'] ) ) { |
|
| 375 | $insert['edit_date'] = true; |
|
| 376 | } |
|
| 377 | ||
| 378 | // this two-step process ensures any changes submitted along with status=trash get saved before trashing |
|
| 379 | if ( isset( $input['status'] ) && 'trash' === $input['status'] ) { |
|
| 380 | // if we insert it with status='trash', it will get double-trashed, so insert it as a draft first |
|
| 381 | unset( $insert['status'] ); |
|
| 382 | $post_id = wp_update_post( (object) $insert ); |
|
| 383 | // now call wp_trash_post so post_meta gets set and any filters get called |
|
| 384 | wp_trash_post( $post_id ); |
|
| 385 | } else { |
|
| 386 | $post_id = wp_update_post( (object) $insert ); |
|
| 387 | } |
|
| 388 | } |
|
| 389 | ||
| 390 | ||
| 391 | if ( !$post_id || is_wp_error( $post_id ) ) { |
|
| @@ 345-389 (lines=45) @@ | ||
| 342 | $media_id_string = join( ',', array_filter( array_map( 'absint', $media_results['media_ids'] ) ) ); |
|
| 343 | } |
|
| 344 | ||
| 345 | if ( $new ) { |
|
| 346 | if ( isset( $input['content'] ) && ! has_shortcode( $input['content'], 'gallery' ) && ( $has_media || $has_media_by_url ) ) { |
|
| 347 | switch ( ( $has_media + $has_media_by_url ) ) { |
|
| 348 | case 0 : |
|
| 349 | // No images - do nothing. |
|
| 350 | break; |
|
| 351 | case 1 : |
|
| 352 | // 1 image - make it big |
|
| 353 | $insert['post_content'] = $input['content'] = sprintf( |
|
| 354 | "[gallery size=full ids='%s' columns=1]\n\n", |
|
| 355 | $media_id_string |
|
| 356 | ) . $input['content']; |
|
| 357 | break; |
|
| 358 | default : |
|
| 359 | // Several images - 3 column gallery |
|
| 360 | $insert['post_content'] = $input['content'] = sprintf( |
|
| 361 | "[gallery ids='%s']\n\n", |
|
| 362 | $media_id_string |
|
| 363 | ) . $input['content']; |
|
| 364 | break; |
|
| 365 | } |
|
| 366 | } |
|
| 367 | ||
| 368 | $post_id = wp_insert_post( add_magic_quotes( $insert ), true ); |
|
| 369 | } else { |
|
| 370 | $insert['ID'] = $post->ID; |
|
| 371 | ||
| 372 | // wp_update_post ignores date unless edit_date is set |
|
| 373 | // See: http://codex.wordpress.org/Function_Reference/wp_update_post#Scheduling_posts |
|
| 374 | // See: https://core.trac.wordpress.org/browser/tags/3.9.2/src/wp-includes/post.php#L3302 |
|
| 375 | if ( isset( $input['date_gmt'] ) || isset( $input['date'] ) ) { |
|
| 376 | $insert['edit_date'] = true; |
|
| 377 | } |
|
| 378 | ||
| 379 | // this two-step process ensures any changes submitted along with status=trash get saved before trashing |
|
| 380 | if ( isset( $input['status'] ) && 'trash' === $input['status'] ) { |
|
| 381 | // if we insert it with status='trash', it will get double-trashed, so insert it as a draft first |
|
| 382 | unset( $insert['status'] ); |
|
| 383 | $post_id = wp_update_post( (object) $insert ); |
|
| 384 | // now call wp_trash_post so post_meta gets set and any filters get called |
|
| 385 | wp_trash_post( $post_id ); |
|
| 386 | } else { |
|
| 387 | $post_id = wp_update_post( (object) $insert ); |
|
| 388 | } |
|
| 389 | } |
|
| 390 | ||
| 391 | ||
| 392 | if ( !$post_id || is_wp_error( $post_id ) ) { |
|