, Wow-Company * @copyright 2024 Dmytro Lobov * @license GPL-2.0+ * */ namespace FloatMenuLite\Admin; use FloatMenuLite\WOWP_Plugin; class Dashboard { public static function init(): void { add_filter( 'plugin_action_links', [ __CLASS__, 'settings_link' ], 10, 2 ); add_filter( 'admin_footer_text', [ __CLASS__, 'footer_text' ] ); add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_assets' ] ); add_action( 'admin_menu', [ __CLASS__, 'admin_page' ] ); AdminNotices::init(); } public static function settings_link( $links, $file ) { if ( false === strpos( $file, WOWP_Plugin::basename() ) ) { return $links; } $link = admin_url( 'admin.php?page=' . WOWP_Plugin::SLUG ); $text = esc_attr__( 'Settings', 'float-menu' ); $settings_link = '' . esc_attr( $text ) . ''; array_unshift( $links, $settings_link ); return $links; } public static function footer_text( $footer_text ) { global $pagenow; if ( $pagenow === 'admin.php' && ( isset( $_GET['page'] ) && $_GET['page'] === WOWP_Plugin::SLUG ) ) { $text = sprintf( /* translators: 1: Rating link (URL), 2: Plugin name */ __( 'Thank you for using %2$s! Please rate us', 'float-menu' ), esc_url( WOWP_Plugin::info( 'rating' ) ), esc_attr( WOWP_Plugin::info( 'name' ) ) ); return str_replace( '', '', $footer_text ) . ' | ' . $text . ''; } return $footer_text; } public static function admin_assets( $hook ): void { $page = 'wow-plugins_page_' . WOWP_Plugin::SLUG; if ( $page !== $hook ) { return; } do_action( WOWP_Plugin::PREFIX . '_admin_load_assets' ); $slug = WOWP_Plugin::SLUG; $version = WOWP_Plugin::info( 'version' ); $assets_url = WOWP_Plugin::url() . 'admin/assets/'; $styles = DashboardHelper::get_files( 'assets/css' ); if ( ! empty( $styles ) ) { foreach ( $styles as $key => $style ) { $name = $style['file']; $file = $key . '.' . $name; wp_enqueue_style( $slug . '-admin-' . $name, $assets_url . 'css/' . $file . '.css', null, $version ); } } $scripts = DashboardHelper::get_files( 'assets/js' ); if ( ! empty( $scripts ) ) { foreach ( $scripts as $key => $script ) { $name = $script['file']; $file = $key . '.' . $name; wp_enqueue_script( $slug . '-admin-' . $name, $assets_url . 'js/' . $file . '.js', [ 'jquery' ], $version, true ); } } } public static function admin_page(): void { $page_title = WOWP_Plugin::info( 'name' ); $menu_title = WOWP_Plugin::info( 'menu_title' ); $capability = 'manage_options'; $parent_slug = 'wow-company'; add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, WOWP_Plugin::SLUG, [ __CLASS__, 'dashboard' ] ); } public static function dashboard(): void { self::header(); echo '
'; self::menu(); self::include_pages(); echo '
'; } public static function header(): void { $logo_url = self::logo_url(); ?>
'; foreach ( $pages as $key => $page ) { $class = ( $page['file'] === $current_page ) ? ' nav-tab-active' : ''; $id = ''; if ( $action === 'update' && $page['file'] === 'settings' ) { $id = ( isset( $_REQUEST["id"] ) ) ? absint( $_REQUEST["id"] ) : ''; $page['name'] = __( 'Update', 'float-menu' ) . ' #' . $id; } elseif ( $page['file'] === 'settings' && ( $action !== 'new' && $action !== 'duplicate' ) ) { continue; } echo '' . esc_html( $page['name'] ) . ''; } echo ''; } public static function get_current_page(): string { $default = DashboardHelper::first_file( 'pages' ); return ( isset( $_REQUEST["tab"] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST["tab"] ) ) : $default; } public static function include_pages(): void { $current_page = self::get_current_page(); $pages = DashboardHelper::get_files( 'pages' ); $default = DashboardHelper::first_file( 'pages' ); $current = DashboardHelper::search_value( $pages, $current_page ) ? $current_page : $default; $file = DashboardHelper::get_file( $current, 'pages' ); if ( $file !== false ) { $file = apply_filters( WOWP_Plugin::PREFIX . '_admin_filter_file', $file, $current ); $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/' . $file; if ( file_exists( $page_path ) ) { require_once $page_path; } } } }