-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #537 from equalizedigital/william/467/make-meta-bo…
…xes-functions-into-a-class Convert editor meta boxes function into a class
- Loading branch information
Showing
7 changed files
with
185 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Class for handling the editor meta box. | ||
* | ||
* @package Accessibility_Checker | ||
*/ | ||
|
||
namespace EDAC\Admin; | ||
|
||
/** | ||
* Class Meta_Box | ||
* | ||
* Handles the editor meta box registration and rendering. | ||
*/ | ||
class Meta_Boxes { | ||
|
||
/** | ||
* Initialize the hooks for the editor meta box. | ||
* | ||
* @return void | ||
*/ | ||
public function init_hooks(): void { | ||
add_action( 'add_meta_boxes', array( $this, 'register_meta_boxes' ) ); | ||
} | ||
|
||
/** | ||
* Register custom meta boxes for each post type. | ||
* | ||
* @since 1.10.0 | ||
* | ||
* @return void | ||
*/ | ||
public function register_meta_boxes(): void { | ||
$post_types = get_option( 'edac_post_types' ); | ||
if ( $post_types ) { | ||
foreach ( $post_types as $post_type ) { | ||
add_meta_box( | ||
'edac-meta-box', | ||
__( 'Accessibility Checker', 'accessibility-checker' ), | ||
array( $this, 'render' ), | ||
$post_type, | ||
'normal', | ||
'high' | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Render the custom meta box html. | ||
* | ||
* @since 1.10.0 | ||
* | ||
* @return void | ||
*/ | ||
public function render(): void { | ||
do_action( 'edac_before_meta_box' ); | ||
include_once plugin_dir_path( __DIR__ ) . 'partials/custom-meta-box.php'; | ||
do_action( 'edac_after_meta_box' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* Test class for the editor metabox. | ||
* | ||
* @package Accessibility_Checker | ||
*/ | ||
|
||
use EDAC\Admin\Admin; | ||
use EDAC\Admin\Meta_Boxes; | ||
|
||
/** | ||
* Tests for the editor meta box class. | ||
*/ | ||
class MetaBoxesTest extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test the hooks are added only in admin. | ||
* | ||
* @return void | ||
*/ | ||
public function test_meta_boxes_are_registered_in_admin(): void { | ||
|
||
$meta_boxes = $this->getMockBuilder( Meta_Boxes::class ) | ||
->onlyMethods( array( 'register_meta_boxes' ) ) | ||
->getMock(); | ||
|
||
$meta_boxes->expects( $this->once() ) | ||
->method( 'register_meta_boxes' ); | ||
|
||
$this->invoke_admin_init( $meta_boxes ); | ||
do_action( 'add_meta_boxes' ); | ||
} | ||
|
||
/** | ||
* Test the init_hooks method. | ||
* | ||
* @return void | ||
*/ | ||
public function test_init_hooks(): void { | ||
$meta_boxes = new Meta_Boxes(); | ||
$meta_boxes->init_hooks(); | ||
|
||
$this->assertEquals( | ||
10, | ||
has_action( | ||
'add_meta_boxes', | ||
array( | ||
$meta_boxes, | ||
'register_meta_boxes', | ||
) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Test the render method. | ||
* | ||
* @return void | ||
*/ | ||
public function test_render(): void { | ||
$meta_boxes = new Meta_Boxes(); | ||
$meta_boxes->render(); | ||
|
||
$this->expectOutputRegex( '/^<div id="edac-tabs">/' ); | ||
} | ||
|
||
/** | ||
* Invoke the admin init method. | ||
* | ||
* @param Meta_Boxes $meta_boxes The metabox class. | ||
* @return void | ||
*/ | ||
private function invoke_admin_init( $meta_boxes ): void { | ||
$admin = new Admin( $meta_boxes ); | ||
$admin->init(); | ||
} | ||
} |