diff --git a/lib/admin/dependencies.php b/lib/admin/dependencies.php index 5733a8426..7191536b0 100644 --- a/lib/admin/dependencies.php +++ b/lib/admin/dependencies.php @@ -240,7 +240,7 @@ function mai_change_plugin_dependency_text( $actions ) { * Disables ACF updates settings page. * * @since 2.32.0 - * @since TBD Disabled so uses can update their own licenses. + * @since 2.35.0 Disabled so users can update their own licenses. * * @param bool $value The current value. * diff --git a/lib/customize/output.php b/lib/customize/output.php index f6bd034d3..c93828ad0 100644 --- a/lib/customize/output.php +++ b/lib/customize/output.php @@ -605,7 +605,7 @@ function mai_add_classic_editor_styles() { * @link http://wordpress.stackexchange.com/a/226623/2807 * * @since 2.25.0 - * @since TBD Added transient for CSS. + * @since 2.35.0 Added transient for CSS. * * @return void */ diff --git a/lib/fields/grid-display.php b/lib/fields/grid-display.php index 117cf10ad..57d52347b 100644 --- a/lib/fields/grid-display.php +++ b/lib/fields/grid-display.php @@ -18,7 +18,7 @@ * * @since 0.1.0 * @since 2.25.6 Added admin check. - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @param array $field Field array. * @@ -53,7 +53,7 @@ function mai_acf_load_show( $field ) { * * @since 0.1.0 * @since 2.25.6 Added admin check. - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @param array $args Field args. * diff --git a/lib/fields/grid-layout.php b/lib/fields/grid-layout.php index cf069c38b..3d58387f4 100644 --- a/lib/fields/grid-layout.php +++ b/lib/fields/grid-layout.php @@ -20,7 +20,7 @@ * * @since 2.4.0 * @since 2.25.6 Added admin check. - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @param array $field The existing field. * diff --git a/lib/fields/icons.php b/lib/fields/icons.php index 668be4393..a2ed63d4d 100644 --- a/lib/fields/icons.php +++ b/lib/fields/icons.php @@ -19,7 +19,7 @@ * * @since 0.1.0 * @since 2.25.6 Added admin check. - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @param array $field The ACF field. * @@ -46,7 +46,7 @@ function mai_load_icon_choices( $field ) { * * @since 0.1.0 * @since 2.25.6 Added admin check. - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @param array $field Field args. * diff --git a/lib/fields/validate.php b/lib/fields/validate.php index 387ebd7e0..9b6003cd8 100644 --- a/lib/fields/validate.php +++ b/lib/fields/validate.php @@ -18,7 +18,7 @@ * We need this because we wrongly used custom field keys that don't start with `field_`. * Our engine blocks use `mai_` and plugin blocks use `maicca_', `maipub_`, etc., so we check for `mai`. * - * @since TBD + * @since 2.35.0 * * @param bool $bool The result. * @param string $id The identifier. diff --git a/lib/fields/wp-term-query.php b/lib/fields/wp-term-query.php index bbbe62f4f..d5febf774 100644 --- a/lib/fields/wp-term-query.php +++ b/lib/fields/wp-term-query.php @@ -18,7 +18,7 @@ * * @since 2.21.0 * @since 2.25.6 Added admin check. - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @param array $field The existing field array. * @@ -34,13 +34,45 @@ function mai_grid_load_taxonomy_field( $field ) { return $field; } +add_filter( 'acf/prepare_field/key=mai_grid_block_taxonomy', 'mai_grid_prepare_taxonomy_field' ); +/** + * Load taxonomy choices based on existing saved field value. + * Since we're using ajax to load choices, we need to load the saved value as an initial choice. + * + * @link https://github.com/maithemewp/mai-engine/issues/93 + * + * @since 2.35.0 + * + * @param array $field The existing field array. + * + * @return array + */ +function mai_grid_prepare_taxonomy_field( $field ) { + // Bail if not in admin. No AJAX check here because we need this on page load. + if ( ! is_admin() ) { + return $field; + } + + if ( $field['value'] ) { + foreach ( $field['value'] as $taxonomy ) { + $taxonomy = get_taxonomy( $taxonomy ); + + if ( $taxonomy ) { + $field['choices'] = [ $taxonomy->name => $taxonomy->label ]; + } + } + } + + return $field; +} + add_filter( 'acf/load_field/key=mai_grid_block_tax_include', 'mai_grid_load_include_terms_field' ); add_filter( 'acf/load_field/key=mai_grid_block_tax_exclude', 'mai_grid_load_include_terms_field' ); /** * Sets taxonomy based on the block taxonomies field, when the include/exclude fields are initially loaded. * * @since 2.27.0 - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @param array $field * @@ -83,7 +115,7 @@ function mai_grid_load_include_terms_field( $field ) { * @since 0.1.0 * @since 2.25.6 Added admin check. * @since 2.27.0 Force first taxonomy. See #631. - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @param array $args Field args. * @@ -115,7 +147,7 @@ function mai_acf_get_terms( $args, $field, $post_id ) { * * @since 0.1.0 * @since 2.25.6 Added admin check. - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @param array $args Field args. * @@ -156,7 +188,7 @@ function mai_acf_get_term_parents( $args ) { * * @since 2.22.0 * @since 2.25.6 Added admin check. - * @since TBD Added ajax check. + * @since 2.35.0 Added ajax check. * * @link https://www.powderkegwebdesign.com/fantastic-way-allow-searching-id-advanced-custom-fields-objects/ * @@ -195,6 +227,12 @@ function mai_acf_get_terms_by_id( $args, $field, $post_id ) { * @return array */ function mai_get_taxonomy_choices() { + static $choices = null; + + if ( ! is_null( $choices ) ) { + return $choices; + } + $choices = []; $taxonomies = get_taxonomies( [ diff --git a/lib/support/facetwp.php b/lib/support/facetwp.php index d1a66063b..4e4583930 100644 --- a/lib/support/facetwp.php +++ b/lib/support/facetwp.php @@ -15,7 +15,7 @@ /** * Forces FacetWP support for when the MPG has `facetwp-template` class. * - * @since TBD + * @since 2.35.0 * * @param array $query_args WP_Query args. * @param array $args Mai Post Grid args.