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
wp-coder / includes / class-wowp-dashboard.php

class-wowp-dashboard.php in WP Coder – Insert & Manage Code Snippets 4.3, at includes/class-wowp-dashboard.php

129 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPCoder;
4
5 use WPCoder\Admin\AdminInitializer;
6 use WPCoder\Dashboard\DashboardInitializer;
7 use WPCoder\Dashboard\ImporterExporter;
8
9 defined( 'ABSPATH' ) || exit;
10
11 class WOWP_Dashboard {
12
13 public function __construct() {
14 add_filter( WPCoder::PREFIX . '_menu_logo', [ $this, 'menu_logo' ] );
15 add_action( WPCoder::PREFIX . '_admin_load_styles_scripts', [ $this, 'load_styles_scripts' ] );
16 add_action( WPCoder::PREFIX . '_admin_page', [ $this, 'dashboard' ] );
17 add_action( WPCoder::PREFIX . '_admin_header_links', [ $this, 'header_links' ] );
18 add_filter( WPCoder::PREFIX . '_save_settings', [ $this, 'save_settings' ], 10, 2 );
19 add_filter( WPCoder::PREFIX . '_default_custom_post', [ $this, 'default_custom_post' ] );
20 AdminInitializer::init();
21 add_action( 'admin_init', [ ImporterExporter::class, 'export_items' ] );
22 }
23
24 public function menu_logo( $logo ): string {
25 $logo = '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><title>code</title><g fill="#212121"><path d="M19.562,18.75c-.69-.862-1.948-1.003-2.811-.312L1.75,30.438c-.474,.379-.75,.954-.75,1.562s.276,1.182,.75,1.562l15,12c.369,.295,.81,.438,1.248,.438,.587,0,1.168-.257,1.563-.75,.69-.863,.55-2.121-.312-2.811l-13.048-10.438,13.048-10.438c.862-.69,1.002-1.948,.312-2.811Z" fill="#212121"></path><path d="M47.25,18.438c-.862-.691-2.121-.55-2.811,.312-.69,.863-.55,2.121,.312,2.811l13.048,10.438-13.048,10.438c-.862,.69-1.002,1.948-.312,2.811,.395,.494,.976,.75,1.563,.75,.438,0,.879-.143,1.248-.438l15-12c.474-.379,.75-.954,.75-1.562s-.276-1.182-.75-1.562l-15-12Z" fill="#212121"></path><path d="M39.539,5.074c-1.063-.298-2.167,.324-2.465,1.387l-14,50c-.298,1.063,.323,2.167,1.387,2.465,.18,.051,.362,.075,.54,.075,.875,0,1.678-.578,1.925-1.461L40.926,7.539c.298-1.063-.323-2.167-1.387-2.465Z" fill="#212121"></path></g></svg>';
26
27 return $logo;
28 }
29
30 public function default_custom_post( $display_def ) {
31 if ( str_contains( $display_def, 'custom_post_selected' ) ) {
32 return 'post_selected';
33 }
34 if ( str_contains( $display_def, 'custom_post_tax' ) ) {
35 return 'post_category';
36 }
37 if ( str_contains( $display_def, 'custom_post_all' ) ) {
38 return 'post_all';
39 }
40
41 return $display_def;
42 }
43
44 public function save_settings( $settings, $request ): array {
45 $param = ! empty( $request['param'] ) ? map_deep( $request['param'], [ $this, 'sanitize_param' ] ) : [];
46
47 $settings['data']['title'] = ! empty( $request['title'] ) ? sanitize_text_field( wp_unslash( $request['title'] ) ) : '';
48 $settings['formats'][] = '%s';
49 $settings['data']['html_code'] = ! empty( $request['html_code'] ) ? wp_unslash( $request['html_code'] ) : '';
50 $settings['formats'][] = '%s';
51 $settings['data']['css_code'] = ! empty( $request['css_code'] ) ? wp_unslash( $request['css_code'] ) : '';
52 $settings['formats'][] = '%s';
53 $settings['data']['js_code'] = ! empty( $request['js_code'] ) ? wp_unslash( $request['js_code'] ) : '';
54 $settings['formats'][] = '%s';
55 $settings['data']['php_code'] = ! empty( $request['php_code'] ) ? wp_unslash( $request['php_code'] ) : '';
56 $settings['formats'][] = '%s';
57 $settings['data']['status'] = ! empty( $request['status'] ) ? sanitize_textarea_field( wp_unslash( $request['status'] ) ) : '';
58 $settings['formats'][] = '%d';
59 $settings['data']['mode'] = ! empty( $request['mode'] ) ? sanitize_textarea_field( wp_unslash( $request['mode'] ) ) : '';
60 $settings['formats'][] = '%d';
61 $settings['data']['tag'] = ! empty( $request['tag'] ) ? sanitize_textarea_field( wp_unslash( $request['tag'] ) ) : '';
62 $settings['formats'][] = '%s';
63 $settings['data']['php_include'] = ! empty( $request['php_include'] ) ? sanitize_textarea_field( wp_unslash( $request['php_include'] ) ) : '';
64 $settings['formats'][] = '%d';
65
66
67 if ( ! empty( $request['param']['include_file'] ) ) {
68 $param['include_file'] = ! empty( $request['param']['include_file'] ) ? map_deep( $request['param']['include_file'],
69 'esc_url' ) : [];
70 }
71
72 $settings['data']['param'] = maybe_serialize( $param );
73 $settings['formats'][] = '%s';
74
75 return $settings;
76 }
77
78 public function sanitize_param( $value ) {
79 return wp_unslash( sanitize_text_field( $value ) );
80 }
81
82 public function load_styles_scripts(): void {
83 $assets_url = WPCoder::url() . 'assets/';
84 $version = WPCoder::info( 'version' );
85 $slug = WPCoder::SLUG;
86
87 wp_enqueue_style( $slug . '-icons', $assets_url . 'icons/css/icons.css', null, $version );
88 wp_enqueue_style( $slug . '-admin', $assets_url . 'css/admin.css', null, $version );
89
90 wp_enqueue_script( 'code-editor' );
91 wp_enqueue_style( 'code-editor' );
92 wp_enqueue_script( 'htmlhint' );
93 wp_enqueue_script( 'csslint' );
94 wp_enqueue_script( 'jshint' );
95 wp_enqueue_style( 'thickbox' );
96 wp_enqueue_script( 'thickbox' );
97
98 wp_enqueue_media();
99
100 wp_enqueue_script( $slug . '-admin', $assets_url . 'js/admin.js', array( 'jquery' ), $version );
101
102 wp_enqueue_script( $slug . '-admin-jquery', $assets_url . 'js/admin-jquery.js', array( 'jquery' ), $version );
103 }
104
105 public function dashboard(): void {
106 DashboardInitializer::init();
107 }
108
109
110 public function header_links(): void {
111 ?>
112
113 <a href="https://wpcoder.pro/category/documentation/?utm_source=wordpress&utm_medium=admin-menu&utm_campaign=documentation"
114 class="wowp-button button button-secondary">
115 <span class="dashicons dashicons-book-alt"></span> Documentation
116 </a>
117 <a href="https://wordpress.org/support/plugin/wp-coder/reviews/" class="wowp-button button button-secondary">
118 <span class="dashicons dashicons-star-filled"></span> Reviews
119 </a>
120
121 <a href="https://wpcoder.pro/" target="_blank"
122 class="wowp-button button button-dark">
123 <span></span> See PRO Features
124 </a>
125 <?php
126 }
127
128
129 }