Changeset 3219198
- Timestamp:
- 01/08/2025 05:00:45 PM (11 months ago)
- Location:
- default-featured-image
- Files:
-
- 8 edited
- 1 copied
-
tags/1.8.0 (copied) (copied from default-featured-image/trunk)
-
tags/1.8.0/app/class-dfi-exceptions.php (modified) (2 diffs)
-
tags/1.8.0/app/class-dfi.php (modified) (8 diffs)
-
tags/1.8.0/readme.txt (modified) (2 diffs)
-
tags/1.8.0/set-default-featured-image.php (modified) (5 diffs)
-
trunk/app/class-dfi-exceptions.php (modified) (2 diffs)
-
trunk/app/class-dfi.php (modified) (8 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/set-default-featured-image.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
default-featured-image/tags/1.8.0/app/class-dfi-exceptions.php
r3036889 r3219198 11 11 * Exclude dfi from shortcode: wpuf_edit 12 12 * 13 * @param mixed $ false unused, just pass along.13 * @param mixed $_false unused, just pass along. 14 14 * @param string $tag The shortcode. 15 15 * 16 16 * @return mixed 17 17 */ 18 public static function wp_user_frontend_pre( $ false, $tag ) {18 public static function wp_user_frontend_pre( $_false, $tag ) { 19 19 if ( 'wpuf_edit' === $tag ) { 20 20 add_filter( 'dfi_thumbnail_id', '__return_null' ); 21 21 } 22 22 23 return $ false;23 return $_false; 24 24 } 25 25 … … 54 54 } 55 55 } 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 void62 */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 }67 56 } -
default-featured-image/tags/1.8.0/app/class-dfi.php
r2895660 r3219198 19 19 */ 20 20 public static function instance() { 21 if ( null === s tatic::$inst ) {22 s tatic::$inst = new self();23 } 24 return s tatic::$inst;21 if ( null === self::$inst ) { 22 self::$inst = new self(); 23 } 24 return self::$inst; 25 25 } 26 26 … … 52 52 * Add the dfi_id to the meta data if needed. 53 53 * 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. 55 55 * @param int $object_id ID of the object metadata is for. 56 56 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for 57 57 * the specified object. 58 * @param bool $single Optional, default is false. If true, return only the first value of the59 * specified meta_key. This parameter has no effect if meta_key is not specified.60 58 * 61 59 * @return string|string[] Single metadata value, or array of values 62 60 */ 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 ) { 64 62 // Only affect thumbnails on the frontend, do allow ajax calls. 65 63 if ( ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) ) { 66 return $ null;64 return $_null; 67 65 } 68 66 69 67 // Check only empty meta_key and '_thumbnail_id'. 70 68 if ( ! empty( $meta_key ) && '_thumbnail_id' !== $meta_key ) { 71 return $ null;69 return $_null; 72 70 } 73 71 … … 75 73 // Check if this post type supports featured images. 76 74 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. 78 76 } 79 77 … … 97 95 // Is the _thumbnail_id present in cache? 98 96 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. 100 98 } 101 99 … … 107 105 wp_cache_set( $object_id, $meta_cache, 'post_meta' ); 108 106 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() { 118 116 register_setting( 119 117 'media', // settings page. 120 118 '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 ) 122 128 ); 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(); 123 138 add_settings_field( 124 139 'dfi', // id. … … 126 141 array( &$this, 'settings_html' ), // display callback. 127 142 'media', // settings page. 128 'default' // settings section.143 'default', // settings section. 129 144 ); 130 145 } … … 188 203 'manager_title' => __( 'Select default featured image', 'default-featured-image' ), 189 204 'manager_button' => __( 'Set default featured image', 'default-featured-image' ), 190 ) 205 ), 191 206 ); 192 207 } … … 258 273 // Attributes can be a query string, parse that. 259 274 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 ); 261 279 } 262 280 -
default-featured-image/tags/1.8.0/readme.txt
r3204711 r3219198 5 5 Tested up to: 6.7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1. 7.37 Stable tag: 1.8.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 109 109 110 110 == Changelog == 111 = 1.8.0 = 112 * Expose the DFI option via the rest API. 113 111 114 = 1.7.3 = 112 115 * 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 4 4 * Plugin URI: http://wordpress.org/extend/plugins/default-featured-image/ 5 5 * Description: Allows users to select a default featured image in the media settings 6 * Version: 1. 7.36 * Version: 1.8.0 7 7 * Requires at least: 6.2 8 8 * Requires PHP: 7.4 … … 15 15 */ 16 16 17 define( 'DFI_VERSION', '1. 7.3' );17 define( 'DFI_VERSION', '1.8.0' ); 18 18 define( 'DFI_DIR', plugin_dir_path( __FILE__ ) ); 19 19 define( 'DFI_URL', plugin_dir_url( __FILE__ ) ); … … 27 27 // add the settings field to the media page. 28 28 add_action( 'admin_init', array( $dfi, 'media_setting' ) ); 29 add_action( 'rest_api_init', array( $dfi, 'register_media_setting' ) ); 29 30 // enqueue the js. 30 31 add_action( 'admin_print_scripts-options-media.php', array( $dfi, 'admin_scripts' ) ); … … 32 33 add_action( 'wp_ajax_dfi_change_preview', array( $dfi, 'ajax_wrapper' ) ); 33 34 // set dfi meta key on every occasion. 34 add_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10, 4);35 add_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10, 3 ); 35 36 // display a default featured image. 36 37 add_filter( 'post_thumbnail_html', array( $dfi, 'show_dfi' ), 20, 5 ); … … 56 57 */ 57 58 add_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 11 11 * Exclude dfi from shortcode: wpuf_edit 12 12 * 13 * @param mixed $ false unused, just pass along.13 * @param mixed $_false unused, just pass along. 14 14 * @param string $tag The shortcode. 15 15 * 16 16 * @return mixed 17 17 */ 18 public static function wp_user_frontend_pre( $ false, $tag ) {18 public static function wp_user_frontend_pre( $_false, $tag ) { 19 19 if ( 'wpuf_edit' === $tag ) { 20 20 add_filter( 'dfi_thumbnail_id', '__return_null' ); 21 21 } 22 22 23 return $ false;23 return $_false; 24 24 } 25 25 … … 54 54 } 55 55 } 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 void62 */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 }67 56 } -
default-featured-image/trunk/app/class-dfi.php
r2895660 r3219198 19 19 */ 20 20 public static function instance() { 21 if ( null === s tatic::$inst ) {22 s tatic::$inst = new self();23 } 24 return s tatic::$inst;21 if ( null === self::$inst ) { 22 self::$inst = new self(); 23 } 24 return self::$inst; 25 25 } 26 26 … … 52 52 * Add the dfi_id to the meta data if needed. 53 53 * 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. 55 55 * @param int $object_id ID of the object metadata is for. 56 56 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for 57 57 * the specified object. 58 * @param bool $single Optional, default is false. If true, return only the first value of the59 * specified meta_key. This parameter has no effect if meta_key is not specified.60 58 * 61 59 * @return string|string[] Single metadata value, or array of values 62 60 */ 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 ) { 64 62 // Only affect thumbnails on the frontend, do allow ajax calls. 65 63 if ( ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) ) { 66 return $ null;64 return $_null; 67 65 } 68 66 69 67 // Check only empty meta_key and '_thumbnail_id'. 70 68 if ( ! empty( $meta_key ) && '_thumbnail_id' !== $meta_key ) { 71 return $ null;69 return $_null; 72 70 } 73 71 … … 75 73 // Check if this post type supports featured images. 76 74 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. 78 76 } 79 77 … … 97 95 // Is the _thumbnail_id present in cache? 98 96 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. 100 98 } 101 99 … … 107 105 wp_cache_set( $object_id, $meta_cache, 'post_meta' ); 108 106 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() { 118 116 register_setting( 119 117 'media', // settings page. 120 118 '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 ) 122 128 ); 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(); 123 138 add_settings_field( 124 139 'dfi', // id. … … 126 141 array( &$this, 'settings_html' ), // display callback. 127 142 'media', // settings page. 128 'default' // settings section.143 'default', // settings section. 129 144 ); 130 145 } … … 188 203 'manager_title' => __( 'Select default featured image', 'default-featured-image' ), 189 204 'manager_button' => __( 'Set default featured image', 'default-featured-image' ), 190 ) 205 ), 191 206 ); 192 207 } … … 258 273 // Attributes can be a query string, parse that. 259 274 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 ); 261 279 } 262 280 -
default-featured-image/trunk/readme.txt
r3204711 r3219198 5 5 Tested up to: 6.7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1. 7.37 Stable tag: 1.8.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 109 109 110 110 == Changelog == 111 = 1.8.0 = 112 * Expose the DFI option via the rest API. 113 111 114 = 1.7.3 = 112 115 * 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 4 4 * Plugin URI: http://wordpress.org/extend/plugins/default-featured-image/ 5 5 * Description: Allows users to select a default featured image in the media settings 6 * Version: 1. 7.36 * Version: 1.8.0 7 7 * Requires at least: 6.2 8 8 * Requires PHP: 7.4 … … 15 15 */ 16 16 17 define( 'DFI_VERSION', '1. 7.3' );17 define( 'DFI_VERSION', '1.8.0' ); 18 18 define( 'DFI_DIR', plugin_dir_path( __FILE__ ) ); 19 19 define( 'DFI_URL', plugin_dir_url( __FILE__ ) ); … … 27 27 // add the settings field to the media page. 28 28 add_action( 'admin_init', array( $dfi, 'media_setting' ) ); 29 add_action( 'rest_api_init', array( $dfi, 'register_media_setting' ) ); 29 30 // enqueue the js. 30 31 add_action( 'admin_print_scripts-options-media.php', array( $dfi, 'admin_scripts' ) ); … … 32 33 add_action( 'wp_ajax_dfi_change_preview', array( $dfi, 'ajax_wrapper' ) ); 33 34 // set dfi meta key on every occasion. 34 add_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10, 4);35 add_filter( 'get_post_metadata', array( $dfi, 'set_dfi_meta_key' ), 10, 3 ); 35 36 // display a default featured image. 36 37 add_filter( 'post_thumbnail_html', array( $dfi, 'show_dfi' ), 20, 5 ); … … 56 57 */ 57 58 add_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.