Skip to content

Instantly share code, notes, and snippets.

@hotzeplotz
Created April 17, 2014 17:21
Show Gist options
  • Select an option

  • Save hotzeplotz/10999327 to your computer and use it in GitHub Desktop.

Select an option

Save hotzeplotz/10999327 to your computer and use it in GitHub Desktop.
diff between PodsAPI.php (Pods 2.4) and my patched version (from Pods 2.3.12, with commit e7fbf4dcf8b928adbf88604ae7ee1dee63679e37 removed altogether)
--- classes/PodsAPI.php 2014-04-17 17:53:31.474513029 +0100
+++ /tmp/PodsAPI.php 2014-04-17 18:01:09.000000000 +0100
@@ -106,13 +106,12 @@
* @param array $meta (optional) Associative array of meta keys and values
* @param bool $strict (optional) Decides whether the previous saved meta should be deleted or not
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
- * @param array $fields (optional) The array of fields and their options, for further processing with
*
* @return bool|mixed
*
* @since 2.0
*/
- public function save_wp_object ( $object_type, $data, $meta = array(), $strict = false, $sanitized = false, $fields = array() ) {
+ public function save_wp_object ( $object_type, $data, $meta = array(), $strict = false, $sanitized = false ) {
if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
$object_type = 'post';
@@ -122,7 +121,7 @@
}
if ( in_array( $object_type, array( 'post', 'user', 'comment' ) ) )
- return call_user_func( array( $this, 'save_' . $object_type ), $data, $meta, $strict, false, $fields );
+ return call_user_func( array( $this, 'save_' . $object_type ), $data, $meta, $strict, false );
elseif ( 'settings' == $object_type ) {
// Nothing to save
if ( empty( $meta ) )
@@ -168,13 +167,12 @@
* @param array $post_meta (optional) All meta to be saved (set value to null to delete)
* @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
- * @param array $fields (optional) The array of fields and their options, for further processing with
*
* @return mixed|void
*
* @since 2.0
*/
- public function save_post ( $post_data, $post_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
+ public function save_post ( $post_data, $post_meta = null, $strict = false, $sanitized = false ) {
$conflicted = pods_no_conflict_check( 'post' );
if ( !$conflicted )
@@ -208,7 +206,7 @@
return pods_error( $post_error->get_error_message(), $this );
}
- $this->save_post_meta( $post_data[ 'ID' ], $post_meta, $strict, $fields );
+ $this->save_post_meta( $post_data[ 'ID' ], $post_meta, $strict );
if ( !$conflicted )
pods_no_conflict_off( 'post' );
@@ -222,15 +220,12 @@
* @param int $id Post ID
* @param array $post_meta All meta to be saved (set value to null to delete)
* @param bool $strict Whether to delete previously saved meta not in $post_meta
- * @param array $fields (optional) The array of fields and their options, for further processing with
*
* @return int Id of the post with the meta
*
* @since 2.0
*/
- public function save_post_meta ( $id, $post_meta = null, $strict = false, $fields = array() ) {
- $simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
-
+ public function save_post_meta ( $id, $post_meta = null, $strict = false ) {
$conflicted = pods_no_conflict_check( 'post' );
if ( !$conflicted )
@@ -257,28 +252,8 @@
delete_post_meta( $id, $meta_key, $old_meta_value );
}
- else {
- $simple = false;
-
- if ( isset( $fields[ $meta_key ] ) && is_array( $meta_value ) ) {
- $field_data = $fields[ $meta_key ];
-
- $simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
- }
-
- if ( $simple ) {
- delete_post_meta( $id, $meta_key );
-
- update_post_meta( $id, '_pods_' . $meta_key, $meta_value );
-
- foreach ( $meta_value as $value ) {
- add_post_meta( $id, $meta_key, $value );
- }
- }
- else {
- update_post_meta( $id, $meta_key, $meta_value );
- }
- }
+ else
+ update_post_meta( $id, $meta_key, $meta_value );
}
if ( $strict ) {
@@ -301,13 +276,12 @@
* @param array $user_meta (optional) All meta to be saved (set value to null to delete)
* @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
- * @param array $fields (optional) The array of fields and their options, for further processing with
*
* @return int Returns user id on success
*
* @since 2.0
*/
- public function save_user ( $user_data, $user_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
+ public function save_user ( $user_data, $user_meta = null, $strict = false, $sanitized = false ) {
if ( !is_array( $user_data ) || empty( $user_data ) )
return pods_error( __( 'User data is required but is either invalid or empty', 'pods' ), $this );
@@ -348,7 +322,7 @@
return pods_error( $user_error->get_error_message(), $this );
}
- $this->save_user_meta( $user_data[ 'ID' ], $user_meta, $strict, $fields );
+ $this->save_user_meta( $user_data[ 'ID' ], $user_meta, $strict );
if ( !$conflicted )
pods_no_conflict_off( 'user' );
@@ -362,16 +336,13 @@
* @param int $id User ID
* @param array $user_meta (optional) All meta to be saved (set value to null to delete)
* @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
- * @param array $fields (optional) The array of fields and their options, for further processing with
*
* @return int User ID
*
* @since 2.0
*
*/
- public function save_user_meta ( $id, $user_meta = null, $strict = false, $fields = array() ) {
- $simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
-
+ public function save_user_meta ( $id, $user_meta = null, $strict = false ) {
$conflicted = pods_no_conflict_check( 'user' );
if ( !$conflicted )
@@ -393,26 +364,8 @@
delete_user_meta( $id, $meta_key, $old_meta_value );
}
- else {
- $simple = false;
-
- if ( isset( $fields[ $meta_key ] ) && is_array( $meta_value ) ) {
- $field_data = $fields[ $meta_key ];
-
- $simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
- }
-
- if ( $simple ) {
- delete_user_meta( $id, $meta_key );
-
- foreach ( $meta_value as $value ) {
- add_user_meta( $id, $meta_key, $value );
- }
- }
- else {
- update_user_meta( $id, $meta_key, $meta_value );
- }
- }
+ else
+ update_user_meta( $id, $meta_key, $meta_value );
}
if ( $strict ) {
@@ -435,13 +388,12 @@
* @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
* @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
- * @param array $fields (optional) The array of fields and their options, for further processing with
*
* @return int Comment ID
*
* @since 2.0
*/
- public function save_comment ( $comment_data, $comment_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
+ public function save_comment ( $comment_data, $comment_meta = null, $strict = false, $sanitized = false ) {
if ( !is_array( $comment_data ) || empty( $comment_data ) )
return pods_error( __( 'Comment data is required but is either invalid or empty', 'pods' ), $this );
@@ -475,7 +427,7 @@
return pods_error( $comment_error->get_error_message(), $this );
}
- $this->save_comment_meta( $comment_data[ 'comment_ID' ], $comment_meta, $strict, $fields );
+ $this->save_comment_meta( $comment_data[ 'comment_ID' ], $comment_meta, $strict );
if ( !$conflicted )
pods_no_conflict_off( 'comment' );
@@ -489,15 +441,12 @@
* @param int $id Comment ID
* @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
* @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
- * @param array $fields (optional) The array of fields and their options, for further processing with
*
* @return int Comment ID
*
* @since 2.0
*/
- public function save_comment_meta ( $id, $comment_meta = null, $strict = false, $fields = array() ) {
- $simple_tableless_objects = PodsForm::field_method( 'pick', 'simple_objects' );
-
+ public function save_comment_meta ( $id, $comment_meta = null, $strict = false ) {
$conflicted = pods_no_conflict_check( 'comment' );
if ( !$conflicted )
@@ -519,26 +468,8 @@
delete_comment_meta( $id, $meta_key, $old_meta_value );
}
- else {
- $simple = false;
-
- if ( isset( $fields[ $meta_key ] ) && is_array( $meta_value ) ) {
- $field_data = $fields[ $meta_key ];
-
- $simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
- }
-
- if ( $simple ) {
- delete_comment_meta( $id, $meta_key );
-
- foreach ( $meta_value as $value ) {
- add_comment_meta( $id, $meta_key, $value );
- }
- }
- else {
- update_comment_meta( $id, $meta_key, $meta_value );
- }
- }
+ else
+ update_comment_meta( $id, $meta_key, $meta_value );
}
if ( $strict ) {
@@ -562,13 +493,12 @@
* @param string $taxonomy Taxonomy name
* @param array $term_data All term data to be saved (using wp_insert_term / wp_update_term)
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
- * @param array $fields (optional) The array of fields and their options, for further processing with
*
* @return int Term ID
*
* @since 2.0
*/
- public function save_term ( $term_ID, $term, $taxonomy, $term_data, $sanitized = false, $fields = array() ) {
+ public function save_term ( $term_ID, $term, $taxonomy, $term_data, $sanitized = false ) {
$conflicted = pods_no_conflict_check( 'taxonomy' );
if ( !$conflicted )
@@ -1510,23 +1440,14 @@
*/
global $wp_query;
- $reserved_query_vars = array(
- 'post_type',
- 'taxonomy',
- 'output'
- );
-
- if ( is_object( $wp_query ) ) {
- $reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
- }
+ $reserved_query_vars = array_keys( $wp_query->fill_query_vars( array() ) );
if ( isset( $pod[ 'options' ][ 'query_var_string' ] ) ) {
if ( in_array( $pod[ 'options' ][ 'query_var_string' ], $reserved_query_vars ) ) {
$pod[ 'options' ][ 'query_var_string' ] = $pod[ 'options' ][ 'type' ] . '_' . $pod[ 'options' ][ 'query_var_string' ];
}
}
-
- if ( isset( $pod[ 'options' ][ 'query_var' ] ) ) {
+ elseif ( isset( $pod[ 'options' ][ 'query_var' ] ) ) {
if ( in_array( $pod[ 'options' ][ 'query_var' ], $reserved_query_vars ) ) {
$pod[ 'options' ][ 'query_var' ] = $pod[ 'options' ][ 'type' ] . '_' . $pod[ 'options' ][ 'query_var' ];
}
@@ -2197,12 +2118,8 @@
$field[ 'pick_val' ] = $field[ 'options' ][ 'pick_table' ];
$field[ 'pick_object' ] = 'table';
}
- elseif ( false === strpos( $field[ 'pick_object' ], '-' ) && !in_array( $field[ 'pick_object' ], array( 'pod', 'post_type', 'taxonomy' ) ) ) {
- $field[ 'pick_val' ] = '';
- }
- elseif ( 'custom-simple' == $field[ 'pick_object' ] ) {
+ elseif ( false === strpos( $field[ 'pick_object' ], '-' ) && !in_array( $field[ 'pick_object' ], array( 'pod', 'post_type', 'taxonomy' ) ) )
$field[ 'pick_val' ] = '';
- }
$field[ 'options' ][ 'pick_object' ] = $field[ 'pick_object' ];
$field[ 'options' ][ 'pick_val' ] = $field[ 'pick_val' ];
@@ -2370,10 +2287,10 @@
if ( $table_operation && 'table' == $pod[ 'storage' ] && !pods_tableless() ) {
if ( !empty( $old_id ) ) {
- if ( ( $field[ 'type' ] != $old_type || $old_simple != $simple ) && empty( $definition ) )
+ if ( $field[ 'type' ] != $old_type && empty( $definition ) )
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$old_name}`", false );
elseif ( 0 < strlen( $definition ) ) {
- if ( $old_name != $field[ 'name' ] || $old_simple != $simple ) {
+ if ( $old_name != $field[ 'name' ] ) {
$test = false;
if ( 0 < strlen( $old_definition ) )
@@ -2743,7 +2660,6 @@
* $params['id'] int The item ID
* $params['data'] array (optional) Associative array of field names + values
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
- * $params['track_changed_fields'] bool Set to true to enable tracking of saved fields via PodsAPI::get_changed_fields()
*
* @param array|object $params An associative array of parameters
*
@@ -2752,9 +2668,6 @@
* @since 1.7.9
*/
public function save_pod_item ( $params ) {
-
- global $wpdb;
-
$params = (object) pods_str_replace( '@wp_', '{prefix}', $params );
$tableless_field_types = PodsForm::tableless_field_types();
@@ -2821,24 +2734,6 @@
if ( !isset( $params->from ) )
$params->from = 'save';
- if ( !isset( $params->location ) )
- $params->location = null;
-
- if ( !isset( $params->track_changed_fields ) )
- $params->track_changed_fields = false;
-
- /**
- * Override $params['track_changed_fields']
- *
- * Use for globally setting field change tracking.
- *
- * @param bool
- *
- * @since 2.3.19
- */
- $track_changed_fields = apply_filters( 'pods_api_save_pod_item_track_changed_fields_' . $params->pod, (boolean) $params->track_changed_fields, $params );
- $changed_fields = array();
-
if ( !isset( $params->clear_slug_cache ) ) {
$params->clear_slug_cache = true;
}
@@ -2944,19 +2839,21 @@
unset( $params->data );
}
- if ( empty( $params->id ) && !in_array( 'created', $fields_active ) && isset( $fields[ 'created' ] ) && in_array( $fields[ 'created' ][ 'type' ], array( 'date', 'datetime' ) ) ) {
- $fields[ 'created' ][ 'value' ] = current_time( 'mysql' );
- $fields_active[] = 'created';
- }
+ if ( 'pod' == $pod[ 'type' ] ) {
+ if ( empty( $params->id ) && !in_array( 'created', $fields_active ) && isset( $fields[ 'created' ] ) ) {
+ $fields[ 'created' ][ 'value' ] = current_time( 'mysql' );
+ $fields_active[] = 'created';
+ }
- if ( !in_array( 'modified', $fields_active ) && isset( $fields[ 'modified' ] ) && in_array( $fields[ 'modified' ][ 'type' ], array( 'date', 'datetime' ) ) ) {
- $fields[ 'modified' ][ 'value' ] = current_time( 'mysql' );
- $fields_active[] = 'modified';
- }
+ if ( !in_array( 'modified', $fields_active ) && isset( $fields[ 'modified' ] ) ) {
+ $fields[ 'modified' ][ 'value' ] = current_time( 'mysql' );
+ $fields_active[] = 'modified';
+ }
- if ( in_array( $pod[ 'type' ], array( 'pod', 'table' ) ) && empty( $params->id ) && !empty( $pod[ 'pod_field_index' ] ) && in_array( $pod[ 'pod_field_index' ], $fields_active ) && !in_array( $pod[ 'pod_field_slug' ], $fields_active ) && isset( $fields[ $pod[ 'pod_field_slug' ] ] ) ) {
- $fields[ $pod[ 'pod_field_slug' ] ][ 'value' ] = ''; // this will get picked up by slug pre_save method
- $fields_active[] = $pod[ 'pod_field_slug' ];
+ if ( empty( $params->id ) && !empty( $pod[ 'pod_field_index' ] ) && in_array( $pod[ 'pod_field_index' ], $fields_active ) && !in_array( $pod[ 'pod_field_slug' ], $fields_active ) && isset( $fields[ $pod[ 'pod_field_slug' ] ] ) ) {
+ $fields[ $pod[ 'pod_field_slug' ] ][ 'value' ] = ''; // this will get picked up by slug pre_save method
+ $fields_active[] = $pod[ 'pod_field_slug' ];
+ }
}
// Handle hidden fields
@@ -2974,42 +2871,6 @@
}
}
}
-
- // Set default field values for object fields
- if ( !empty( $object_fields ) ) {
- foreach ( $object_fields as $field => $field_data ) {
- if ( in_array( $field, $fields_active ) ) {
- continue;
- }
- elseif ( !isset( $field_data[ 'default' ] ) || strlen( $field_data[ 'default' ] ) < 1 ) {
- continue;
- }
-
- $value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
-
- if ( null !== $value && '' !== $value && false !== $value ) {
- $object_fields[ $field ][ 'value' ] = $value;
- $fields_active[] = $field;
- }
- }
- }
-
- // Set default field values for Pod fields
- foreach ( $fields as $field => $field_data ) {
- if ( in_array( $field, $fields_active ) ) {
- continue;
- }
- elseif ( !isset( $field_data[ 'default' ] ) || strlen( $field_data[ 'default' ] ) < 1 ) {
- continue;
- }
-
- $value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
-
- if ( null !== $value && '' !== $value && false !== $value ) {
- $fields[ $field ][ 'value' ] = $value;
- $fields_active[] = $field;
- }
- }
}
$columns =& $fields; // @deprecated 2.0
@@ -3018,19 +2879,17 @@
$pre_save_helpers = $post_save_helpers = array();
- $pieces = array(
- 'fields',
- 'params',
- 'pod',
- 'fields_active',
- 'object_fields',
- 'custom_fields',
- 'custom_data',
- 'track_changed_fields',
- 'changed_fields'
- );
-
if ( false === $bypass_helpers ) {
+ $pieces = array(
+ 'fields',
+ 'params',
+ 'pod',
+ 'fields_active',
+ 'object_fields',
+ 'custom_fields',
+ 'custom_data'
+ );
+
// Plugin hooks
$hooked = $this->do_hook( 'pre_save_pod_item', compact( $pieces ), $is_new_item, $params->id );
@@ -3089,10 +2948,6 @@
}
}
- if ( $track_changed_fields ) {
- $changed_fields = $this->get_changed_fields( compact( $pieces ) );
- }
-
$table_data = $table_formats = $update_values = $rel_fields = $rel_field_ids = array();
$object_type = $pod[ 'type' ];
@@ -3268,23 +3123,7 @@
if ( $allow_custom_fields && !empty( $custom_data ) )
$object_meta = array_merge( $custom_data, $object_meta );
- $fields_to_send = array_flip( array_keys( $object_meta ) );
-
- foreach ( $fields_to_send as $field => $field_data ) {
- if ( isset( $object_fields[ $field ] ) ) {
- $field_data = $object_fields[ $field ];
- }
- elseif ( isset( $fields[ $field ] ) ) {
- $field_data = $fields[ $field ];
- }
- else {
- unset( $fields_to_send[ $field ] );
- }
-
- $fields_to_send[ $field ] = $field_data;
- }
-
- $params->id = $this->save_wp_object( $object_type, $object_data, $object_meta, false, true, $fields_to_send );
+ $params->id = $this->save_wp_object( $object_type, $object_data, $object_meta, false, true );
if ( !empty( $params->id ) && 'settings' == $object_type )
$params->id = $pod[ 'id' ];
@@ -3344,143 +3183,72 @@
if ( !empty( $rel_fields ) ) {
foreach ( $rel_fields as $type => $data ) {
// Only handle tableless fields
- if ( !in_array( $type, $tableless_field_types ) ) {
+ if ( !in_array( $type, $tableless_field_types ) )
continue;
- }
foreach ( $data as $field => $values ) {
- $pick_val = pods_var( 'pick_val', $fields[ $field ] );
+ $pick_val = pods_var( 'pick_val', $fields[ $field ][ 'options' ] );
- if ( 'table' == pods_var( 'pick_object', $fields[ $field ] ) ) {
+ if ( 'table' == pods_var( 'pick_object', $fields[ $field ][ 'options' ] ) )
$pick_val = pods_var( 'pick_table', $fields[ $field ][ 'options' ], $pick_val, null, true );
- }
if ( '__current__' == $pick_val ) {
- if ( is_object( $pod ) ) {
+ if ( is_object( $pod ) )
$pick_val = $pod->pod;
- }
- elseif ( is_array( $pod ) ) {
+ elseif ( is_array( $pod ) )
$pick_val = $pod[ 'name' ];
- }
- elseif ( 0 < strlen( $pod ) ) {
+ elseif ( 0 < strlen( $pod ) )
$pick_val = $pod;
- }
}
- $fields[ $field ][ 'options' ][ 'table_info' ] = pods_api()->get_table_info( pods_var( 'pick_object', $fields[ $field ] ), $pick_val, null, null, $fields[ $field ][ 'options' ] );
+ $fields[ $field ][ 'options' ][ 'table_info' ] = pods_api()->get_table_info( pods_var( 'pick_object', $fields[ $field ][ 'options' ] ), $pick_val, null, null, $fields[ $field ][ 'options' ] );
- if ( isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && !empty( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ] ) ) {
- $search_data = pods( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ] );
+ $search_data = pods_data();
+ $search_data->table( $fields[ $field ][ 'options' ][ 'table_info' ] );
- $data_mode = 'pods';
+ if ( isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && !empty( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ] ) ) {
+ $search_data->pod = $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ];
+ $search_data->fields = $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'fields' ];
}
- else {
- $search_data = pods_data();
- $search_data->table( $fields[ $field ][ 'options' ][ 'table_info' ] );
-
- $data_mode = 'data';
- }
-
- $find_rel_params = array(
- 'select' => "`t`.`{$search_data->field_id}`",
- 'where' => "`t`.`{$search_data->field_slug}` = %s OR `t`.`{$search_data->field_index}` = %s",
- 'limit' => 1,
- 'pagination' => false,
- 'search' => false
- );
-
- if ( empty( $search_data->field_slug ) && !empty( $search_data->field_index ) ) {
- $find_rel_params[ 'where' ] = "`t`.`{$search_data->field_index}` = %s";
- }
- elseif ( empty( $search_data->field_slug ) && empty( $search_data->field_index ) ) {
- $find_rel_params = false;
- }
$related_limit = (int) pods_var_raw( $type . '_limit', $fields[ $field ][ 'options' ], 0 );
- if ( 'single' == pods_var_raw( $type . '_format_type', $fields[ $field ][ 'options' ] ) ) {
+ if ( 'single' == pods_var_raw( $type . '_format_type', $fields[ $field ][ 'options' ] ) )
$related_limit = 1;
- }
// Enforce integers / unique values for IDs
$value_ids = array();
- $is_file_field = in_array( $type, PodsForm::file_field_types() );
- $is_taggable = ( in_array( $type, PodsForm::tableless_field_types() ) && 1 == pods_v( $type . '_taggable', $fields[ $field ][ 'options' ] ) );
-
- // @todo Handle simple relationships eventually
foreach ( $values as $v ) {
if ( !empty( $v ) ) {
- if ( !is_array( $v ) ) {
- if ( !preg_match( '/[^0-9]/', $v ) ) {
- $v = (int) $v;
- }
- // File handling
- elseif ( $is_file_field ) {
- // Get ID from GUID
- $v = pods_image_id_from_field( $v );
-
- // If file not found, add it
- if ( empty( $v ) ) {
- $v = pods_attachment_import( $v );
- }
- }
- // Reference by slug
- else {
- $v_data = false;
-
- if ( false !== $find_rel_params ) {
- $rel_params = $find_rel_params;
- $rel_params[ 'where' ] = $wpdb->prepare( $rel_params[ 'where' ], array( $v, $v ) );
-
- $search_data->select( $rel_params );
-
- $v_data = $search_data->fetch( $v );
- }
-
- if ( !empty( $v_data ) && isset( $v_data[ $search_data->field_id ] ) ) {
- $v = (int) $v_data[ $search_data->field_id ];
- }
- // Allow tagging for Pods objects
- elseif ( $is_taggable && 'pods' == $data_mode ) {
- $tag_data = array(
- $search_data->field_index => $v
- );
-
- if ( 'post_type' == $search_data->pod_data[ 'type' ] ) {
- $tag_data[ 'post_status' ] = 'publish';
- }
-
- /**
- * Filter for changing tag before adding new item.
- *
- * @param array $tag_data Fields for creating new item.
- * @param int $v Field ID of tag.
- * @param obj $search_data Search object for tag.
- * @param string $field Table info for field.
- * @param array $pieces Field array.
- *
- * @since 2.3.19
- */
- $tag_data = apply_filters( 'pods_api_save_pod_item_taggable_data', $tag_data, $v, $search_data, $field, compact( $pieces ) );
-
- // Save $v to a new item on related object
- $v = $search_data->add( $tag_data );
-
- // @todo Support non-Pods for tagging
- }
- }
- }
- elseif ( $is_file_field && isset( $v[ 'id' ] ) ) {
- $v = (int) $v[ 'id' ];
- }
- else {
- continue;
- }
-
- if ( !empty( $v ) && !in_array( $v, $value_ids ) ) {
- $value_ids[] = $v;
- }
+ if ( !is_array( $v ) ) {
+ if ( !preg_match( '/[^0-9]*/', $v ) )
+ $v = (int) $v;
+ // File handling
+ elseif ( in_array( $type, PodsForm::file_field_types() ) ) {
+ // Get ID from GUID
+ $v = pods_image_id_from_field( $v );
+
+ // If file not found, add it
+ if ( empty( $v ) )
+ $v = pods_attachment_import( $v );
+ }
+ // Reference by slug
+ else {
+ $v_data = $search_data->fetch( $v );
+
+ if ( !empty( $v_data ) && isset( $v_data[ $search_data->field_id ] ) )
+ $v = (int) $v_data[ $search_data->field_id ];
+ }
+ // @todo Handle simple relationships eventually
+ }
+ elseif ( in_array( $type, PodsForm::file_field_types() ) && isset( $v[ 'id' ] ) )
+ $v = (int) $v[ 'id' ];
+ else
+ continue;
+
+ if ( !empty( $v ) && !in_array( $v, $value_ids ) )
+ $value_ids[] = $v;
}
}
@@ -3527,6 +3295,16 @@
pods_no_conflict_off( $pod[ 'type' ] );
if ( false === $bypass_helpers ) {
+ $pieces = array(
+ 'fields',
+ 'params',
+ 'pod',
+ 'fields_active',
+ 'object_fields',
+ 'custom_fields',
+ 'custom_data'
+ );
+
$pieces = compact( $pieces );
// Plugin hooks
@@ -3581,7 +3359,6 @@
// Success! Return the id
return $params->id;
-
}
/**
@@ -3620,34 +3397,6 @@
return $ids;
}
- /**
- * Get the fields that have changed during a save
- *
- * @param array $pieces Pieces array from save_pod_item
- *
- * @return array Array of fields and values that have changed
- */
- public function get_changed_fields( $pieces ) {
-
- $fields = $pieces[ 'fields' ];
- $fields_active = $pieces[ 'fields_active' ];
-
- $fields_changed = array();
-
- if ( 0 < $pieces[ 'params' ]->id ) {
- $pod = pods( $pieces[ 'params' ]->pod, $pieces[ 'params' ]->id );
-
- foreach ( $fields_active as $field ) {
- if ( isset( $fields[ $field ] ) && $pod->raw( $field ) != $fields[ $field ][ 'value' ] ) {
- $fields_changed[ $field ] = $fields[ $field ][ 'value' ];
- }
- }
- }
-
- return $fields_changed;
-
- }
-
/**
* Save relationships
*
@@ -4991,9 +4740,8 @@
/**
* @var $sitepress SitePress
- * @var $wpdb wpdb
*/
- global $sitepress, $icl_adjust_id_url_filter_off, $wpdb;
+ global $sitepress, $icl_adjust_id_url_filter_off;
$current_language = false;
$load_fields = true;
@@ -5013,7 +4761,7 @@
elseif ( is_array( $params ) && isset( $params[ 'fields' ] ) && !$params[ 'fields' ] )
$load_fields = false;
- $transient = 'pods_' . $wpdb->prefix . '_pod';
+ $transient = 'pods_pod';
if ( !empty( $current_language ) )
$transient .= '_' . $current_language;
@@ -5030,7 +4778,7 @@
if ( pods_api_cache() )
$pod = pods_transient_get( $transient . '_' . $params->post_name );
- if ( false !== $pod && ( pods_var_raw( 'table_info', $params, false ) || isset( $pod[ 'table' ] ) ) ) {
+ if ( false !== $pod && isset( $pod[ 'table' ] ) ) {
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
$pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
@@ -5081,7 +4829,7 @@
elseif ( pods_api_cache() )
$pod = pods_transient_get( $transient . '_' . $params->name );
- if ( false !== $pod && ( pods_var_raw( 'table_info', $params, false ) || isset( $pod[ 'table' ] ) ) ) {
+ if ( false !== $pod && ( !pods_var_raw( 'table_info', $params, true ) || isset( $pod[ 'table' ] ) ) ) {
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
$pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
@@ -5117,7 +4865,7 @@
if ( pods_api_cache() )
$pod = pods_transient_get( $transient . '_' . $_pod[ 'post_name' ] );
- if ( false !== $pod && ( pods_var_raw( 'table_info', $params, false ) || isset( $pod[ 'table' ] ) ) ) {
+ if ( false !== $pod && ( !pods_var_raw( 'table_info', $params, true ) || isset( $pod[ 'table' ] ) ) ) {
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
$pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
@@ -5173,7 +4921,7 @@
unset( $pod[ 'options' ][ 'object' ] );
unset( $pod[ 'options' ][ 'alias' ] );
- if ( pods_var_raw( 'table_info', $params, false ) )
+ if ( false !== pods_var_raw( 'table_info', $params, true ) )
$pod = array_merge( $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ), $pod );
if ( isset( $pod[ 'pod' ] ) )
@@ -5198,7 +4946,7 @@
if ( !empty( $fields ) ) {
foreach ( $fields as $field ) {
$field->pod = $pod[ 'name' ];
- $field->table_info = (boolean) pods_var_raw( 'table_info', $params, false );
+ $field->table_info = (boolean) pods_var_raw( 'table_info', $params, true );
if ( $load_fields ) {
$field = $this->load_field( $field );
@@ -5743,7 +5491,7 @@
$field[ 'table_info' ] = array();
- if ( 'pick' == $field[ 'type' ] && $params->table_info )
+ if ( 'pick' == $field[ 'type' ] && true === $params->table_info )
$field[ 'table_info' ] = $this->get_table_info( $field[ 'pick_object' ], $field[ 'pick_val' ], null, null, $field );
return $field;
@@ -6441,7 +6189,7 @@
// Verify required fields
if ( 1 == pods_var( 'required', $options[ 'options' ], 0 ) && 'slug' != $type ) {
- if ( '' == $value || null === $value || array() === $value || 0 === $value || '0' === $value || 0.00 === $value || '0.00' === $value )
+ if ( '' == $value || null === $value || array() === $value )
return pods_error( sprintf( __( '%s is empty', 'pods' ), $label ), $this );
if ( 'multi' == pods_var( 'pick_format_type', $options[ 'options' ] ) && 'autocomplete' != pods_var( 'pick_format_multi', $options[ 'options' ] ) ) {
@@ -6465,7 +6213,7 @@
// @todo move this to after pre-save preparations
// Verify unique fields
- if ( 1 == pods_var( 'unique', $options[ 'options' ], 0 ) && '' !== $value && null !== $value && array() !== $value && 0 !== $value && '0' !== $value && 0.00 !== $value && '0.00' !== $value ) {
+ if ( 1 == pods_var( 'unique', $options[ 'options' ], 0 ) && '' !== $value && null !== $value && array() !== $value && 0 !== $value && '0' !== $value ) {
if ( empty( $pod ) )
return false;
@@ -6889,7 +6637,7 @@
if ( is_array( $field_name ) )
$field_name = pods_var_raw( 'name', $field_name, ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $pod_name, JSON_UNESCAPED_UNICODE ) : json_encode( $field_name ) ), null, true );
- $transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
+ $transient = 'pods_get_table_info_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
$current_language = false;
$current_language_t_id = $current_language_tt_id = 0;
@@ -6908,7 +6656,7 @@
}
if ( !empty( $current_language ) )
- $transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . $current_language . '_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
+ $transient = 'pods_get_table_info_' . $current_language . '_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
$_info = false;
@@ -7061,22 +6809,7 @@
if ( is_object( $post_type_object ) && $post_type_object->hierarchical )
$info[ 'object_hierarchical' ] = true;
- /**
- * Default Post Stati to query for.
- *
- * Use to change "default" post status from publish to any other status or statuses.
- *
- * @param array $post_stati List of post statuses. Default is 'publish'
- * @param string $post_type Post type of current object
- * @param array $info Array of information about the object.
- * @param string $object Type of object
- * @param string $name Name of pod to load
- * @param array $pod Array with Pod information. Result of PodsAPI::load_pod()
- * @param array $field Array with field information
- *
- * @since unknown
- */
- $post_stati = apply_filters( 'pods_api_get_table_info_default_post_status', array( 'publish' ), $post_type, $info, $object_type, $object, $name, $pod, $field );
+ $post_stati = $this->do_hook( 'get_table_info_default_post_status', array( 'publish' ), $post_type, $info, $object_type, $object, $name, $pod, $field );
$info[ 'where' ] = array(
//'post_status' => '`t`.`post_status` IN ( "inherit", "publish" )', // @todo Figure out what statuses Attachments can be
@@ -7708,7 +7441,6 @@
$id = pods_var( '_pods_id', $params );
$uri = pods_var( '_pods_uri', $params );
$form = pods_var( '_pods_form', $params );
- $location = pods_var( '_pods_location', $params );
if ( is_object( $obj ) ) {
$pod = $obj->pod;
@@ -7748,8 +7480,7 @@
'pod' => $pod,
'id' => $id,
'data' => $data,
- 'from' => 'process_form',
- 'location' => $location
+ 'from' => 'process_form'
);
$id = $this->save_pod_item( $params );
@@ -7820,4 +7551,4 @@
else
pods_deprecated( "PodsAPI::{$name}", '2.0' );
}
-}
\ No newline at end of file
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment