-
-
Save tommcfarlin/2fd7f50706c3f1767dc8b5c2b7deefff to your computer and use it in GitHub Desktop.
[WordPress] A Simple Guide for Organizing WordPress-centric Classes
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
<?php | |
namespace Acme\WordPress\Admin\MetaBox; | |
abstract class AbstractMetaBox | |
{ | |
protected $postType; | |
public function __construct() | |
{ | |
$this->postType = 'acme_post_type'; | |
} | |
abstract public function render(); | |
abstract public function display(); | |
} |
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
<?php | |
namespace Acme\WordPress\Admin\MetaBox; | |
class AcmeMetaBox extends AbstractMetaBox | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function render() | |
{ | |
add_meta_box( | |
'acme-product-image', | |
'Product Image', | |
[$this, 'display'], | |
$this->postType, | |
'side', | |
'default' | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function display() | |
{ | |
include_once plugin_dir_path(__FILE__).'Views/acme-product-image.php'; | |
} | |
} |
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
<div class="product-image-metabox"> | |
<p> | |
<img src="<?= esc_html(get_post_meta(get_the_ID(), 'product_image', true)); ?>" alt="<?= esc_attr(get_the_title()); ?>" /> | |
<input type="text" value="<?= esc_html(get_post_meta(get_the_ID(), 'product_image', true)); ?>" /> | |
</p> | |
</div> |
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
<testsuites> | |
<testsuite name="Plugin"> | |
<directory>./tests</directory> | |
<exclude>./tests/phpunit</exclude> | |
<exclude>./src/WordPress</exclude> | |
</testsuite> | |
</testsuites> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment