| @@ -4,15 +4,16 @@ | ||
| 4 | 4 | |
| 5 | 5 | defined( 'ABSPATH' ) || exit; |
| 6 | 6 | |
| 7 | 7 | // Exit if accessed directly. |
| 8 | -use WPCoder\WOW_Plugin; | |
| 8 | +use WPCoder\Dashboard\DashboardHelper; | |
| 9 | +use WPCoder\WPCoder; | |
| 9 | 10 | |
| 10 | 11 | class AdminInitializer { |
| 11 | 12 | |
| 12 | 13 | public static function init(): void { |
| 13 | 14 | add_filter( 'plugin_action_links', [ __CLASS__, 'settings_link' ], 10, 2 ); |
| 14 | - add_filter( 'admin_footer_text', [ __CLASS__, 'footer_text' ] ); | |
| 15 | + add_filter( 'admin_footer_text', [ __CLASS__, 'footer_text' ], 20 ); | |
| 15 | 16 | add_action( 'admin_menu', [ __CLASS__, 'add_admin_page' ] ); |
| 16 | 17 | add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_scripts' ] ); |
| 17 | 18 | new AdminNotices; |
| 18 | 19 | new AdminActions; |
| @@ -18,12 +19,12 @@ | ||
| 18 | 19 | new AdminActions; |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | 22 | public static function settings_link( $links, $file ) { |
| 22 | - if ( false === strpos( $file, WOW_Plugin::basename() ) ) { | |
| 23 | + if ( false === strpos( $file, WPCoder::basename() ) ) { | |
| 23 | 24 | return $links; |
| 24 | 25 | } |
| 25 | - $link = admin_url( 'admin.php?page=' . WOW_Plugin::SLUG ); | |
| 26 | + $link = admin_url( 'admin.php?page=' . WPCoder::SLUG ); | |
| 26 | 27 | $text = esc_attr__( 'Settings', 'wpcoder' ); |
| 27 | 28 | $settings_link = '<a href="' . esc_url( $link ) . '">' . esc_attr( $text ) . '</a>'; |
| 28 | 29 | array_unshift( $links, $settings_link ); |
| 29 | 30 | |
| @@ -32,13 +33,13 @@ | ||
| 32 | 33 | |
| 33 | 34 | public static function footer_text( $footer_text ) { |
| 34 | 35 | global $pagenow; |
| 35 | 36 | |
| 36 | - if ( $pagenow === 'admin.php' && ( isset( $_GET['page'] ) && $_GET['page'] === WOW_Plugin::SLUG ) ) { | |
| 37 | + if ( $pagenow === 'admin.php' && ( isset( $_GET['page'] ) && $_GET['page'] === WPCoder::SLUG ) ) { | |
| 37 | 38 | $text = sprintf( |
| 38 | 39 | __( 'Thank you for using <b>%2$s</b>! Please <a href="%1$s" target="_blank">rate us</a>', 'wpcoder' ), |
| 39 | - esc_url( WOW_Plugin::PluginURL ), | |
| 40 | - esc_attr( WOW_Plugin::NAME ) | |
| 40 | + esc_url( WPCoder::PluginURL ), | |
| 41 | + esc_attr( WPCoder::info( 'name' ) ) | |
| 41 | 42 | ); |
| 42 | 43 | |
| 43 | 44 | return str_replace( '</span>', '', $footer_text ) . ' | ' . $text . '</span>'; |
| 44 | 45 | } |
| @@ -46,27 +47,92 @@ | ||
| 46 | 47 | return $footer_text; |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | public static function add_admin_page(): void { |
| 50 | - $parent = 'wow-company'; | |
| 51 | - $title = WOW_Plugin::NAME . ' version ' . WOW_Plugin::VERSION; | |
| 52 | - $menu_title = WOW_Plugin::NAME; | |
| 53 | - $capability = 'manage_options'; | |
| 54 | - $slug = WOW_Plugin::SLUG; | |
| 55 | - add_submenu_page( $parent, $title, $menu_title, $capability, $slug, [ __CLASS__, 'plugin_page' ] ); | |
| 51 | + $icon = 'data:image/svg+xml;base64,' . base64_encode( self::icon() ); | |
| 52 | + $parent = 'wp-coder'; | |
| 53 | + $title = WPCoder::info( 'name' ) . ' version ' . WPCoder::info( 'version' ); | |
| 54 | + $main_title = WPCoder::info( 'name' ); | |
| 55 | + $menu_title = 'All Codes'; | |
| 56 | + $capability = 'unfiltered_html'; | |
| 57 | + $slug = WPCoder::SLUG; | |
| 58 | + $url_update = 'https://wpcoder.pro/pricing/?utm_source=wordpress&utm_medium=admin-menu&utm_campaign=upgrade-to-pro'; | |
| 59 | + | |
| 60 | + add_menu_page( $main_title, $main_title, 'unfiltered_html', $slug, [ __CLASS__, 'plugin_page' ], $icon ); | |
| 61 | + | |
| 62 | + add_submenu_page( $slug, $title, $menu_title, $capability, $slug, [ __CLASS__, 'plugin_page' ] ); | |
| 63 | + | |
| 64 | + add_submenu_page( $slug, $title, 'Add new', $capability, $slug . '-settings', [ __CLASS__, 'settings' ] ); | |
| 65 | + add_submenu_page( $slug, $title, 'Snippets', $capability, $slug . '-snippets', [ __CLASS__, 'snippets' ] ); | |
| 66 | + add_submenu_page( $slug, $title, 'Global PHP', $capability, $slug . '-global', [ __CLASS__, 'global_php' ] ); | |
| 67 | + add_submenu_page( $slug, $title, 'Import / Export', $capability, $slug . '-tools', [ __CLASS__, 'tools' ] ); | |
| 68 | + add_submenu_page( $slug, $title, 'Support', $capability, $slug . '-support', [ __CLASS__, 'support' ] ); | |
| 69 | + add_submenu_page( $slug, $title, 'Upgrade to Pro', $capability, $url_update ); | |
| 56 | 70 | } |
| 57 | 71 | |
| 72 | + public static function icon(): string { | |
| 73 | + return '<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><title>48px_code</title><g><path d="M14.562 14.75a1.998 1.998 0 0 0-2.811-.312l-10.001 8a2 2 0 0 0 0 3.124l10 8a1.997 1.997 0 0 0 2.811-.312 2 2 0 0 0-.312-2.81L6.201 24l8.048-6.438a2 2 0 0 0 .312-2.81v-.003h.001z" fill="url(#1699598250888-4824476_nc-code-0_linear_235_116)"></path><path d="M36.25 14.438a2 2 0 0 0-2.499 3.123L41.799 24l-8.048 6.438a2 2 0 0 0 2.499 3.123l10-8a2 2 0 0 0 0-3.124l-10-8v.002z" fill="url(#1699598250888-4824476_nc-code-1_linear_235_116)"></path><path d="M29.535 4.073a2.003 2.003 0 0 0-2.462 1.392l-10 36a2 2 0 0 0 3.854 1.07l10-36a2 2 0 0 0-1.392-2.462z" fill="url(#1699598250888-4824476_nc-code-2_linear_235_116)"></path><defs><linearGradient id="1699598250888-4824476_nc-code-0_linear_235_116" x1="8" y1="13.999" x2="8" y2="34" gradientUnits="userSpaceOnUse"><stop stop-color="#5B5E71"></stop><stop offset="1" stop-color="#393A46"></stop></linearGradient><linearGradient id="1699598250888-4824476_nc-code-1_linear_235_116" x1="40" y1="13.999" x2="40" y2="33.998" gradientUnits="userSpaceOnUse"><stop stop-color="#5B5E71"></stop><stop offset="1" stop-color="#393A46"></stop></linearGradient><linearGradient id="1699598250888-4824476_nc-code-2_linear_235_116" x1="24" y1="4" x2="24" y2="44" gradientUnits="userSpaceOnUse"><stop stop-color="#E0E0E6"></stop><stop offset="1" stop-color="#C2C3CD"></stop></linearGradient></defs></g></svg>'; | |
| 74 | + } | |
| 75 | + | |
| 58 | 76 | public static function plugin_page(): void { |
| 59 | - do_action( WOW_Plugin::PREFIX . '_admin_page' ); | |
| 77 | + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/1.list.php'; | |
| 78 | + | |
| 79 | + if ( file_exists( $page_path ) ) { | |
| 80 | + require_once $page_path; | |
| 81 | + } | |
| 60 | 82 | } |
| 61 | 83 | |
| 84 | + public static function settings(): void { | |
| 85 | + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/2.settings.php'; | |
| 86 | + | |
| 87 | + if ( file_exists( $page_path ) ) { | |
| 88 | + require_once $page_path; | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 92 | + public static function snippets() { | |
| 93 | + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/3.snippets.php'; | |
| 94 | + | |
| 95 | + if ( file_exists( $page_path ) ) { | |
| 96 | + require_once $page_path; | |
| 97 | + } | |
| 98 | + } | |
| 99 | + | |
| 100 | + public static function global_php() { | |
| 101 | + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/global-php.php'; | |
| 102 | + | |
| 103 | + if ( file_exists( $page_path ) ) { | |
| 104 | + require_once $page_path; | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + public static function tools() { | |
| 109 | + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/3.tools.php'; | |
| 110 | + | |
| 111 | + if ( file_exists( $page_path ) ) { | |
| 112 | + require_once $page_path; | |
| 113 | + } | |
| 114 | + } | |
| 115 | + | |
| 116 | + public static function support() { | |
| 117 | + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/4.support.php'; | |
| 118 | + | |
| 119 | + if ( file_exists( $page_path ) ) { | |
| 120 | + require_once $page_path; | |
| 121 | + } | |
| 122 | + } | |
| 123 | + | |
| 62 | 124 | public static function admin_scripts( $hook ): void { |
| 63 | - $page = 'wow-plugins_page_' . WOW_Plugin::SLUG; | |
| 125 | +// $page = 'toplevel_page_' . WPCoder::SLUG; | |
| 126 | + $assets_url = WPCoder::url() . 'assets/'; | |
| 127 | + wp_enqueue_style( 'wowp-general-admin', $assets_url . 'css/admin-general.css' ); | |
| 64 | 128 | |
| 65 | - if ( $page !== $hook ) { | |
| 129 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; | |
| 130 | + | |
| 131 | + if ( strpos( $page, WPCoder::SLUG ) === false ) { | |
| 66 | 132 | return; |
| 67 | 133 | } |
| 68 | 134 | |
| 69 | - do_action( WOW_Plugin::PREFIX . '_admin_load_styles_scripts' ); | |
| 135 | + do_action( WPCoder::PREFIX . '_admin_load_styles_scripts' ); | |
| 70 | 136 | } |
| 71 | 137 | |
| 72 | 138 | } |