Skip to content

Commit

Permalink
save post meta
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed Apr 19, 2022
1 parent 045dcbd commit d91bf54
Show file tree
Hide file tree
Showing 7 changed files with 730 additions and 27 deletions.
48 changes: 47 additions & 1 deletion includes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,54 @@ class Plugin {
* Constructor.
*/
public function __construct() {
$meta_key = 'use_schedule';
new Assets();
new Term_UI( __DIR__ );
new Term_UI( __DIR__, $meta_key );
new Term_Meta( $meta_key );

foreach ( get_post_types() as $post_type ) {
$schema = array(
'items' => array(
'type' => 'object',
'properties' => array(
'term' => array(
'type' => 'string',
),
'is_active' => array(
'type' => 'boolean',
),
'datetime' => array(
'type' => 'string',
'format' => 'datetime',
),
),
),
);
register_post_meta(
$post_type,
'use_schedule_set_attach_datetime',
array(
'single' => true,
'type' => 'array',
'show_in_rest' => array(
'schema' => $schema,
),
)
);

register_post_meta(
$post_type,
'use_schedule_set_detach_datetime',
array(

'single' => true,
'type' => 'array',
'show_in_rest' => array(
'schema' => $schema,
),
)
);
}
}

}
31 changes: 31 additions & 0 deletions includes/Term_Meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* The Term Meta class.
*/
namespace HAMWORKS\WP\Schedule_Terms;

/**
* Term Meta class.
*/
class Term_Meta {

/**
* The single instance of the class.
*/
public function __construct( $meta_key ) {
foreach ( get_taxonomies() as $taxonomy ) {
register_term_meta(
$taxonomy,
$meta_key,
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
'sanitize_callback' => function ( $value ) {
return (bool) $value;
},
)
);
}
}
}
8 changes: 5 additions & 3 deletions includes/Term_UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ class Term_UI extends UI {
*
* @var string
*/
public $meta_key = 'use_schedule';
public $meta_key = '';

/**
* Constrouctor.
*
* @param string $file Plugin file.
* @param string $meta_key Metadata key.
*/
public function __construct( $file = '' ) {
$this->labels = array(
public function __construct( $file, string $meta_key ) {
$this->meta_key = $meta_key;
$this->labels = array(
'singular' => esc_html__( 'Scheduled', 'schedule-posts' ),
);

Expand Down
Loading

0 comments on commit d91bf54

Please sign in to comment.