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