-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified: CHANGELOG.md modified: README.md new file: src/changelog.txt modified: src/src/admin/class-admin-notifications.php modified: src/src/core/class-lifecycle.php modified: src/src/registerables/metaboxes/class-base-metabox.php modified: src/src/registerables/metaboxes/class-image-upload-metabox.php modified: src/src/utilities/class-wp-filesystem-utility.php
- Loading branch information
Showing
8 changed files
with
235 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
Empty file.
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
159 changes: 130 additions & 29 deletions
159
src/src/registerables/metaboxes/class-base-metabox.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,154 @@ | ||
<?php | ||
/** | ||
* The Base Metabox class file | ||
* | ||
* This file registers the Base Metabox class. | ||
* This file includes: | ||
* - Strict Typing declaration, | ||
* - Namespace declaration, | ||
* - Use declarations, | ||
* - Check for direct access, | ||
* - Base Metabox Class Declaration | ||
* | ||
* @link https://site.tld | ||
* @since 1.0.0 Introduced on 2023-08-01 15:30 | ||
* @package Company\Plugins\PluginName\Registerables\Metaboxes | ||
* @author Your Name <your-name@site.tld> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
/** | ||
* Declare strict typing | ||
* | ||
* @see https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict | ||
*/ | ||
declare( strict_types = 1 ); | ||
|
||
/** | ||
* Declare the namespace | ||
* | ||
* @see https://www.php.net/manual/en/language.namespaces.php | ||
*/ | ||
namespace Company\Plugins\PluginName\Registerables\Metaboxes; | ||
|
||
use Company\Plugins\PluginName\Registerables\Base_WP_Registerable; | ||
|
||
if (!defined('ABSPATH')) { | ||
exit; | ||
/** | ||
* Exit the code if this file is accessed directly | ||
*/ | ||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* The Base Metabox Class | ||
* | ||
* Base Metabox class provides abstracts and methods to register a new Metabox. | ||
* | ||
* @since 1.0.0 Introduced on 2023-08-01 15:30 | ||
* @package Company\Plugins\PluginName\Registerables\Metaboxes | ||
* @author Your Name <your-name@site.tld> | ||
*/ | ||
abstract class Base_Metabox extends Base_WP_Registerable { | ||
protected array $post_types = []; | ||
protected array $user_roles = []; | ||
protected array $taxonomies = []; | ||
|
||
abstract public function render(): void; | ||
/** | ||
* Post types to assign metabox | ||
* | ||
* @since 1.0.0 Introduced on 2023-08-02 14:14 | ||
* @author Your Name <your-name@site.tld> | ||
* @access private | ||
* @var array $post_types Array of the post types to assign the metabox to. | ||
*/ | ||
protected array $post_types = array(); | ||
|
||
public function register(): void { | ||
if (!empty($this->post_types)) { | ||
add_action('add_meta_boxes', [$this, 'register_metaboxes_for_post_types']); | ||
/** | ||
* User Roles to assign metabox | ||
* | ||
* @since 1.0.0 Introduced on 2023-08-02 14:14 | ||
* @author Your Name <your-name@site.tld> | ||
* @access private | ||
* @var array $user_roles Array of the user roles to assign the metabox to. | ||
*/ | ||
protected array $user_roles = array(); | ||
|
||
/** | ||
* Taxonomies to assign metabox | ||
* | ||
* @since 1.0.0 Introduced on 2023-08-02 14:14 | ||
* @author Your Name <your-name@site.tld> | ||
* @access private | ||
* @var array $taxonomies Array of the taxonomies to assign the metabox to. | ||
*/ | ||
protected array $taxonomies = array(); | ||
|
||
/** | ||
* Abstract method to render metabox | ||
* | ||
* Provides an abstract to render the metabox | ||
* | ||
* @since 1.0.0 Introduced on 2023-10-08 17:09 | ||
* @see https://developer.wordpress.org/reference/functions/add_meta_box/#parameters | ||
* @author Beda Schmid <beda@tukutoi.com> | ||
* @return array | ||
*/ | ||
abstract public function render(): void; | ||
|
||
/** | ||
* Register Metabox | ||
* | ||
* Registers the metabox with WordPress | ||
* | ||
* @since 1.0.0 Introduced on 2023-10-08 17:09 | ||
* @see https://developer.wordpress.org/reference/functions/add_meta_box/ | ||
* @author Beda Schmid <beda@tukutoi.com> | ||
* @return void | ||
*/ | ||
public function register(): void { | ||
|
||
/** | ||
* Register for Post types if any | ||
*/ | ||
if ( ! empty( $this->post_types ) ) { | ||
add_action( 'add_meta_boxes', array( $this, 'register_metaboxes_for_post_types' ) ); | ||
} | ||
|
||
// Register metabox for users | ||
if (!empty($this->user_roles)) { | ||
add_action('show_user_profile', [$this, 'render']); | ||
add_action('edit_user_profile', [$this, 'render']); | ||
} | ||
/** | ||
* Register for User Roles if any | ||
*/ | ||
if ( ! empty( $this->user_roles ) ) { | ||
add_action( 'show_user_profile', array( $this, 'render' ) ); | ||
add_action( 'edit_user_profile', array( $this, 'render' ) ); | ||
} | ||
|
||
// Register metabox for taxonomies | ||
foreach ($this->taxonomies as $taxonomy) { | ||
add_action("{$taxonomy}_add_form_fields", [$this, 'render']); | ||
add_action("{$taxonomy}_edit_form_fields", [$this, 'render']); | ||
} | ||
} | ||
/** | ||
* Register for Taxonomies if any | ||
*/ | ||
foreach ( $this->taxonomies as $taxonomy ) { | ||
add_action( "{$taxonomy}_add_form_fields", array( $this, 'render' ) ); | ||
add_action( "{$taxonomy}_edit_form_fields", array( $this, 'render' ) ); | ||
} | ||
} | ||
|
||
/** | ||
* Callback for Post Types | ||
* | ||
* True metaboxes are only available on Post Types. | ||
* | ||
* @since 1.0.0 Introduced on 2023-10-08 17:09 | ||
* @see https://developer.wordpress.org/reference/functions/add_meta_box/#parameters | ||
* @author Beda Schmid <beda@tukutoi.com> | ||
* @return void | ||
*/ | ||
public function register_metaboxes_for_post_types(): void { | ||
foreach ($this->post_types as $post_type) { | ||
foreach ( $this->post_types as $post_type ) { | ||
add_meta_box( | ||
$this->get_key() . '_' . $post_type, | ||
ucwords(str_replace('_', ' ', $this->get_key())), | ||
[$this, 'render'], | ||
$post_type, | ||
'side', | ||
'high', | ||
ucwords( str_replace( '_', ' ', $this->get_key() ) ), | ||
array( $this, 'render' ), | ||
$post_type, | ||
'side', | ||
'high', | ||
null | ||
); | ||
} | ||
} | ||
|
||
// Additional methods to set the post types, user roles, and taxonomies can be added if needed | ||
} |
97 changes: 82 additions & 15 deletions
97
src/src/registerables/metaboxes/class-image-upload-metabox.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,97 @@ | ||
<?php | ||
/** | ||
* The Specialised Image Upload Metabox class file | ||
* | ||
* This file registers the Image Upload Metabox class. | ||
* This file includes: | ||
* - Strict Typing declaration, | ||
* - Namespace declaration, | ||
* - Use declarations, | ||
* - Check for direct access, | ||
* - Image Upload Metabox Class Declaration | ||
* | ||
* @link https://site.tld | ||
* @since 1.0.0 Introduced on 2023-08-01 15:30 | ||
* @package Company\Plugins\PluginName\Registerables\Metaboxes | ||
* @author Your Name <your-name@site.tld> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
/** | ||
* Declare strict typing | ||
* | ||
* @see https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict | ||
*/ | ||
declare( strict_types = 1 ); | ||
|
||
/** | ||
* Declare the namespace | ||
* | ||
* @see https://www.php.net/manual/en/language.namespaces.php | ||
*/ | ||
namespace Company\Plugins\PluginName\Registerables\MetaBoxes; | ||
|
||
use Company\Plugins\PluginName\Registerables\Metaboxes\Base_Metabox; | ||
|
||
if (!defined('ABSPATH')) { | ||
exit; | ||
/** | ||
* Exit the code if this file is accessed directly | ||
*/ | ||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* The Image Upload Metabox Class | ||
* | ||
* Image Upload Metabox class registers a Media Upload metabox for: | ||
* - posts, pages, items, | ||
* - administrators, editors, | ||
* - categories, tags, collections. | ||
* | ||
* @since 1.0.0 Introduced on 2023-08-01 15:30 | ||
* @package Company\Plugins\PluginName\Registerables\Metaboxes | ||
* @author Your Name <your-name@site.tld> | ||
*/ | ||
class Image_Upload_Metabox extends Base_Metabox { | ||
|
||
|
||
public function __construct() { | ||
// Define the post types, user roles, and taxonomies where the metabox should be added | ||
$this->post_types = ['post', 'page', 'item']; | ||
$this->user_roles = ['administrator', 'editor']; | ||
$this->taxonomies = ['category', 'post_tag', 'collection']; | ||
} | ||
/** | ||
* Initiate class properties | ||
* | ||
* Defines object types to which the metebox will be assigned | ||
* | ||
* @since 1.0.0 Introduced on 2023-10-08 17:09 | ||
* @author Beda Schmid <beda@tukutoi.com> | ||
* @return void | ||
*/ | ||
public function __construct() { | ||
$this->post_types = array( 'post', 'page', 'item' ); | ||
$this->user_roles = array( 'administrator', 'editor' ); | ||
$this->taxonomies = array( 'category', 'post_tag', 'collection' ); | ||
} | ||
|
||
/** | ||
* Set registerable key | ||
* | ||
* Sets the metabox unique key. | ||
* | ||
* @since 1.0.0 Introduced on 2023-10-08 17:09 | ||
* @author Beda Schmid <beda@tukutoi.com> | ||
* @return void | ||
*/ | ||
protected function set_key(): void { | ||
$this->key = 'my-box'; | ||
} | ||
|
||
public function render(): void { | ||
echo '<input type="file" name="custom_image_upload" />'; | ||
} | ||
$this->key = 'my-box'; | ||
} | ||
|
||
/** | ||
* Render the metabox | ||
* | ||
* A metabox needs to be rendered. This can be as simple or as complex as required. | ||
* | ||
* @since 1.0.0 Introduced on 2023-10-08 17:09 | ||
* @author Beda Schmid <beda@tukutoi.com> | ||
* @return void | ||
*/ | ||
public function render(): void { | ||
echo '<input type="file" name="custom_image_upload" />'; | ||
} | ||
} |
Oops, something went wrong.