GithubHelp home page GithubHelp logo

inpsyde / metaboxorchestra Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 4.0 97 KB

A Composer package that provides metabox orchestration for WordPress.

License: GNU General Public License v2.0

PHP 100.00%
wordpress metadata metaboxes php

metaboxorchestra's People

Contributors

alexp11223 avatar chrico avatar gmazzap avatar kashalo avatar meszarosrob avatar mvarugh avatar soean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

soean

metaboxorchestra's Issues

PHP 8.1 Deprecations

Description of the bug

I tested a plugin with PHP 8.1 which uses metabox-orchestra and see some deprecation warnings.

We can add bool, void needs PHP 7.1 and mixedneeds PHP 8.0.

Should we add #[\ReturnTypeWillChange] to the methods?

Environment info

PHP 8.1

Relevant log output

Deprecated: Return type of MetaboxOrchestra\BoxInfo::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .../vendor/inpsyde/metabox-orchestra/src/BoxInfo.php on line 107

Deprecated: Return type of MetaboxOrchestra\BoxInfo::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .../vendor/inpsyde/metabox-orchestra/src/BoxInfo.php on line 115

Deprecated: Return type of MetaboxOrchestra\BoxInfo::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .../vendor/inpsyde/metabox-orchestra/src/BoxInfo.php on line 123

Deprecated: Return type of MetaboxOrchestra\BoxInfo::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .../vendor/inpsyde/metabox-orchestra/src/BoxInfo.php on line 131

Code of Conduct

  • I agree to follow this project's Code of Conduct

Terms MetaBoxes is printing twice

Term MetaBoxes is being printed twice

Right now the MetBox Orchestra is using global $wp_meta_boxes; in Boxes.php Class to check if there is a hook in order to print the Terms Metboxes and it's dose not remove the hook after it's being executed which cause the possibility of same MetaBoxes of being printer again.

For Example:

If other plugins use the same structure to print the MetaBoxes terms for example MultiLanguage Press which basically use same exact code, and if any package use MetaBoxes Orchestra Package to register the terms MetBoxes the terms MetaBoxes will be printed twice.

Suggested solution:

Remove the current hook from $wp_meta_boxes; after it's being executed to make sure no other plugin/packages will print the MetaBoxes again.

Code Before:

	/**
	 * WordPress does not print metaboxes for terms, let's fix this.
	 *
	 * @param \WP_Term $term
	 */
	public function print_term_boxes( \WP_Term $term ) {

		if ( current_filter() !== "{$term->taxonomy}_edit_form" ) {
			return;
		}

		global $wp_meta_boxes;

		if ( empty( $wp_meta_boxes[ "edit-{$term->taxonomy}" ] ) ) {
			return;
		}
		$script = '!function(J,D){J(function(){J(".meta-box-sortables").sortable();'
		          . 'J(D).on("click",".termbox-container button.handlediv",function(){'
		          . 'var D=J(this),t=D.siblings(".inside");t.toggle();var e=t.is(":visible")?"true":"false";'
		          . 'D.attr("aria-expanded",e)})})}(jQuery,document);';
		wp_enqueue_script( 'jquery-ui-sortable' );
		wp_add_inline_script( 'jquery-ui-sortable', $script ); 
		echo '<div id="poststuff"><div class="postbox-container termbox-container">';
		// WordPress does not print metaboxes for terms, let's fix this
		do_meta_boxes( "edit-{$term->taxonomy}", 'side', $term );
		do_meta_boxes( "edit-{$term->taxonomy}", 'normal', $term );
		do_meta_boxes( "edit-{$term->taxonomy}", 'advanced', $term );
		echo '</div></div>';
	}

Code After:

/**
	 * WordPress does not print metaboxes for terms, let's fix this.
	 *
	 * @param \WP_Term $term
	 */
	public function print_term_boxes( \WP_Term $term ) {

		if ( current_filter() !== "{$term->taxonomy}_edit_form" ) {
			return;
		}

		global $wp_meta_boxes;

		if ( empty( $wp_meta_boxes[ "edit-{$term->taxonomy}" ] ) ) {
			return;
		}
		$script = '!function(J,D){J(function(){J(".meta-box-sortables").sortable();'
		          . 'J(D).on("click",".termbox-container button.handlediv",function(){'
		          . 'var D=J(this),t=D.siblings(".inside");t.toggle();var e=t.is(":visible")?"true":"false";'
		          . 'D.attr("aria-expanded",e)})})}(jQuery,document);';
		wp_enqueue_script( 'jquery-ui-sortable' );
		wp_add_inline_script( 'jquery-ui-sortable', $script ); 
		echo '<div id="poststuff"><div class="postbox-container termbox-container">';
		// WordPress does not print metaboxes for terms, let's fix this
		do_meta_boxes( "edit-{$term->taxonomy}", 'side', $term );
		do_meta_boxes( "edit-{$term->taxonomy}", 'normal', $term );
		do_meta_boxes( "edit-{$term->taxonomy}", 'advanced', $term );
		echo '</div></div>';
		// remove the hook after beign excuted
		unset($wp_meta_boxes["edit-{$term->taxonomy}"]);
	}

Do not mark `MetaboxOrchestra\BoxInfo` as final

Does make sense since the class does not implements the following methods by an interface that the class isn't marked as final.

  • id
  • title
  • context
  • priority

I understand that's just a data structure but in terms of unit tests correctness I want to mock the instance of that class but obviously it's not possible.

Additional reasons are:

  • The constructor make calls to Wp functions which is something I would not do in an unit test
  • I cannot make expectations for the instance and I have to construct more instances within the same test if I want to make smaller different tests.
  • A class should not be marked as final if there are methods which are not part of an interface. That's just an opinionable idea but like any other reason to mark a class final .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.