| 369 | | function load_image_to_edit($post_id, $mime_type, $size = 'full') { |
| 370 | | $filepath = get_attached_file($post_id); |
| 371 | | |
| 372 | | if ( $filepath && file_exists($filepath) ) { |
| 373 | | if ( 'full' != $size && ( $data = image_get_intermediate_size($post_id, $size) ) ) { |
| 374 | | $filepath = apply_filters('load_image_to_edit_filesystempath', path_join( dirname($filepath), $data['file'] ), $post_id, $size); |
| 375 | | } |
| 376 | | } elseif ( function_exists('fopen') && function_exists('ini_get') && true == ini_get('allow_url_fopen') ) { |
| 377 | | $filepath = apply_filters('load_image_to_edit_attachmenturl', wp_get_attachment_url($post_id) , $post_id, $size); |
| 378 | | } |
| 379 | | |
| 380 | | $filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size); |
| 381 | | if ( empty($filepath) ) |
| | 366 | /** |
| | 367 | * Load an image resource for editing. |
| | 368 | * |
| | 369 | * @since 2.9.0 |
| | 370 | * |
| | 371 | * @param string $attachment_id Attachment ID. |
| | 372 | * @param string $mime_type Image mime type. |
| | 373 | * @param string $size Optional. Image size, defaults to 'full'. |
| | 374 | * @return resource|false The resulting image resource on success, false on failure. |
| | 375 | */ |
| | 376 | function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) { |
| | 377 | $filepath = _load_image_to_edit_path( $attachment_id, $size ); |
| | 378 | if ( empty( $filepath ) ) |
| | 404 | |
| | 405 | /** |
| | 406 | * Attempt to load an attachment from URL (for replication plugins). |
| | 407 | * |
| | 408 | * @since 3.4.0 |
| | 409 | * @access private |
| | 410 | * |
| | 411 | * @param string $attachment_id Attachment ID. |
| | 412 | * @param string $size Optional. Image size, defaults to 'full'. |
| | 413 | * @return string|false File path on success, false on failure. |
| | 414 | */ |
| | 415 | function _load_image_to_edit_path( $attachment_id, $size = 'full' ) { |
| | 416 | $filepath = get_attached_file( $attachment_id ); |
| | 417 | |
| | 418 | if ( $filepath && file_exists( $filepath ) ) { |
| | 419 | if ( 'full' != $size && ( $data = image_get_intermediate_size( $attachment_id, $size ) ) ) { |
| | 420 | $filepath = apply_filters( 'load_image_to_edit_filesystempath', path_join( dirname( $filepath ), $data['file'] ), $attachment_id, $size ); |
| | 421 | } |
| | 422 | } elseif ( function_exists( 'fopen' ) && function_exists( 'ini_get' ) && true == ini_get( 'allow_url_fopen' ) ) { |
| | 423 | $filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size ); |
| | 424 | } |
| | 425 | |
| | 426 | return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size ); |
| | 427 | } |
| | 428 | |
| | 429 | /** |
| | 430 | * Copy an existing image file. |
| | 431 | * |
| | 432 | * @since 3.4.0 |
| | 433 | * @access private |
| | 434 | * |
| | 435 | * @param string $attachment_id Attachment ID. |
| | 436 | * @return string|false New file path on success, false on failure. |
| | 437 | */ |
| | 438 | function _copy_image_file( $attachment_id ) { |
| | 439 | $dst_file = $src_file = get_attached_file( $attachment_id ); |
| | 440 | if ( ! file_exists( $src_file ) ) |
| | 441 | $src_file = _load_image_to_edit_path( $attachment_id ); |
| | 442 | |
| | 443 | if ( $src_file ) { |
| | 444 | $dst_file = str_replace( basename( $dst_file ), 'copy-' . basename( $dst_file ), $dst_file ); |
| | 445 | $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) ); |
| | 446 | if ( ! @copy( $src_file, $dst_file ) ) |
| | 447 | $dst_file = false; |
| | 448 | } else { |
| | 449 | $dst_file = false; |
| | 450 | } |
| | 451 | |
| | 452 | return $dst_file; |
| | 453 | } |