Plugin Directory

Changeset 3036818


Ignore:
Timestamp:
02/16/2024 11:40:38 AM (22 months ago)
Author:
totalpressorg
Message:

5.0.1

Location:
custom-post-types
Files:
75 added
9 edited

Legend:

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

    r2989869 r3036818  
    88Text Domain: custom-post-types
    99Domain Path: /languages/
    10 Version: 5.0.0
     10Version: 5.0.1
    1111*/
    1212
  • custom-post-types/trunk/includes/class-cpt-field-groups.php

    r2989869 r3036818  
    1919     */
    2020    public function init_hooks() {
    21         add_action( 'init', array( $this, 'init_field_groups' ) );
     21        add_action( 'init', array( $this, 'init_field_groups' ), PHP_INT_MAX );
    2222    }
    2323
     
    147147            }
    148148
    149             $field_group['label'] = esc_html( $field_group['label'] );
    150 
    151149            foreach ( $supports as $content ) {
    152150                $type = ! empty( $content['type'] ) ? $content['type'] : self::SUPPORT_TYPE_CPT;
  • custom-post-types/trunk/includes/class-cpt-fields.php

    r2989869 r3036818  
    5151            return;
    5252        }
     53        if( ! empty( $field_config['extra']['placeholder'] ) ){
     54            $field_config['extra']['placeholder'] = esc_html( $field_config['extra']['placeholder'] );
     55        }
     56        if( ! empty( $field_config['value'] ) && is_string( $field_config['value'] ) ){
     57            $field_config['value'] = esc_html( $field_config['value'] );
     58        }
    5359        ob_start();
    5460        ?>
     
    5763            data-field-type="<?php echo $field_config['type']; ?>">
    5864            <div class="cpt-field-inner">
    59                 <input type="hidden" name="<?php echo $input_name; ?>" value="">
     65                <input type="hidden" name="<?php echo esc_html( $input_name ); ?>" value="">
    6066                <?php
    6167                printf(
    6268                    '<div class="cpt-field-wrap%s"%s><label for="%s">%s</label><div class="input">%s</div>%s</div>',
    63                     ( ! empty( $field_config['wrap']['layout'] ) ? ' ' . $field_config['wrap']['layout'] : '' ) .
     69                    esc_html( ! empty( $field_config['wrap']['layout'] ) ? ' ' . $field_config['wrap']['layout'] : '' ) .
    6470                    ( $field_config['required'] ? ' cpt-field-required' : '' ) .
    65                     ( ! empty( $field_config['wrap']['class'] ) ? ' ' . $field_config['wrap']['class'] : '' ) .
    66                     ( ! empty( $field_config['extra']['prepend'] ) ? ' cpt-field-prepend' : '' ) .
    67                     ( ! empty( $field_config['extra']['append'] ) ? ' cpt-field-append' : '' ),
    68                     ! empty( $field_config['wrap']['id'] ) ? ' id="' . $field_config['wrap']['id'] . '"' : '',
    69                     $input_id,
     71                    esc_html( ! empty( $field_config['wrap']['class'] ) ? ' ' . $field_config['wrap']['class'] : '' ) .
     72                    esc_html( ! empty( $field_config['extra']['prepend'] ) ? ' cpt-field-prepend' : '' ) .
     73                    esc_html( ! empty( $field_config['extra']['append'] ) ? ' cpt-field-append' : '' ),
     74                    ! empty( $field_config['wrap']['id'] ) ? ' id="' . esc_html( $field_config['wrap']['id'] ) . '"' : '',
     75                    esc_html( $input_id ),
    7076                    wp_kses_post( $field_config['label'] ),
    7177                    $field_type::render( $input_name, $input_id, $field_config ),
     
    9197        wp_nonce_field( CPT_NONCE_KEY, 'fields-nonce' );
    9298        ?>
    93         <div class="cpt-fields-section" data-id="<?php echo $fields_group_id; ?>">
     99        <div class="cpt-fields-section" data-id="<?php echo esc_html( $fields_group_id ); ?>">
    94100            <?php
    95101            foreach ( $fields as $field ) {
     
    124130        }
    125131        $meta_values = isset( $_POST['meta-fields'] ) ? $_POST['meta-fields'] : array();
    126 
    127         $field_group_id = $field_group['id'];
    128         $fields         = $field_group['fields'];
     132        $fields      = $field_group['fields'];
    129133
    130134        foreach ( $fields as $field ) {
     
    135139            } elseif ( ! empty( $meta_values[ $meta_key ] ) ) {
    136140                $meta_value     = $meta_values[ $meta_key ];
    137                 $sanitize_value = apply_filters( 'cpt_field_sanitize', $meta_value, $meta_key, $meta_type, $field_group_id, $content_type, $content_id );
     141                $sanitize_value = apply_filters( 'cpt_field_sanitize', $meta_value, $meta_key, $meta_type, $field_group, $content_type, $content_id );
    138142            } else {
    139143                $sanitize_value = '';
  • custom-post-types/trunk/includes/class-cpt-ui.php

    r2989869 r3036818  
    102102     * @return mixed|string
    103103     */
    104     public function sanitize_ui_id_fields( $meta_value, $meta_key, $meta_type, $field_group_id ) {
     104    public function sanitize_ui_id_fields( $meta_value, $meta_key, $meta_type, $field_group ) {
     105        $field_group_id = $field_group['id'];
    105106        if (
    106107            'id' == $meta_key && //phpcs:ignore Universal.Operators.StrictComparisons
  • custom-post-types/trunk/includes/compatibilities/v4.php

    r2989869 r3036818  
    6969add_filter(
    7070    'cpt_field_sanitize',
    71     function ( $meta_value, $meta_key, $meta_type, $field_group_id, $content_type, $content_id ) {
     71    function ( $meta_value, $meta_key, $meta_type, $field_group, $content_type, $content_id ) {
    7272        $meta_value = apply_filters( 'cpt_sanitize_field_' . $meta_key, $meta_value );
    7373        $meta_value = apply_filters( 'cpt_sanitize_' . $content_id, $meta_value );
  • custom-post-types/trunk/includes/fields/class-cpt-field-html.php

    r2989869 r3036818  
    4848     */
    4949    public static function render( $input_name, $input_id, $field_config ) {
    50         return ! empty( $field_config['extra']['content'] ) ? $field_config['extra']['content'] : '';
     50        return ! empty( $field_config['extra']['content'] ) ? wp_kses_post( $field_config['extra']['content'] ) : '';
    5151    }
    5252}
  • custom-post-types/trunk/includes/fields/class-cpt-field-repeater.php

    r2989869 r3036818  
    126126        return ob_get_clean();
    127127    }
     128
     129    /**
     130     * @param $fields
     131     *
     132     * @return array
     133     */
     134    public static function get_repeater_fields_map( $fields ) {
     135        $result = array();
     136
     137        foreach ( $fields as $field ) {
     138            $result[ $field['key'] ] = array( 'type' => $field['type'] );
     139            if ( 'repeater' == $field['type'] ) {
     140                $result[ $field['key'] ]['fields'] = self::get_repeater_fields_map( $field['extra']['fields'] );
     141            }
     142        }
     143
     144        return $result;
     145    }
     146
     147    /**
     148     * @param $meta_value
     149     * @param $meta_key
     150     * @param $meta_type
     151     * @param $field_group
     152     * @param $content_type
     153     * @param $content_id
     154     * @param $fields
     155     *
     156     * @return array|mixed
     157     */
     158    public static function sanitize_recursive( $meta_value, $meta_key, $meta_type, $field_group, $content_type, $content_id, $fields ) {
     159        if ( empty( $meta_value ) ) {
     160            return $meta_value;
     161        }
     162
     163        if ( 'extra' == $meta_key && CPT_UI_PREFIX . '_field' == $field_group['id'] ) {
     164            $fields     = self::get_repeater_fields_map( cpt_fields()->get_field( $meta_type )::get_extra() );
     165            $meta_value = array( $meta_value );
     166        }
     167
     168        foreach ( $meta_value as $i => $meta_group ) {
     169            foreach ( $meta_group as $key => $value ) {
     170                if ( 'extra' == $key && CPT_UI_PREFIX . '_field' == $field_group['id'] ) {
     171                    $meta_value[ $i ][ $key ] = self::sanitize_recursive( $value, $key, $meta_group['type'], $field_group, $content_type, $content_id, $fields );
     172                } elseif ( 'repeater' == $fields[ $key ]['type'] ) {
     173                    $meta_value[ $i ][ $key ] = self::sanitize_recursive( $value, $key, 'repeater', $field_group, $content_type, $content_id, $fields[ $key ]['fields'] );
     174                } else {
     175                    $meta_value[ $i ][ $key ] = apply_filters( 'cpt_field_sanitize', $value, $key, $fields[ $key ]['type'], $field_group, $content_type, $content_id );
     176                }
     177            }
     178        }
     179
     180        return ( 'extra' == $meta_key && CPT_UI_PREFIX . '_field' == $field_group['id'] ) ? $meta_value[0] : $meta_value;
     181    }
    128182}
    129183
     
    137191            'callback' => function ( $params ) {
    138192                $fields_group_id = $params['fields-group-id'];
    139                 $fields = is_array( json_decode( stripslashes( $params['fields'] ), true ) ) ? json_decode( stripslashes( $params['fields'] ), true ) : array();
     193                $fields          = is_array( json_decode( stripslashes( $params['fields'] ), true ) ) ? json_decode( stripslashes( $params['fields'] ), true ) : array();
    140194                if ( empty( $fields ) ) {
    141195                    wp_send_json_error();
    142196                }
    143197                $parent = ! empty( $params['parent'] ) ? $params['parent'] : '';
     198
    144199                return CPT_Field_Repeater::render_group( $fields, $parent, $fields_group_id );
    145200            },
     
    148203            'required' => array( 'field-type', 'fields-group-id' ),
    149204            'callback' => function ( $params ) {
    150                 $field_type = $params['field-type'];
     205                $field_type      = $params['field-type'];
    151206                $fields_group_id = $params['fields-group-id'];
    152                 $parent    = ! empty( $params['parent'] ) ? $params['parent'] : '';
    153                 $fields    = cpt_fields()->get_field( $field_type )::get_extra();
     207                $parent          = ! empty( $params['parent'] ) ? $params['parent'] : '';
     208                $fields          = cpt_fields()->get_field( $field_type )::get_extra();
    154209                ob_start();
    155210                foreach ( $fields as $field ) {
    156                     $field['value']  = '';
    157                     $field['parent'] = $parent . '[extra]';
     211                    $field['value']           = '';
     212                    $field['parent']          = $parent . '[extra]';
    158213                    $field['fields_group_id'] = $fields_group_id;
    159214                    echo cpt_fields()->get_field_template( $field );
    160215                }
     216
    161217                return ob_get_clean();
    162218            },
    163219        );
     220
    164221        return $actions;
    165222    }
    166223);
     224
     225add_filter(
     226    'cpt_field_sanitize',
     227    function ( $meta_value, $meta_key, $meta_type, $field_group, $content_type, $content_id ) {
     228        $field_group_id = $field_group['id'];
     229        if (
     230            'fields' == $meta_key && //phpcs:ignore Universal.Operators.StrictComparisons
     231            CPT_UI_PREFIX . '_field' == $field_group_id && //phpcs:ignore Universal.Operators.StrictComparisons
     232            ! empty( $meta_value )
     233        ) {
     234            foreach ( $meta_value as $i => $meta_args ) {
     235                $meta_value[ $i ]['key']     = sanitize_title( $meta_args['key'] );
     236                $meta_value[ $i ]['wrap_id'] = sanitize_title( $meta_args['wrap_id'] );
     237            }
     238        }
     239
     240        if ( 'repeater' == $meta_type ) {
     241            $fields     = CPT_Field_Repeater::get_repeater_fields_map( $field_group['fields'] )[ $meta_key ]['fields'];
     242            $meta_value = CPT_Field_Repeater::sanitize_recursive( $meta_value, $meta_key, $meta_type, $field_group, $content_type, $content_id, $fields );
     243        }
     244
     245        return $meta_value;
     246    },
     247    10,
     248    6
     249);
  • custom-post-types/trunk/includes/fields/class-cpt-field-text.php

    r2989869 r3036818  
    5757     */
    5858    public static function sanitize( $meta_value ) {
    59         return sanitize_text_field( $meta_value );
     59        return wp_kses_post( $meta_value );
    6060    }
    6161}
  • custom-post-types/trunk/readme.txt

    r3016585 r3036818  
    55Requires at least: 4.0
    66Tested up to: 6.4
    7 Stable tag: 5.0.0
     7Stable tag: 5.0.1
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    188188== Changelog ==
    189189
     190= 5.0.1 - 2024-02-16 =
     191* FIX: Authenticated (Administrator+) Stored Cross-Site Scripting (thanks to Taihei Shimamine);
     192* FIX: add sanitization on repeater fields;
     193* FIX: html field render only allowed HTML tags for post content;
     194* FIX: post types by code on field groups assignment (thanks to @alessiac95)
     195* FEAT: now text field accept allowed HTML tags for post content;
     196
    190197= 5.0.0 - 2023-11-06 =
    191198* FIX: stored XSS vulnerability in admin screens with UI labels (thanks to Taihei Shimamine);
Note: See TracChangeset for help on using the changeset viewer.