Skip to content

Commit

Permalink
term ui
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed Apr 18, 2022
1 parent 56d39e3 commit 045dcbd
Show file tree
Hide file tree
Showing 8 changed files with 863 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"autoload": {
"psr-4": {
"HAMWORKS\\WP\\Schedule_Terms\\": "./includes",
"JJJ\\WP\\Term\\Meta\\": "./lib/JJJ/WP/Term/Meta",
"HAMWORKS\\WP\\Schedule_Terms\\Tests\\": "./tests"
}
},
Expand Down
7 changes: 3 additions & 4 deletions includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@ public function __construct() {
* Enqueue block editor assets.
*/
public function enqueue_block_editor_assets() {
$asset_file = include plugin_dir_path( __DIR__ ) . 'build/index.asset.php';
$asset_file = include plugin_dir_path( __DIR__ ) . 'build/editor.asset.php';

foreach ( $asset_file['dependencies'] as $style ) {
wp_enqueue_style( $style );
}

wp_register_script(
wp_enqueue_script(
'schedule-terms',
plugins_url( 'build/index.js', __DIR__ ),
plugins_url( 'build/editor.js', __DIR__ ),
$asset_file['dependencies'],
$asset_file['version'],
true
);
wp_enqueue_script( 'schedule-terms' );
}

}
1 change: 1 addition & 0 deletions includes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Plugin {
*/
public function __construct() {
new Assets();
new Term_UI( __DIR__ );
}

}
113 changes: 113 additions & 0 deletions includes/Term_UI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Term_UI class.
*
* @package Schedule_Terms
*/

namespace HAMWORKS\WP\Schedule_Terms;

use JJJ\WP\Term\Meta\UI;

/**
* Term meta UI controller.
*/
class Term_UI extends UI {

/**
* Plugin version.
*
* @var string
*/
public $version = '2.0.0';

/**
* Database version.
*
* @var string
*/
public $db_version = 202204190000;

/**
* Metadata key.
*
* @var string
*/
public $meta_key = 'use_schedule';

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

parent::__construct( $file );
}

/**
* Enqueue scripts.
*/
public function enqueue_scripts() {
$asset_file = include plugin_dir_path( __DIR__ ) . 'build/admin.asset.php';

foreach ( $asset_file['dependencies'] as $style ) {
wp_enqueue_style( $style );
}

wp_enqueue_script(
'schedule-terms-admin',
plugins_url( 'build/admin.js', __DIR__ ),
$asset_file['dependencies'],
$asset_file['version'],
true
);
}

/**
* Output.
*
* @param mixed $meta term meta.
*/
protected function format_output( $meta = '' ) {
if ( $meta ) {
?>
<span data-use-schedule><?php esc_html_e( 'Use Schedule', 'schedule-posts' ); ?></span>
<?php
}
}

/**
* Output the form field
*
* @param \WP_Term|null $term term meta.
*/
protected function form_field( $term = null ) {
$value = isset( $term->term_id )
? $this->get_meta( $term->term_id )
: '';

?>
<input
type="checkbox"
name="term-<?php echo esc_attr( $this->meta_key ); ?>"
id="term-<?php echo esc_attr( $this->meta_key ); ?>"
<?php checked( ! ! $value, true, true ); ?>
/>
<?php
}

/**
* Output the form field
*/
protected function quick_edit_form_field() {
?>
<input type="checkbox" name="term-<?php echo esc_attr( $this->meta_key ); ?>">
<?php
}


}
Loading

0 comments on commit 045dcbd

Please sign in to comment.