PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.5
WP Coder – Insert & Manage Code Snippets v4.5
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 / Dashboard / SaveGlobal.php

SaveGlobal.php in WP Coder – Insert & Manage Code Snippets 4.5, at classes/Dashboard/SaveGlobal.php

102 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPCoder\Dashboard;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use WPCoder\WPCoder;
8
9 class SaveGlobal {
10
11 public static function init(): void {
12 self::send();
13 $content = self::get_content();
14 $enabled = get_option( '_wpcoder_enable_php' );
15 ?>
16
17
18 <form method="post">
19 <div class="wowp-settings">
20
21 <div class="wowp-settings__page">
22
23
24 <div class="wowp-settings__page-sidebar">
25
26 <div class="wowp-field has-checkbox is-reverse">
27 <span class="label">
28 <?php esc_html_e( 'Enable PHP code', 'wp-coder' ); ?>
29 <sup class="wowp-tooltip" data-tooltip="Enable execution of this PHP code globally. Be careful: errors may affect your site."></sup>
30 </span>
31 <label class="switch">
32 <input type="checkbox" value="1" name="wp_coder_global_php_enable" id="wpcoder-global-php-enable"<?php checked( $enabled ); ?>>
33 <span class="slider"></span>
34 </label>
35 </div>
36
37 <?php submit_button( __( 'Save', 'wp-coder' ), 'wowp-button button button-dark', 'submit', false ); ?>
38
39
40 <button class="button-editor button" id="phpglobalnav"><?php esc_html_e( 'Add NAV Comment', 'wp-coder' ); ?></button>
41 <ol id="phpNavigationMenu" class="wowp-php-nav-menu"></ol>
42
43 </div>
44
45 <div class="wowp-settings__page-content">
46 <textarea name="wp_coder_global_php" id="wpcoder-global-php" cols="40" rows="5"><?php
47 echo esc_textarea( $content ); ?></textarea>
48 </div>
49
50
51 </div>
52
53 <?php wp_nonce_field( WPCoder::PREFIX . '_global_action', WPCoder::PREFIX . '_save_name' ); ?>
54 </div>
55 </form>
56
57
58 <?php
59 }
60
61 private static function get_content() {
62 $content = '';
63 $path_global = FolderManager::path_upload_dir() . 'global-php.php';
64
65 if ( file_exists( $path_global ) ) {
66 $content_file = file_get_contents( $path_global );
67 $lines = explode( PHP_EOL, $content_file );
68 $lines = array_slice( $lines, 3 );
69 $content = implode( PHP_EOL, $lines );
70 }
71
72 return $content;
73 }
74
75 private static function send(): void {
76 if ( ! self::verify() ) {
77 return;
78 }
79 $checked = ! empty( $_POST['wp_coder_global_php_enable'] ) ? 1 : 0;
80 update_option( '_wpcoder_enable_php', $checked );
81
82 $path_global = FolderManager::path_upload_dir() . 'global-php.php';
83
84 if ( isset( $_POST['wp_coder_global_php'] ) ) {
85 file_put_contents( $path_global,
86 "<?php\ndefined( 'ABSPATH' ) || exit;\n\n" . wp_unslash( $_POST['wp_coder_global_php'] ) );
87 }
88 }
89
90 private static function verify(): bool {
91 $wp_coder = $_POST['wp_coder_global_php'] ?? '';
92 $nonce_name = WPCoder::PREFIX . '_save_name';
93 $nonce_action = WPCoder::PREFIX . '_global_action';
94 if ( empty( $_POST[ $nonce_name ] ) ) {
95 return false;
96 }
97
98 return isset( $wp_coder ) && wp_verify_nonce( $_POST[ $nonce_name ],
99 $nonce_action ) && current_user_can( 'unfiltered_html' );
100 }
101 }
102