Plugin Directory

Changeset 3219198


Ignore:
Timestamp:
01/08/2025 05:00:45 PM (11 months ago)
Author:
janw.oostendorp
Message:

Update to version 1.8.0 from GitHub

Location:
default-featured-image
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • default-featured-image/tags/1.8.0/app/class-dfi-exceptions.php

    r3036889 r3219198  
    1111     * Exclude dfi from shortcode: wpuf_edit
    1212     *
    13      * @param mixed  $false unused, just pass along.
     13     * @param mixed  $_false unused, just pass along.
    1414     * @param string $tag The shortcode.
    1515     *
    1616     * @return mixed
    1717     */
    18     public static function wp_user_frontend_pre( $false, $tag ) {
     18    public static function wp_user_frontend_pre( $_false, $tag ) {
    1919        if ( 'wpuf_edit' === $tag ) {
    2020            add_filter( 'dfi_thumbnail_id', '__return_null' );
    2121        }
    2222
    23         return $false;
     23        return $_false;
    2424    }
    2525
     
    5454        }
    5555    }
    56 
    57     /**
    58      * When WPML translates a post it will try to get the featured image, but there is none, so it gets the DFI.
    59      * This will prevent that from happening.
    60      *
    61      * @return void
    62      */
    63     public static function wpml_dont_save_dfi_on_translate() {
    64         $dfi = DFI::instance();
    65         remove_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10 );
    66     }
    6756}
  • default-featured-image/tags/1.8.0/app/class-dfi.php

    r2895660 r3219198  
    1919     */
    2020    public static function instance() {
    21         if ( null === static::$inst ) {
    22             static::$inst = new self();
    23         }
    24         return static::$inst;
     21        if ( null === self::$inst ) {
     22            self::$inst = new self();
     23        }
     24        return self::$inst;
    2525    }
    2626
     
    5252     * Add the dfi_id to the meta data if needed.
    5353     *
    54      * @param null|mixed $null      Should be null, we don't use it because we update the meta cache.
     54     * @param null|mixed $_null      Should be null, we don't use it because we update the meta cache.
    5555     * @param int        $object_id ID of the object metadata is for.
    5656     * @param string     $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
    5757     *                              the specified object.
    58      * @param bool       $single    Optional, default is false. If true, return only the first value of the
    59      *                              specified meta_key. This parameter has no effect if meta_key is not specified.
    6058     *
    6159     * @return string|string[] Single metadata value, or array of values
    6260     */
    63     public function set_dfi_meta_key( $null, $object_id, $meta_key, $single ) {
     61    public function set_dfi_meta_key( $_null, $object_id, $meta_key ) {
    6462        // Only affect thumbnails on the frontend, do allow ajax calls.
    6563        if ( ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) ) {
    66             return $null;
     64            return $_null;
    6765        }
    6866
    6967        // Check only empty meta_key and '_thumbnail_id'.
    7068        if ( ! empty( $meta_key ) && '_thumbnail_id' !== $meta_key ) {
    71             return $null;
     69            return $_null;
    7270        }
    7371
     
    7573        // Check if this post type supports featured images.
    7674        if ( false !== $post_type && ! post_type_supports( $post_type, 'thumbnail' ) ) {
    77             return $null; // post type does not support featured images.
     75            return $_null; // post type does not support featured images.
    7876        }
    7977
     
    9795        // Is the _thumbnail_id present in cache?
    9896        if ( ! empty( $meta_cache['_thumbnail_id'][0] ) ) {
    99             return $null; // it is present, don't check anymore.
     97            return $_null; // it is present, don't check anymore.
    10098        }
    10199
     
    107105        wp_cache_set( $object_id, $meta_cache, 'post_meta' );
    108106
    109         return $null;
    110     }
    111 
    112     /**
    113      * Register the setting on the media settings page.
    114      *
    115      * @return void
    116      */
    117     public function media_setting() {
     107        return $_null;
     108    }
     109
     110    /**
     111     * Register the DFI option.
     112     *
     113     * @return void
     114     */
     115    public function register_media_setting() {
    118116        register_setting(
    119117            'media', // settings page.
    120118            'dfi_image_id', // option name.
    121             array( &$this, 'input_validation' ) // validation callback.
     119            array(
     120                'sanitize_callback' => array( &$this, 'input_validation' ),
     121                'show_in_rest'      => array(
     122                    'schema' => array(
     123                        'type'    => 'integer',
     124                        'minimum' => 1,
     125                    ),
     126                ),
     127            )
    122128        );
     129    }
     130
     131    /**
     132     * Register the setting on the media settings page.
     133     *
     134     * @return void
     135     */
     136    public function media_setting() {
     137        $this->register_media_setting();
    123138        add_settings_field(
    124139            'dfi', // id.
     
    126141            array( &$this, 'settings_html' ), // display callback.
    127142            'media', // settings page.
    128             'default' // settings section.
     143            'default', // settings section.
    129144        );
    130145    }
     
    188203                'manager_title'  => __( 'Select default featured image', 'default-featured-image' ),
    189204                'manager_button' => __( 'Set default featured image', 'default-featured-image' ),
    190             )
     205            ),
    191206        );
    192207    }
     
    258273        // Attributes can be a query string, parse that.
    259274        if ( is_string( $attr ) ) {
    260             wp_parse_str( $attr, $attr );
     275            $str_attr = $attr;
     276            $attr     = array();
     277            wp_parse_str( $str_attr, $attr );
     278            unset( $str_attr );
    261279        }
    262280
  • default-featured-image/tags/1.8.0/readme.txt

    r3204711 r3219198  
    55Tested up to: 6.7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.7.3
     7Stable tag: 1.8.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    109109
    110110== Changelog ==
     111= 1.8.0 =
     112* Expose the DFI option via the rest API.
     113
    111114= 1.7.3 =
    112115* PHP 7.4 and WP 6.2 are now required. This is to use the new [WP_HTML_Tag_Processor](https://make.wordpress.org/core/2023/03/07/introducing-the-html-api-in-wordpress-6-2/) functions.
  • default-featured-image/tags/1.8.0/set-default-featured-image.php

    r3036889 r3219198  
    44 * Plugin URI: http://wordpress.org/extend/plugins/default-featured-image/
    55 * Description: Allows users to select a default featured image in the media settings
    6  * Version: 1.7.3
     6 * Version: 1.8.0
    77 * Requires at least: 6.2
    88 * Requires PHP: 7.4
     
    1515 */
    1616
    17 define( 'DFI_VERSION', '1.7.3' );
     17define( 'DFI_VERSION', '1.8.0' );
    1818define( 'DFI_DIR', plugin_dir_path( __FILE__ ) );
    1919define( 'DFI_URL', plugin_dir_url( __FILE__ ) );
     
    2727// add the settings field to the media page.
    2828add_action( 'admin_init', array( $dfi, 'media_setting' ) );
     29add_action( 'rest_api_init', array( $dfi, 'register_media_setting' ) );
    2930// enqueue the js.
    3031add_action( 'admin_print_scripts-options-media.php', array( $dfi, 'admin_scripts' ) );
     
    3233add_action( 'wp_ajax_dfi_change_preview', array( $dfi, 'ajax_wrapper' ) );
    3334// set dfi meta key on every occasion.
    34 add_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10, 4 );
     35add_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10, 3 );
    3536// display a default featured image.
    3637add_filter( 'post_thumbnail_html', array( $dfi, 'show_dfi' ), 20, 5 );
     
    5657 */
    5758add_filter( 'dfi_thumbnail_id', array( 'DFI_Exceptions', 'wp_all_import_dfi_workaround' ), 9 );
    58 
    59 /**
    60  * Exception: https://wpml.org/
    61  *
    62  * @see https://wordpress.org/support/topic/wpml-compatibility-281/
    63  */
    64 add_filter( 'dfi_thumbnail_id', array( 'DFI_Exceptions', 'wpml_dont_save_dfi_on_translate' ), 9 );
  • default-featured-image/trunk/app/class-dfi-exceptions.php

    r3036889 r3219198  
    1111     * Exclude dfi from shortcode: wpuf_edit
    1212     *
    13      * @param mixed  $false unused, just pass along.
     13     * @param mixed  $_false unused, just pass along.
    1414     * @param string $tag The shortcode.
    1515     *
    1616     * @return mixed
    1717     */
    18     public static function wp_user_frontend_pre( $false, $tag ) {
     18    public static function wp_user_frontend_pre( $_false, $tag ) {
    1919        if ( 'wpuf_edit' === $tag ) {
    2020            add_filter( 'dfi_thumbnail_id', '__return_null' );
    2121        }
    2222
    23         return $false;
     23        return $_false;
    2424    }
    2525
     
    5454        }
    5555    }
    56 
    57     /**
    58      * When WPML translates a post it will try to get the featured image, but there is none, so it gets the DFI.
    59      * This will prevent that from happening.
    60      *
    61      * @return void
    62      */
    63     public static function wpml_dont_save_dfi_on_translate() {
    64         $dfi = DFI::instance();
    65         remove_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10 );
    66     }
    6756}
  • default-featured-image/trunk/app/class-dfi.php

    r2895660 r3219198  
    1919     */
    2020    public static function instance() {
    21         if ( null === static::$inst ) {
    22             static::$inst = new self();
    23         }
    24         return static::$inst;
     21        if ( null === self::$inst ) {
     22            self::$inst = new self();
     23        }
     24        return self::$inst;
    2525    }
    2626
     
    5252     * Add the dfi_id to the meta data if needed.
    5353     *
    54      * @param null|mixed $null      Should be null, we don't use it because we update the meta cache.
     54     * @param null|mixed $_null      Should be null, we don't use it because we update the meta cache.
    5555     * @param int        $object_id ID of the object metadata is for.
    5656     * @param string     $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
    5757     *                              the specified object.
    58      * @param bool       $single    Optional, default is false. If true, return only the first value of the
    59      *                              specified meta_key. This parameter has no effect if meta_key is not specified.
    6058     *
    6159     * @return string|string[] Single metadata value, or array of values
    6260     */
    63     public function set_dfi_meta_key( $null, $object_id, $meta_key, $single ) {
     61    public function set_dfi_meta_key( $_null, $object_id, $meta_key ) {
    6462        // Only affect thumbnails on the frontend, do allow ajax calls.
    6563        if ( ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) ) {
    66             return $null;
     64            return $_null;
    6765        }
    6866
    6967        // Check only empty meta_key and '_thumbnail_id'.
    7068        if ( ! empty( $meta_key ) && '_thumbnail_id' !== $meta_key ) {
    71             return $null;
     69            return $_null;
    7270        }
    7371
     
    7573        // Check if this post type supports featured images.
    7674        if ( false !== $post_type && ! post_type_supports( $post_type, 'thumbnail' ) ) {
    77             return $null; // post type does not support featured images.
     75            return $_null; // post type does not support featured images.
    7876        }
    7977
     
    9795        // Is the _thumbnail_id present in cache?
    9896        if ( ! empty( $meta_cache['_thumbnail_id'][0] ) ) {
    99             return $null; // it is present, don't check anymore.
     97            return $_null; // it is present, don't check anymore.
    10098        }
    10199
     
    107105        wp_cache_set( $object_id, $meta_cache, 'post_meta' );
    108106
    109         return $null;
    110     }
    111 
    112     /**
    113      * Register the setting on the media settings page.
    114      *
    115      * @return void
    116      */
    117     public function media_setting() {
     107        return $_null;
     108    }
     109
     110    /**
     111     * Register the DFI option.
     112     *
     113     * @return void
     114     */
     115    public function register_media_setting() {
    118116        register_setting(
    119117            'media', // settings page.
    120118            'dfi_image_id', // option name.
    121             array( &$this, 'input_validation' ) // validation callback.
     119            array(
     120                'sanitize_callback' => array( &$this, 'input_validation' ),
     121                'show_in_rest'      => array(
     122                    'schema' => array(
     123                        'type'    => 'integer',
     124                        'minimum' => 1,
     125                    ),
     126                ),
     127            )
    122128        );
     129    }
     130
     131    /**
     132     * Register the setting on the media settings page.
     133     *
     134     * @return void
     135     */
     136    public function media_setting() {
     137        $this->register_media_setting();
    123138        add_settings_field(
    124139            'dfi', // id.
     
    126141            array( &$this, 'settings_html' ), // display callback.
    127142            'media', // settings page.
    128             'default' // settings section.
     143            'default', // settings section.
    129144        );
    130145    }
     
    188203                'manager_title'  => __( 'Select default featured image', 'default-featured-image' ),
    189204                'manager_button' => __( 'Set default featured image', 'default-featured-image' ),
    190             )
     205            ),
    191206        );
    192207    }
     
    258273        // Attributes can be a query string, parse that.
    259274        if ( is_string( $attr ) ) {
    260             wp_parse_str( $attr, $attr );
     275            $str_attr = $attr;
     276            $attr     = array();
     277            wp_parse_str( $str_attr, $attr );
     278            unset( $str_attr );
    261279        }
    262280
  • default-featured-image/trunk/readme.txt

    r3204711 r3219198  
    55Tested up to: 6.7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.7.3
     7Stable tag: 1.8.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    109109
    110110== Changelog ==
     111= 1.8.0 =
     112* Expose the DFI option via the rest API.
     113
    111114= 1.7.3 =
    112115* PHP 7.4 and WP 6.2 are now required. This is to use the new [WP_HTML_Tag_Processor](https://make.wordpress.org/core/2023/03/07/introducing-the-html-api-in-wordpress-6-2/) functions.
  • default-featured-image/trunk/set-default-featured-image.php

    r3036889 r3219198  
    44 * Plugin URI: http://wordpress.org/extend/plugins/default-featured-image/
    55 * Description: Allows users to select a default featured image in the media settings
    6  * Version: 1.7.3
     6 * Version: 1.8.0
    77 * Requires at least: 6.2
    88 * Requires PHP: 7.4
     
    1515 */
    1616
    17 define( 'DFI_VERSION', '1.7.3' );
     17define( 'DFI_VERSION', '1.8.0' );
    1818define( 'DFI_DIR', plugin_dir_path( __FILE__ ) );
    1919define( 'DFI_URL', plugin_dir_url( __FILE__ ) );
     
    2727// add the settings field to the media page.
    2828add_action( 'admin_init', array( $dfi, 'media_setting' ) );
     29add_action( 'rest_api_init', array( $dfi, 'register_media_setting' ) );
    2930// enqueue the js.
    3031add_action( 'admin_print_scripts-options-media.php', array( $dfi, 'admin_scripts' ) );
     
    3233add_action( 'wp_ajax_dfi_change_preview', array( $dfi, 'ajax_wrapper' ) );
    3334// set dfi meta key on every occasion.
    34 add_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10, 4 );
     35add_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10, 3 );
    3536// display a default featured image.
    3637add_filter( 'post_thumbnail_html', array( $dfi, 'show_dfi' ), 20, 5 );
     
    5657 */
    5758add_filter( 'dfi_thumbnail_id', array( 'DFI_Exceptions', 'wp_all_import_dfi_workaround' ), 9 );
    58 
    59 /**
    60  * Exception: https://wpml.org/
    61  *
    62  * @see https://wordpress.org/support/topic/wpml-compatibility-281/
    63  */
    64 add_filter( 'dfi_thumbnail_id', array( 'DFI_Exceptions', 'wpml_dont_save_dfi_on_translate' ), 9 );
Note: See TracChangeset for help on using the changeset viewer.