Changeset 3036818
- Timestamp:
- 02/16/2024 11:40:38 AM (22 months ago)
- Location:
- custom-post-types
- Files:
-
- 75 added
- 9 edited
-
tags/5.0.1 (added)
-
tags/5.0.1/assets (added)
-
tags/5.0.1/assets/css (added)
-
tags/5.0.1/assets/css/backend.css (added)
-
tags/5.0.1/assets/dashboard-icon.svg (added)
-
tags/5.0.1/assets/icon-256x256.png (added)
-
tags/5.0.1/assets/icon.svg (added)
-
tags/5.0.1/assets/js (added)
-
tags/5.0.1/assets/js/backend.js (added)
-
tags/5.0.1/custom-post-types.php (added)
-
tags/5.0.1/includes (added)
-
tags/5.0.1/includes/abstracts (added)
-
tags/5.0.1/includes/abstracts/class-cpt-component.php (added)
-
tags/5.0.1/includes/abstracts/class-cpt-field.php (added)
-
tags/5.0.1/includes/args (added)
-
tags/5.0.1/includes/args/core-admin-pages-pro.php (added)
-
tags/5.0.1/includes/args/core-admin-pages.php (added)
-
tags/5.0.1/includes/args/core-post-types.php (added)
-
tags/5.0.1/includes/args/fields-field-group.php (added)
-
tags/5.0.1/includes/args/fields-post-type.php (added)
-
tags/5.0.1/includes/args/fields-repeater.php (added)
-
tags/5.0.1/includes/args/fields-taxonomy.php (added)
-
tags/5.0.1/includes/args/post-types-default-args.php (added)
-
tags/5.0.1/includes/args/post-types-default-labels.php (added)
-
tags/5.0.1/includes/args/taxonomies-default-args.php (added)
-
tags/5.0.1/includes/args/taxonomies-default-labels.php (added)
-
tags/5.0.1/includes/class-cpt-admin-notices.php (added)
-
tags/5.0.1/includes/class-cpt-admin-pages.php (added)
-
tags/5.0.1/includes/class-cpt-ajax.php (added)
-
tags/5.0.1/includes/class-cpt-core.php (added)
-
tags/5.0.1/includes/class-cpt-field-groups.php (added)
-
tags/5.0.1/includes/class-cpt-fields.php (added)
-
tags/5.0.1/includes/class-cpt-plugin.php (added)
-
tags/5.0.1/includes/class-cpt-post-types.php (added)
-
tags/5.0.1/includes/class-cpt-shortcodes.php (added)
-
tags/5.0.1/includes/class-cpt-taxonomies.php (added)
-
tags/5.0.1/includes/class-cpt-ui.php (added)
-
tags/5.0.1/includes/class-cpt-utils.php (added)
-
tags/5.0.1/includes/compatibilities (added)
-
tags/5.0.1/includes/compatibilities/saswp.php (added)
-
tags/5.0.1/includes/compatibilities/v4.php (added)
-
tags/5.0.1/includes/fields (added)
-
tags/5.0.1/includes/fields/class-cpt-field-checkbox.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-color.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-date.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-email.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-embed.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-file.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-html.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-link.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-map.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-number.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-password.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-post-rel.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-radio.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-range.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-repeater.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-select.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-separator.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-switch.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-tax-rel.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-tel.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-text.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-textarea.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-time.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-tinymce.php (added)
-
tags/5.0.1/includes/fields/class-cpt-field-user-rel.php (added)
-
tags/5.0.1/includes/functions.php (added)
-
tags/5.0.1/includes/templates (added)
-
tags/5.0.1/includes/templates/modal-feedback.php (added)
-
tags/5.0.1/includes/templates/page-tools.php (added)
-
tags/5.0.1/index.php (added)
-
tags/5.0.1/languages (added)
-
tags/5.0.1/languages/custom-post-types.pot (added)
-
tags/5.0.1/readme.txt (added)
-
trunk/custom-post-types.php (modified) (1 diff)
-
trunk/includes/class-cpt-field-groups.php (modified) (2 diffs)
-
trunk/includes/class-cpt-fields.php (modified) (5 diffs)
-
trunk/includes/class-cpt-ui.php (modified) (1 diff)
-
trunk/includes/compatibilities/v4.php (modified) (1 diff)
-
trunk/includes/fields/class-cpt-field-html.php (modified) (1 diff)
-
trunk/includes/fields/class-cpt-field-repeater.php (modified) (3 diffs)
-
trunk/includes/fields/class-cpt-field-text.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
custom-post-types/trunk/custom-post-types.php
r2989869 r3036818 8 8 Text Domain: custom-post-types 9 9 Domain Path: /languages/ 10 Version: 5.0. 010 Version: 5.0.1 11 11 */ 12 12 -
custom-post-types/trunk/includes/class-cpt-field-groups.php
r2989869 r3036818 19 19 */ 20 20 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 ); 22 22 } 23 23 … … 147 147 } 148 148 149 $field_group['label'] = esc_html( $field_group['label'] );150 151 149 foreach ( $supports as $content ) { 152 150 $type = ! empty( $content['type'] ) ? $content['type'] : self::SUPPORT_TYPE_CPT; -
custom-post-types/trunk/includes/class-cpt-fields.php
r2989869 r3036818 51 51 return; 52 52 } 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 } 53 59 ob_start(); 54 60 ?> … … 57 63 data-field-type="<?php echo $field_config['type']; ?>"> 58 64 <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=""> 60 66 <?php 61 67 printf( 62 68 '<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'] : '' ) . 64 70 ( $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 ), 70 76 wp_kses_post( $field_config['label'] ), 71 77 $field_type::render( $input_name, $input_id, $field_config ), … … 91 97 wp_nonce_field( CPT_NONCE_KEY, 'fields-nonce' ); 92 98 ?> 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 ); ?>"> 94 100 <?php 95 101 foreach ( $fields as $field ) { … … 124 130 } 125 131 $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']; 129 133 130 134 foreach ( $fields as $field ) { … … 135 139 } elseif ( ! empty( $meta_values[ $meta_key ] ) ) { 136 140 $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 ); 138 142 } else { 139 143 $sanitize_value = ''; -
custom-post-types/trunk/includes/class-cpt-ui.php
r2989869 r3036818 102 102 * @return mixed|string 103 103 */ 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']; 105 106 if ( 106 107 'id' == $meta_key && //phpcs:ignore Universal.Operators.StrictComparisons -
custom-post-types/trunk/includes/compatibilities/v4.php
r2989869 r3036818 69 69 add_filter( 70 70 '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 ) { 72 72 $meta_value = apply_filters( 'cpt_sanitize_field_' . $meta_key, $meta_value ); 73 73 $meta_value = apply_filters( 'cpt_sanitize_' . $content_id, $meta_value ); -
custom-post-types/trunk/includes/fields/class-cpt-field-html.php
r2989869 r3036818 48 48 */ 49 49 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'] ) : ''; 51 51 } 52 52 } -
custom-post-types/trunk/includes/fields/class-cpt-field-repeater.php
r2989869 r3036818 126 126 return ob_get_clean(); 127 127 } 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 } 128 182 } 129 183 … … 137 191 'callback' => function ( $params ) { 138 192 $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(); 140 194 if ( empty( $fields ) ) { 141 195 wp_send_json_error(); 142 196 } 143 197 $parent = ! empty( $params['parent'] ) ? $params['parent'] : ''; 198 144 199 return CPT_Field_Repeater::render_group( $fields, $parent, $fields_group_id ); 145 200 }, … … 148 203 'required' => array( 'field-type', 'fields-group-id' ), 149 204 'callback' => function ( $params ) { 150 $field_type = $params['field-type'];205 $field_type = $params['field-type']; 151 206 $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(); 154 209 ob_start(); 155 210 foreach ( $fields as $field ) { 156 $field['value'] = '';157 $field['parent'] = $parent . '[extra]';211 $field['value'] = ''; 212 $field['parent'] = $parent . '[extra]'; 158 213 $field['fields_group_id'] = $fields_group_id; 159 214 echo cpt_fields()->get_field_template( $field ); 160 215 } 216 161 217 return ob_get_clean(); 162 218 }, 163 219 ); 220 164 221 return $actions; 165 222 } 166 223 ); 224 225 add_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 57 57 */ 58 58 public static function sanitize( $meta_value ) { 59 return sanitize_text_field( $meta_value );59 return wp_kses_post( $meta_value ); 60 60 } 61 61 } -
custom-post-types/trunk/readme.txt
r3016585 r3036818 5 5 Requires at least: 4.0 6 6 Tested up to: 6.4 7 Stable tag: 5.0. 07 Stable tag: 5.0.1 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 188 188 == Changelog == 189 189 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 190 197 = 5.0.0 - 2023-11-06 = 191 198 * FIX: stored XSS vulnerability in admin screens with UI labels (thanks to Taihei Shimamine);
Note: See TracChangeset
for help on using the changeset viewer.