| 1 |
<?php |
| 2 |
namespace StreamCast; |
| 3 |
|
| 4 |
if (!defined('ABSPATH')) exit; |
| 5 |
|
| 6 |
|
| 7 |
if (!class_exists('STREAMCAST_Admin')) { |
| 8 |
class STREAMCAST_Admin { |
| 9 |
public function __construct() { |
| 10 |
add_action('init', [__CLASS__, 'register_post_type']); |
| 11 |
add_filter('gettext', [$this, 'change_publish_button_text'], 10, 2); |
| 12 |
add_filter('post_updated_messages', [$this, 'custom_updated_message']); |
| 13 |
add_filter('post_row_actions', [$this, 'remove_row_actions'], 10, 2); |
| 14 |
add_action('admin_head-post.php', [$this, 'hide_publishing_actions']); |
| 15 |
add_action('admin_head-post-new.php', [$this, 'hide_publishing_actions']); |
| 16 |
add_filter('manage_streamcast_posts_columns', [$this, 'manage_columns'], 10); |
| 17 |
add_action('manage_streamcast_posts_custom_column', [$this, 'manage_custom_columns'], 10, 2); |
| 18 |
add_action('edit_form_after_title', [$this, 'shortcode_area']); |
| 19 |
} |
| 20 |
|
| 21 |
public static function register_post_type() { |
| 22 |
register_post_type('streamcast', [ |
| 23 |
'labels' => [ |
| 24 |
'name' => __('StreamCast', 'streamcast'), |
| 25 |
'singular_name' => __('StreamCast', 'streamcast'), |
| 26 |
'add_new' => __('Add New Radio Player', 'streamcast'), |
| 27 |
'add_new_item' => __('Add New Radio Player', 'streamcast'), |
| 28 |
'edit_item' => __('Edit Radio', 'streamcast'), |
| 29 |
'new_item' => __('New Radio', 'streamcast'), |
| 30 |
'view_item' => __('View Radio', 'streamcast'), |
| 31 |
'all_items' => __('All Player', 'streamcast'), |
| 32 |
'search_items' => __('Search Radio', 'streamcast'), |
| 33 |
'not_found' => __('Sorry, we couldn\'t find the Radio you are looking for.', 'streamcast'), |
| 34 |
], |
| 35 |
'public' => false, |
| 36 |
'show_ui' => true, |
| 37 |
'publicly_queryable' => true, |
| 38 |
'exclude_from_search' => true, |
| 39 |
'menu_position' => 14, |
| 40 |
'menu_icon' => 'dashicons-microphone', |
| 41 |
'has_archive' => false, |
| 42 |
'hierarchical' => false, |
| 43 |
'capability_type' => 'page', |
| 44 |
'rewrite' => ['slug' => 'behance'], |
| 45 |
'supports' => ['title'], |
| 46 |
]); |
| 47 |
} |
| 48 |
|
| 49 |
public function change_publish_button_text($translation, $original) |
| 50 |
{ |
| 51 |
global $post; |
| 52 |
if (is_admin() && $post && $post->post_type === 'streamcast') { |
| 53 |
if ($original === 'Publish') { |
| 54 |
return 'Save'; |
| 55 |
} |
| 56 |
if ($original === 'Update') { |
| 57 |
return 'Updated'; |
| 58 |
} |
| 59 |
} |
| 60 |
return $translation; |
| 61 |
} |
| 62 |
|
| 63 |
public function custom_updated_message($messages) |
| 64 |
{ |
| 65 |
global $post; |
| 66 |
if ($post && $post->post_type === 'streamcast') { |
| 67 |
$messages['streamcast'][1] = __('Updated', 'streamcast'); |
| 68 |
} |
| 69 |
return $messages; |
| 70 |
} |
| 71 |
|
| 72 |
public function remove_row_actions($actions) { |
| 73 |
global $post; |
| 74 |
if ($post && $post->post_type === 'streamcast') { |
| 75 |
unset($actions['view']); |
| 76 |
unset($actions['inline hide-if-no-js']); |
| 77 |
} |
| 78 |
return $actions; |
| 79 |
} |
| 80 |
|
| 81 |
public function hide_publishing_actions() { |
| 82 |
global $post; |
| 83 |
if ($post && $post->post_type === 'streamcast') { |
| 84 |
echo '<style>#misc-publishing-actions,#minor-publishing-actions{display:none;}</style>'; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
public function manage_columns($columns) |
| 89 |
{ |
| 90 |
unset($columns['date']); |
| 91 |
$columns['shortcode'] = 'Shortcode'; |
| 92 |
$columns['date'] = 'Date'; |
| 93 |
return $columns; |
| 94 |
} |
| 95 |
|
| 96 |
public function manage_custom_columns($column_name, $post_ID) |
| 97 |
{ |
| 98 |
if ($column_name === 'shortcode') { |
| 99 |
echo '<div class="bPlAdminShortcode" id="bPlAdminShortcode-' . esc_attr($post_ID) . '"> |
| 100 |
<input value="[radio_player id=' . esc_attr($post_ID) . ']" onclick="copyBPlAdminShortcode(\'' . esc_attr($post_ID) . '\')" readonly> |
| 101 |
<span class="tooltip">Copy To Clipboard</span> |
| 102 |
</div>'; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* The shortcode rail, under the title. One copy target, and the shortcode is |
| 108 |
* presented as the value it is rather than as a button -- same object as the |
| 109 |
* side column's copy rail, scaled up for the main column. |
| 110 |
* |
| 111 |
* The streamcast_shortcode_copy_btn class and the .copy-text span are the hooks |
| 112 |
* assets/admin.js binds to; it toggles .copied and swaps the label. |
| 113 |
*/ |
| 114 |
public function shortcode_area() { |
| 115 |
if ('streamcast' != get_post_type()) { |
| 116 |
return; |
| 117 |
} |
| 118 |
global $post; |
| 119 |
|
| 120 |
$shortcode = "[radio_player id='" . $post->ID . "']"; |
| 121 |
?> |
| 122 |
<div class="streamcast-rail-box"> |
| 123 |
<div class="streamcast-rail"> |
| 124 |
<span class="streamcast-rail__slot"> |
| 125 |
<span class="streamcast-jack" aria-hidden="true"></span> |
| 126 |
<span class="streamcast-rail__lbl"><?php esc_html_e('Shortcode', 'streamcast'); ?></span> |
| 127 |
</span> |
| 128 |
|
| 129 |
<code class="streamcast-rail__code"><?php echo esc_html($shortcode); ?></code> |
| 130 |
|
| 131 |
<button type="button" |
| 132 |
class="streamcast-rail__copy streamcast_shortcode_copy_btn" |
| 133 |
data-shortcode="<?php echo esc_attr($shortcode); ?>" |
| 134 |
title="<?php esc_attr_e('Copy shortcode', 'streamcast'); ?>"> |
| 135 |
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" aria-hidden="true" focusable="false"><rect x="9" y="9" width="12" height="12" rx="2"></rect><path d="M5 15V5a2 2 0 0 1 2-2h10"></path></svg> |
| 136 |
<span class="copy-text"><?php esc_html_e('Copy', 'streamcast'); ?></span> |
| 137 |
</button> |
| 138 |
</div> |
| 139 |
|
| 140 |
<p class="streamcast-rail__hint"><?php esc_html_e('Paste it into any post, page, or widget.', 'streamcast'); ?></p> |
| 141 |
</div> |
| 142 |
<?php |
| 143 |
} |
| 144 |
|
| 145 |
} |
| 146 |
} |
| 147 |
|