plugin_name = $plugin_name; $this->version = $version; } // ------------------------------------------------------------------// // PRO state // ------------------------------------------------------------------// /** * Whether the PRO add-on is installed and running. * * This edition reads no licence option: it only checks whether the * companion plugin is loaded. Unlocking happens inside the add-on, so no * feature of this plugin is gated by a licence check. * * While the add-on is absent the premium options stay visible as plain * text pointing to the separate plugin. * * @return bool */ public function is_pro_active() { return defined( 'FSWEB_COMMENTS_CORE_PRO_VERSION' ); } /** * URL of the product page. * * @return string */ private function pro_url() { return defined( 'FSWEB_COMMENTS_CORE_PRO_URL' ) ? FSWEB_COMMENTS_CORE_PRO_URL : 'https://flowsyncweb.com/'; } // ------------------------------------------------------------------// // Assets // ------------------------------------------------------------------// /** * Enqueue the admin stylesheet on our screens. * * The version comes from the file timestamp so a changed stylesheet is * never served from the browser cache. * * @param string $hook_suffix Current admin page. * @return void */ public function enqueue_styles( $hook_suffix ) { if ( ! $this->is_plugin_screen( $hook_suffix ) ) { return; } $stylesheet = FSWEB_COMMENTS_CORE_DIR . 'admin/css/fsweb-comments-core-admin.css'; wp_enqueue_style( $this->plugin_name, FSWEB_COMMENTS_CORE_URL . 'admin/css/fsweb-comments-core-admin.css', array(), file_exists( $stylesheet ) ? (string) filemtime( $stylesheet ) : $this->version ); } /** * Enqueue the admin script on our screens. * * @param string $hook_suffix Current admin page. * @return void */ public function enqueue_scripts( $hook_suffix ) { if ( ! $this->is_plugin_screen( $hook_suffix ) ) { return; } $script = FSWEB_COMMENTS_CORE_DIR . 'admin/js/fsweb-comments-core-admin.js'; wp_enqueue_script( $this->plugin_name, FSWEB_COMMENTS_CORE_URL . 'admin/js/fsweb-comments-core-admin.js', array(), file_exists( $script ) ? (string) filemtime( $script ) : $this->version, true ); } /** * Whether the current screen belongs to the plugin. * * @param string $hook_suffix Current admin page. * @return bool */ private function is_plugin_screen( $hook_suffix ) { if ( false !== strpos( (string) $hook_suffix, 'fsweb-comments-core' ) ) { return true; } $screen = get_current_screen(); return $screen && 'fsweb_review' === $screen->post_type; } // ------------------------------------------------------------------// // Menu // ------------------------------------------------------------------// /** * Register the submenu pages. * * With the add-on installed it owns the overview and both builders, so the * free edition only keeps the settings screen and the PRO page. * * @return void */ public function add_admin_menu() { $parent = 'edit.php?post_type=fsweb_review'; if ( ! $this->is_pro_active() ) { add_submenu_page( $parent, __( 'Overview', 'fsweb-comments-core' ), __( 'Overview', 'fsweb-comments-core' ), 'manage_options', 'fsweb-comments-core', array( $this, 'render_overview_page' ), 3 ); add_submenu_page( $parent, __( 'Form Builder', 'fsweb-comments-core' ), __( 'Form Builder', 'fsweb-comments-core' ), 'manage_options', 'fsweb-comments-core-builder', array( $this, 'render_builder_page' ), 4 ); add_submenu_page( $parent, __( 'Views Builder', 'fsweb-comments-core' ), __( 'Views Builder', 'fsweb-comments-core' ), 'manage_options', 'fsweb-comments-core-views', array( $this, 'render_views_page' ), 5 ); } add_submenu_page( $parent, __( 'Settings', 'fsweb-comments-core' ), __( 'Settings', 'fsweb-comments-core' ), 'manage_options', 'fsweb-comments-core-settings', array( $this, 'render_settings_page' ), 6 ); // The offer only exists while the add-on is not installed: with the // companion plugin there is nothing left to sell here. if ( ! $this->is_pro_active() ) { add_submenu_page( $parent, __( 'Go PRO', 'fsweb-comments-core' ), '', 'manage_options', 'fsweb-comments-core-go-pro', array( $this, 'render_go_pro_page' ), 7 ); } } /** * URL of one of our screens. * * @param string $slug Screen slug. * @return string */ private function page_url( $slug ) { return admin_url( 'edit.php?post_type=fsweb_review&page=' . $slug ); } // ------------------------------------------------------------------// // Shared UI // ------------------------------------------------------------------// /** * Screens shown in the hero navigation. * * @param string $current Slug of the current screen. * @return array */ private function nav_screens( $current ) { $screens = array(); $pro = $this->is_pro_active(); if ( $pro ) { $screens['fsweb-comments-core-pro'] = array( 'label' => __( 'Dashboard', 'fsweb-comments-core' ), 'icon' => 'dashicons-dashboard', ); } else { $screens['fsweb-comments-core'] = array( 'label' => __( 'Overview', 'fsweb-comments-core' ), 'icon' => 'dashicons-dashboard', ); } $screens['fsweb-comments-core-builder'] = array( 'label' => __( 'Form Builder', 'fsweb-comments-core' ), 'icon' => 'dashicons-feedback', ); $screens['fsweb-comments-core-views'] = array( 'label' => __( 'Views Builder', 'fsweb-comments-core' ), 'icon' => 'dashicons-layout', ); $screens['fsweb-comments-core-settings'] = array( 'label' => __( 'Settings', 'fsweb-comments-core' ), 'icon' => 'dashicons-admin-generic', ); if ( $pro ) { $screens['fsweb-comments-core-license'] = array( 'label' => __( 'License', 'fsweb-comments-core' ), 'icon' => 'dashicons-awards', ); } if ( ! $this->is_pro_active() ) { $screens['fsweb-comments-core-go-pro'] = array( 'label' => __( 'Go PRO', 'fsweb-comments-core' ), 'icon' => 'dashicons-star-filled', ); } return $screens; } /** * Render the hero header shared by every screen. * * @param string $title Screen title. * @param string $description One-line description. * @param string $current Slug of the current screen. * @return void */ private function render_hero( $title, $description, $current = '' ) { $screens = $this->nav_screens( $current ); ?>
is_pro_active() ) { return; } ?>