/** * Retrieve a list of players available for usage on the front-end * * Requires the following fields: * - nonce WordPress nonce to prevent replay attacks * - account ID of the account we're referencing * * Will return an array of objects (in JSON) representing available players. Each player will roughly contain: * - accountId (string) * - id (string) * - name (string) * - description (string) * - branches (object) * - created_at (datetime) * - url (string) * - embed_count (integer) * * @see http://docs.brightcove.com/en/video-cloud/player-management/reference/versions/v1/index.html#api-Players-Get_All_Players * * @global BC_Accounts $bc_accounts */ public function ajax_players() { global $bc_accounts; // Ensure all required fields were sent foreach (array('nonce', 'account') as $parameter) { if (!isset($_POST[$parameter])) { wp_send_json_error(); } } // Validate our nonce if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], '_bc_ajax_players')) { wp_send_json_error(); // Nonce was invalid, fail } // Set up the account from which we're fetching data $account_id = sanitize_text_field($_POST['account']); $account = $bc_accounts->set_current_account_by_id($account_id); if (false === $account) { wp_send_json_error(); // Account was invalid, fail } // Get players from Brightcove $players = $this->player_api->player_list(); // Restore our global, default account $bc_accounts->restore_default_account(); if (false === $players) { wp_send_json_error(); // Retrieval failed, fail } wp_send_json_success($players); }
/** * Check permission level for an account. * * @return array List of permission issues. */ protected function check_permissions_level() { $permission_issues = array(); $video_id = false; // Start enumerating permissions that we'll need to ensure the account is good. $cms_api = new BC_CMS_API(); // Create a video $video_creation = $cms_api->video_add(__('Brightcove WordPress plugin test video', 'brightcove')); if (!$video_creation || is_wp_error($video_creation)) { $permission_issues[] = esc_html__('create videos', 'brightcove'); } else { $video_id = $video_creation['id']; // Update a video $renamed_title = __('Brightcove WordPress plugin test video renamed', 'brightcove'); $video_renamed = $cms_api->video_update($video_id, array('name' => $renamed_title)); if (!$video_renamed || $renamed_title !== $video_renamed['name']) { $permission_issues[] = esc_html__('modify videos', 'brightcove'); } } $playlist = $cms_api->playlist_add(__('Brightcove WordPress plugin test playlist', 'brightcove')); if (!$playlist || !is_array($playlist) || !isset($playlist['id'])) { $permission_issues[] = esc_html__('create playlists', 'brightcove'); } else { // For use through other Playlist test API calls. $playlist_id = $playlist['id']; $update_data = array('video_ids' => array($video_id), 'type' => 'EXPLICIT'); $updated_playlist = $cms_api->playlist_update($playlist_id, $update_data); if (!$updated_playlist || !is_array($updated_playlist) || !isset($updated_playlist['id'])) { $permission_issues[] = esc_html__('modify playlists', 'brightcove'); } // Delete a playlist if (!$cms_api->playlist_delete($playlist_id)) { $permission_issues[] = esc_html__('delete playlists', 'brightcove'); } } // Delete a video if (!$cms_api->video_delete($video_id)) { $permission_issues[] = esc_html__('delete videos', 'brightcove'); } $player_api = new BC_Player_Management_API($this); // Fetch all players $players = $player_api->player_list(); if (is_wp_error($players) || !is_array($players['items'])) { $permission_issues[] = esc_html__('fetch players', 'brightcove'); } return $permission_issues; }
public function render_edit_html($account) { global $bc_accounts; ?> <div class="wrap"> <h2><?php printf('<img src="%s" class="brightcove-admin-icon"/>', plugins_url('images/admin/menu-icon.svg', dirname(dirname(__DIR__)))); ?> <?php esc_html_e('Edit Source', 'brightcove'); ?> </h2> <form action="" method="post"> <table class="form-table brightcove-add-source-name"> <tbody> <tr class="brightcove-account-row"> <th scope="row"><?php esc_html_e('Source Name', 'brightcove'); ?> </th> <td> <?php echo esc_html($account['account_name']); ?> </td> </tr> </tbody> </table> <table class="form-table brightcove-add-source-details"> <tbody> <tr class="brightcove-account-row"> <th scope="row"><?php esc_html_e('Account ID', 'brightcove'); ?> </th> <td> <?php echo esc_html($account['account_id']); ?> </td> </tr> </table> <table class="form-table"> <tr class="brightcove-account-row"> <th scope="row"><?php esc_html_e('Default Source', 'brightcove'); ?> </th> <td> <input type="checkbox" name="source-default-account" <?php checked(get_option('_brightcove_default_account'), $account['hash']); ?> > <?php esc_html_e('Make this the default source for new users', 'brightcove'); ?> </td> </tr> <!-- Pending Unblocking on Player API setting Default Player <tr class="brightcove-account-row"> <th scope="row"><?php esc_html_e('Default Player', 'brightcove'); ?> </th> <td> <?php $bc_accounts->get_account_details_for_user(); $player_api = new BC_Player_Management_API(); $players = $player_api->player_list(); ?> <select name="sources-players"> <?php foreach ($players['items'] as $player) { printf('<option value="%1$s" %3$s>%2$s</option>', esc_attr($player['id']), esc_html($player['name']), selected('default', $player['id'])); } ?> </select> </td> </tr>--> </table> <?php wp_nonce_field('_brightcove_check_oauth_for_source', 'brightcove-check_oauth', false, true); ?> <p class="submit"> <input type="hidden" name="hash" value="<?php echo esc_attr($account['hash']); ?> "> <input type="hidden" name="source-action" value="update"/> <input type="submit" name="brightcove-edit-account-submit" id="brightcove-edit-account-submit" class="button button-primary" value="<?php esc_html_e('Save Changes', 'brightcove'); ?> "> </p> </form> </div> <?php }