PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.1
WP Coder – Insert & Manage Code Snippets v4.1
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 4.1, at classes/Tools/ToolsManager.php

90 lines 2.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\Tools;
4
5 use WPCoder\WPCoder;
6
7 class ToolsManager {
8
9 public static function init(): void {
10 self::send();
11
12 ?>
13
14 <div class="wowp-settings wowp-tools">
15 <form method="post">
16
17 <div class="wowp-snippets__header">
18 <h3 class="wowp-snippets__header-title">Tools & Integrations</h3>
19 <p class="wowp-snippets__header-description">Manage useful features and external service
20 integrations to enhance your site.</p>
21 </div>
22
23
24 <?php require_once plugin_dir_path( __FILE__ ) . '/page.php'; ?>
25
26 <?php submit_button( __( 'Save', 'wp-coder' ), 'wowp-button button button-dark button-hero', 'submit', false ); ?>
27
28 <?php wp_nonce_field( WPCoder::PREFIX . '_tools_action', WPCoder::PREFIX . '_save_tools' ); ?>
29
30 </form>
31 </div>
32 <?php
33
34 }
35
36 private static function option( $name = '', $def = '' ) {
37 $options = get_option( '_wp_coder_tools', [] );
38 $res = ! empty( $options[ $name ] ) ? $options[ $name ] : $def;
39
40 return $res;
41 }
42
43 private static function expand( $name ) {
44 $res = self::option( $name );
45 if ( ! empty( $res ) ) {
46 echo ' open';
47 }
48 }
49
50 private static function field( $type = 'checkbox', $name = '', $def = '', $placeholder = '' ) {
51 $options = get_option( '_wp_coder_tools', [] );
52 if ( $type === 'checkbox' ) {
53 $checked = array_key_exists( $name, $options ) ? 'checked' : '';
54 echo '<input type="checkbox" name="wp_coder_tool[' . esc_attr( $name ) . ']" ' . esc_attr( $checked ) . ' value="1" id="' . esc_attr( $name ) . '">';
55 } elseif ( $type === 'textarea' ) {
56 $value = ! empty( $options[ $name ] ) ? $options[ $name ] : $def;
57 echo '<textarea name="wp_coder_tool[' . esc_attr( $name ) . ']" placeholder="' . esc_attr( $placeholder ) . '">' . esc_attr( $value ) . '</textarea>';
58 } else {
59 $value = ! empty( $options[ $name ] ) ? $options[ $name ] : $def;
60 echo '<input type="' . esc_attr( $type ) . '" name="wp_coder_tool[' . esc_attr( $name ) . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '">';
61 }
62 }
63
64 private static function send(): void {
65 if ( ! self::verify() ) {
66 return;
67 }
68
69 if ( empty( $_POST['wp_coder_tool'] ) ) {
70 $snippets = [];
71 } else {
72 $snippets = map_deep( $_POST['wp_coder_tool'], 'sanitize_text_field' );
73 }
74
75
76 update_option( '_wp_coder_tools', $snippets );
77 }
78
79 private static function verify(): bool {
80 $wp_coder = $_POST['wp_coder_tool'] ?? '';
81 $nonce_name = WPCoder::PREFIX . '_save_tools';
82 $nonce_action = WPCoder::PREFIX . '_tools_action';
83 if ( empty( $_POST[ $nonce_name ] ) ) {
84 return false;
85 }
86
87 return wp_verify_nonce( $_POST[ $nonce_name ],
88 $nonce_action ) && current_user_can( 'unfiltered_html' );
89 }
90 }