plugin updates

This commit is contained in:
Tony Volpe
2024-09-05 11:04:01 -04:00
parent ed6b060261
commit 50cd64dd3d
925 changed files with 16918 additions and 13003 deletions

View File

@@ -47,13 +47,35 @@ class Bindings {
* @param array $source_attrs An array of the source attributes requested.
* @param \WP_Block $block_instance The block instance.
* @param string $attribute_name The block's bound attribute name.
* @return string The block binding value.
* @return string|null The block binding value or an empty string on failure.
*/
public function get_value( array $source_attrs, \WP_Block $block_instance, string $attribute_name ) {
if ( ! isset( $source_attrs['key'] ) || ! is_string( $source_attrs['key'] ) ) {
$value = null;
$value = '';
} else {
$value = get_field( $source_attrs['key'] );
$field = get_field_object( $source_attrs['key'], false, true, true, true );
if ( ! $field ) {
return '';
}
if ( ! acf_field_type_supports( $field['type'], 'bindings', true ) ) {
if ( is_preview() ) {
return apply_filters( 'acf/bindings/field_not_supported_message', '[' . esc_html__( 'The requested ACF field type does not support output in Block Bindings or the ACF shortcode.', 'acf' ) . ']' );
} else {
return '';
}
}
if ( isset( $field['allow_in_bindings'] ) && ! $field['allow_in_bindings'] ) {
if ( is_preview() ) {
return apply_filters( 'acf/bindings/field_not_allowed_message', '[' . esc_html__( 'The requested ACF field is not allowed to be output in bindings or the ACF Shortcode.', 'acf' ) . ']' );
} else {
return '';
}
}
$value = $field['value'];
if ( is_array( $value ) ) {
$value = implode( ', ', $value );

View File

@@ -28,7 +28,7 @@ if ( current_user_can( acf_get_setting( 'capability' ) ) ) {
}
$acf_error_msg = sprintf(
/* translators: %1$s - name of the ACF plugin. %2$s - Link to documentation. %3$s - Link to show more details about the error */
/* translators: %1$s - name of the ACF plugin. %2$s - Link to documentation. */
__( '%1$s ACF now automatically escapes unsafe HTML when rendered by <code>the_field</code> or the ACF shortcode. We\'ve detected the output of some of your fields has been modified by this change, but this may not be a breaking change. %2$s.', 'acf' ),
$acf_plugin_name,
$acf_learn_how_to_fix

View File

@@ -1008,7 +1008,7 @@ function acf_shortcode( $atts ) {
// Return if the ACF shortcode is disabled.
if ( ! acf_get_setting( 'enable_shortcode' ) ) {
if ( is_preview() ) {
return apply_filters( 'acf/shortcode/disabled_message', __( '[The ACF shortcode is disabled on this site]', 'acf' ) );
return apply_filters( 'acf/shortcode/disabled_message', esc_html__( '[The ACF shortcode is disabled on this site]', 'acf' ) );
} else {
return;
}
@@ -1024,7 +1024,7 @@ function acf_shortcode( $atts ) {
// Limit previews of ACF shortcode data for users without publish_posts permissions.
$preview_capability = apply_filters( 'acf/shortcode/preview_capability', 'publish_posts' );
if ( is_preview() && ! current_user_can( $preview_capability ) ) {
return apply_filters( 'acf/shortcode/preview_capability_message', __( '[ACF shortcode value disabled for preview]', 'acf' ) );
return apply_filters( 'acf/shortcode/preview_capability_message', esc_html__( '[ACF shortcode value disabled for preview]', 'acf' ) );
}
// Mitigate issue where some AJAX requests can return ACF field data.
@@ -1051,7 +1051,7 @@ function acf_shortcode( $atts ) {
if ( $decoded_post_id['type'] === 'post' ) {
if ( $atts['post_id'] !== false && ( (int) $atts['post_id'] !== (int) acf_get_valid_post_id() ) && ( ! is_post_publicly_viewable( $decoded_post_id['id'] ) ) && apply_filters( 'acf/shortcode/prevent_access_to_fields_on_non_public_posts', true ) ) {
if ( is_preview() ) {
return apply_filters( 'acf/shortcode/post_not_public_message', __( '[The ACF shortcode cannot display fields from non-public posts]', 'acf' ) );
return apply_filters( 'acf/shortcode/post_not_public_message', esc_html__( '[The ACF shortcode cannot display fields from non-public posts]', 'acf' ) );
} else {
return;
}
@@ -1072,6 +1072,22 @@ function acf_shortcode( $atts ) {
$field_type = is_array( $field ) && isset( $field['type'] ) ? $field['type'] : 'text';
if ( ! acf_field_type_supports( $field_type, 'bindings', true ) ) {
if ( is_preview() ) {
return apply_filters( 'acf/shortcode/field_not_supported_message', '[' . esc_html__( 'The requested ACF field type does not support output in bindings or the ACF Shortcode.', 'acf' ) . ']' );
} else {
return;
}
}
if ( isset( $field['allow_in_bindings'] ) && ! $field['allow_in_bindings'] ) {
if ( is_preview() ) {
return apply_filters( 'acf/shortcode/field_not_allowed_message', '[' . esc_html__( 'The requested ACF field is not allowed to be output in bindings or the ACF Shortcode.', 'acf' ) . ']' );
} else {
return;
}
}
if ( apply_filters( 'acf/shortcode/prevent_access', false, $atts, $decoded_post_id['id'], $decoded_post_id['type'], $field_type, $field ) ) {
return;
}

View File

@@ -26,7 +26,10 @@ if ( ! class_exists( 'acf_field__accordion' ) ) :
$this->description = __( 'Allows you to group and organize custom fields into collapsable panels that are shown while editing content. Useful for keeping large datasets tidy.', 'acf' );
$this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-accordion.png';
$this->doc_url = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/accordion/', 'docs', 'field-type-selection' );
$this->supports = array( 'required' => false );
$this->supports = array(
'required' => false,
'bindings' => false,
);
$this->defaults = array(
'open' => 0,
'multi_expand' => 0,

View File

@@ -24,6 +24,9 @@ if ( ! class_exists( 'acf_field__group' ) ) :
$this->description = __( 'Provides a way to structure fields into groups to better organize the data and the edit screen.', 'acf' );
$this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-group.png';
$this->doc_url = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/group/', 'docs', 'field-type-selection' );
$this->supports = array(
'bindings' => false,
);
$this->defaults = array(
'sub_fields' => array(),
'layout' => 'block',

View File

@@ -24,7 +24,10 @@ if ( ! class_exists( 'acf_field_message' ) ) :
$this->category = 'layout';
$this->description = __( 'Used to display a message to editors alongside other fields. Useful for providing additional context or instructions around your fields.', 'acf' );
$this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-message.png';
$this->supports = array( 'required' => false );
$this->supports = array(
'required' => false,
'bindings' => false,
);
$this->defaults = array(
'message' => '',
'esc_html' => 0,

View File

@@ -42,67 +42,59 @@ if ( ! class_exists( 'acf_field_select' ) ) :
/**
* description
* Enqueues admin scripts for the Select field.
*
* @type function
* @date 16/12/2015
* @since 5.3.2
* @since 5.3.2
*
* @param $post_id (int)
* @return $post_id (int)
* @return void
*/
function input_admin_enqueue_scripts() {
// bail early if no enqueue
public function input_admin_enqueue_scripts() {
// Bail early if not enqueuing select2.
if ( ! acf_get_setting( 'enqueue_select2' ) ) {
return;
}
// globals
global $wp_scripts, $wp_styles;
global $wp_scripts;
// vars
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$major = acf_get_setting( 'select2_version' );
$version = '';
$script = '';
$style = '';
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$major = acf_get_setting( 'select2_version' );
// attempt to find 3rd party Select2 version
// - avoid including v3 CSS when v4 JS is already enququed
// - avoid including v3 CSS when v4 JS is already enqueued.
if ( isset( $wp_scripts->registered['select2'] ) ) {
$major = (int) $wp_scripts->registered['select2']->ver;
}
// v4
if ( $major == 4 ) {
$version = '4.0.13';
$script = acf_get_url( "assets/inc/select2/4/select2.full{$min}.js" );
$style = acf_get_url( "assets/inc/select2/4/select2{$min}.css" );
// v3
} else {
if ( $major === 3 ) {
// Use v3 if necessary.
$version = '3.5.2';
$script = acf_get_url( "assets/inc/select2/3/select2{$min}.js" );
$style = acf_get_url( 'assets/inc/select2/3/select2.css' );
} else {
// Default to v4.
$version = '4.0.13';
$script = acf_get_url( "assets/inc/select2/4/select2.full{$min}.js" );
$style = acf_get_url( "assets/inc/select2/4/select2{$min}.css" );
}
// enqueue
wp_enqueue_script( 'select2', $script, array( 'jquery' ), $version );
wp_enqueue_style( 'select2', $style, '', $version );
// localize
acf_localize_data(
array(
'select2L10n' => array(
'matches_1' => _x( 'One result is available, press enter to select it.', 'Select2 JS matches_1', 'acf' ),
/* translators: %d - number of results available in select field */
'matches_n' => _x( '%d results are available, use up and down arrow keys to navigate.', 'Select2 JS matches_n', 'acf' ),
'matches_0' => _x( 'No matches found', 'Select2 JS matches_0', 'acf' ),
'input_too_short_1' => _x( 'Please enter 1 or more characters', 'Select2 JS input_too_short_1', 'acf' ),
/* translators: %d - number of characters to enter into select field input */
'input_too_short_n' => _x( 'Please enter %d or more characters', 'Select2 JS input_too_short_n', 'acf' ),
'input_too_long_1' => _x( 'Please delete 1 character', 'Select2 JS input_too_long_1', 'acf' ),
/* translators: %d - number of characters that should be removed from select field */
'input_too_long_n' => _x( 'Please delete %d characters', 'Select2 JS input_too_long_n', 'acf' ),
'selection_too_long_1' => _x( 'You can only select 1 item', 'Select2 JS selection_too_long_1', 'acf' ),
/* translators: %d - maximum number of items that can be selected in the select field */
'selection_too_long_n' => _x( 'You can only select %d items', 'Select2 JS selection_too_long_n', 'acf' ),
'load_more' => _x( 'Loading more results&hellip;', 'Select2 JS load_more', 'acf' ),
'searching' => _x( 'Searching&hellip;', 'Select2 JS searching', 'acf' ),

View File

@@ -25,7 +25,10 @@ if ( ! class_exists( 'acf_field_tab' ) ) :
$this->description = __( 'Allows you to group fields into tabbed sections in the edit screen. Useful for keeping fields organized and structured.', 'acf' );
$this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-tabs.png';
$this->doc_url = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/tab/', 'docs', 'field-type-selection' );
$this->supports = array( 'required' => false );
$this->supports = array(
'required' => false,
'bindings' => false,
);
$this->defaults = array(
'placement' => 'top',
'endpoint' => 0, // added in 5.2.8

View File

@@ -78,8 +78,9 @@ if ( ! class_exists( 'acf_field' ) ) :
$this->add_action( 'acf/field_group/admin_head', array( $this, 'field_group_admin_head' ), 10, 0 );
$this->add_action( 'acf/field_group/admin_footer', array( $this, 'field_group_admin_footer' ), 10, 0 );
// Most fields can use the "Required" validation setting as well as most presentation settings.
// Add field global settings configurable by supports on specific field types.
$this->add_field_action( 'acf/field_group/render_field_settings_tab/validation', array( $this, 'render_required_setting' ), 5 );
$this->add_field_action( 'acf/field_group/render_field_settings_tab/presentation', array( $this, 'render_bindings_setting' ), 5 );
foreach ( acf_get_combined_field_type_settings_tabs() as $tab_key => $tab_label ) {
$this->add_field_action( "acf/field_group/render_field_settings_tab/{$tab_key}", array( $this, "render_field_{$tab_key}_settings" ), 9, 1 );
@@ -318,6 +319,53 @@ if ( ! class_exists( 'acf_field' ) ) :
true
);
}
/**
* Renders the "Allow in Bindings" setting on the field type "Presentation" settings tab.
*
* @since 6.3.6
*
* @param array $field The field type being rendered.
* @return void
*/
public function render_bindings_setting( $field ) {
$supports_bindings = acf_field_type_supports( $field['type'], 'bindings', true );
// Only prevent rendering if explicitly disabled.
if ( ! $supports_bindings ) {
return;
}
/* translators: %s A "Learn More" link to documentation explaining the setting further. */
$binding_string = esc_html__( 'Allow content editors to access and display the field value in the editor UI using Block Bindings or the ACF Shortcode. %s', 'acf' );
$binding_url = '<a target="_blank" href="' . acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/bindings-security/', 'docs', 'field-settings' ) . '">' . esc_html__( 'Learn more.', 'acf' ) . '</a>';
$binding_instructions = sprintf(
$binding_string,
$binding_url
);
// This field setting has a unique behaviour. If the value isn't defined on the field object, it defaults to true, but for new fields, it defaults to off.
if ( ! isset( $field['allow_in_bindings'] ) ) {
if ( empty( $field['ID'] ) ) {
$field['allow_in_bindings'] = false;
} else {
$field['allow_in_bindings'] = true;
}
}
acf_render_field_setting(
$field,
array(
'label' => __( 'Allow Access to Value in Editor UI', 'acf' ),
'instructions' => $binding_instructions,
'type' => 'true_false',
'name' => 'allow_in_bindings',
'ui' => 1,
'class' => 'field-show-in-bindings',
),
true
);
}
}
endif; // class_exists check

View File

@@ -118,40 +118,40 @@ if ( ! class_exists( 'acf_validation' ) ) :
$this->errors = array();
}
/**
* This function will validate the $_POST data via AJAX
* Validates $_POST data via AJAX prior to save.
*
* @type function
* @date 27/10/2014
* @since 5.0.9
*
* @param n/a
* @return n/a
* @return void
*/
function ajax_validate_save_post() {
// validate
public function ajax_validate_save_post() {
if ( ! acf_verify_ajax() ) {
die();
wp_send_json_success(
array(
'valid' => 0,
'errors' => array(
array(
'input' => false,
'message' => __( 'ACF was unable to perform validation due to an invalid security nonce being provided.', 'acf' ),
),
),
)
);
}
// vars
$json = array(
'valid' => 1,
'errors' => 0,
);
// success
if ( acf_validate_save_post() ) {
wp_send_json_success( $json );
}
// update vars
$json['valid'] = 0;
$json['errors'] = acf_get_validation_errors();
// return
wp_send_json_success( $json );
}