plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function albaau_albatross_audio_enqueue_admin_styles($hook) { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/albatross-audio-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function albaau_albatross_audio_enqueue_admin_scripts($hook) { wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/albatross-audio-admin.js', array( 'jquery' ), $this->version, false ); // localize home_url() to use for player placeholder img wp_localize_script( $this->plugin_name, 'wpData', array( 'pluginUrl' => esc_url( plugins_url() ), ) ); } /*================================================================ * albatross_audio post type ==================================================================*/ public function albaau_albatross_audio() { $labels = array( 'name' => __('Albatross Audio', 'albatross-audio'), 'singular_name' => __('Playlist', 'albatross-audio'), 'add_new' => __('New Playlist', 'albatross-audio'), 'add_new_item' => __('New Playlist', 'albatross-audio'), 'edit_item' => __('Edit Playlist', 'albatross-audio'), 'new_item' => __('New Playlist', 'albatross-audio'), 'all_items' => __('Playlists', 'albatross-audio'), 'view_item' => __('View Playlist', 'albatross-audio'), 'search_items' => __('Search Playlists', 'albatross-audio'), 'not_found' => __('Nothing Found', 'albatross-audio'), 'not_found_in_trash' => __('Nothing Found In Trash', 'albatross-audio'), 'remove_featured_image' => __('Remove Image', 'albatross-audio'), 'parent_item_colon' => '', 'menu_name' => 'Albatross' ); $args = array( 'labels' => $labels, 'public' => true, 'hierarchical' => true, 'show_in_menu' => true, 'menu_position' => 11, 'menu_icon' => 'dashicons-playlist-audio', 'supports' => array( 'title', 'thumbnail' ), 'show_in_nav_menus' => true, 'has_archive' => 'albatross-audio', 'show_in_rest' => true, 'with_front' => false, 'rewrite' => array( 'slug' => 'albatross-audio', ) , ); register_post_type('albatross-audio', $args); } /*================================================================ * albatross_audio Taxonomy ==================================================================*/ public function albaau_albatross_audio_taxonomy() { $labels = array( 'name' => __( 'Albatross Audio Categories', 'albatross-audio' ), 'singular_name' => __( 'Category', 'albatross-audio' ), 'search_items' => __( 'Search Categories', 'albatross-audio' ), 'all_items' => __( 'All Categories', 'albatross-audio' ), 'parent_item' => __( 'Parent Category', 'albatross-audio' ), 'parent_item_colon' => __( 'Parent Category:', 'albatross-audio' ), 'edit_item' => __( 'Edit Category', 'albatross-audio' ), 'update_item' => __( 'Update Category', 'albatross-audio' ), 'add_new_item' => __( 'Add New Category', 'albatross-audio' ), 'new_item_name' => __( 'New Category Name', 'albatross-audio' ), 'menu_name' => __( 'Categories', 'albatross-audio' ), ); // register taxonomy register_taxonomy('albatross_audio_categories',array('albatross-audio'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_in_rest' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'category' ), )); } /*================================================================ * albatross_audio Admin Columns ==================================================================*/ public function albaau_albatross_audio_admin_columns( $columns ) { $columns = array( 'cb' => $columns['cb'], 'title' => __( 'Title', 'albatross-audio' ), 'songs' => __( 'Songs', 'albatross-audio' ), 'cats' => __( 'Categories', 'albatross-audio' ), 'shortcode' => __( 'Shortcode', 'albatross-audio' ), 'date' => $columns['date'], ); return $columns; } public function albaau_albatross_audio_admin_columns_data( $column, $post_id ) { // songs column if ( 'songs' === $column ) { $songs = get_post_meta($post_id, 'albatross_audio_songs', true ); if($songs) { echo ''.esc_html(count($songs)).''; } else { echo '0'; } } // shortcode column if ( 'shortcode' === $column ) { echo '[albatross-audio id='.esc_html(get_the_ID()).']'; } // cats column if ( 'cats' === $column ) { $terms = get_the_terms( get_the_ID(), 'albatross_audio_categories' ); if( ! empty($terms) ) { echo ''; if( is_array($terms) ) { foreach($terms as $term) { echo ''.esc_html($term->name).''; if (next($terms )) { echo ', '; } } } else { if (!is_wp_error($terms)) { if (!is_wp_error($terms)) { if (!is_wp_error($terms)) { if (!is_wp_error($terms) && isset($terms->name)) { echo esc_html($terms->name); } } } } } echo ''; } } } /*================================================================ * albatross_audio metabox ==================================================================*/ public function albaau_albatross_audio_songs_metabox() { add_meta_box( /** * Metabox ID for the Albatross Audio plugin. * * This ID is used to register the metabox for Albatross songs in the WordPress admin area. * * @var string $blr_albatross_songs_metabox */ 'blr_albatross_songs_metabox', // Metabox ID __('Songs', 'albatross-audio'), // Metabox title array($this, 'albaau_albatross_metabox_callback'), 'albatross-audio', // Post type 'normal', // Context 'high' // Priority ); } public function albaau_albatross_metabox_callback() { // Get the current post ID $post_id = get_the_ID(); // Nonce for security wp_nonce_field('albaau_albatross_audio_metabox_nonce', 'albaau_albatross_audio_metabox_nonce'); $songs = get_post_meta($post_id, 'albatross_audio_songs', true ); // Retrieve stored warnings and display them if ( 'auto-draft' !== get_post_status( $post_id ) ) { $warnings = get_option('albaau_albatross_audio_warnings', []); if (!empty($warnings)) { foreach ($warnings as $warning) { echo '
' . esc_html($warning) . '
If empty, the featured image will be set with the first available song thumbnail when post is saved.
" . esc_html($warning) . "