Skip to content

Commit

Permalink
Pods 3.2.7 (#7331)
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0ttkclark authored Aug 28, 2024
2 parents f681e77 + 3a45454 commit 3a3b4b0
Show file tree
Hide file tree
Showing 63 changed files with 2,413 additions and 497 deletions.
18 changes: 18 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ Found a bug? Have a great feature idea? Get on GitHub and tell us about it and w

Our GitHub has the full list of all prior releases of Pods: https://github.com/pods-framework/pods/releases

= 3.2.7 - August 28th, 2024 =

* Feature: New Pods Related Item List block that works like a Pods Item List block but uses the Pods Single Item block context where you specify a relationship field name to reference. (@sc0ttkclark)
* Feature: You can now link field value output from Pods Field Value block to any website field or just use `permalink` to link to the current item of the field. Works with single select relationship field as the link reference. (@sc0ttkclark)
* Feature: Add support for having multiple filters/pagination on the same page when using Pods shortcodes/blocks. (@sc0ttkclark)
* Feature: When a relationship field is using Taxonomy syncing, you can not choose to hide the Taxonomy UI from the Block Editor and Classic Editor. (@sc0ttkclark)
* Feature: New support for Query Monitor now shows Pods debug logs in a QM panel. (@sc0ttkclark)
* Tweak: Toggle add file button on single file field depending on whether a file is provided yet. #7315 (@heybran)
* Tweak: Added a `<p>` wrapper for the span-based pagination. (@sc0ttkclark)
* Removed: PHP support for Pod Templates and Pod Pages has been finally turned off by default (`PODS_DISABLE_EVAL` constant set to `false` can be used to re-enable it). It will be completely removed in Pods 3.3 after being deprecated in Pods 2.3. (@sc0ttkclark)
* Fixed: Improve REST authentication method to support other auth forms when registering fields. #7340 #7341 (@JoryHogeveen, @sc0ttkclark)
* Fixed: Fix invalid default value for REST API `write_all` option. #7339 (@JoryHogeveen)
* Fixed: Resolve issue with Taxonomy syncing for relationship fields. #7336 #7334 (@pdclark, @sc0ttkclark)
* Fixed: Add fallback for clipboard.writeText. #7314 (@heybran)
* Fixed: Reset items loop before running the fetch loop in `Pods::template()` and the Templates component. (@sc0ttkclark)
* Fixed: Resolve issues with cached queries in PodsData not having the correct corresponding total found for pagination. (@sc0ttkclark)
* Fixed: More phpstan/phpcs fixes across the codebase. (@sc0ttkclark)

= 3.2.6 - July 22nd, 2024 =

* Fixed: Resolve issue with WordPress 6.5 and earlier compatibility by adding polyfill for `react-jsx-runtime` dependency that WP 6.6 related tooling now requires. (@sc0ttkclark)
Expand Down
68 changes: 44 additions & 24 deletions classes/Pods.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @property null|string $search Whether search is enabled.
* @property null|string $search_var The query variable used for search.
* @property null|string $search_mode The search mode to use.
* @property null|string $params The last find() params.
* @property null|string $filter_var The query variable used for filters.
* @property null|array $params The last find() params.
* @property null|string $sql The last find() SQL query.
*/
class Pods implements Iterator {
Expand Down Expand Up @@ -1349,11 +1350,19 @@ public function field( $name, $single = null, $raw = false ) {

$item_data = array();

// Debug purposes
if ( 1 == pods_v( 'pods_debug_params_all', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) {
pods_debug( __METHOD__ . ':' . __LINE__ );
pods_debug( $sql );
}

if ( ! $related_obj || ! $related_obj->valid() ) {
if ( ! is_object( $this->alt_data ) ) {
$this->alt_data = pods_data();
}

pods_debug_log_data( [ 'field_name' => $params->name, 'sql' => $sql ], 'related-field-params', __METHOD__, __LINE__ );

$item_data = $this->alt_data->select( $sql );
} else {
// Support 'find' output ordering.
Expand All @@ -1364,6 +1373,8 @@ public function field( $name, $single = null, $raw = false ) {
$sql['orderby'] = 'FIELD( `t`.`' . $table['field_id'] . '`, ' . $order_ids . ' )';
}

pods_debug_log_data( [ 'field_name' => $params->name, 'sql' => $sql ], 'related-field-params', __METHOD__, __LINE__ );

$related_obj->find( $sql );

// Support 'find' output.
Expand Down Expand Up @@ -2391,6 +2402,7 @@ public function find( $params = null, $limit = 15, $where = null, $sql = null )
'search_across_picks' => false,
'search_across_files' => false,
// Advanced parameters.
'filter_var' => $this->filter_var,
'filters' => $this->filters,
'sql' => $sql,
// Caching parameters.
Expand Down Expand Up @@ -2428,6 +2440,7 @@ public function find( $params = null, $limit = 15, $where = null, $sql = null )
$this->pagination = (boolean) $params->pagination;
$this->search = (boolean) $params->search;
$this->search_var = $params->search_var;
$this->filter_var = $params->filter_var;
$params->join = (array) $params->join;

if ( empty( $params->search_query ) ) {
Expand Down Expand Up @@ -3367,28 +3380,29 @@ public function pagination( $params = null ) {
$append = '&';
}

$defaults = array(
'type' => 'advanced',
'label' => __( 'Go to page:', 'pods' ),
'show_label' => true,
'first_text' => __( '&laquo; First', 'pods' ),
'prev_text' => __( '&lsaquo; Previous', 'pods' ),
'next_text' => __( 'Next &rsaquo;', 'pods' ),
'last_text' => __( 'Last &raquo;', 'pods' ),
'prev_next' => true,
'first_last' => true,
'limit' => (int) $this->limit,
'offset' => (int) $this->offset,
'page' => max( 1, (int) $this->page ),
'mid_size' => 2,
'end_size' => 1,
'total_found' => $this->total_found(),
'page_var' => $this->page_var,
'base' => "{$url}{$append}%_%",
'format' => "{$this->page_var}=%#%",
'class' => '',
'link_class' => '',
);
$defaults = [
'type' => 'advanced',
'label' => __( 'Go to page:', 'pods' ),
'show_label' => true,
'first_text' => __( '&laquo; First', 'pods' ),
'prev_text' => __( '&lsaquo; Previous', 'pods' ),
'next_text' => __( 'Next &rsaquo;', 'pods' ),
'last_text' => __( 'Last &raquo;', 'pods' ),
'prev_next' => true,
'first_last' => true,
'limit' => (int) $this->limit,
'offset' => (int) $this->offset,
'page' => max( 1, (int) $this->page ),
'mid_size' => 2,
'end_size' => 1,
'total_found' => $this->total_found(),
'page_var' => $this->page_var,
'base' => "{$url}{$append}%_%",
'format' => "{$this->page_var}=%#%",
'class' => '',
'link_class' => '',
'wrap_pagination' => false,
];

if ( is_object( $params ) ) {
$params = get_object_vars( $params );
Expand All @@ -3408,6 +3422,8 @@ public function pagination( $params = null ) {
$pagination = 'advanced';
}

$wrap_pagination = (bool) $params->wrap_pagination;

ob_start();

pods_view( PODS_DIR . 'ui/front/pagination/' . $pagination . '.php', compact( array_keys( get_defined_vars() ) ) );
Expand Down Expand Up @@ -3526,7 +3542,7 @@ public function filters( $params = null ) {
$search = trim( $params['search'] );

if ( '' === $search ) {
$search = pods_v_sanitized( $pod->search_var, 'get', '' );
$search = sanitize_text_field( pods_v( $pod->search_var, 'get', '' ) );
}

ob_start();
Expand Down Expand Up @@ -3708,6 +3724,8 @@ public function template( $template_name, $code = null, $deprecated = false, $ch
if ( ! empty( $code ) ) {
// Only detail templates need $this->id.
if ( empty( $this->id ) ) {
$this->reset();

while ( $this->fetch() ) {
$info['item_id'] = $this->id();

Expand Down Expand Up @@ -4630,6 +4648,7 @@ public function __get( $name ) {
'page_var',
'search',
'search_var',
'filter_var',
'search_mode',
'api',
'row_number',
Expand Down Expand Up @@ -4695,6 +4714,7 @@ public function __set( $name, $value ): void {
'page_var' => 'string',
'search' => 'boolean',
'search_var' => 'string',
'filter_var' => 'string',
'search_mode' => 'string',
'id' => 'int',
);
Expand Down
89 changes: 34 additions & 55 deletions classes/PodsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1749,12 +1749,8 @@ public function save_pod( $params, $sanitized = false, $db = true ) {
$pod = null;
}

if ( $fail_on_load ) {
if ( is_wp_error( $pod ) ) {
return $pod;
} elseif ( empty( $pod ) ) {
return pods_error( __( 'Pod not found', 'pods' ), $this );
}
if ( $fail_on_load && ! $pod instanceof Pod ) {
return pods_error( __( 'Pod not found', 'pods' ), $this );
}
}
}
Expand Down Expand Up @@ -3285,7 +3281,7 @@ public function save_field( $params, $table_operation = true, $sanitized = false
if ( $load_params ) {
$field_obj = $this->load_field( $load_params );

if ( $fail_on_load && ( empty( $field_obj ) || is_wp_error( $field_obj ) ) ) {
if ( $fail_on_load && ! $field_obj instanceof Field ) {
return $field_obj;
}
}
Expand Down Expand Up @@ -4830,11 +4826,12 @@ public function save_pod_item( $params ) {
*
* Use for globally setting field change tracking.
*
* @param bool
* @param bool $track_changed_fields Whether to track changed fields or not.
* @param object $params The parameters passed to save_pod_item.
*
* @since 2.3.19
*/
$track_changed_fields = apply_filters( "pods_api_save_pod_item_track_changed_fields_{$pod_name}", (boolean) $params->track_changed_fields, $params );
$track_changed_fields = (bool) apply_filters( "pods_api_save_pod_item_track_changed_fields_{$pod_name}", (bool) $params->track_changed_fields, $params );

$changed_fields = array();

Expand Down Expand Up @@ -5083,10 +5080,10 @@ public function save_pod_item( $params ) {
*
* @since 3.0
*
* @param bool $is_visible Whether the field is visible from conditional logic.
* @param Field $field The field object.
* @param array $field_values The field values referenced.
* @param object $params The save_pod_item parameters.
* @param bool $is_visible Whether the field is visible from conditional logic.
* @param Field|Value_Field $field The field object.
* @param array $field_values The field values referenced.
* @param object $params The save_pod_item parameters.
*/
$is_visible = (bool) apply_filters(
'pods_api_save_pod_item_conditional_logic_field_is_visible',
Expand Down Expand Up @@ -6192,17 +6189,17 @@ public static function handle_changed_fields( $pod, $id, $mode = 'set' ) {
return [];
}

$changed_pods_cache = pods_static_cache_get( 'changed_pods_cache', __CLASS__ ) ?: [];
$old_fields_cache = pods_static_cache_get( 'old_fields_cache', __CLASS__ ) ?: [];
$changed_fields_cache = pods_static_cache_get( 'changed_fields_cache', __CLASS__ ) ?: [];
$changed_pods_cache = (array) ( pods_static_cache_get( 'changed_pods_cache', __CLASS__ ) ?: [] );
$old_fields_cache = (array) ( pods_static_cache_get( 'old_fields_cache', __CLASS__ ) ?: [] );
$changed_fields_cache = (array) ( pods_static_cache_get( 'changed_fields_cache', __CLASS__ ) ?: [] );

$cache_key = $pod . '|' . $id;

$export_params = array(
'depth' => 1,
);

if ( in_array( $mode, array( 'set', 'reset' ), true ) ) {
if ( in_array( $mode, [ 'set', 'reset' ], true ) ) {
if ( isset( $changed_fields_cache[ $cache_key ] ) ) {
unset( $changed_fields_cache[ $cache_key ] );
}
Expand Down Expand Up @@ -7957,19 +7954,6 @@ public function delete_pod_item( $params, $wp = true ) {
// Plugin hook
$this->do_hook( 'pre_delete_pod_item', $params, $pod );
$this->do_hook( "pre_delete_pod_item_{$params->pod}", $params, $pod );

// Call any pre-save helpers (if not bypassed)
if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
if ( ! empty( $pod ) ) {
$helpers = array( 'pre_delete_helpers', 'post_delete_helpers' );

foreach ( $helpers as $helper ) {
if ( isset( $pod[ $helper ] ) && ! empty( $pod[ $helper ] ) ) {
${$helper} = explode( ',', $pod[ $helper ] );
}
}
}
}
}

// Delete object from relationship fields
Expand Down Expand Up @@ -8349,7 +8333,7 @@ public function get_pod_type_count( $type ) {
*
* @param bool $strict Makes sure the pod exists, throws an error if it doesn't work.
*
* @return Pods\Whatsit\Pod|false Pod object or false if not found.
* @return Pods\Whatsit\Pod|false|WP_Error Pod object or false if not found.
*
* @throws Exception
* @since 1.7.9
Expand Down Expand Up @@ -9785,7 +9769,7 @@ public function lookup_related_items( $field_id, $pod_id, $ids, $field = null, $

$related = get_comments( $comment_args );

if ( ! is_wp_error( $related ) ) {
if ( $related ) {
$related_ids = $related;
}
} elseif (
Expand Down Expand Up @@ -10456,13 +10440,13 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null
/**
* Allow filtering the table information for an object.
*
* @param array $info The table information.
* @param string $object_type The object type.
* @param string $object The object name.
* @param string $name The pod name.
* @param array|Pod $pod The pod config (if found).
* @param array|Field $field The field config (if found).
* @param self $obj The PodsAPI object.
* @param array $info The table information.
* @param string $object_type The object type.
* @param string $object The object name.
* @param string|null $name The pod name.
* @param array|Pod|null $pod The pod config (if found).
* @param array|Field|null $field The field config (if found).
* @param self $obj The PodsAPI object.
*/
return apply_filters( 'pods_api_get_table_info', $info, $object_type, $object, $name, $pod, $field, $this );
} else {
Expand Down Expand Up @@ -10570,13 +10554,14 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null
*
* Use to change "default" post status from publish to any other status or statuses.
*
* @param array $post_status List of post statuses. Default is 'publish' or field setting (if available).
* @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.
* @param array $post_status List of post statuses. Default is 'publish' or field setting (if available).
* @param string $post_type Post type of current object.
* @param array $info Array of information about the object.
* @param string $object_type Type of object.
* @param string $object Object name if provided.
* @param string|null $name Name of pod to load.
* @param array|Pod|null $pod The pod config (if found).
* @param array|Field|null $field The field config (if found).
*
* @since unknown
*/
Expand Down Expand Up @@ -10993,10 +10978,6 @@ public function import( $import_data, $numeric_mode = false, $format = null ) {
*/
global $wpdb;

if ( null === $format && null !== $this->format ) {
$format = $this->format;
}

if ( 'csv' === $format && ! is_array( $import_data ) ) {
$data = pods_migrate( 'sv', ',' )->parse( $import_data );

Expand All @@ -11016,8 +10997,6 @@ public function import( $import_data, $numeric_mode = false, $format = null ) {

if ( ! empty( $this->pod_data ) ) {
$pod = $this->pod_data;
} elseif ( ! empty( $this->pod ) ) {
$pod = $this->load_pod( [ 'name' => $this->pod ], false );
}

if ( false === $pod ) {
Expand Down Expand Up @@ -11183,8 +11162,6 @@ public function export( $pod = null, $params = null ) {
if ( empty( $pod ) ) {
if ( ! empty( $this->pod_data ) ) {
$pod = $this->pod_data;
} elseif ( ! empty( $this->pod ) ) {
$pod = $this->load_pod( [ 'name' => $this->pod ], false );
}
}

Expand Down Expand Up @@ -11341,6 +11318,8 @@ public function cache_flush_pods(
} else {
// Do normal cache clear.
pods_cache_clear( true );

wp_cache_flush();
}

if ( $flush_rewrites ) {
Expand Down Expand Up @@ -11681,7 +11660,7 @@ public function get_pods_object_from_wp_post( $post ) {
$post = get_post( $post );
}

if ( ! $post || is_wp_error( $post ) ) {
if ( ! $post instanceof WP_Post ) {
return false;
}

Expand Down
Loading

0 comments on commit 3a3b4b0

Please sign in to comment.