Make WordPress Core

Changeset 48905


Ignore:
Timestamp:
08/28/2020 04:43:31 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Media: Make the is_gd_image() function available on front end.

This avoids a fatal error if a plugin calls image creation or editing functions like wp_imagecreatetruecolor() outside of the admin.

Follow-up to [48798]

Props BackuPs.
Fixes #51174. See #50833.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image.php

    r48799 r48905  
    914914
    915915/**
    916  * Determines whether the value is an acceptable type for GD image functions.
    917  *
    918  * In PHP 8.0, the GD extension uses GdImage objects for its data structures.
    919  * This function checks if the passed value is either a resource of type `gd`
    920  * or a GdImage object instance. Any other type will return false.
    921  *
    922  * @since 5.6.0
    923  *
    924  * @param resource|GdImage|false $image A value to check the type for.
    925  * @return bool True if $image is either a GD image resource or GdImage instance,
    926  *              false otherwise.
    927  */
    928 function is_gd_image( $image ) {
    929     if ( is_resource( $image ) && 'gd' === get_resource_type( $image )
    930         || is_object( $image ) && $image instanceof GdImage
    931     ) {
    932         return true;
    933     }
    934 
    935     return false;
    936 }
    937 
    938 /**
    939916 * Load an image resource for editing.
    940917 *
  • trunk/src/wp-includes/media.php

    r48855 r48905  
    34603460
    34613461/**
     3462 * Determines whether the value is an acceptable type for GD image functions.
     3463 *
     3464 * In PHP 8.0, the GD extension uses GdImage objects for its data structures.
     3465 * This function checks if the passed value is either a resource of type `gd`
     3466 * or a GdImage object instance. Any other type will return false.
     3467 *
     3468 * @since 5.6.0
     3469 *
     3470 * @param resource|GdImage|false $image A value to check the type for.
     3471 * @return bool True if $image is either a GD image resource or GdImage instance,
     3472 *              false otherwise.
     3473 */
     3474function is_gd_image( $image ) {
     3475    if ( is_resource( $image ) && 'gd' === get_resource_type( $image )
     3476        || is_object( $image ) && $image instanceof GdImage
     3477    ) {
     3478        return true;
     3479    }
     3480
     3481    return false;
     3482}
     3483
     3484/**
    34623485 * Create new GD image resource with transparency support
    34633486 *
Note: See TracChangeset for help on using the changeset viewer.