PluginProbe
PatternsWP – Gutenberg Block Patterns & Page Templates Library / 1.0.5
PatternsWP – Gutenberg Block Patterns & Page Templates Library v1.0.5
trunk 1.0.0 1.0.1 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
patternswp / includes / class-patternswp-admin.php

class-patternswp-admin.php in PatternsWP – Gutenberg Block Patterns & Page Templates Library 1.0.5, at includes/class-patternswp-admin.php

256 lines 14.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Page
4 */
5
6 class PatternsWP_Admin {
7
8 /**
9 * Constructor
10 */
11 public function __construct() {
12 // Add menu and pages
13 add_action('admin_menu', array($this, 'add_admin_menu'));
14 add_action('admin_init', array($this, 'patternswp_clear_cache'));
15 }
16
17 /**
18 * Add admin menu
19 */
20 public function add_admin_menu() {
21 // Custom SVG icon (base64 encoded)
22 $custom_icon = 'data:image/svg+xml;base64,' . base64_encode('
23 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="currentColor">
24 <path d="M9.34 24L4.45 21.16L4.03 20.92V15.3L9.34 12V24Z"/>
25 <path fill-rule="evenodd" clip-rule="evenodd" d="M14.66 9.2L20.97 6L14.66 2.8V9.2Z"/>
26 <path d="M14.66 2.8L9.34 6L4.03 9.2V2.8L9.34 0L14.66 2.8Z"/>
27 <path fill-rule="evenodd" clip-rule="evenodd" d="M10.79 11.44V17.84L14.66 15.3L20.97 12V6L14.66 9.2L10.79 11.44Z"/>
28 </svg>
29 ');
30
31 // Add top-level menu with custom SVG icon
32 $menu_slug = 'patternswp-plugin-menu';
33 add_menu_page(
34 'PatternsWP',
35 'PatternsWP',
36 'manage_options',
37 $menu_slug,
38 array($this, 'render_main_page'),
39 $custom_icon,
40 60
41 );
42
43 // Add subpages
44 $this->add_subpage($menu_slug, 'Dashboard', 'Dashboard', 'patternswp-plugin-menu', array($this, 'render_main_page'));
45 $this->add_subpage($menu_slug, 'Support', 'Support', 'patternswp-plugin-page-1', array($this, 'patternswp_support'));
46 $this->add_subpage($menu_slug, 'Clear Cache', 'Clear Cache', 'patternswp-clear-cache', array($this, 'patternswp_clear_cache_form'));
47 }
48
49 /**
50 * Add subpage
51 */
52 private function add_subpage($parent_slug, $page_title, $menu_title, $menu_slug, $callback) {
53 // Add subpage
54 add_submenu_page($parent_slug, $page_title, $menu_title, 'manage_options', $menu_slug, $callback);
55 }
56
57 /**
58 * Render main page
59 */
60 public function render_main_page() { ?>
61 <div class="wrap">
62 <h1><?php esc_html_e('PatternsWP', 'patternswp'); ?></h1>
63 <h2 class="nav-tab-wrapper">
64 <a href="?page=patternswp-plugin-menu" class="nav-tab nav-tab-active"><?php esc_html_e('Dashboard', 'patternswp'); ?></a>
65 <a href="?page=patternswp-plugin-page-1" class="nav-tab"><?php esc_html_e('Support', 'patternswp'); ?></a>
66 <a href="?page=patternswp-clear-cache" class="nav-tab"><?php esc_html_e('Clear Cache', 'patternswp'); ?></a>
67 <a href="?page=patternswp-license_section" class="nav-tab"><?php esc_html_e('License', 'patternswp'); ?></a>
68 </h2>
69 <div class="patterns-wp-tabs-content">
70 <div id="tab-1" class="patterns-wp-tab-content patterns-wp-tab-active">
71 <div class="wrap">
72 <div class="pw-feature-box big-box" style="max-width: 1280px; padding: 40px; background-color: white; border-radius: 10px; overflow: hidden;">
73 <div class="about__section has-1-columns">
74 <div class="column" style="text-align:center;">
75 <h4><?php echo esc_html('Hello, ' . wp_get_current_user()->display_name . ' 👋'); ?></h4>
76 <h1 class="feature-title"><?php esc_html_e('Welcome to PatternsWP', 'patternswp'); ?></h1>
77 <p><?php esc_html_e('Thanks for choosing PatternsWP! Follow these three simple steps to get started!', 'patternswp'); ?></p>
78 </div>
79 </div>
80 <div class="about__section has-3-columns">
81 <div class="column" style="padding: 40px;">
82 <div class="about__image">
83 <img src="<?php echo esc_url(plugin_dir_url(__FILE__) . 'pwp-welcome-01.png'); ?>" alt="" height="auto" width="100%">
84 </div>
85 <h4><?php esc_html_e('01. Open the PatternsWP Library', 'patternswp'); ?></h4>
86 <p><?php esc_html_e('When editing a page or post in the block editor, locate the PatternsWP Library button in the editor’s header. Click it to access a collection of pre-designed patterns and full-page templates.', 'patternswp'); ?></p>
87 </div>
88 <div class="column" style="padding: 40px;">
89 <div class="about__image">
90 <img src="<?php echo esc_url(plugin_dir_url(__FILE__) . 'pwp-welcome-02.png'); ?>" alt="" height="auto" width="100%">
91 </div>
92 <h4><?php esc_html_e('02. Browse Patterns & Templates', 'patternswp'); ?></h4>
93 <p><?php esc_html_e('Explore a diverse range of block patterns and full-page layouts. Use the search box or filter by category to quickly find the perfect design for your website.', 'patternswp'); ?></p>
94 </div>
95 <div class="column" style="padding: 40px;">
96 <div class="about__image">
97 <img src="<?php echo esc_url(plugin_dir_url(__FILE__) . 'pwp-welcome-03.png'); ?>" alt="" height="auto" width="100%">
98 </div>
99 <h4><?php esc_html_e('03. Add Patterns & Customize', 'patternswp'); ?></h4>
100 <p><?php esc_html_e('Once you’ve found the right pattern, add it to your page with a single click. Every pattern is fully customizable, allowing you to tweak colors, typography, and content effortlessly.', 'patternswp'); ?></p>
101 </div>
102 </div>
103 </div>
104 </div>
105 </div>
106 </div>
107 </div>
108 <?php }
109
110 /**
111 * Support page
112 */
113 public function patternswp_support() { ?>
114 <div class="wrap">
115 <h1><?php esc_html_e('Support', 'patternswp'); ?></h1>
116 <h2 class="nav-tab-wrapper">
117 <a href="?page=patternswp-plugin-menu" class="nav-tab"><?php esc_html_e('Dashboard', 'patternswp'); ?></a>
118 <a href="?page=patternswp-plugin-page-1" class="nav-tab nav-tab-active"><?php esc_html_e('Support', 'patternswp'); ?></a>
119 <a href="?page=patternswp-clear-cache" class="nav-tab"><?php esc_html_e('Clear Cache', 'patternswp'); ?></a>
120 <a href="?page=patternswp-license_section" class="nav-tab"><?php esc_html_e('License', 'patternswp'); ?></a>
121 </h2>
122 <div class="patterns-wp-tabs-content">
123 <div id="tab-1" class="patterns-wp-tab-content patterns-wp-tab-active">
124 </div>
125 <div id="tab-2" class="patterns-wp-tab-content">
126 <div class="wrap">
127 <div class="pw-feature-box big-box" style="max-width: 1280px; padding: 40px; background-color: white; border-radius: 10px; overflow: hidden;">
128 <div class="about__section has-1-columns">
129 <div class="column" style="">
130 <h1 class="feature-title"><?php esc_html_e('Support', 'patternswp'); ?></h1>
131 <p><?php esc_html_e('Need help with PatternsWP? Whether you have a question, need technical assistance, or just want to reach out, we’re here for you. Contact us, and we’ll be happy to assist!', 'patternswp'); ?></p>
132 </div>
133 <div style="height: 1px; background-color: #ccc; width: 100%; margin: 20px 0;"></div>
134 </div>
135 <div class="about__section has-2-columns">
136 <div class="column" style="padding-right: 100px;">
137
138 <h4><?php esc_html_e('Frequently asked questions', 'patternswp'); ?></h4>
139 <p>
140 <?php
141 printf(
142 esc_attr('Here, you will find answers to commonly asked questions about using PatternsWP. If you need further assistance, feel free to %s.', 'patternswp'),
143 '<a href="https://thepatternswp.com/contact/" target="_blank">'.esc_attr('contact us via the support form →', 'patternswp').'</a>'
144 );
145 ?>
146 </p>
147 </div>
148 <div class="column" style="padding: 0px;">
149 <h5>
150 <a href="https://thepatternswp.com/docs/getting-started-with-patternswp/" target="_blank" style="color: #3858e9; text-decoration: none;">
151 <?php esc_html_e('Getting Started with PatternsWP →', 'patternswp'); ?>
152 </a>
153 </h5>
154 <div style="height: 1px; background-color: #ccc; width: 100%; margin: 10px 0;"></div>
155 <h5>
156 <a href="https://thepatternswp.com/docs/how-to-install-patternswp/" target="_blank" style="color: #3858e9; text-decoration: none;">
157 <?php esc_html_e('How to install PatternsWP →', 'patternswp'); ?>
158 </a>
159 </h5> <div style="height: 1px; background-color: #ccc; width: 100%; margin: 10px 0;"></div>
160 <h5>
161 <a href="https://thepatternswp.com/docs/how-to-upgrade-patternswp-to-pro/" target="_blank" style="color: #3858e9; text-decoration: none;">
162 <?php esc_html_e('How to Upgrade PatternsWP to Pro →', 'patternswp'); ?>
163 </a>
164 </h5> <div style="height: 1px; background-color: #ccc; width: 100%; margin: 10px 0;"></div>
165 <h5>
166 <a href="https://thepatternswp.com/docs/patternswp-support/" target="_blank" style="color: #3858e9; text-decoration: none;">
167 <?php esc_html_e('PatternsWP Support →', 'patternswp'); ?>
168 </a>
169 </h5> <div style="height: 1px; background-color: #ccc; width: 100%; margin: 10px 0;"></div>
170 </div>
171
172 </div>
173 </div>
174 </div>
175 </div>
176 </div>
177 </div>
178 <?php }
179
180 /**
181 * Clear Cache page
182 */
183 public function patternswp_clear_cache_form() { ?>
184 <div class="wrap">
185 <h1><?php esc_html_e('Clear Cache', 'patternswp'); ?></h1>
186 <h2 class="nav-tab-wrapper">
187 <a href="?page=patternswp-plugin-menu" class="nav-tab"><?php esc_html_e('Dashboard', 'patternswp'); ?></a>
188 <a href="?page=patternswp-plugin-page-1" class="nav-tab"><?php esc_html_e('Support', 'patternswp'); ?></a>
189 <a href="?page=patternswp-clear-cache" class="nav-tab nav-tab-active"><?php esc_html_e('Clear Cache', 'patternswp'); ?></a>
190 <a href="?page=patternswp-license_section" class="nav-tab"><?php esc_html_e('License', 'patternswp'); ?></a>
191 </h2>
192 <div class="patterns-wp-tabs-content">
193 <div id="tab-1" class="patterns-wp-tab-content patterns-wp-tab-active">
194 <div class="wrap">
195 <div class="container" style="padding: 20px; background-color: white; border-radius: 5px; overflow: hidden; width: 70%;">
196 <div class="">
197 <form id="patternswp_clearcache_form" method="post">
198 <?php wp_nonce_field('patternswp_clear_cache_action', 'patternswp_clear_cache_nonce'); ?>
199 <input name="patternswp_clear_cache" type="submit" class="button button-primary" value="Clear Cache">
200 <div>
201 </div>
202 </form>
203 </div>
204 </div>
205 </div>
206 </div>
207 </div>
208 </div>
209 <?php }
210
211 /**
212 * Clear Cache
213 */
214 public function patternswp_clear_cache() {
215 global $wpdb;
216
217 if (isset($_POST['patternswp_clear_cache'])) {
218 if (!isset($_POST['patternswp_clear_cache_nonce']) || !wp_verify_nonce($_POST['patternswp_clear_cache_nonce'], 'patternswp_clear_cache_action')) {
219 wp_die(esc_attr('Security check failed. Please try again.', 'patternswp'));
220 }
221 if (!current_user_can('manage_options')) {
222 wp_die(esc_attr('You do not have sufficient permissions to perform this action.', 'patternswp'));
223 }
224
225 // Delete category type transient
226 delete_transient('patternswp_category_type');
227
228 // Delete all API-related transients
229 $pattern = '_transient_patternswp_';
230 $results = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s", $wpdb->esc_like($pattern) . '%'));
231
232 // Delete all patterns cache
233 $patterns = 'patterns_cache_';
234 $wpdb->query(
235 $wpdb->prepare(
236 "DELETE FROM $wpdb->options WHERE option_name LIKE %s",
237 $wpdb->esc_like($patterns) . '%'
238 )
239 );
240
241 foreach ($results as $transient) {
242 delete_option($transient);
243 delete_option(str_replace('_transient_', '_transient_timeout_', $transient));
244 }
245
246 wp_redirect(add_query_arg(array(
247 'page' => 'patternswp-clear-cache',
248 'pt_msg' => urlencode('Clear Cache Successfully'),
249 'status' => 'success'
250 ), admin_url('admin.php')));
251 exit;
252 }
253 }
254 }
255
256 new PatternsWP_Admin();