public function brightcove_profile_ui($user) { global $bc_accounts; $accounts = $bc_accounts->get_sanitized_all_accounts(); $default_account = BC_Utility::get_user_meta($user->ID, '_brightcove_default_account_' . get_current_blog_id(), true); if (!$default_account) { // If for some reason a user doesn't have a default account, fall back on the site default account $default_account = get_option('_brightcove_default_account'); } ?> <h3><img class="profile-brightcove-logo" src="<?php echo esc_url(BRIGHTCOVE_URL . 'images/menu-icon.svg'); ?> " /><?php esc_html_e('Brightcove Preferences', 'brightcove'); ?> </h3> <table class="form-table"> <tr> <th scope="row"><?php esc_html_e('Default Source', 'brightcove'); ?> </th> <td> <select name="bc-user-default-source"> <?php foreach ($accounts as $hash => $account) { echo sprintf('<option value="%1$s" ' . selected($default_account, $hash) . '>%2$s</option>', esc_attr($hash), esc_html($account['account_name'])); } ?> </select> </td> </tr> </table> <?php wp_nonce_field('bc_profile_nonce', '_bc_profile_nonce'); }
/** * @param bool $user_id (default is current ID) * * @return $account if exists or false if no accounts or permission denied. */ public function get_account_details_for_user($user_id = false) { if (!$user_id) { $user_id = get_current_user_id(); } else { if (!current_user_can('brightcove_get_user_default_account')) { return false; // Permissions violation. } } $hash = BC_Utility::get_user_meta($user_id, '_brightcove_default_account_' . get_current_blog_id(), true); if ('' !== $hash) { $account = $this->get_account_by_hash($hash); // Stored hash may have already been deleted, so we check that account exists. if ($account) { return $account; } } // No default account for user, revert to site default. $account = $this->get_account_details_for_site(); if ($account) { return $account; } // If no site default exists, just return the first account they have stored. $accounts = $this->get_all_accounts(); return current($accounts); }