pluginPrefix = $pluginPrefix; $this->pluginInstallSearching = $pluginInstallSearching; $this->pluginDirURL = $pluginDirURL; $this->pluginFolderSlug = $pluginFolderSlug; } public static function get_instance($pluginPrefix, $pluginInstallSearching, $pluginDirURL, $pluginFolderSlug) { if (null == self::$instance) { self::$instance = new static($pluginPrefix, $pluginInstallSearching, $pluginDirURL, $pluginFolderSlug); self::$instance->doHooks(); } return self::$instance; } public function is_plugin_exist() { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $all_plugins = get_plugins(); if (is_array($this->pluginFolderSlug)) { foreach ($this->pluginFolderSlug as $slug) { if (array_key_exists($slug, $all_plugins)) return true; } } else { if (array_key_exists($this->pluginFolderSlug, $all_plugins)) return true; } return false; } public function doHooks() { add_action('init', function(){ if (!$this->is_plugin_exist()) { $notificationOption = get_option("njt_notification_{$this->pluginPrefix}_cross"); //Save the next time notification will appear $popupOption = get_option("njt_popup_{$this->pluginPrefix}_cross"); //Save the next time notification will appear if ($notificationOption === false || time() >= +$notificationOption ) { add_action('admin_notices', array($this, 'add_notification')); add_action("wp_ajax_njt_{$this->pluginPrefix}_cross_notification", array($this, 'ajax_set_notification')); } if ($popupOption === false || time() >= $popupOption) { $this->showPopup = true; } add_action('wp_dashboard_setup', array($this, 'add_dashboard')); add_action('admin_footer', array($this, 'add_global_script_styles')); add_action("wp_ajax_njt_{$this->pluginPrefix}_cross_install", array($this, 'ajax_install_plugin')); add_action("wp_ajax_njt_{$this->pluginPrefix}_cross_hide", array($this, 'ajax_hide_cross')); } }); } public function need_update_option(){ $time = time() + (1 * 60 * 60 * 24); //1 day update_option("njt_popup_{$this->pluginPrefix}_cross", $time); update_option("njt_notification_{$this->pluginPrefix}_cross", $time); } public function add_global_script_styles() { if ( function_exists('current_user_can') && current_user_can('install_plugins') ) { $nonce = wp_create_nonce('install-plugin_' . $this->pluginPrefix); $url = self_admin_url('update.php?action=install-plugin&plugin=' . $this->pluginPrefix . '&_wpnonce=' . $nonce); } else { $url = admin_url("plugin-install.php?s={$this->pluginInstallSearching}&tab=search&type=term"); } if ( function_exists('get_current_screen') ) { $screen = get_current_screen(); if ( !in_array($screen->id , array('plugins', 'dashboard', 'upload')) ) return; } else return; wp_register_script("njt-popup-{$this->pluginPrefix}-cross", $this->pluginDirURL . '/assets/js/cross.js', ['jquery'], '1.0', true); wp_localize_script("njt-popup-{$this->pluginPrefix}-cross", 'njtCross', array( 'nonce' => wp_create_nonce("njt_{$this->pluginPrefix}_cross_nonce"), 'media_url' => admin_url('upload.php'), 'filebird_install_url' => $url, 'show_popup' => $this->showPopup )); wp_enqueue_script("njt-popup-{$this->pluginPrefix}-cross"); ?> id, array('plugins')) ) return; } else return; if ( function_exists('current_user_can') && current_user_can('install_plugins') ) { $nonce = wp_create_nonce('install-plugin_' . $this->pluginPrefix); $url = self_admin_url('update.php?action=install-plugin&plugin=' . $this->pluginPrefix . '&_wpnonce=' . $nonce); } else { $url = admin_url("plugin-install.php?s={$this->pluginInstallSearching}&tab=search&type=term"); } ?>

To easily manage your files in WordPress media library with folders, please try FileBird plugin.

filebird

Your WordPress media library is messy?

Start using FileBird to organize your files into folders by drag and drop.
screenshot_demo
Install for free
Go Pro
_('You do not have permission to install plugins.'))); wp_die(); } $installed = $this->pluginInstaller('filebird'); if ($installed === false) { wp_send_json_error(array('message' => $installed)); } try { $result = activate_plugin('filebird/filebird.php'); if (is_wp_error($result)) { throw new \Exception($result->get_error_message()); } wp_send_json_success(); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function pluginInstaller ($slug) { require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); require_once( ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php' ); require_once( ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php' ); $api = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => false, 'donate_link' => false, ), ) ); if (is_wp_error($api)) { throw new \Exception(_('Could not fetch plugin information.')); } $skin = new \WP_Ajax_Upgrader_Skin(); $upgrader = new \Plugin_Upgrader( $skin ); try { $result = $upgrader->install( $api->download_link ); if (is_wp_error($result)) { throw new \Exception($result->get_error_message()); } return true; } catch (\Exception $e) { throw new \Exception($e->getMessage()); } return false; } public function ajax_set_notification(){ check_ajax_referer("njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true); //Save after 30 days update_option("njt_notification_{$this->pluginPrefix}_cross", time() + (30 * 60 * 60 * 24)); wp_send_json_success(); } public function ajax_hide_cross(){ check_ajax_referer("njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true); $type = sanitize_text_field($_POST['type']); $time = time() + (30 * 60 * 60 * 24); // hide 30 days update_option("njt_{$type}_{$this->pluginPrefix}_cross", $time); wp_send_json_success(); } } } if ( !class_exists('FileBirdCross') ) { class FileBirdCross extends NjtCross { public function is_plugin_exist() { return ( defined('NJT_FILEBIRD_VERSION') || defined('NJFB_VERSION') || parent::is_plugin_exist() ); } } FileBirdCross::get_instance('filebird', 'filebird+ninjateam', NJT_FS_BN_PLUGIN_URL, array('filebird/filebird.php', 'filebird-pro/filebird.php')); }