Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.2 deprecation notices #2514

Open
plazorax opened this issue Aug 16, 2023 · 3 comments
Open

PHP 8.2 deprecation notices #2514

plazorax opened this issue Aug 16, 2023 · 3 comments

Comments

@plazorax
Copy link
Contributor

Issue description:

Using PHP 8.2 Kirki causes a couple of deprecation notices related to dynamic properties.

Version used:

5.0.0

Using theme_mods or options?

theme_mods

PHP error messages that might be related

Deprecated: Creation of dynamic property Kirki\Compatibility\Field::$compiler is deprecated in /Users/workspace/Servers/Themeforest/newsblock/wp-content/plugins/kirki/kirki-packages/compatibility/src/Field.php on line 307

Code to reproduce the issue (config + field(s))

add_action( 'customize_register', function( $wp_customize ) {
	if ( class_exists( 'Kirki_Control_Base' ) ) {
		/**
		 * The custom control class
		 */
		class Kirki_Collapsible extends Kirki_Control_Base {
			/**
			 * Control's Type.
			 *
			 * @since 3.4.0
			 * @var string
			 */
			public $type = 'collapsible';

			/**
			 * Renders the control content.
			 *
			 * @since 0.1
			 * @access protected
			 * @return void
			 */
			protected function render_content() {

				$collapsed_class = null;

				if ( isset( $this->input_attrs['collapsed'] ) && $this->input_attrs['collapsed'] ) {
					$collapsed_class = 'customize-collapsed';
				}
				?>
				<div class="customize-collapsible <?php echo esc_attr( $collapsed_class ); ?>"><h3><?php echo esc_attr( $this->label ); ?></h3></div>
				<?php
			}
		}

		// Register our custom control with Kirki.
		add_filter( 'kirki_control_types', function( $controls ) {
			$controls['collapsible'] = 'Kirki_Collapsible';
			return $controls;
		} );
	}
} );

Kirki::add_section(
	'design',
	array(
		'title'    => esc_html__( 'Design', 'newsblock' ),
		'priority' => 20,
	)
);

Kirki::add_section(
	'design_base',
	array(
		'title'    => esc_html__( 'design', 'newsblock' ),
		'panel'    => 'design',
		'priority' => 10,
	)
);

Kirki::add_field(
	'csco_theme_mod',
	array(
		'type'        => 'collapsible',
		'settings'    => 'design_collapsible_common',
		'section'     => 'design',
		'label'       => esc_html__( 'Common', 'newsblock' ),
		'priority'    => 10,
		'input_attrs' => array(
			'collapsed' => true,
		),
	)
);

Kirki::add_field(
	'csco_theme_mod',
	array(
		'type'     => 'color',
		'settings' => 'color_site_background',
		'label'    => esc_html__( 'Site Background', 'newsblock' ),
		'section'  => 'design',
		'priority' => 10,
		'default'  => '#FFFFFF',
		'choices'  => array(
			'alpha' => true,
		),
		'output'   => array(
			array(
				'element'  => ':root, [site-data-scheme="default"]',
				'property' => '--cs-color-site-background',
				'context'  => array( 'editor', 'front' ),
			),
		),
	)
);

Solution:


namespace Kirki\Compatibility;

use Kirki\Compatibility\Kirki;

/**
 * Please do not use this class directly.
 * You should instead extend it per-field-type.
 */
class Field {

	/**
	 * An array of the field arguments.
	 *
	 * @access protected
	 * @var array
	 */
	public $label;
	public $row_label;
	public $button_label;
	public $description;
	public $help;
	public $compiler; // <----------

@plazorax
Copy link
Contributor Author

I was also able to solve this problem with:

/**
 * Kirki Config
 *
 * @param array $config is an array of Kirki configuration parameters.
 */
function csco_kirki_config( $config ) {

	if ( isset( $config['compiler'] ) ) {
		unset( $config['compiler'] );
	}

	return $config;
}
add_filter( 'kirki/config', 'csco_kirki_config', 999 );

@eduardovaladares
Copy link

I was also able to solve this problem with:

/**
 * Kirki Config
 *
 * @param array $config is an array of Kirki configuration parameters.
 */
function csco_kirki_config( $config ) {

	if ( isset( $config['compiler'] ) ) {
		unset( $config['compiler'] );
	}

	return $config;
}
add_filter( 'kirki/config', 'csco_kirki_config', 999 );

Which file should I add this information to?

@plazorax
Copy link
Contributor Author

plazorax commented Aug 30, 2023

Which file should I add this information to?

functions.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants