alleyinteractive / wordpress-fieldmanager

Custom field types for WordPress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Datasource Term throws a warning on save in PHP 7.4

salcode opened this issue · comments

image

I'm running Fieldmanager version 1.3.0 with PHP version 7.4 with code to create a submenu with a select field with a datasource of category.

Details to Reproduce

Setup

PHP Version 7.4

On a WordPress install running on PHP version 7.4

Set WP DEBUG to true

In wp-config.php set

define( 'WP_DEBUG', true );

Activate Fieldmanager plugin version 1.3.0

Install and activate the Fieldmanager plugin version 1.3.0

<?php

namespace salcode\FieldManager\BugReport\DataSourceTaxonomyCategory;

add_action( 'after_setup_theme', __NAMESPACE__ . '\setup' );

function setup() {
	fm_register_submenu_page(
		'bug_datasource_tax_category',
		'options-general.php',
		'Bug Report Datasource Taxonomy Category'
	);
	add_action(
		'fm_submenu_bug_datasource_tax_category',
		__NAMESPACE__ . '\options_init'
	);
}

function options_init() {
	$fm = new \Fieldmanager_Group( [
		'name' => 'bug_datasource_tax_category',
		'label' => 'Bug Report Datasource Tax Category',
		'children' => [
			'select' => new \Fieldmanager_Select(
				'Category Dropdown',
				[
					'datasource' => new \Fieldmanager_Datasource_Term(
						[ 'taxonomy' => 'category' ]
					)
				]
			),
		]
	] );
	$fm->activate_submenu_page();
}

Reproduction Steps

1. Go to the Sub Menu

Go to Settings > Bug Report Datasource Taxonomy Category (the URL is /wp-admin/options-general.php?page=bug_datasource_tax_category)

image

2. Save Changes

Click the Save Changes button

image

3. View the Warning

At this point the warning should be displayed

Warning: Creating default object from empty value in /var/www/html/wp-content/plugins/wordpress-fieldmanager/php/datasource/class-fieldmanager-datasource-term.php on line 283

Note: I'm running xdebug, which is why the screenshot of my error message at the top of this issue is formatted as a table with a stack trace

I'm able to replicate this. The check on

if ( ! isset( $oldest_parent->current_context->taxonomies_to_save[ $taxonomy ] ) ) {
is undefined on PHP 7.3 and 7.4 ($oldest_parent->current_context is not set).