PluginProbe
Pods – Custom Content Types and Fields / 3.3.9
Pods – Custom Content Types and Fields v3.3.9
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 All 42 releases
← All changes | classes/PodsAPI.php +46 -274 trunk3.3.9 View file →
@@ -4977,12 +4977,12 @@
4977 4977 $fields_active = [];
4978 4978 $custom_data = [];
4979 4979 $custom_fields = [];
4980 4980
4981 - $is_process_form = ! empty( $params->from ) && in_array( $params->from, [
4982 - 'process_form',
4983 - 'process_form_meta',
4984 - ], true );
4981 + $is_process_form = in_array( $params->from, [
4982 + 'process_form',
4983 + 'process_form_meta',
4984 + ], true );
4985 4985
4986 4986 // Find the active fields (loop through $params->data to retain order)
4987 4987 if ( ! empty( $params->data ) && is_array( $params->data ) ) {
4988 4988 foreach ( $params->data as $field => $value ) {
@@ -9650,19 +9650,12 @@
9650 9650 } elseif ( ! is_array( $pod ) && ! $pod instanceof Pod ) {
9651 9651 $pod = null;
9652 9652 }
9653 9653
9654 - $pod_name = pods_v( 'name', $pod );
9655 - $pod_type = pods_v( 'type', $pod );
9656 9654 $type = $options['type'];
9657 9655 $label = $options['label'];
9658 9656 $label = empty( $label ) ? $field : $label;
9659 9657
9660 - $is_process_form = $params && ! empty( $params->from ) && in_array( $params->from, [
9661 - 'process_form',
9662 - 'process_form_meta',
9663 - ], true );
9664 -
9665 9658 /**
9666 9659 * Allow filtering whether to check the required fields for values.
9667 9660 *
9668 9661 * @since 2.8.9
@@ -9707,16 +9700,11 @@
9707 9700 }
9708 9701
9709 9702 if ( ! in_array( $type, $tableless_field_types, true ) ) {
9710 9703 $exclude = '';
9711 - $prepare = [
9712 - $field,
9713 - $check_value,
9714 - ];
9715 9704
9716 9705 if ( ! empty( $id ) ) {
9717 - $exclude = 'AND `id` != %d';
9718 - $prepare[] = $id;
9706 + $exclude = "AND `id` != {$id}";
9719 9707 }
9720 9708
9721 9709 $check = false;
9722 9710
@@ -9724,19 +9712,9 @@
9724 9712
9725 9713 // @todo handle meta-based fields
9726 9714 // Trigger an error if not unique
9727 9715 if ( 'table' === $pod['storage'] ) {
9728 - $check = pods_query(
9729 - [
9730 - '
9731 - SELECT `id` FROM `@wp_pods_' . sanitize_key( $pod['name'] ) . '`
9732 - WHERE %i = %s ' . $exclude . '
9733 - LIMIT 1
9734 - ',
9735 - $prepare,
9736 - ],
9737 - $this
9738 - );
9716 + $check = pods_query( "SELECT `id` FROM `@wp_pods_" . $pod['name'] . "` WHERE `{$field}` = '{$check_value}' {$exclude} LIMIT 1", $this );
9739 9717 }
9740 9718
9741 9719 if ( ! empty( $check ) ) {
9742 9720 // translators: %s is the field label.
@@ -9752,90 +9730,8 @@
9752 9730 // translators: %s is the field label.
9753 9731 return pods_error( sprintf( __( '%s is an unexpected value', 'pods' ), $label ), $this );
9754 9732 }
9755 9733
9756 - $submitted_fields = ! empty( $params->submitted_fields ) ? (array) $params->submitted_fields : [];
9757 -
9758 - if ( $is_process_form && in_array( $field, $submitted_fields, true ) ) {
9759 - // Check whether certain user fields can be edited during form processing.
9760 - if (
9761 - 0 < $id
9762 - && in_array( 'user', [
9763 - $pod_name,
9764 - $pod_type,
9765 - ], true )
9766 - ) {
9767 - $can_edit_user_field = true;
9768 -
9769 - if (
9770 - in_array( $field, [
9771 - 'user_login',
9772 - 'user_email',
9773 - 'user_pass',
9774 - ], true )
9775 - && (
9776 - ! is_user_logged_in()
9777 - || ! current_user_can( 'edit_user', $id )
9778 - )
9779 - ) {
9780 - $can_edit_user_field = false;
9781 - } elseif (
9782 - in_array( $field, [
9783 - 'user_activation_key',
9784 - 'spam',
9785 - 'deleted',
9786 - 'caps',
9787 - 'cap_key',
9788 - 'roles',
9789 - 'role',
9790 - 'allcaps',
9791 - ], true )
9792 - && (
9793 - ! is_user_logged_in()
9794 - || ! current_user_can( 'edit_users' )
9795 - )
9796 - ) {
9797 - $can_edit_user_field = false;
9798 - }
9799 -
9800 - if ( ! $can_edit_user_field ) {
9801 - // translators: %s is the field label.
9802 - return pods_error( sprintf( __( '%s cannot be changed, you do not have access to this user', 'pods' ), $label ), $this );
9803 - }
9804 - } elseif ( 'post_type' === $pod_type ) {
9805 - // Check whether certain post fields can be edited during form processing.
9806 - $can_edit_post_field = true;
9807 -
9808 - if ( 'post_type' === $field ) {
9809 - $can_edit_post_field = false;
9810 - } elseif (
9811 - 0 < $id
9812 - && 'post_password' === $field
9813 - && (
9814 - ! is_user_logged_in()
9815 - || ! current_user_can( 'edit_post', $id )
9816 - )
9817 - ) {
9818 - $can_edit_post_field = false;
9819 - } elseif ( 'post_status' === $field ) {
9820 - if ( ! is_user_logged_in() ) {
9821 - $can_edit_post_field = false;
9822 - } elseif ( 0 < $id ) {
9823 - $can_edit_post_field = current_user_can( 'publish_post', $id );
9824 - } else {
9825 - $can_edit_post_field = current_user_can( 'publish_posts', $id );
9826 - }
9827 -
9828 - $can_edit_post_field = (bool) $this->do_hook( 'field_validation_allow_post_status', $can_edit_post_field, $value, $field, $object_fields, $fields, $pod, $params );
9829 - }
9830 -
9831 - if ( ! $can_edit_post_field ) {
9832 - // translators: %s is the field label.
9833 - return pods_error( sprintf( __( '%s cannot be changed, you do not have access to this post', 'pods' ), $label ), $this );
9834 - }
9835 - }
9836 - }
9837 -
9838 9734 $validate = PodsForm::validate( $options['type'], $value, $field, $options, $fields, $pod, $id, $params );
9839 9735
9840 9736 $validate = $this->do_hook( 'field_validation', $validate, $value, $field, $object_fields, $fields, $pod, $params );
9841 9737
@@ -11270,37 +11166,16 @@
11270 11166 if ( in_array( $type, PodsForm::file_field_types(), true ) || in_array( $pick_object, [
11271 11167 'media',
11272 11168 'attachment',
11273 11169 ], true ) ) {
11274 - $sql_where_field = 'guid';
11275 - $sql_where_value = $pick_value;
11170 + $where = "`guid` = '" . pods_sanitize( $pick_value ) . "'";
11276 11171
11277 11172 if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
11278 - $sql_where_field = 'ID';
11279 - $sql_where_value = pods_absint( $pick_value );
11173 + $where = "`ID` = " . pods_absint( $pick_value );
11280 11174 }
11281 11175
11282 - $sql = [
11283 - '
11284 - SELECT `ID` AS `id`
11285 - FROM %i
11286 - WHERE `post_type` = %s AND %i = %s
11287 - ORDER BY `ID`
11288 - LIMIT 1
11289 - ',
11290 - [
11291 - $wpdb->posts,
11292 - 'attachment',
11293 - $sql_where_field,
11294 - $sql_where_value,
11295 - ],
11296 - ];
11176 + $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = 'attachment' AND {$where} ORDER BY `ID`", $this );
11297 11177
11298 - $result = pods_query(
11299 - $sql,
11300 - $this
11301 - );
11302 -
11303 11178 if ( ! empty( $result ) ) {
11304 11179 $pick_values[] = $result[0]->id;
11305 11180 }
11306 11181 } elseif ( 'pick' === $type ) {
@@ -11320,42 +11195,16 @@
11320 11195 ];
11321 11196 }
11322 11197
11323 11198 if ( in_array( 'taxonomy', [ $pick_object, $related_pod['type'] ] ) ) {
11324 - $sql_where_alias = 't';
11325 - $sql_where_field = 'name';
11326 - $sql_where_value = $pick_value;
11199 + $where = "`t`.`name` = '" . pods_sanitize( $pick_value ) . "'";
11327 11200
11328 11201 if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
11329 - $sql_where_alias = 'tt';
11330 - $sql_where_field = 'term_id';
11331 - $sql_where_value = pods_absint( $pick_value );
11202 + $where = "`tt`.`term_id` = " . pods_absint( $pick_value );
11332 11203 }
11333 11204
11334 - $sql = [
11335 - '
11336 - SELECT `t`.`term_id` AS `id`
11337 - FROM %i AS `tt`
11338 - LEFT JOIN %i AS `t` ON `t`.`term_id` = `tt`.`term_id`
11339 - WHERE `tt`.`taxonomy` = %s AND %i.%i = %s
11340 - ORDER BY `t`.`term_id`
11341 - LIMIT 1
11342 - ',
11343 - [
11344 - $wpdb->term_taxonomy,
11345 - $wpdb->terms,
11346 - $pick_val,
11347 - $sql_where_alias,
11348 - $sql_where_field,
11349 - $sql_where_value,
11350 - ],
11351 - ];
11205 + $result = pods_query( "SELECT `t`.`term_id` AS `id` FROM `{$wpdb->term_taxonomy}` AS `tt` LEFT JOIN `{$wpdb->terms}` AS `t` ON `t`.`term_id` = `tt`.`term_id` WHERE `taxonomy` = '{$pick_val}' AND {$where} ORDER BY `t`.`term_id` LIMIT 1", $this );
11352 11206
11353 - $result = pods_query(
11354 - $sql,
11355 - $this
11356 - );
11357 -
11358 11207 if ( ! empty( $result ) ) {
11359 11208 $pick_values[] = $result[0]->id;
11360 11209 }
11361 11210 } elseif ( in_array( 'post_type', [
@@ -11361,91 +11210,35 @@
11361 11210 } elseif ( in_array( 'post_type', [
11362 11211 $pick_object,
11363 11212 $related_pod['type'],
11364 11213 ] ) || in_array( 'media', [ $pick_object, $related_pod['type'] ] ) ) {
11365 - $sql_where_field = 'post_title';
11366 - $sql_where_value = $pick_value;
11214 + $where = "`post_title` = '" . pods_sanitize( $pick_value ) . "'";
11367 11215
11368 11216 if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
11369 - $sql_where_field = 'ID';
11370 - $sql_where_value = pods_absint( $pick_value );
11217 + $where = "`ID` = " . pods_absint( $pick_value );
11371 11218 }
11372 11219
11373 - $sql = [
11374 - '
11375 - SELECT `ID` AS `id`
11376 - FROM %i
11377 - WHERE `post_type` = %s AND %i = %s
11378 - ORDER BY `ID`
11379 - LIMIT 1
11380 - ',
11381 - [
11382 - $wpdb->posts,
11383 - $pick_val,
11384 - $sql_where_field,
11385 - $sql_where_value,
11386 - ],
11387 - ];
11220 + $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID` LIMIT 1", $this );
11388 11221
11389 - $result = pods_query(
11390 - $sql,
11391 - $this
11392 - );
11393 -
11394 11222 if ( ! empty( $result ) ) {
11395 11223 $pick_values[] = $result[0]->id;
11396 11224 }
11397 11225 } elseif ( in_array( 'user', [ $pick_object, $related_pod['type'] ] ) ) {
11398 - $sql_where_field = 'user_login';
11399 - $sql_where_value = $pick_value;
11226 + $where = "`user_login` = '" . pods_sanitize( $pick_value ) . "'";
11400 11227
11401 11228 if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
11402 - $sql_where_field = 'ID';
11403 - $sql_where_value = pods_absint( $pick_value );
11229 + $where = "`ID` = " . pods_absint( $pick_value );
11404 11230 }
11405 11231
11406 - $sql = [
11407 - '
11408 - SELECT `ID` AS `id`
11409 - FROM %i
11410 - WHERE %i = %s
11411 - ORDER BY `ID`
11412 - LIMIT 1
11413 - ',
11414 - [
11415 - $wpdb->users,
11416 - $sql_where_field,
11417 - $sql_where_value,
11418 - ],
11419 - ];
11232 + $result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID` LIMIT 1", $this );
11420 11233
11421 - $result = pods_query(
11422 - $sql,
11423 - $this
11424 - );
11425 -
11426 11234 if ( ! empty( $result ) ) {
11427 11235 $pick_values[] = $result[0]->id;
11428 11236 }
11429 11237 } elseif ( in_array( 'comment', [ $pick_object, $related_pod['type'] ] ) ) {
11430 - $sql = [
11431 - '
11432 - SELECT `comment_ID` AS `id`
11433 - FROM %i
11434 - WHERE `comment_ID` = %d
11435 - ORDER BY `comment_ID`
11436 - LIMIT 1
11437 - ',
11438 - [
11439 - $wpdb->comments,
11440 - $pick_value,
11441 - ],
11442 - ];
11238 + $where = "`comment_ID` = " . pods_absint( $pick_value );
11443 11239
11444 - $result = pods_query(
11445 - $sql,
11446 - $this
11447 - );
11240 + $result = pods_query( "SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID` LIMIT 1", $this );
11448 11241
11449 11242 if ( ! empty( $result ) ) {
11450 11243 $pick_values[] = $result[0]->id;
11451 11244 }
@@ -11451,38 +11244,16 @@
11451 11244 }
11452 11245 } elseif ( in_array( $pick_object, $simple_tableless_objects, true ) ) {
11453 11246 $pick_values[] = $pick_value;
11454 11247 } elseif ( ! empty( $related_pod['id'] ) ) {
11455 - $sql_where_field = $related_pod['field_index'];
11456 - $sql_where_value = $pick_value;
11248 + $where = "`" . $related_pod['field_index'] . "` = '" . pods_sanitize( $pick_value ) . "'";
11457 11249
11458 11250 if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
11459 - $sql_where_field = $related_pod['field_id'];
11460 - $sql_where_value = pods_absint( $pick_value );
11251 + $where = "`" . $related_pod['field_id'] . "` = " . pods_absint( $pick_value );
11461 11252 }
11462 11253
11463 - $sql = [
11464 - '
11465 - SELECT %i AS `id`
11466 - FROM %i
11467 - WHERE %i = %s
11468 - ORDER BY %i
11469 - LIMIT 1
11470 - ',
11471 - [
11472 - $related_pod['field_id'],
11473 - $related_pod['table'],
11474 - $sql_where_field,
11475 - $sql_where_value,
11476 - $related_pod['field_id'],
11477 - ],
11478 - ];
11254 + $result = pods_query( "SELECT `" . $related_pod['field_id'] . "` AS `id` FROM `" . $related_pod['table'] . "` WHERE {$where} ORDER BY `" . $related_pod['field_id'] . "` LIMIT 1", $this );
11479 11255
11480 - $result = pods_query(
11481 - $sql,
11482 - $this
11483 - );
11484 -
11485 11256 if ( ! empty( $result ) ) {
11486 11257 $pick_values[] = $result[0]->id;
11487 11258 }
11488 11259 }
@@ -11776,15 +11547,13 @@
11776 11547 $old_display_errors = $this->display_errors;
11777 11548
11778 11549 $this->display_errors = false;
11779 11550
11780 - $nonce_field_names = pods_access_form_field_names( 'form' );
11781 -
11782 - $nonce = pods_v_sanitized( $nonce_field_names['nonce'], $form_params );
11783 - $pod = pods_v_sanitized( $nonce_field_names['pod'], $form_params );
11784 - $id = pods_v_sanitized( $nonce_field_names['id'], $form_params );
11785 - $uri = pods_v_sanitized( $nonce_field_names['uri'], $form_params );
11786 - $form = pods_v_sanitized( $nonce_field_names['form'], $form_params );
11551 + $nonce = pods_v_sanitized( '_pods_nonce', $form_params );
11552 + $pod = pods_v_sanitized( '_pods_pod', $form_params );
11553 + $id = pods_v_sanitized( '_pods_id', $form_params );
11554 + $uri = pods_v_sanitized( '_pods_uri', $form_params );
11555 + $form = pods_v_sanitized( '_pods_form', $form_params );
11787 11556 $form_key = pods_v_sanitized( '_pods_form_key', $form_params );
11788 11557 $location = pods_v_sanitized( '_pods_location', $form_params );
11789 11558
11790 11559 $obj = null;
@@ -11813,23 +11582,27 @@
11813 11582 } else {
11814 11583 $fields = [];
11815 11584 }
11816 11585
11817 - if (
11818 - ! pods_access_form_nonce_present_in_request( 'form', '', $form_params )
11819 - || empty( $nonce )
11820 - || empty( $pod )
11821 - || empty( $uri )
11822 - || empty( $fields )
11823 - ) {
11586 + if ( empty( $nonce ) || empty( $pod ) || empty( $uri ) || empty( $fields ) ) {
11824 11587 return pods_error( __( 'Invalid submission', 'pods' ), $this );
11825 11588 }
11826 11589
11827 - if ( empty( pods_access_form_uid() ) ) {
11590 + $uid = pods_session_id();
11591 +
11592 + if ( is_user_logged_in() ) {
11593 + $uid = 'user_' . get_current_user_id();
11594 + }
11595 +
11596 + $field_hash = wp_create_nonce( 'pods_fields_' . $form );
11597 +
11598 + $action = 'pods_form_' . $pod . '_' . $uid . '_' . $id . '_' . $uri . '_' . $field_hash;
11599 +
11600 + if ( empty( $uid ) ) {
11828 11601 return pods_error( __( 'Access denied for your session, please refresh and try again.', 'pods' ), $this );
11829 11602 }
11830 11603
11831 - if ( ! pods_access_verify_form_nonce( $nonce, $pod, $id, $form, $uri ) ) {
11604 + if ( false === wp_verify_nonce( $nonce, $action ) ) {
11832 11605 return pods_error( __( 'Access denied, please refresh and try again.', 'pods' ), $this );
11833 11606 }
11834 11607
11835 11608 $data = [];
@@ -11880,14 +11653,13 @@
11880 11653 $data['post_content'] = trim( $data['post_content'] );
11881 11654 }
11882 11655
11883 11656 $params = [
11884 - 'pod' => $pod,
11885 - 'id' => $id,
11886 - 'data' => $data,
11887 - 'from' => 'process_form',
11888 - 'location' => $location,
11889 - 'submitted_fields' => array_keys( $data ),
11657 + 'pod' => $pod,
11658 + 'id' => $id,
11659 + 'data' => $data,
11660 + 'from' => 'process_form',
11661 + 'location' => $location,
11890 11662 ];
11891 11663
11892 11664 $id = $this->save_pod_item( $params );
11893 11665