PluginProbe
HTML Editor for Contact Form 7 / 0.2
HTML Editor for Contact Form 7 v0.2
trunk 0.1 0.2 1.0 1.0.1
cf7-coder / cf7-coder.php

cf7-coder.php in HTML Editor for Contact Form 7 0.2, at cf7-coder.php

176 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: CF7 HTML Editor
4 * Plugin URI: https://wordpress.org/cf7-coder
5 * Description: Add HTML editor to Contact Form 7.
6 * Version: 0.2
7 * Author: Wow-Company
8 * Author URI: https://wow-estore.com/
9 * License: GPL-2.0+
10 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11 * Text Domain: cf7-coder
12 * Domain Path: /languages
13 *
14 * PHP version 5.6.0
15 *
16 * @category Wordpress_Plugin
17 * @package Wow_Plugin
18 * @copyright 2021 Wow-Company
19 * @license GNU Public License
20 * @version 0.1
21 */
22
23 if ( ! defined( "ABSPATH" ) ) {
24 exit();
25 }
26
27 class CF7_Coder {
28 public function __construct() {
29 add_action( 'plugins_loaded', [ $this, "text_domain" ] );
30 add_action( "admin_enqueue_scripts", [ $this, "style_script" ] );
31 add_action( 'wpcf7_admin_misc_pub_section', [ $this, 'wpcf7_add_test_mode' ] );
32 add_filter( 'wpcf7_contact_form_properties', [ $this, 'wpcf7_add_properties' ] );
33 add_action( 'wpcf7_save_contact_form', [ $this, 'wpcf7_save' ] );
34 add_filter( 'do_shortcode_tag', [ $this, 'wpcf7_frontend' ], 10, 4 );
35 }
36
37 // Download the folder with languages
38 public function text_domain() {
39 $languages_folder = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
40 load_plugin_textdomain( 'cf7-coder', false, $languages_folder );
41 }
42
43 // Include script and style in CF7 page
44 public function style_script( $hook ) {
45 $page_new = 'contact_page_wpcf7-new';
46 $page = 'toplevel_page_wpcf7';
47
48
49 if ( $page === $hook || $page_new === $hook ) {
50 $version = '0.2';
51
52 wp_enqueue_script( 'code-editor' );
53 wp_enqueue_style( 'code-editor' );
54 wp_enqueue_script( 'htmlhint' );
55
56
57 $url_style = plugin_dir_url( __FILE__ ) . 'assets/style.css';
58 wp_enqueue_style( "coder-wpcf7", $url_style );
59
60 $url_matirial = plugin_dir_url( __FILE__ ) . 'assets/material.css';
61 wp_enqueue_style( "coder-wpcf7-matirial", $url_matirial );
62
63 $url_script = plugin_dir_url( __FILE__ ) . 'assets/script.js';
64 wp_enqueue_script( "coder-wpcf7", $url_script, [ "jquery" ], $version, false );
65 }
66 }
67
68
69 // Add checkbox 'Test Mode' in sidebar
70 public function wpcf7_add_test_mode() {
71 $post_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : '-1';
72 $checked = get_post_meta( $post_id, '_wpcf7_test_mode', true );
73 ?>
74 <div class="misc-pub-section">
75 <label class="wpcf7-test-mode">
76 <input value="1" type="checkbox" name="wpcf7-test-mode" <?php checked( $checked ); ?>>
77 <?php esc_html_e( 'Test Mode', 'cf7-coder' ); ?>
78 <sup class="has-tooltip" data-tooltip="The Form will only be displayed for administrators."></sup>
79 </label>
80 </div>
81 <?php
82 $post_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : '-1';
83 $checked = get_post_meta( $post_id, '_wpcf7_remove_auto_tags', true );
84 ?>
85 <div class="misc-pub-section">
86 <label class="wpcf7-remove-auto-tags">
87 <input value="1" type="checkbox" name="wpcf7-remove-auto-tags" <?php checked( $checked ); ?>>
88 <?php esc_html_e( 'Remove Auto tags p and br', 'cf7-coder' ); ?>
89 </label>
90 </div>
91 <?php
92 $checked = get_post_meta( $post_id, '_wpcf7_codemiror_dark', true );
93 ?>
94 <div class="misc-pub-section">
95 <label class="wpcf7-remove-auto-tags">
96 <input value="1" type="checkbox" id="wpcf7_codemiror_dark"
97 name="wpcf7_codemiror_dark" <?php checked( $checked ); ?>>
98 <?php esc_html_e( 'Enable dark theme (Material)', 'cf7-coder' ); ?>
99 </label>
100 </div>
101 <div class="misc-pub-section">
102 <a href="https://wordpress.org/plugins/wp-coder/" target="_blank">Check out WP Coder advanced code
103 injection</a>
104 </div>
105 <?php
106 }
107
108 // Add properties for form
109 public function wpcf7_add_properties( $properties ) {
110 $more_properties = array(
111 'wpcf7_test_mode' => '',
112 'wpcf7_remove_auto_tags' => '',
113 'wpcf7_codemiror_dark' => '',
114 );
115
116 return array_merge( $more_properties, $properties );
117 }
118
119 // Save custom properties
120 public function wpcf7_save( $contact_form ) {
121 $properties = $contact_form->get_properties();
122
123 $properties['wpcf7_test_mode'] = isset( $_POST['wpcf7-test-mode'] ) ? '1' : '';
124 $properties['wpcf7_remove_auto_tags'] = isset( $_POST['wpcf7-remove-auto-tags'] ) ? '1' : '';
125 $properties['wpcf7_codemiror_dark'] = isset( $_POST['wpcf7_codemiror_dark'] ) ? '1' : '';
126
127 $contact_form->set_properties( $properties );
128 }
129
130 // Work with Frontend
131 public function wpcf7_frontend( $output, $tag, $atts, $m ) {
132 if ( $tag === 'contact-form-7' ) {
133 if ( ! function_exists( 'wpcf7_get_contact_form_by_hash' ) ) {
134 return $output;
135 }
136
137 $form = wpcf7_get_contact_form_by_hash( $atts['id'] );
138
139 $form_id = null;
140
141 if ( $form instanceof WPCF7_ContactForm ) {
142 $form_id = $form->id();
143 }
144
145 if ( $form_id === null ) {
146 return $output;
147 }
148
149 $remove_tags = get_post_meta( $form_id, '_wpcf7_remove_auto_tags', true );
150 if ( ! empty( $remove_tags ) ) {
151 $output = str_replace( array( '<p>', '</p>', '<br/>' ), '', $output );;
152 }
153
154 $test_mode = get_post_meta( $form_id, '_wpcf7_test_mode', true );
155 if ( ! empty( $test_mode ) && ! current_user_can( 'administrator' ) ) {
156 $output = '';
157 }
158 }
159
160 return $output;
161 }
162
163 }
164
165 add_action( 'plugins_loaded', 'wpcf7_coder_load', 999 );
166 function wpcf7_coder_load() {
167 if ( ! class_exists( 'WPCF7' ) ) {
168 require_once 'class.wpcf7coder-extension-activation.php';
169 $activation = new wpcf7_Coder_Extension_Activation( plugin_dir_path( __FILE__ ), basename( __FILE__ ) );
170 $activation = $activation->run();
171 deactivate_plugins( plugin_basename( __FILE__ ) );
172 } else {
173 new CF7_Coder();
174 }
175 }
176