config = $config; $this->options = $options; $this->version = $version; if ($config["type"] === "fake_tab") { add_filter("wpdiscuz_settings", [$this, "addFakeTab"], $config["filter_priority"]); } else { add_action("wpdiscuz_settings_tab_after", [$this, "render"], $config["render_priority"], 2); if (!empty($config["sidebar_title"])) { add_filter("wpdiscuz_settings", [$this, "addToTeasersList"], $config["render_priority"]); } } add_action("admin_enqueue_scripts", [$this, "enqueue"]); } private function isAddonActive() { if (apply_filters($this->config["isactive_filter"], false)) { return true; } if (!empty($this->config["plugin_file"]) && function_exists("is_plugin_active")) { if (is_plugin_active($this->config["plugin_file"])) { return true; } } return false; } private function isNew() { if (empty($this->config["published"])) { return false; } return strtotime($this->config["published"]) >= strtotime("-3 months"); } public function addFakeTab($settings) { if ($this->isAddonActive()) { return $settings; } $settings["teasers"][$this->config["tab_key"]] = [ "title" => $this->config["title"], "title_original" => $this->config["title_original"], "icon" => !empty($this->config["icon"]) ? plugins_url(WPDISCUZ_DIR_NAME . "/" . $this->config["icon"]) : "", "icon-height" => "", "file_path" => $this->config["template_path"], "values" => null, "options" => [], "is_new" => $this->isNew(), "no_save" => true, ]; return $settings; } public function addToTeasersList($settings) { if ($this->isAddonActive()) { return $settings; } $settings["teasers"][$this->config["tab_key"]] = [ "title" => $this->config["sidebar_title"], "title_original" => $this->config["sidebar_title_original"], "icon" => !empty($this->config["icon"]) ? plugins_url(WPDISCUZ_DIR_NAME . "/" . $this->config["icon"]) : "", "icon-height" => "", "file_path" => null, "values" => null, "options" => [], "is_new" => $this->isNew(), "anchor" => !empty($this->config["anchor"]) ? $this->config["anchor"] : "", ]; return $settings; } public function render($tab, $setting) { if ($tab !== $this->config["tab_key"]) { return; } if ($this->isAddonActive()) { return; } include $this->config["template_path"]; } public function enqueue($hook) { if ($this->isAddonActive()) { return; } if (!isset($_GET["page"]) || $_GET["page"] !== WpdiscuzCore::PAGE_SETTINGS) { return; } if ($this->config["type"] === "inline") { // Only enqueue when on the tab (accordion JS + CSS needed there). if (!isset($_GET["wpd_tab"]) || $_GET["wpd_tab"] !== $this->config["tab_key"]) { return; } wp_enqueue_style( "wpd-pro-teasers-shared-css", plugins_url(WPDISCUZ_DIR_NAME . "/options/pro-teasers/assets/css/pro-teasers-shared.css"), [], $this->version ); wp_enqueue_script( "wpd-pro-teasers-shared-js", plugins_url(WPDISCUZ_DIR_NAME . "/options/pro-teasers/assets/js/pro-teasers-shared.js"), ["jquery"], $this->version, true ); return; } // fake_tab type wp_enqueue_style( "wpd-pro-teasers-shared-css", plugins_url(WPDISCUZ_DIR_NAME . "/options/pro-teasers/assets/css/pro-teasers-shared.css"), [], $this->version ); wp_enqueue_script( "wpd-pro-teasers-shared-js", plugins_url(WPDISCUZ_DIR_NAME . "/options/pro-teasers/assets/js/pro-teasers-shared.js"), ["jquery"], $this->version, true ); } }