| 1 |
<?php |
| 2 |
namespace STP; |
| 3 |
|
| 4 |
if (!defined('ABSPATH')) exit; |
| 5 |
|
| 6 |
|
| 7 |
if (!class_exists('STP_Admin')) { |
| 8 |
class STP_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 |
public function shortcode_area() { |
| 107 |
if ('streamcast' != get_post_type()) { |
| 108 |
return; |
| 109 |
} |
| 110 |
global $post; |
| 111 |
$id = $post->ID; |
| 112 |
|
| 113 |
$shortcode = "[radio_player id='" . esc_attr($id) . "']"; |
| 114 |
?> |
| 115 |
<div class="stp_shortcode_box_after_title"> |
| 116 |
<label><?php esc_html_e('Copy and paste this shortcode into your posts, pages and widget', 'streamcast'); ?></label> |
| 117 |
<div class="shortcode_area"> |
| 118 |
<button class="button button-bplugins button-large stp_shortcode_copy_btn" |
| 119 |
data-shortcode="<?php echo esc_attr($shortcode) ?>"><span class="copy-text"><?php echo esc_html($shortcode); ?></span></button> |
| 120 |
<svg class='stp_shortcode_copy_btn' data-type="icon" |
| 121 |
data-shortcode='<?php echo esc_attr($shortcode) ?>' |
| 122 |
width='22px' height='22px' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'> |
| 123 |
<path |
| 124 |
d='M8 4V16C8 17.1046 8.89543 18 10 18L18 18C19.1046 18 20 17.1046 20 16V7.24162C20 6.7034 19.7831 6.18789 19.3982 5.81161L16.0829 2.56999C15.7092 2.2046 15.2074 2 14.6847 2H10C8.89543 2 8 2.89543 8 4Z' |
| 125 |
stroke='#000000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/> |
| 126 |
<path d='M16 18V20C16 21.1046 15.1046 22 14 22H6C4.89543 22 4 21.1046 4 20V9C4 7.89543 4.89543 7 6 7H8' |
| 127 |
stroke='#000000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/> |
| 128 |
</svg> |
| 129 |
</div> |
| 130 |
</div> |
| 131 |
<?php |
| 132 |
} |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
new STP_Admin(); |
| 137 |
} |
| 138 |
|