PluginProbe
WP Coder – Insert & Manage Code Snippets / trunk
WP Coder – Insert & Manage Code Snippets vtrunk
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 / classes / Tools / ToolsManager.php

ToolsManager.php in WP Coder – Insert & Manage Code Snippets trunk, at classes/Tools/ToolsManager.php

122 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPCoder\Tools;
4
5 use WPCoder\WPCoder;
6
7 class ToolsManager {
8
9 public static function init(): void {
10 self::send();
11
12 $options = get_option( '_wp_coder_tools', [] );
13
14 $tools = [
15 'integrations' => __( 'Integrations', 'wpcoderpro' ),
16 'content' => __( 'Content & Templates', 'wpcoderpro' ),
17 'developer' => __( 'Developer', 'wpcoderpro' ),
18 ];
19
20 ?>
21
22 <div class="wowp-settings wowp-tools">
23 <form method="post">
24
25 <div class="wowp-snippets__header">
26 <h3 class="wowp-snippets__header-title">Tools & Integrations</h3>
27 <p class="wowp-snippets__header-description">Manage useful features and external service
28 integrations to enhance your site.</p>
29 </div>
30
31 <div class="wowp-snippets__tabs" id="wowp-snippets-tabs">
32 <?php
33 foreach ( $tools as $key => $value ) {
34 $tab = ! empty( $options['tool_tab'] ) ? $options['tool_tab'] : 'integrations';
35 echo '<input type="radio" class="wowp-snippets__tabs-radio" name="wp_coder_tool[tool_tab]" value="' . esc_attr( $key ) . '" id="wowp-tab-' . esc_attr( $key ) . '" ' . checked( $tab,
36 $key, false ) . '>';
37 }
38 echo '<div class="wowp-snippets__tabs-labels">';
39 foreach ( $tools as $key => $value ) {
40 echo '<label class="wowp-snippets__tabs-tab" for="wowp-tab-' . esc_attr( $key ) . '"><span class="icon icon-' . esc_attr( $key ) . '"></span>' . esc_html( $value ) . '</label>';
41 }
42 echo '</div>';
43 foreach ( $tools as $key => $value ) {
44 echo '<div class="wowp-snippets__tabs-content" data-content="wowp-tab-' . esc_attr( $key ) . '">';
45 require_once plugin_dir_path( __FILE__ ) . 'pages/' . esc_attr( $key ) . '.php';
46 echo '<input type="submit" name="submit" class="wowp-button button button-dark button-hero" value="' . esc_attr__( 'Save',
47 'wpcoderpro' ) . '">';
48 echo '</div>';
49 }
50
51 ?>
52 </div>
53
54 <?php
55 // require_once plugin_dir_path( __FILE__ ) . '/page.php'; ?>
56
57 <?php
58 // submit_button( __( 'Save', 'wpcoderpro' ), 'wowp-button button button-dark button-hero', 'submit', false ); ?>
59
60 <?php
61 wp_nonce_field( WPCoder::PREFIX . '_tools_action', WPCoder::PREFIX . '_save_tools' ); ?>
62
63 </form>
64 </div>
65 <?php
66 }
67
68 private static function option( $name = '', $def = '' ) {
69 $options = get_option( '_wp_coder_tools', [] );
70 $res = ! empty( $options[ $name ] ) ? $options[ $name ] : $def;
71
72 return $res;
73 }
74
75 private static function expand( $name ) {
76 $res = self::option( $name );
77 if ( ! empty( $res ) ) {
78 echo ' open';
79 }
80 }
81
82 private static function field( $type = 'checkbox', $name = '', $def = '', $placeholder = '' ) {
83 $options = get_option( '_wp_coder_tools', [] );
84 if ( $type === 'checkbox' ) {
85 $checked = array_key_exists( $name, $options ) ? 'checked' : '';
86 echo '<input type="checkbox" name="wp_coder_tool[' . esc_attr( $name ) . ']" ' . esc_attr( $checked ) . ' value="1" id="' . esc_attr( $name ) . '">';
87 } elseif ( $type === 'textarea' ) {
88 $value = ! empty( $options[ $name ] ) ? $options[ $name ] : $def;
89 echo '<textarea name="wp_coder_tool[' . esc_attr( $name ) . ']" placeholder="' . esc_attr( $placeholder ) . '">' . esc_attr( $value ) . '</textarea>';
90 } else {
91 $value = ! empty( $options[ $name ] ) ? $options[ $name ] : $def;
92 echo '<input type="' . esc_attr( $type ) . '" name="wp_coder_tool[' . esc_attr( $name ) . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '">';
93 }
94 }
95
96 private static function send(): void {
97 if ( ! self::verify() ) {
98 return;
99 }
100
101 if ( empty( $_POST['wp_coder_tool'] ) ) {
102 $snippets = [];
103 } else {
104 $snippets = map_deep( $_POST['wp_coder_tool'], 'sanitize_text_field' );
105 }
106
107
108 update_option( '_wp_coder_tools', $snippets );
109 }
110
111 private static function verify(): bool {
112 $wp_coder = $_POST['wp_coder_tool'] ?? '';
113 $nonce_name = WPCoder::PREFIX . '_save_tools';
114 $nonce_action = WPCoder::PREFIX . '_tools_action';
115 if ( empty( $_POST[ $nonce_name ] ) ) {
116 return false;
117 }
118
119 return wp_verify_nonce( $_POST[ $nonce_name ],
120 $nonce_action ) && current_user_can( 'unfiltered_html' );
121 }
122 }