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.