API
2 years ago
Blocks
5 years ago
License
5 years ago
AdminNotice.php
5 years ago
AdminNotices.php
4 years ago
AjaxActions.php
2 years ago
Blocks.php
5 years ago
Compatibility.php
4 years ago
Menu.php
3 years ago
Migrations.php
5 years ago
Player.php
2 years ago
ProCompatibility.php
2 years ago
ReusableVideos.php
4 years ago
Scripts.php
2 years ago
Settings.php
4 years ago
Shortcodes.php
2 years ago
Streamer.php
4 years ago
Translation.php
2 years ago
VideoPostType.php
4 years ago
Menu.php
156 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PrestoPlayer\Services; |
| 4 | |
| 5 | use PrestoPlayer\Plugin; |
| 6 | use PrestoPlayer\WPackio\Enqueue; |
| 7 | |
| 8 | class Menu |
| 9 | { |
| 10 | protected $enqueue; |
| 11 | |
| 12 | public function register() |
| 13 | { |
| 14 | add_action('admin_menu', [$this, 'addMenu']); |
| 15 | } |
| 16 | |
| 17 | public function addMenu() |
| 18 | { |
| 19 | add_menu_page( |
| 20 | __('Presto Player', 'presto-player'), |
| 21 | __('Presto Player', 'presto-player'), |
| 22 | 'publish_posts', |
| 23 | 'edit.php?post_type=pp_video_block', |
| 24 | '', |
| 25 | PRESTO_PLAYER_PLUGIN_URL . 'img/menu-icon.svg' |
| 26 | ); |
| 27 | |
| 28 | add_submenu_page( |
| 29 | 'edit.php?post_type=pp_video_block', |
| 30 | __('Media Hub', 'presto-player'), |
| 31 | __('Media Hub', 'presto-player'), |
| 32 | 'publish_posts', |
| 33 | 'edit.php?post_type=pp_video_block' |
| 34 | ); |
| 35 | |
| 36 | $analyics_page = add_submenu_page( |
| 37 | 'edit.php?post_type=pp_video_block', |
| 38 | __('Analytics', 'presto-player'), |
| 39 | !Plugin::isPro() ? __('Analytics', 'presto-player') . ' <span class="update-plugins" style="background-color: #ffffff1c"><span class="plugin-count">Pro</span></span>' : __('Analytics', 'presto-player'), |
| 40 | 'publish_posts', |
| 41 | 'presto-analytics', |
| 42 | function () { |
| 43 | ob_start(); |
| 44 | ?> |
| 45 | <div class="presto-player-dashboard__header"> |
| 46 | <img class="presto-player-dashboard__logo" src="<?php echo esc_url(PRESTO_PLAYER_PLUGIN_URL . '/img/logo.svg'); ?>" /> |
| 47 | <div class="presto-player-dashboard__version">v<?php echo esc_html(Plugin::version()); ?></div> |
| 48 | </div> |
| 49 | <div id="presto-analytics-page"></div> |
| 50 | <?php wp_auth_check_html(); ?> |
| 51 | <?php |
| 52 | $page = ob_get_clean(); |
| 53 | echo $page; |
| 54 | } |
| 55 | ); |
| 56 | |
| 57 | add_action("admin_print_scripts-{$analyics_page}", [$this, 'analyticsAssets']); |
| 58 | |
| 59 | $settings_page = add_submenu_page( |
| 60 | 'edit.php?post_type=pp_video_block', |
| 61 | __('Presto Player Settings', 'presto-player'), |
| 62 | __('Settings', 'presto-player'), |
| 63 | 'manage_options', |
| 64 | 'presto-player-settings', |
| 65 | "PrestoPlayer\Services\Settings::template", |
| 66 | 5 |
| 67 | ); |
| 68 | |
| 69 | add_action("admin_print_scripts-{$settings_page}", [$this, 'settingsAssets']); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Scripts needed on settings page |
| 74 | */ |
| 75 | public function settingsAssets() |
| 76 | { |
| 77 | wp_enqueue_media(); |
| 78 | wp_enqueue_code_editor(['type' => "text/css"]); |
| 79 | |
| 80 | $assets = include trailingslashit(PRESTO_PLAYER_PLUGIN_DIR) . 'dist/settings.asset.php'; |
| 81 | wp_enqueue_script( |
| 82 | 'surecart/settings/admin', |
| 83 | trailingslashit(PRESTO_PLAYER_PLUGIN_URL) . 'dist/settings.js', |
| 84 | array_merge(['wp-codemirror'], $assets['dependencies']), |
| 85 | $assets['version'], |
| 86 | true |
| 87 | ); |
| 88 | // setting style. |
| 89 | wp_enqueue_style('surecart/settings/admin', trailingslashit(PRESTO_PLAYER_PLUGIN_URL) . 'dist/settings.css', [], $assets['version']); |
| 90 | |
| 91 | wp_enqueue_style('wp-components'); |
| 92 | |
| 93 | if (function_exists('wp_set_script_translations')) { |
| 94 | wp_set_script_translations('surecart/settings/admin', 'presto-player'); |
| 95 | } |
| 96 | |
| 97 | wp_localize_script( |
| 98 | 'surecart/settings/admin', |
| 99 | 'prestoPlayer', |
| 100 | apply_filters('presto-settings-js-options', [ |
| 101 | 'root' => esc_url_raw(get_rest_url()), |
| 102 | 'nonce' => wp_create_nonce('wp_rest'), |
| 103 | 'proVersion' => Plugin::proVersion(), |
| 104 | 'isSetup' => [ |
| 105 | 'bunny' => false |
| 106 | ], |
| 107 | 'isPremium' => Plugin::isPro(), |
| 108 | 'ajaxurl' => admin_url('admin-ajax.php'), |
| 109 | 'wpVersionString' => 'wp/v2/', |
| 110 | 'prestoVersionString' => 'presto-player/v1/', |
| 111 | 'debug' => defined('SCRIPT_DEBUG') && SCRIPT_DEBUG |
| 112 | ]) |
| 113 | ); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Scripts needed on analytics page |
| 118 | */ |
| 119 | public function analyticsAssets() |
| 120 | { |
| 121 | |
| 122 | $assets = include trailingslashit(PRESTO_PLAYER_PLUGIN_DIR) . 'dist/analytics.asset.php'; |
| 123 | wp_enqueue_script( |
| 124 | 'surecart/analytics/admin', |
| 125 | trailingslashit(PRESTO_PLAYER_PLUGIN_URL) . 'dist/analytics.js', |
| 126 | array_merge(['hls.js', 'presto-components', 'media'], $assets['dependencies']), |
| 127 | $assets['version'], |
| 128 | true |
| 129 | ); |
| 130 | wp_enqueue_style('surecart/analytics/admin', trailingslashit(PRESTO_PLAYER_PLUGIN_URL) . 'dist/analytics.css', [], $assets['version']); |
| 131 | |
| 132 | wp_enqueue_style('wp-components'); |
| 133 | wp_enqueue_media(); |
| 134 | |
| 135 | if (function_exists('wp_set_script_translations')) { |
| 136 | wp_set_script_translations('surecart/analytics/admin', 'presto-player'); |
| 137 | } |
| 138 | |
| 139 | wp_localize_script('surecart/analytics/admin', 'prestoPlayer', [ |
| 140 | 'root' => esc_url_raw(get_rest_url()), |
| 141 | 'isPremium' => Plugin::isPro(), |
| 142 | 'plugin_url' => esc_url_raw(trailingslashit(PRESTO_PLAYER_PLUGIN_URL)), |
| 143 | 'nonce' => wp_create_nonce('wp_rest'), |
| 144 | 'ajaxurl' => admin_url('admin-ajax.php'), |
| 145 | 'wpVersionString' => 'wp/v2/', |
| 146 | 'prestoVersionString' => 'presto-player/v1/', |
| 147 | 'i18n' => Translation::geti18n() |
| 148 | ]); |
| 149 | } |
| 150 | |
| 151 | public function template() |
| 152 | { |
| 153 | echo '<div id="presto-player-dashboard"></div>'; |
| 154 | } |
| 155 | } |
| 156 |