You've already forked wp-fedistream
136 lines
4.8 KiB
PHP
136 lines
4.8 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* Mood custom taxonomy.
|
||
|
|
*
|
||
|
|
* @package WP_FediStream
|
||
|
|
*/
|
||
|
|
|
||
|
|
namespace WP_FediStream\Taxonomies;
|
||
|
|
|
||
|
|
// Prevent direct file access.
|
||
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Mood taxonomy class.
|
||
|
|
*
|
||
|
|
* Non-hierarchical taxonomy for track/playlist moods.
|
||
|
|
*/
|
||
|
|
class Mood extends AbstractTaxonomy {
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Taxonomy key.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected string $taxonomy = 'fedistream_mood';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Post types this taxonomy applies to.
|
||
|
|
*
|
||
|
|
* @var array
|
||
|
|
*/
|
||
|
|
protected array $post_types = array(
|
||
|
|
'fedistream_track',
|
||
|
|
'fedistream_playlist',
|
||
|
|
);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Register the taxonomy.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function register(): void {
|
||
|
|
$labels = array(
|
||
|
|
'name' => _x( 'Moods', 'taxonomy general name', 'wp-fedistream' ),
|
||
|
|
'singular_name' => _x( 'Mood', 'taxonomy singular name', 'wp-fedistream' ),
|
||
|
|
'search_items' => __( 'Search Moods', 'wp-fedistream' ),
|
||
|
|
'popular_items' => __( 'Popular Moods', 'wp-fedistream' ),
|
||
|
|
'all_items' => __( 'All Moods', 'wp-fedistream' ),
|
||
|
|
'edit_item' => __( 'Edit Mood', 'wp-fedistream' ),
|
||
|
|
'view_item' => __( 'View Mood', 'wp-fedistream' ),
|
||
|
|
'update_item' => __( 'Update Mood', 'wp-fedistream' ),
|
||
|
|
'add_new_item' => __( 'Add New Mood', 'wp-fedistream' ),
|
||
|
|
'new_item_name' => __( 'New Mood Name', 'wp-fedistream' ),
|
||
|
|
'separate_items_with_commas' => __( 'Separate moods with commas', 'wp-fedistream' ),
|
||
|
|
'add_or_remove_items' => __( 'Add or remove moods', 'wp-fedistream' ),
|
||
|
|
'choose_from_most_used' => __( 'Choose from the most used moods', 'wp-fedistream' ),
|
||
|
|
'not_found' => __( 'No moods found.', 'wp-fedistream' ),
|
||
|
|
'no_terms' => __( 'No moods', 'wp-fedistream' ),
|
||
|
|
'menu_name' => __( 'Moods', 'wp-fedistream' ),
|
||
|
|
'items_list_navigation' => __( 'Moods list navigation', 'wp-fedistream' ),
|
||
|
|
'items_list' => __( 'Moods list', 'wp-fedistream' ),
|
||
|
|
'back_to_items' => __( '← Back to Moods', 'wp-fedistream' ),
|
||
|
|
);
|
||
|
|
|
||
|
|
$args = array(
|
||
|
|
'labels' => $labels,
|
||
|
|
'hierarchical' => false, // Like tags.
|
||
|
|
'public' => true,
|
||
|
|
'show_ui' => true,
|
||
|
|
'show_in_menu' => false, // Will be added to custom menu.
|
||
|
|
'show_admin_column' => true,
|
||
|
|
'show_in_nav_menus' => true,
|
||
|
|
'show_tagcloud' => true,
|
||
|
|
'show_in_rest' => true,
|
||
|
|
'rest_base' => 'moods',
|
||
|
|
'query_var' => true,
|
||
|
|
'rewrite' => array( 'slug' => 'mood' ),
|
||
|
|
'capabilities' => array(
|
||
|
|
'manage_terms' => 'manage_fedistream_moods',
|
||
|
|
'edit_terms' => 'manage_fedistream_moods',
|
||
|
|
'delete_terms' => 'manage_fedistream_moods',
|
||
|
|
'assign_terms' => 'edit_fedistream_tracks',
|
||
|
|
),
|
||
|
|
);
|
||
|
|
|
||
|
|
register_taxonomy( $this->taxonomy, $this->post_types, $args );
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get default moods.
|
||
|
|
*
|
||
|
|
* @return array Array of moods.
|
||
|
|
*/
|
||
|
|
public static function get_default_moods(): array {
|
||
|
|
return array(
|
||
|
|
__( 'Energetic', 'wp-fedistream' ),
|
||
|
|
__( 'Calm', 'wp-fedistream' ),
|
||
|
|
__( 'Uplifting', 'wp-fedistream' ),
|
||
|
|
__( 'Melancholic', 'wp-fedistream' ),
|
||
|
|
__( 'Aggressive', 'wp-fedistream' ),
|
||
|
|
__( 'Romantic', 'wp-fedistream' ),
|
||
|
|
__( 'Happy', 'wp-fedistream' ),
|
||
|
|
__( 'Sad', 'wp-fedistream' ),
|
||
|
|
__( 'Relaxing', 'wp-fedistream' ),
|
||
|
|
__( 'Intense', 'wp-fedistream' ),
|
||
|
|
__( 'Dreamy', 'wp-fedistream' ),
|
||
|
|
__( 'Dark', 'wp-fedistream' ),
|
||
|
|
__( 'Groovy', 'wp-fedistream' ),
|
||
|
|
__( 'Epic', 'wp-fedistream' ),
|
||
|
|
__( 'Peaceful', 'wp-fedistream' ),
|
||
|
|
__( 'Motivational', 'wp-fedistream' ),
|
||
|
|
__( 'Nostalgic', 'wp-fedistream' ),
|
||
|
|
__( 'Playful', 'wp-fedistream' ),
|
||
|
|
__( 'Sensual', 'wp-fedistream' ),
|
||
|
|
__( 'Suspenseful', 'wp-fedistream' ),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Install default moods.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public static function install_defaults(): void {
|
||
|
|
$moods = self::get_default_moods();
|
||
|
|
|
||
|
|
foreach ( $moods as $mood ) {
|
||
|
|
if ( ! term_exists( $mood, 'fedistream_mood' ) ) {
|
||
|
|
wp_insert_term( $mood, 'fedistream_mood' );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|