public static function action_init()
 {
     global $bc_accounts;
     require_once BRIGHTCOVE_PATH . 'includes/classes/class-bc-errors.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/class-bc-callbacks.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/class-bc-logging.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/class-bc-playlist-shortcode.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/class-bc-video-shortcode.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/class-bc-video-upload.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/sync/class-bc-playlists.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/sync/class-bc-videos.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/sync/class-bc-players.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/class-bc-accounts.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/api/class-bc-api.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/api/class-bc-cms-api.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/api/class-bc-oauth.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/api/class-bc-player-management-api.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/class-bc-notifications.php';
     require_once BRIGHTCOVE_PATH . 'includes/classes/class-bc-tags.php';
     $locale = apply_filters('plugin_locale', get_locale(), 'brightcove');
     load_textdomain('brightcove', WP_LANG_DIR . '/brightcove/brightcove-' . $locale . '.mo');
     load_plugin_textdomain('brightcove', false, 'languages');
     // Preload Errors Class First
     new BC_Errors();
     new BC_Callbacks();
     $bc_accounts = new BC_Accounts();
     // Load Administrative Resources
     if (BC_Utility::current_user_can_brightcove()) {
         require_once BRIGHTCOVE_PATH . 'includes/classes/admin/api/class-bc-admin-media-api.php';
         require_once BRIGHTCOVE_PATH . 'includes/classes/admin/class-bc-admin-settings-page.php';
         require_once BRIGHTCOVE_PATH . 'includes/classes/admin/class-bc-admin-playlists-page.php';
         require_once BRIGHTCOVE_PATH . 'includes/classes/admin/class-bc-admin-videos-page.php';
         require_once BRIGHTCOVE_PATH . 'includes/classes/admin/class-bc-admin-sources.php';
         require_once BRIGHTCOVE_PATH . 'includes/classes/admin/class-bc-admin-user-profile.php';
         require_once BRIGHTCOVE_PATH . 'includes/classes/admin/class-bc-templates.php';
         // Load Brightcove API resources
         if ($bc_accounts->get_account_details_for_user()) {
             $cms_api = new BC_CMS_API();
             new BC_Notifications($cms_api);
         }
         new BC_Admin_Media_API();
         new BC_Admin_Settings_Page();
         new BC_Admin_Playlists_Page();
         new BC_Admin_Videos_Page();
         new BC_Admin_Sources();
         new BC_Admin_Templates();
         new BC_Admin_User_Profile();
     }
     new BC_Playlists();
     new BC_Videos();
     new BC_Players();
     add_action('admin_enqueue_scripts', array('BC_Setup', 'admin_enqueue_scripts'));
     add_action('wp_enqueue_scripts', array('BC_Setup', 'frontend_enqueue_scripts'));
     add_filter('upload_mimes', array('BC_Setup', 'mime_types'));
     add_action('media_buttons', array('BC_Setup', 'add_brightcove_media_button'));
     add_action('admin_footer', array('BC_Setup', 'add_brightcove_media_modal_container'));
     // Show admin notice only if there are not sources
     add_action('admin_notices', array('BC_Setup', 'bc_activation_admin_notices'));
 }
 public static function deactivate()
 {
     require_once BRIGHTCOVE_PATH . 'includes/class-bc-accounts.php';
     $bc_accounts = new BC_Accounts();
     $accounts = $bc_accounts->get_sanitized_all_accounts();
     foreach ($accounts as $account => $account_data) {
         $bc_accounts->set_current_account($account);
         $account_hash = $bc_accounts->get_account_hash();
         self::delete_cache_item('brightcove_oauth_access_token_' . $account_hash);
         $bc_accounts->restore_default_account();
     }
     self::delete_cache_item('brightcove_sync_playlists');
     self::delete_cache_item('brightcove_sync_videos');
     delete_option('_brightcove_plugin_activated');
 }
 public function delete_account($hash)
 {
     if (!BC_Accounts::get_account_by_hash($hash)) {
         return new WP_Error('brightcove-account-not-configured', esc_html__('The specified Brightcove Account has not been configured in WordPress', 'brightcove'));
     }
     $all_accounts = $this->get_all_accounts();
     $account_id = $all_accounts[$hash]['account_id'];
     $account_id_in_accounts_list = false;
     foreach ($all_accounts as $account) {
         if ($account_id === $account['account_id']) {
             $account_id_in_accounts_list = true;
         }
     }
     if ($account_id_in_accounts_list) {
         //only run deletion for the provided account ID if it is actually an active account.
         BC_Utility::remove_all_media_objects_for_account_id($account_id);
     }
     unset($all_accounts[$hash]);
     if ($hash === get_option('_brightcove_default_account')) {
         if (!empty($all_accounts)) {
             $remaining_accounts = $all_accounts;
             // The deleted account was the default. Now set the default to be the first account in the remaining list, if there is a remaining account
             $default_account = array_shift($remaining_accounts);
             $new_default_account = $default_account['hash'];
         } else {
             // Set default account to false instead of delete
             $new_default_account = false;
         }
         update_option('_brightcove_default_account', $new_default_account);
     }
     update_option($this->options_key, $all_accounts);
     return true;
 }