setup_globals(); $this->includes(); $this->setup_actions(); } /** * Admin globals * * @since version (1.0) * @access private * * @uses buddydrive() to get some globals of plugin instance * @uses bp_core_do_network_admin() to define the best menu (network) */ private function setup_globals() { $buddydrive = buddydrive(); $this->admin_dir = trailingslashit( $buddydrive->includes_dir . 'admin' ); // Admin path $this->admin_url = trailingslashit( $buddydrive->includes_url . 'admin' ); // Admin url $this->styles_url = trailingslashit( $this->admin_url . 'css' ); // Admin styles URL*/ $this->js_url = trailingslashit( $this->admin_url . 'js' ); $this->settings_page = 'options-general.php'; $this->notice_hook = 'admin_notices' ; $this->user_columns_filter = 'manage_users_columns'; $this->requires_db_upgrade = buddydrive_get_db_number_version() < buddydrive_get_number_version(); if ( bp_core_do_network_admin() ) { $this->settings_page = 'settings.php'; $this->notice_hook = 'network_admin_notices'; $this->user_columns_filter = 'wpmu_users_columns'; $this->buddydrive_page = esc_url( add_query_arg( 'page','buddydrive-files', network_admin_url( 'admin.php' ) ) ); } else { $this->buddydrive_page = esc_url( add_query_arg( 'page','buddydrive-files', admin_url( 'admin.php' ) ) ); } // We are now using a BackBone UI $this->items_admin_callback = array( $this, 'items_admin_screen' ); /** * Use add_filter( 'buddydrive_use_deprecated_ui', '__return_true' ); to use the deprecated UI */ if ( true === buddydrive_use_deprecated_ui() ) { $this->items_admin_callback = 'buddydrive_files_admin'; } } /** * Include required files * * @since version (1.0) * @access private */ private function includes() { require( $this->admin_dir . 'buddydrive-settings.php' ); /** * Use add_filter( 'buddydrive_use_deprecated_ui', '__return_true' ); to use the deprecated UI */ if ( true === buddydrive_use_deprecated_ui() ) { require( $this->admin_dir . 'buddydrive-items.php' ); } } /** * Setup the admin hooks, actions and filters * * @since version (1.0) * @access private * * @uses add_action() To add various actions * @uses bp_core_admin_hook() to hook the right menu (network or not) * @uses add_filter() To add various filters */ private function setup_actions() { // Bail if config does not match what we need if ( buddydrive::bail() ) return; /** General Actions ***************************************************/ add_action( bp_core_admin_hook(), array( $this, 'admin_menus' ) ); // Add menu item to settings menu add_action( 'buddydrive_admin_head', array( $this, 'admin_head' ) ); // Add some general styling to the admin area add_action( $this->notice_hook, array( $this, 'activation_notice' ), 9 ); // Checks for BuddyDrive Upload directory once activated add_action( 'buddydrive_admin_register_settings', array( $this, 'register_admin_settings' ) ); // Add settings add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10, 1 ); // Add enqueued JS and CSS add_action( 'wp_ajax_buddydrive_upgrader', array( $this, 'do_upgrade' ) ); /** Filters ***********************************************************/ // Modify BuddyDrive's admin links add_filter( 'plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 ); add_filter( 'network_admin_plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 ); if ( ! buddydrive_use_deprecated_ui() ) { add_filter( 'bp_admin_menu_order', array( $this, 'items_admin_menu_order' ), 10, 1 ); } // Allow plugins to modify these actions do_action_ref_array( 'buddydrive_admin_loaded', array( &$this ) ); } /** * Builds BuddyDrive admin menus * * @uses bp_current_user_can() to check for user's capability * @uses add_submenu_page() to add the settings page * @uses add_menu_page() to add the admin area for BuddyDrive items * @uses add_dashboard_page() to add the BuddyDrive Welcome Screen */ public function admin_menus() { // Bail if user cannot manage options if ( ! bp_current_user_can( 'manage_options' ) ) return; $this->hook_suffixes[] = add_submenu_page( $this->settings_page, _x( 'BuddyDrive', 'BuddyDrive Settings page title', 'buddydrive' ), _x( 'BuddyDrive', 'BuddyDrive Settings menu title', 'buddydrive' ), 'manage_options', 'buddydrive', 'buddydrive_admin_settings' ); $hook = add_menu_page( _x( 'BuddyDrive', 'BuddyDrive User Files Admin page title', 'buddydrive' ), _x( 'BuddyDrive', 'BuddyDrive User Files Admin menu title', 'buddydrive' ), 'manage_options', 'buddydrive-files', $this->items_admin_callback, 'div' ); $this->hook_suffixes[] = $hook; // About $this->hook_suffixes[] = add_dashboard_page( __( 'Welcome to BuddyDrive', 'buddydrive' ), __( 'Welcome to BuddyDrive', 'buddydrive' ), 'manage_options', 'buddydrive-about', array( $this, 'about_screen' ) ); // Upgrade DB Screen if ( $this->requires_db_upgrade ) { $this->hook_suffixes['upgrade'] = add_dashboard_page( __( 'BuddyDrive Upgrades', 'buddydrive' ), __( 'BuddyDrive Upgrades', 'buddydrive' ), 'manage_options', 'buddydrive-upgrade', array( $this, 'upgrade_screen' ) ); } /** * Use add_filter( 'buddydrive_use_deprecated_ui', '__return_true' ); to use the deprecated UI */ if ( true === buddydrive_use_deprecated_ui() ) { // Hook into early actions to load custom CSS and our init handler. add_action( "load-$hook", 'buddydrive_files_admin_load' ); } // Putting user edit hooks there, this way we're sure they will load at the right place add_action( 'edit_user_profile', array( $this, 'edit_user_quota' ), 10, 1 ); add_action( 'edit_user_profile_update', array( $this, 'save_user_quota' ), 10, 1 ); add_action( 'set_user_role', array( $this, 'update_user_quota_to_role' ), 10, 2 ); add_filter( $this->user_columns_filter, array( $this, 'user_quota_column' ) ); add_filter( 'manage_users_custom_column', array( $this, 'user_quota_row' ), 10, 3 ); if( is_multisite() ) { $hook_settings = $this->hook_suffixes[0]; add_action( "load-$hook_settings", array( $this, 'multisite_upload_trick' ) ); } } /** * Loads some common css and hides the BuddyDrive about submenu * * @uses remove_submenu_page() to remove the BuddyDrive About submenu */ public function admin_head() { // Hide About page remove_submenu_page( 'index.php', 'buddydrive-about' ); if ( $this->requires_db_upgrade ) { remove_submenu_page( 'index.php', 'buddydrive-upgrade' ); } $version = buddydrive_get_version(); ?> id ) && in_array( $current_screen->id, $this->hook_suffixes ) ) { $display_upgrade_notice = false; } if ( $this->requires_db_upgrade && $display_upgrade_notice ) { bp_core_add_admin_notice( sprintf( __( 'BuddyDrive is almost ready. It needs to update some of the datas it is using. If you have not done a database backup yet, please do it before clicking on this link.', 'buddydrive' ), esc_url( add_query_arg( array( 'page' => 'buddydrive-upgrade' ), bp_get_admin_url( 'index.php' ) ) ) ), 'error' ); } } /** * Registers admin settings for BuddyDrive * * @uses buddydrive_admin_get_settings_sections() to get the settings section * @uses buddydrive_admin_get_settings_fields_for_section() to get the fields * @uses bp_current_user_can() to check for user's capability * @uses add_settings_section() to add the settings section * @uses add_settings_field() to add the fields * @uses register_setting() to fianlly register the settings */ public static function register_admin_settings() { // Bail if no sections available $sections = buddydrive_admin_get_settings_sections(); if ( empty( $sections ) ) return false; // Loop through sections foreach ( (array) $sections as $section_id => $section ) { // Only proceed if current user can see this section if ( ! bp_current_user_can( 'manage_options' ) ) continue; // Only add section and fields if section has fields $fields = buddydrive_admin_get_settings_fields_for_section( $section_id ); if ( empty( $fields ) ) continue; // Add the section add_settings_section( $section_id, $section['title'], $section['callback'], $section['page'] ); // Loop through fields for this section foreach ( (array) $fields as $field_id => $field ) { // Add the field add_settings_field( $field_id, $field['title'], $field['callback'], $section['page'], $section_id, $field['args'] ); // Register the setting register_setting( $section['page'], $field_id, $field['sanitize_callback'] ); } } } /** * Eqnueues scripts and styles if needed * * @param string $hook the WordPress admin page * @uses wp_enqueue_style() to enqueue the style * @uses wp_enqueue_script() to enqueue the script */ public function enqueue_scripts( $hook = false ) { if ( ! in_array( $hook, $this->hook_suffixes ) ) { return; } $min = '.min'; if ( defined( 'SCRIPT_DEBUG' ) && true == SCRIPT_DEBUG ) { $min = ''; } wp_enqueue_style( 'buddydrive-admin-css', $this->styles_url . "buddydrive-admin{$min}.css", array(), buddydrive_get_version() ); if ( ! empty( $this->hook_suffixes[1] ) && $hook == $this->hook_suffixes[1] && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) { /** * Use add_filter( 'buddydrive_use_deprecated_ui', '__return_true' ); to use the deprecated UI */ if ( true === buddydrive_use_deprecated_ui() ) { wp_enqueue_script ( 'buddydrive-admin-js', $this->js_url .'buddydrive-admin.js' ); wp_localize_script( 'buddydrive-admin-js', 'buddydrive_admin', buddydrive_get_js_l10n() ); } } if ( isset( $this->hook_suffixes['upgrade'] ) && $hook === $this->hook_suffixes['upgrade'] ) { wp_register_script( 'buddydrive-upgrader-js', $this->js_url . "buddydrive-upgrader{$min}.js", array( 'jquery', 'json2', 'wp-backbone' ), buddydrive_get_version(), true ); } } /** * Modifies the links in plugins table * * @param array $links the existing links * @param string $file the file of plugins * @uses plugin_basename() to get the file name of BuddyDrive plugin * @uses add_query_arg() to add args to the link * @uses bp_get_admin_url() to build the new links * @return array the existing links + the new ones */ public function modify_plugin_action_links( $links, $file ) { // Return normal links if not BuddyPress if ( plugin_basename( buddydrive()->file ) != $file ) return $links; // Add a few links to the existing links array return array_merge( $links, array( 'settings' => '' . esc_html__( 'Settings', 'buddydrive' ) . '', 'about' => '' . esc_html__( 'About', 'buddydrive' ) . '' ) ); } /** * Displays the Welcome screen * * @uses buddydrive_get_version() to get the current version of the plugin * @uses bp_get_admin_url() to build the url to settings page * @uses add_query_arg() to add args to the url */ public function about_screen() { $display_version = buddydrive_get_version(); $settings_url = add_query_arg( array( 'page' => 'buddydrive'), bp_get_admin_url( $this->settings_page ) ); ?>
ID ) ) return; $user_quota = buddydrive_get_quota_by_user_id( $profileuser->ID ); ?>$task ) { if ( ! empty( $task['count'] ) && 'upgrade_db_version' !== $task['action_id'] ) { $tasks[ $key ]['count'] = $wpdb->get_var( $task['count'] ); // If nothing needs to be ugraded, remove the task. if ( empty( $tasks[ $key ]['count'] ) ) { unset( $tasks[ $key ] ); } else { $tasks[ $key ]['message'] = sprintf( $task['message'], $tasks[ $key ]['count'] ); } } } printf( _n( 'BuddyDrive is almost ready, please wait for the %s following task to proceed.', 'BuddyDrive is almost ready, please wait for the %s following tasks to proceed.', count( $tasks ), 'buddydrive' ), number_format_i18n( count( $tasks ) ) ); } ?>