| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 |
|
| 4 |
class StreamCast_Admin { |
| 5 |
|
| 6 |
public function __construct() { |
| 7 |
// Hooks |
| 8 |
add_action('init', [$this, 'register_post_type']); |
| 9 |
add_filter('gettext', [$this, 'change_publish_button_text'], 10, 2); |
| 10 |
add_filter('post_updated_messages', [$this, 'custom_updated_message']); |
| 11 |
add_filter('post_row_actions', [$this, 'remove_row_actions'], 10, 2); |
| 12 |
add_action('admin_head-post.php', [$this, 'hide_publishing_actions']); |
| 13 |
add_action('admin_head-post-new.php', [$this, 'hide_publishing_actions']); |
| 14 |
add_filter('manage_streamcast_posts_columns', [$this, 'manage_columns'], 10); |
| 15 |
add_action('manage_streamcast_posts_custom_column', [$this, 'manage_custom_columns'], 10, 2); |
| 16 |
add_action('edit_form_after_title', [$this, 'shortcode_area']); |
| 17 |
} |
| 18 |
|
| 19 |
public function register_post_type() { |
| 20 |
register_post_type('streamcast', [ |
| 21 |
'labels' => [ |
| 22 |
'name' => __( 'StreamCast' ), |
| 23 |
'singular_name' => __( 'StreamCast' ), |
| 24 |
'add_new' => __( 'Add New Radio Player' ), |
| 25 |
'add_new_item' => __( 'Add New Radio' ), |
| 26 |
'edit_item' => __( 'Edit Radio' ), |
| 27 |
'new_item' => __( 'New Radio' ), |
| 28 |
'view_item' => __( 'View Portfolio' ), |
| 29 |
'search_items' => __( 'Search Portfolio' ), |
| 30 |
'not_found' => __( 'Sorry, we couldn\'t find the Portfolio you are looking for.' ), |
| 31 |
], |
| 32 |
'public' => false, |
| 33 |
'show_ui' => true, |
| 34 |
'publicly_queryable' => true, |
| 35 |
'exclude_from_search' => true, |
| 36 |
'menu_position' => 14, |
| 37 |
'menu_icon' => 'dashicons-microphone', |
| 38 |
'has_archive' => false, |
| 39 |
'hierarchical' => false, |
| 40 |
'capability_type' => 'page', |
| 41 |
'rewrite' => [ 'slug' => 'behance' ], |
| 42 |
'supports' => [ 'title' ], |
| 43 |
]); |
| 44 |
} |
| 45 |
|
| 46 |
public function change_publish_button_text( $translation, $original ) { |
| 47 |
global $post; |
| 48 |
if ( is_admin() && $post && $post->post_type === 'streamcast' ) { |
| 49 |
if ( $original === 'Publish' ) return 'Save'; |
| 50 |
if ( $original === 'Update' ) return 'Updated'; |
| 51 |
} |
| 52 |
return $translation; |
| 53 |
} |
| 54 |
|
| 55 |
public function custom_updated_message( $messages ) { |
| 56 |
global $post; |
| 57 |
if ( $post->post_type === 'streamcast' ) { |
| 58 |
$messages['streamcast'][1] = __('Updated', 'streamcast'); |
| 59 |
} |
| 60 |
return $messages; |
| 61 |
} |
| 62 |
|
| 63 |
public function remove_row_actions( $actions ) { |
| 64 |
global $post; |
| 65 |
if ( $post->post_type === 'streamcast' ) { |
| 66 |
unset( $actions['view'] ); |
| 67 |
unset( $actions['inline hide-if-no-js'] ); |
| 68 |
} |
| 69 |
return $actions; |
| 70 |
} |
| 71 |
|
| 72 |
public function hide_publishing_actions() { |
| 73 |
global $post; |
| 74 |
if ( $post && $post->post_type === 'streamcast' ) { |
| 75 |
echo '<style>#misc-publishing-actions,#minor-publishing-actions{display:none;}</style>'; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
public function manage_columns( $columns ) { |
| 80 |
unset($columns['date']); |
| 81 |
$columns['shortcode'] = 'Shortcode'; |
| 82 |
$columns['date'] = 'Date'; |
| 83 |
return $columns; |
| 84 |
} |
| 85 |
|
| 86 |
public function manage_custom_columns( $column_name, $post_ID ) { |
| 87 |
if ( $column_name === 'shortcode' ) { |
| 88 |
echo '<div class="bPlAdminShortcode" id="bPlAdminShortcode-' . esc_attr($post_ID) . '"> |
| 89 |
<input value="[radio_player id=' . esc_attr($post_ID) . ']" onclick="copyBPlAdminShortcode(\'' . esc_attr($post_ID) . '\')" readonly> |
| 90 |
<span class="tooltip">Copy To Clipboard</span> |
| 91 |
</div>'; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
public function shortcode_area() { |
| 96 |
global $post; |
| 97 |
if ( $post->post_type == 'streamcast' ) { |
| 98 |
?> |
| 99 |
<style> |
| 100 |
#btss_meta .postbox-header{display:none}.bshortcode{margin-top:30px;border:5px solid #4527a4;overflow:hidden}.shortcode-heading{background:#4527a4;padding:15px;overflow:hidden;color:#fff}.shortcode-heading .icon{float:left;overflow:hidden;width:50%}.shortcode-heading .text{float:right;overflow:hidden;text-align:right}.shortcode-heading .text a{color:#fff;display:block;text-decoration:none}.bshortcode .shortcode-left{width:50%;float:left;overflow:hidden;padding:20px 0 30px;text-align:center;background:#fff;border-right:5px solid #4527a4;box-sizing:border-box}.bshortcode .shortcode-right{width:50%;float:left;overflow:hidden;padding:20px 0 30px;text-align:center;background:#fff}.bshortcode .shortcode{padding:8px 15px;background:#eae6f9;display:inline-block;user-select:all;font-size:16px} |
| 101 |
</style> |
| 102 |
|
| 103 |
<div class="bshortcode"> |
| 104 |
<div class="shortcode-heading"> |
| 105 |
<div class="icon"><span class="dashicons dashicons-format-audio"></span> <?php _e( 'Radio Player', 'radio-player' )?></div> |
| 106 |
<div class="text"> <a href="https://bplugins.com/support/" target="_blank"><?php _e( 'Supports', 'radio-player' )?></a></div> |
| 107 |
</div> |
| 108 |
<div class="shortcode-left"> |
| 109 |
<h3><?php _e( 'Shortcode', 'radio-player' )?></h3> |
| 110 |
<p><?php _e( 'Copy and paste this shortcode into your posts or pages or widget content:', 'radio-player' )?></p> |
| 111 |
<div class="shortcode" selectable>[radio_player id='<?php echo esc_attr($post->ID); ?>']</div> |
| 112 |
</div> |
| 113 |
<div class="shortcode-right"> |
| 114 |
<h3><?php _e( 'Template Include', 'radio-player' )?></h3> |
| 115 |
<p><?php _e( 'Copy and paste the PHP code into your template file:', 'radio-player' )?></p> |
| 116 |
<div class="shortcode"><?php echo do_shortcode('[radio_player id="<?php echo esc_attr($post->ID); ?>"]'); |
| 117 |
?></div> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
<?php |
| 121 |
}} |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
// Initialize the admin logic |
| 126 |
new StreamCast_Admin(); |
| 127 |
|