diff --git a/bin/baseline.neon b/bin/baseline.neon index bbe200d6..17f2b5bd 100644 --- a/bin/baseline.neon +++ b/bin/baseline.neon @@ -360,23 +360,6 @@ parameters: count: 1 path: ../includes/fields/class-acf-field-wysiwyg.php - - - message: '#^Access to an undefined property acf_form_customizer\:\:\$preview_errors\.$#' - identifier: property.notFound - count: 1 - path: ../includes/forms/form-customizer.php - - - - message: '#^Access to an undefined property acf_form_customizer\:\:\$preview_fields\.$#' - identifier: property.notFound - count: 2 - path: ../includes/forms/form-customizer.php - - - - message: '#^Access to an undefined property acf_form_customizer\:\:\$preview_values\.$#' - identifier: property.notFound - count: 2 - path: ../includes/forms/form-customizer.php - message: '#^Action callback returns type but should not return anything\.$#' diff --git a/includes/forms/form-customizer.php b/includes/forms/form-customizer.php index 71b18bf8..370311b4 100644 --- a/includes/forms/form-customizer.php +++ b/includes/forms/form-customizer.php @@ -4,11 +4,42 @@ exit; // Exit if accessed directly } -if ( ! class_exists( 'acf_form_customizer' ) ) : - #[AllowDynamicProperties] - class acf_form_customizer { +if ( ! class_exists( 'acf_form_customizer' ) || ! class_exists( 'ACF_Form_Customizer' ) ) : + /** + * ACF Form Customizer Class + * + * This class handles the integration of Advanced Custom Fields with the WordPress Customizer. + * It manages preview values, fields, and errors for the customizer interface, and handles + * saving ACF data when customizer changes are applied. + * + * @package wordpress/secure-custom-fields + * @since ACF 3.6.0 + */ + class ACF_Form_Customizer { + /** + * Values to be used in the preview. + * + * @var array + */ + public $preview_values; + + /** + * Fields to be used in the preview. + * + * @var array + */ + public $preview_fields; + + + /** + * Errors to be used in the preview. + * + * @var array + */ + public $preview_errors; + /** * This function will setup the class functionality * @@ -19,7 +50,7 @@ class acf_form_customizer { * @param n/a * @return n/a */ - function __construct() { + public function __construct() { // vars $this->preview_values = array(); @@ -43,11 +74,9 @@ function __construct() { * @type action (admin_enqueue_scripts) * @date 26/01/13 * @since ACF 3.6.0 - * - * @param N/A - * @return N/A + * @return void */ - function customize_controls_init() { + public function customize_controls_init() { // load acf scripts acf_enqueue_scripts( @@ -68,15 +97,16 @@ function customize_controls_init() { * @date 27/05/2015 * @since ACF 5.2.3 * - * @param $instance (array) widget settings - * @param $new_instance (array) widget settings - * @param $old_instance (array) widget settings - * @param $widget (object) widget info - * @return $instance + * @param array $instance (array) widget settings. + * @param array $new_instance (array) widget settings. + * @param array $old_instance (array) widget settings. + * @param object $widget (object) widget info. + * @return array $instance Widget settings. */ - function save_widget( $instance, $new_instance, $old_instance, $widget ) { - + public function save_widget( $instance, $new_instance, $old_instance, $widget ) { // bail early if not valid (customize + acf values + nonce) + + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce is verified in acf_verify_nonce. if ( ! isset( $_POST['wp_customize'] ) || ! isset( $new_instance['acf'] ) || ! acf_verify_nonce( 'widget' ) ) { return $instance; } @@ -122,10 +152,10 @@ function save_widget( $instance, $new_instance, $old_instance, $widget ) { * @date 22/03/2016 * @since ACF 5.3.2 * - * @param $customizer (object) - * @return $value (mixed) + * @param WP_Customize_Manager $customizer Customizer object. + * @return Mixed boolean | array. The sCustomizer Settings Object. */ - function settings( $customizer ) { + public function settings( $customizer ) { // vars $data = array(); @@ -141,14 +171,13 @@ function settings( $customizer ) { // vars $id = $setting->id; - - // verify settings type - if ( substr( $id, 0, 6 ) == 'widget' || substr( $id, 0, 7 ) == 'nav_menu' ) { - // allow - } else { + // Only process widget and nav_menu settings + if ( 'widget' !== substr( $id, 0, 6 ) && 'nav_menu' !== substr( $id, 0, 7 ) ) { continue; } + // At this point, we're dealing with either a widget or nav_menu setting + // get value $value = $setting->post_value(); @@ -181,10 +210,10 @@ function settings( $customizer ) { * @date 22/03/2016 * @since ACF 5.3.2 * - * @param $customizer (object) - * @return n/a + * @param WP_Customize_Manager $customizer Customizer object. + * @return void */ - function customize_preview_init( $customizer ) { + public function customize_preview_init( $customizer ) { // get customizer settings (widgets) $settings = $this->settings( $customizer ); @@ -216,17 +245,19 @@ function customize_preview_init( $customizer ) { } /** - * pre_load_value + * Pre load value function. * - * Used to inject preview value + * Used to inject preview value. * * @date 2/2/18 * @since ACF 5.6.5 * - * @param type $var Description. Default. - * @return type Description. + * @param mixed $value The value to check. + * @param int $post_id The post ID. + * @param array $field The field array. + * @return mixed The preview value if exists, otherwise the original value. */ - function pre_load_value( $value, $post_id, $field ) { + public function pre_load_value( $value, $post_id, $field ) { // check if ( isset( $this->preview_values[ $post_id ][ $field['key'] ] ) ) { @@ -238,17 +269,19 @@ function pre_load_value( $value, $post_id, $field ) { } /** - * pre_load_reference + * Pre load reference function. * - * Used to inject preview value + * Used to inject reference value. * * @date 2/2/18 * @since ACF 5.6.5 * - * @param type $var Description. Default. - * @return type Description. + * @param string $field_key The field key. + * @param string $field_name The field name. + * @param int $post_id The post ID. + * @return string The field key if preview field exists, otherwise the original field key. */ - function pre_load_reference( $field_key, $field_name, $post_id ) { + public function pre_load_reference( $field_key, $field_name, $post_id ) { // check if ( isset( $this->preview_fields[ $post_id ][ $field_name ] ) ) { @@ -269,10 +302,10 @@ function pre_load_reference( $field_key, $field_name, $post_id ) { * @date 22/03/2016 * @since ACF 5.3.2 * - * @param $customizer (object) - * @return n/a + * @param WP_Customize_Manager $customizer The WordPress customizer manager object. + * @return void */ - function customize_save( $customizer ) { + public function customize_save( $customizer ) { // get customizer settings (widgets) $settings = $this->settings( $customizer ); @@ -293,7 +326,7 @@ function customize_save( $customizer ) { // remove [acf] data from saved widget array $id_data = $setting->id_data(); - add_filter( 'pre_update_option_' . $id_data['base'], array( $this, 'pre_update_option' ), 10, 3 ); + add_filter( 'pre_update_option_' . $id_data['base'], array( $this, 'pre_update_option' ), 10, 1 ); } } @@ -305,10 +338,10 @@ function customize_save( $customizer ) { * @date 22/03/2016 * @since ACF 5.3.2 * - * @param $post_id (int) - * @return $post_id (int) + * @param mixed $value The new option value. + * @return mixed The filtered option value. */ - function pre_update_option( $value, $option, $old_value ) { + public function pre_update_option( $value ) { // bail early if no value if ( empty( $value ) ) { @@ -343,7 +376,7 @@ function pre_update_option( $value, $option, $old_value ) { * @param n/a * @return n/a */ - function admin_footer() { + public function admin_footer() { ?>