Plugin Directory

Changeset 3408797


Ignore:
Timestamp:
12/03/2025 05:12:06 AM (4 months ago)
Author:
vedathemes
Message:

taxonomy bug fix

Location:
display-post-types/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • display-post-types/trunk/display-post-types.php

    r3396264 r3408797  
    1515 * Plugin Name: Display Post Types
    1616 * Description: Filter, sort and display post, page or any post type.
    17  * Version: 3.2.3
     17 * Version: 3.2.4
    1818 * Author: easyprolabs
    1919 * Author URI: https://easyprolabs.com/display-post-types/
     
    3131// Currently plugin version.
    3232if ( ! defined( 'DISPLAY_POST_TYPES_VERSION' ) ) {
    33     define( 'DISPLAY_POST_TYPES_VERSION', '3.2.3' );
     33    define( 'DISPLAY_POST_TYPES_VERSION', '3.2.4' );
    3434}
    3535
  • display-post-types/trunk/helper/class-security.php

    r3323385 r3408797  
    3434                'title'         => 'string',
    3535                'post_type'     => 'string',
    36                 'taxonomy'      => 'string',
    37                 'terms'         => 'arrstring',
     36                'taxonomy'      => 'taxonomy',
     37                'terms'         => 'terms',
    3838                'relation'      => 'string',
    3939                'post_ids'      => 'string',
     
    8484        foreach ( $data as $key => $value ) {
    8585            $type = isset( $setting_type[ $key ] ) ? $setting_type[ $key ] : ( is_array( $value ) ? 'arrstring' : 'string' );
    86             $data[ $key ] = self::sanitize( $value, $type );
     86            $data[ $key ] = self::sanitize( $value, $type, $data );
    8787        }
    8888        return $data;
     
    115115     * @param mixed  $data      data to be sanitized.
    116116     * @param string $data_type data type to apply correct sanitization.
    117      */
    118     public static function sanitize( $data, $data_type ) {
     117     * @param array  $instance  All data array to establish connection.
     118     */
     119    public static function sanitize( $data, $data_type, $instance ) {
    119120        switch ( $data_type ) {
    120121            case 'string':
     
    142143                $data = array_map( 'sanitize_text_field', $data );
    143144                break;
     145            case 'taxonomy':
     146                if ( ! empty( $instance['post_type'] ) && 'page' !== $instance['post_type'] ) {
     147                    $taxonomies = get_object_taxonomies( $instance['post_type'], 'objects' );
     148                    $taxonomies = wp_list_pluck( $taxonomies, 'label', 'name' );
     149                    $data       = array_key_exists( $data, $taxonomies ) ? $data : '';
     150                } else {
     151                    $data = '';
     152                }
     153                break;
     154            case 'terms':
     155                $data = ! is_array( $data ) ? explode( ',', $data ) : $data;
     156                if ( $instance['taxonomy'] && $data ) {
     157                    $terms       = get_terms( array( 'taxonomy' => $instance['taxonomy'] ) );
     158                    $terms       = wp_list_pluck( $terms, 'name', 'slug' );
     159                    $valid_terms = array_keys( $terms );
     160
     161                    $data = array_intersect( $data, $valid_terms );
     162                } else {
     163                    $data = array();
     164                }
     165                break;
    144166            case 'check':
    145167                $data = 'yes' === $data ? 'yes' : '';
     168                break;
    146169            default:
    147170                $data = sanitize_text_field( $data );
     
    163186        switch ( $data_type ) {
    164187            case 'string':
     188            case 'taxonomy':
    165189                $data = esc_html( $data );
    166190                break;
     
    183207                break;
    184208            case 'arrstring':
     209            case 'terms':
    185210                $data = ! is_array( $data ) ? explode( ',', $data ) : $data;
    186211                $data = array_map( 'esc_html', $data );
  • display-post-types/trunk/readme.txt

    r3396264 r3408797  
    55Tested up to: 6.8
    66Requires PHP: 7.2
    7 Stable tag: 3.2.3
     7Stable tag: 3.2.4
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    101101
    102102== Changelog ==
     103= 3.2.4 =
     104* Bug Fix: Taxonomy and terms proper sanitization and escaping.
     105
    103106= 3.2.3 =
    104107* Add: Video for using ACF with custom post types.
     
    117120
    118121= 3.0.6 =
    119 * Big Fix: Language textdomain loaded early.
     122* Bug Fix: Language textdomain loaded early.
    120123* Modify: Compatibility check with WordPress 6.8
    121124
Note: See TracChangeset for help on using the changeset viewer.