PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.3
WP Coder – Insert & Manage Code Snippets v4.3
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
← All changes | classes/Admin/AdminInitializer.php +109 -19 3.04.3 View file →
@@ -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,13 +19,13 @@
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 - $text = esc_attr__( 'Settings', 'wpcoder' );
26 + $link = admin_url( 'admin.php?page=' . WPCoder::SLUG );
27 + $text = esc_attr__( 'Settings', 'wp-coder' );
27 28 $settings_link = '<a href="' . esc_url( $link ) . '">' . esc_attr( $text ) . '</a>';
28 29 array_unshift( $links, $settings_link );
29 30
30 31 return $links;
@@ -32,13 +33,14 @@
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 - __( '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 )
39 + /* translators: 1. link to the plugin page 2. plugin name */
40 + __( 'Thank you for using <b>%2$s</b>! Please <a href="%1$s" target="_blank">rate us</a>', 'wp-coder' ),
41 + esc_url( WPCoder::PluginURL ),
42 + esc_attr( WPCoder::info( 'name' ) )
41 43 );
42 44
43 45 return str_replace( '</span>', '', $footer_text ) . ' | ' . $text . '</span>';
44 46 }
@@ -46,27 +48,115 @@
46 48 return $footer_text;
47 49 }
48 50
49 51 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' ] );
52 + $icon = 'data:image/svg+xml;base64,' . base64_encode( self::icon() );
53 + $parent = 'wp-coder';
54 + $title = WPCoder::info( 'name' ) . ' version ' . WPCoder::info( 'version' );
55 + $menu_title = 'All Codes';
56 + $capability = 'unfiltered_html';
57 + $slug = WPCoder::SLUG;
58 +
59 + add_menu_page( 'WP Coder Pro', 'WP Coder', 'unfiltered_html', $slug, [ __CLASS__, 'plugin_page' ], $icon );
60 +
61 + add_submenu_page( $slug, $title, $menu_title, $capability, $slug, [ __CLASS__, 'plugin_page' ] );
62 +
63 + add_submenu_page( $slug, $title, 'Add new', $capability, $slug . '-settings', [ __CLASS__, 'settings' ] );
64 + add_submenu_page( $slug, $title, 'Snippets', $capability, $slug . '-snippets', [ __CLASS__, 'snippets' ] );
65 + add_submenu_page( $slug, $title, 'Tools', $capability, $slug . '-tools', [ __CLASS__, 'tools' ] );
66 + add_submenu_page( $slug, $title, 'Global PHP', $capability, $slug . '-global', [ __CLASS__, 'global_php' ] );
67 + add_submenu_page( $slug, $title, 'Debug Log', $capability, $slug . '-debug', [ __CLASS__, 'debug_log' ] );
68 + add_submenu_page( $slug, $title, 'Import / Export', $capability, $slug . '-import-export', [ __CLASS__, 'import_export' ] );
69 + add_submenu_page( $slug, $title, 'Support', $capability, $slug . '-support', [ __CLASS__, 'support' ] );
70 +
56 71 }
57 72
73 + public static function icon(): string {
74 + return '<svg width="512" height="512" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
75 + <path id="1728127909379-8007129Oval-Copy" fill="#2b7fff" fill-rule="evenodd" stroke="none" d="M 496 101 C 496 128.614227 473.614227 151 446 151 C 418.385773 151 396 128.614227 396 101 C 396 73.385773 418.385773 51 446 51 C 473.614227 51 496 73.385773 496 101 Z"/>
76 + <g id="window-code">
77 + <path id="Path" fill="#212121" stroke="none" d="M 245.714279 232.714294 L 74.285713 61.285736 C 60.571426 47.571411 40 47.571411 26.285713 61.285736 C 12.571427 75 12.571427 95.571442 26.285713 109.285706 L 173.714279 256.714294 L 26.285713 404.142853 C 12.571427 417.857147 12.571427 438.428589 26.285713 452.142853 C 33.142857 459 40 462.428558 50.285713 462.428558 C 60.571426 462.428558 67.428574 459 74.285713 452.142853 L 245.714279 280.714294 C 259.428589 267 259.428589 246.428558 245.714279 232.714294 Z"/>
78 + <path id="Rounded-Rectangle" fill="#212121" fill-rule="evenodd" stroke="none" d="M 256 431 C 256 448.673096 270.326874 463 288 463 L 464 463 C 481.673096 463 496 448.673096 496 431 L 496 429 C 496 411.326904 481.673096 397 464 397 L 288 397 C 270.326874 397 256 411.326904 256 429 Z"/>
79 + </g>
80 +</svg>';
81 + }
82 +
58 83 public static function plugin_page(): void {
59 - do_action( WOW_Plugin::PREFIX . '_admin_page' );
84 + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/1.list.php';
85 +
86 + if ( file_exists( $page_path ) ) {
87 + require_once $page_path;
88 + }
60 89 }
61 90
91 + public static function settings(): void {
92 + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/2.settings.php';
93 +
94 + if ( file_exists( $page_path ) ) {
95 + require_once $page_path;
96 + }
97 + }
98 +
99 + public static function snippets() {
100 + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/3.snippets.php';
101 +
102 + if ( file_exists( $page_path ) ) {
103 + require_once $page_path;
104 + }
105 + }
106 +
107 + public static function tools() {
108 + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/4.tools.php';
109 +
110 + if ( file_exists( $page_path ) ) {
111 + require_once $page_path;
112 + }
113 + }
114 +
115 + public static function global_php() {
116 + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/5.global-php.php';
117 +
118 + if ( file_exists( $page_path ) ) {
119 + require_once $page_path;
120 + }
121 + }
122 +
123 +
124 + public static function import_export() {
125 + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/6.import-export.php';
126 +
127 + if ( file_exists( $page_path ) ) {
128 + require_once $page_path;
129 + }
130 + }
131 +
132 + public static function support() {
133 + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/7.support.php';
134 +
135 + if ( file_exists( $page_path ) ) {
136 + require_once $page_path;
137 + }
138 + }
139 +
140 + public static function debug_log() {
141 + $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/10.debug-log.php';
142 +
143 + if ( file_exists( $page_path ) ) {
144 + require_once $page_path;
145 + }
146 + }
147 +
62 148 public static function admin_scripts( $hook ): void {
63 - $page = 'wow-plugins_page_' . WOW_Plugin::SLUG;
149 +// $page = 'toplevel_page_' . WPCoder::SLUG;
150 + $assets_url = WPCoder::url() . 'assets/';
151 + wp_enqueue_style( 'wowp-general-admin', $assets_url . 'css/admin-general.css' );
64 152
65 - if ( $page !== $hook ) {
153 + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
154 +
155 + if ( strpos( $page, WPCoder::SLUG ) === false ) {
66 156 return;
67 157 }
68 158
69 - do_action( WOW_Plugin::PREFIX . '_admin_load_styles_scripts' );
159 + do_action( WPCoder::PREFIX . '_admin_load_styles_scripts' );
70 160 }
71 161
72 162 }