Changeset 3165530
- Timestamp:
- 10/09/2024 08:28:08 AM (14 months ago)
- Location:
- cubewp-forms/trunk
- Files:
-
- 7 edited
-
cube/assets/js/cubewp-forms-admin.js (modified) (2 diffs)
-
cube/classes/class-cubewp-forms-custom.php (modified) (1 diff)
-
cube/classes/class-cubewp-forms-dashboard.php (modified) (2 diffs)
-
cube/classes/class-cubewp-forms-emails.php (modified) (14 diffs)
-
cube/functions/functions.php (modified) (20 diffs)
-
cubewp-forms.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cubewp-forms/trunk/cube/assets/js/cubewp-forms-admin.js
r3044556 r3165530 58 58 59 59 // Load data by default 60 var defaultSelectedOptions = $('#admin_email_post_types').val(); 61 getEmailTemplateData(defaultSelectedOptions); 62 60 if($('body').hasClass('post-new-php') && $('body').hasClass('post-type-email_template_forms')){ 61 var defaultSelectedOptions = $('#forms_types').val(); 62 getEmailTemplateData(defaultSelectedOptions); 63 } 64 63 65 // Listen for changes in the select field 64 $(' #admin_email_post_types').on('change', function() {66 $('.post-type-email_template_forms.post-new-php #forms_types').on('change', function() { 65 67 // Get the selected option values 66 68 var selectedOptions = $(this).val(); … … 80 82 type: 'POST', 81 83 url: cwp_vars_params.ajax_url, 82 data:'action=cwp_import_dummy_data&data_type= dummy',84 data:'action=cwp_import_dummy_data&data_type=&nonce='+cwp_vars_params.nonce, 83 85 dataType: 'json', 84 86 success: function (response) { -
cubewp-forms/trunk/cube/classes/class-cubewp-forms-custom.php
r3155358 r3165530 25 25 * @var string 26 26 */ 27 public static $CubeWp_Forms_version = '1.1. 3';27 public static $CubeWp_Forms_version = '1.1.4'; 28 28 /** 29 29 * The single instance of the class. -
cubewp-forms/trunk/cube/classes/class-cubewp-forms-dashboard.php
r3155358 r3165530 61 61 } 62 62 $form_details=$data; 63 $output='';64 63 $output = '<div class="cwp-dashboard-leads-container">'; 65 $output =self::lead_details($form_details);66 $output .=self::cwp_form_data_sidebar();64 $output .= self::lead_details($form_details); 65 $output .= self::cwp_form_data_sidebar(); 67 66 $output .= '</div>'; 68 67 return $output; … … 89 88 $output .='</div>'; 90 89 }else{ 91 $output = ''; 92 $output .= ob_start(); 93 ?> 94 <div class="cwp-empty-posts"><img class="cwp-empty-img" src="<?php echo esc_url(CWP_PLUGIN_URI . 'cube/assets/frontend/images/no-result.png') ?>" alt=""> 95 <h2><?php echo esc_html__("No Leads Found", "cubewp-forms"); ?></h2> 96 <p><?php echo esc_html__("There are no leads found.", "cubewp-forms"); ?></p> 97 </div> 98 <?php 99 $output .= ob_get_clean(); 90 $output ='<div class="cwp-empty-posts"><img class="cwp-empty-img" src="'.esc_url(CWP_PLUGIN_URI . 'cube/assets/frontend/images/no-result.png').'" alt=""> 91 <h2>'.esc_html__("No Leads Found", "cubewp-forms").'</h2> 92 <p>'.esc_html__("There are no leads found.", "cubewp-forms").'</p> 93 </div>'; 100 94 } 101 95 return $output; -
cubewp-forms/trunk/cube/classes/class-cubewp-forms-emails.php
r3044556 r3165530 1 1 <?php 2 defined( 'ABSPATH') || exit;2 defined('ABSPATH') || exit; 3 3 4 4 /** 5 5 * CubeWp_Forms_Emails 6 6 */ 7 class CubeWp_Forms_Emails { 7 class CubeWp_Forms_Emails 8 { 8 9 9 10 public static $post_type = 'email_template_forms'; … … 13 14 private static $post_types_for = array(); 14 15 15 public function __construct() { 16 public function __construct() 17 { 16 18 CubeWp_Enqueue::enqueue_script('cubewp-forms-admin'); 17 add_filter( 'cubewp/posttypes/new', array( $this, 'register_email_template_post_type' ));18 add_filter( 'post_updated_messages', array( $this, 'remove_view_email_template_action' ), 10, 2);19 add_action( 'admin_init', array( $this, 'remove_email_template_page' ));19 add_filter('cubewp/posttypes/new', array($this, 'register_email_template_post_type')); 20 add_filter('post_updated_messages', array($this, 'remove_view_email_template_action'), 10, 2); 21 add_action('admin_init', array($this, 'remove_email_template_page')); 20 22 add_action('admin_head', array($this, 'remove_post_actions')); 21 add_action( 'save_post', array( $this, 'restrict_email_template_submission' ));22 add_action( 'add_meta_boxes', array( $this, 'cubewp_email_template_shortcodes_metabox' ));23 add_filter( 'enter_title_here', array( $this, 'change_title_placeholder' ), 10, 2);24 add_filter( 'default_content', array( $this, 'default_post_content' ), 10, 2);25 26 add_filter( 'manage_' . self::$post_type . '_posts_columns', array( $this, 'email_post_type_columns' ));27 add_action( 'manage_' . self::$post_type . '_posts_custom_column', array(23 add_action('save_post', array($this, 'restrict_email_template_submission')); 24 add_action('add_meta_boxes', array($this, 'cubewp_email_template_shortcodes_metabox')); 25 add_filter('enter_title_here', array($this, 'change_title_placeholder'), 10, 2); 26 add_filter('default_content', array($this, 'default_post_content'), 10, 2); 27 28 add_filter('manage_' . self::$post_type . '_posts_columns', array($this, 'email_post_type_columns')); 29 add_action('manage_' . self::$post_type . '_posts_custom_column', array( 28 30 $this, 29 31 'email_post_type_column_content' 30 ), 10, 2 );32 ), 10, 2); 31 33 } 32 34 33 35 34 36 /** 35 * Method remove_post_actions 36 * 37 * @return void 38 * @since 1.0.1 39 */ 40 public static function remove_post_actions() 41 { 42 global $post; 43 if ($post && $post->post_type === 'email_template_forms') { 44 // Remove quick edit and view buttons 45 ?> 46 <style> 47 .row-actions span.view, 48 .row-actions span.inline { 49 display: none; 50 } 51 </style> 52 <?php 53 } 54 } 55 56 public static function cubewp_send_email( $email_to, $template_id, $form_data = array() , $headers = array() ) { 57 58 if ( is_array( $template_id ) ) { 59 $email_subject = isset( $template_id['subject'] ) && ! empty( $template_id['subject'] ) ? $template_id['subject'] : ''; 60 $email_content = isset( $template_id['message'] ) && ! empty( $template_id['message'] ) ? $template_id['message'] : ''; 37 * Method remove_post_actions 38 * 39 * @return void 40 * @since 1.0.1 41 */ 42 public static function remove_post_actions() 43 { 44 global $post; 45 if ($post && $post->post_type === 'email_template_forms') { 46 // Remove quick edit and view buttons 47 ?> 48 <style> 49 .row-actions span.view, 50 .row-actions span.inline { 51 display: none; 52 } 53 </style> 54 <?php 55 } 56 } 57 58 public static function cubewp_send_email($email_to, $template_id, $form_data = array(), $headers = array()) 59 { 60 61 if (is_array($template_id)) { 62 $email_subject = isset($template_id['subject']) && ! empty($template_id['subject']) ? $template_id['subject'] : ''; 63 $email_content = isset($template_id['message']) && ! empty($template_id['message']) ? $template_id['message'] : ''; 61 64 } else { 62 $email_subject = get_the_title( $template_id);63 $email_content = get_the_content( '', '', $template_id);64 } 65 66 if ( empty( $email_subject ) || empty( $email_content )) {65 $email_subject = get_the_title($template_id); 66 $email_content = get_the_content('', '', $template_id); 67 } 68 69 if (empty($email_subject) || empty($email_content)) { 67 70 return false; 68 71 } 69 70 71 $email_subject = self::cubewp_render_email_shortcodes( $email_subject, $form_data, true);72 $email_content = self::cubewp_render_email_shortcodes( $email_content, $form_data);73 74 if ( empty( $email_subject ) || empty( $email_content )) {72 73 74 $email_subject = self::cubewp_render_email_shortcodes($email_subject, $form_data, true); 75 $email_content = self::cubewp_render_email_shortcodes($email_content, $form_data); 76 77 if (empty($email_subject) || empty($email_content)) { 75 78 return false; 76 79 } 77 if ( empty($headers) ){80 if (empty($headers)) { 78 81 $headers = array(); 79 $website_name = get_bloginfo( 'name' ); 80 $admin_email = apply_filters( "cubewp_forms_emails_from_mail", get_option( 'admin_email' ) ); 81 if ( ! empty( $from_email_address ) ) { 82 $headers[] = 'From: ' . esc_html( $website_name ) . ' <' . esc_html( $admin_email ) . '>'; 83 } 84 } 85 return cubewp_send_mail( $email_to, $email_subject, $email_content, $headers ); 86 } 87 88 private static function cubewp_render_email_shortcodes( $content, $form_data, $html_entity_decode = false ) { 89 90 $content = str_replace( '{website_title}', get_bloginfo( 'name' ), $content ); 91 $content = str_replace( '{website_url}', home_url(), $content ); 92 82 $website_name = get_bloginfo('name'); 83 $admin_email = apply_filters("cubewp_forms_emails_from_mail", get_option('admin_email')); 84 if (! empty($from_email_address)) { 85 $headers[] = 'From: ' . esc_html($website_name) . ' <' . esc_html($admin_email) . '>'; 86 } 87 } 88 return cubewp_send_mail($email_to, $email_subject, $email_content, $headers); 89 } 90 91 private static function cubewp_render_email_shortcodes($content, $form_data, $html_entity_decode = false) 92 { 93 94 $content = str_replace('{website_title}', get_bloginfo('name'), $content); 95 $content = str_replace('{website_url}', home_url(), $content); 96 93 97 $pattern = '/\{([^}]+)\}/'; 94 98 // Use preg_replace_callback to replace each shortcode with its corresponding value 95 $content = preg_replace_callback($pattern, function ($matches) use ($form_data) {99 $content = preg_replace_callback($pattern, function ($matches) use ($form_data) { 96 100 $field_slug = $matches[1]; 97 101 // Check if the field slug exists in the fields array … … 105 109 }, $content); 106 110 107 $content = (string) apply_filters( 'cubewp/forms/email/render/shortcodes', $content, $html_entity_decode);108 if ( $html_entity_decode) {109 $content = html_entity_decode( $content, ENT_QUOTES, get_option( 'blog_charset' ));111 $content = (string) apply_filters('cubewp/forms/email/render/shortcodes', $content, $html_entity_decode); 112 if ($html_entity_decode) { 113 $content = html_entity_decode($content, ENT_QUOTES, get_option('blog_charset')); 110 114 } 111 115 return $content; 112 116 } 113 117 114 public static function init() { 118 public static function init() 119 { 115 120 $CubeClass = __CLASS__; 116 121 new $CubeClass; 117 122 } 118 123 119 public function remove_email_template_page() { 120 if ( ! current_user_can( 'administrator' ) ) { 121 remove_menu_page( 'edit.php?post_type=email_template_forms' ); 122 } 123 } 124 125 public function remove_view_email_template_action( $messages ) { 126 if ( isset( $messages[ self::$post_type ] ) ) { 127 $messages[ self::$post_type ][1] = esc_html__( 'Email Template updated.', 'cubewp-frontend' ); 128 $messages[ self::$post_type ][6] = esc_html__( 'Email Template published.', 'cubewp-frontend' ); 129 $messages[ self::$post_type ][8] = esc_html__( 'Email Template submitted.', 'cubewp-frontend' ); 130 $messages[ self::$post_type ][10] = esc_html__( 'Email Template draft updated.', 'cubewp-frontend' ); 124 public function remove_email_template_page() 125 { 126 if (! current_user_can('administrator')) { 127 remove_menu_page('edit.php?post_type=email_template_forms'); 128 } 129 } 130 131 public function remove_view_email_template_action($messages) 132 { 133 if (isset($messages[self::$post_type])) { 134 $messages[self::$post_type][1] = esc_html__('Email Template updated.', 'cubewp-frontend'); 135 $messages[self::$post_type][6] = esc_html__('Email Template published.', 'cubewp-frontend'); 136 $messages[self::$post_type][8] = esc_html__('Email Template submitted.', 'cubewp-frontend'); 137 $messages[self::$post_type][10] = esc_html__('Email Template draft updated.', 'cubewp-frontend'); 131 138 } 132 139 … … 134 141 } 135 142 136 public function restrict_email_template_submission( $post_id ) { 137 if ( get_post_type( $post_id ) === self::$post_type ) { 138 if ( ! current_user_can( 'administrator' ) ) { 139 wp_die( 'You do not have permission to submit posts to the email_template post type.' ); 140 } 141 } 142 } 143 144 public function email_post_type_columns( $columns ) { 145 $new_column['email_recipient'] = esc_html__( 'Email Recipient', 'cubewp-frontend' ); 146 $new_column['email_type'] = esc_html__( 'Email Type', 'cubewp-frontend' ); 147 $position = array_search( 'date', array_keys( $columns ) ); 148 149 return array_slice( $columns, 0, $position, true ) + $new_column + array_slice( $columns, $position, null, true ); 150 } 151 152 public function email_post_type_column_content( $column, $post_id ) { 153 if ( 'email_recipient' == $column || 'email_type' == $column ) { 154 $email_recipient = get_post_meta( $post_id, 'email_recipient', true ); 155 if ( 'email_recipient' == $column ) { 156 echo esc_html( $email_recipient ); 143 public function restrict_email_template_submission($post_id) 144 { 145 if (get_post_type($post_id) === self::$post_type) { 146 if (! current_user_can('administrator')) { 147 wp_die('You do not have permission to submit posts to the email_template post type.'); 148 } 149 } 150 } 151 152 public function email_post_type_columns($columns) 153 { 154 $new_column['email_recipient'] = esc_html__('Email Recipient', 'cubewp-frontend'); 155 $new_column['email_type'] = esc_html__('Email Type', 'cubewp-frontend'); 156 $position = array_search('date', array_keys($columns)); 157 158 return array_slice($columns, 0, $position, true) + $new_column + array_slice($columns, $position, null, true); 159 } 160 161 public function email_post_type_column_content($column, $post_id) 162 { 163 if ('email_recipient' == $column || 'email_type' == $column) { 164 $email_recipient = get_post_meta($post_id, 'email_recipient', true); 165 if ('email_recipient' == $column) { 166 echo esc_html($email_recipient); 157 167 } else { 158 $email_type = get_post_meta( $post_id, 'admin_email_post_types', true ); 159 echo get_the_title( $email_type ); 160 } 161 } 162 } 163 164 public function default_post_content( $content, $post ) { 168 $email_type = get_post_meta($post_id, 'admin_email_post_types', true); 169 echo get_the_title($email_type); 170 } 171 } 172 } 173 174 public function default_post_content($content, $post) 175 { 165 176 $post_type = $post->post_type; 166 if ( $post_type == 'email_template_forms' && empty( $content )) {167 return esc_html__( 'Email Content', 'cubewp-frontend');177 if ($post_type == 'email_template_forms' && empty($content)) { 178 return esc_html__('Email Content', 'cubewp-frontend'); 168 179 } 169 180 … … 171 182 } 172 183 173 public function change_title_placeholder( $title_placeholder, $post ) { 184 public function change_title_placeholder($title_placeholder, $post) 185 { 174 186 $post_type = $post->post_type; 175 if ( $post_type == 'email_template_forms') {176 return esc_html__( 'Email Subject', 'cubewp-frontend');187 if ($post_type == 'email_template_forms') { 188 return esc_html__('Email Subject', 'cubewp-frontend'); 177 189 } 178 190 … … 180 192 } 181 193 182 public function cubewp_email_template_shortcodes_metabox() { 183 184 add_meta_box( 'cubewp-email-template-shortcodes-metabox', __( 'Shortcodes', 'cubewp-frontend' ), array( 185 $this, 186 'cubewp_email_template_shortcode_metabox_render' 187 ), self::$post_type, 'side' ); 188 189 } 190 191 public function cubewp_email_template_shortcode_metabox_render( $post ) { 192 if ( isset( $post->ID ) ) { 194 public function cubewp_email_template_shortcodes_metabox() 195 { 196 197 add_meta_box('cubewp-email-template-shortcodes-metabox', __('Shortcodes', 'cubewp-frontend'), array( 198 $this, 199 'cubewp_email_template_shortcode_metabox_render' 200 ), self::$post_type, 'side'); 201 } 202 203 public function cubewp_email_template_shortcode_metabox_render($post) 204 { 205 if (isset($post->ID)) { 193 206 $shortcodes = $this->cubewp_email_template_shortcodes(); 194 ?>195 <div class="cubewp-email-template-shortcodes">207 ?> 208 <div class="cubewp-email-template-shortcodes"> 196 209 <?php 197 if ( ! empty( $shortcodes ) && is_array( $shortcodes )) {198 foreach ( $shortcodes as $shortcode) {210 if (! empty($shortcodes) && is_array($shortcodes)) { 211 foreach ($shortcodes as $shortcode) { 199 212 $value = $shortcode['shortcode']; 200 213 $label = $shortcode['label']; 201 ?>202 <div class="cubewp-email-template-shortcode">203 <span class="cubewp-email-template-shortcode-label"><?php echo esc_html( $label); ?></span>204 <span class="cubewp-email-template-shortcode-value"><?php echo esc_html( $value); ?></span>205 </div>206 <?php214 ?> 215 <div class="cubewp-email-template-shortcode"> 216 <span class="cubewp-email-template-shortcode-label"><?php echo esc_html($label); ?></span> 217 <span class="cubewp-email-template-shortcode-value"><?php echo esc_html($value); ?></span> 218 </div> 219 <?php 207 220 } 208 221 } 209 222 ?> 210 </div> 211 <?php 212 } 213 } 214 215 private function cubewp_email_template_shortcodes() { 223 </div> 224 <?php 225 } 226 } 227 228 private function cubewp_email_template_shortcodes() 229 { 216 230 $shortcodes = array(); 217 231 $shortcodes[] = array( 218 'label' => esc_html__( 'Website Title', 'cubewp-frontend'),232 'label' => esc_html__('Website Title', 'cubewp-frontend'), 219 233 'shortcode' => '{website_title}', 220 234 ); 221 235 $shortcodes[] = array( 222 'label' => esc_html__( 'Website URL', 'cubewp-frontend'),236 'label' => esc_html__('Website URL', 'cubewp-frontend'), 223 237 'shortcode' => '{website_url}', 224 238 ); 225 226 return (array) apply_filters( 'cubewp/email/shortcodes', $shortcodes ); 227 } 228 229 public function register_email_template_post_type( $post_types ) { 230 231 $post_types[ self::$post_type ] = array( 232 'label' => esc_html__( 'Email Templates', 'cubewp-frontend' ), 233 'singular' => esc_html__( 'Email Template', 'cubewp-frontend' ), 239 240 return (array) apply_filters('cubewp/forms/email/shortcodes', $shortcodes); 241 } 242 243 public function register_email_template_post_type($post_types) 244 { 245 246 $post_types[self::$post_type] = array( 247 'label' => esc_html__('Email Templates', 'cubewp-frontend'), 248 'singular' => esc_html__('Email Template', 'cubewp-frontend'), 234 249 'icon' => 'dashicons-email', 235 250 'slug' => self::$post_type, 236 251 'description' => '', 237 'supports' => array( 'title', 'editor'),252 'supports' => array('title', 'editor'), 238 253 'hierarchical' => false, 239 254 'public' => false, … … 258 273 } 259 274 260 private function email_template_custom_fields() { 275 private function email_template_custom_fields() 276 { 261 277 $save_fields = false; 262 $settings = get_posts( array( 278 //$save_fields = true; 279 $settings = get_posts(array( 263 280 'name' => 'email_form_template_settings', 264 281 'post_type' => 'cwp_form_fields', … … 268 285 'meta_key' => '_cwp_group_types', 269 286 'meta_value' => 'email_template_forms', 270 ) );271 272 $settings_id = count( $settings) > 0 ? $settings[0]->ID : '';273 $setting_fields = $this->email_template_setting_fields( $settings_id);274 if ( empty( $settings_id )) {287 )); 288 289 $settings_id = count($settings) > 0 ? $settings[0]->ID : ''; 290 $setting_fields = $this->email_template_setting_fields($settings_id); 291 if (empty($settings_id)) { 275 292 $settings = array( 276 'post_title' => wp_strip_all_tags( __( 'Email Template Settings', 'cubewp-forms' )),293 'post_title' => wp_strip_all_tags(__('Email Template Settings', 'cubewp-forms')), 277 294 'post_name' => 'email_form_template_settings', 278 295 'post_content' => 'Custom fields for email template settings.', … … 282 299 ); 283 300 // Insert the post into the database 284 $settings_id = wp_insert_post( $settings);285 update_post_meta( $settings_id, '_cwp_group_visibility', 'secure');286 update_post_meta( $settings_id, '_cwp_group_types', 'email_template_forms');287 update_post_meta( $settings_id, '_cwp_group_order', 1);301 $settings_id = wp_insert_post($settings); 302 update_post_meta($settings_id, '_cwp_group_visibility', 'secure'); 303 update_post_meta($settings_id, '_cwp_group_types', 'email_template_forms'); 304 update_post_meta($settings_id, '_cwp_group_order', 1); 288 305 $save_fields = true; 289 306 } 290 $form_fields = get_option( 'cwp_custom_fields');291 if ( !empty($settings_id) && isset($form_fields['admin_email_post_types']) ){292 $forms_types = $form_fields[' admin_email_post_types'];293 $ options = isset($forms_types['options']) ? json_decode($forms_types['options'],true) : array();294 if( isset( $options['label'] ) && is_array( $options['label'] ) && isset( $forms['label'] ) && is_array( $forms['label'] ) ){295 $forms = self::cubewp_email_forms();296 if ( count($forms['label']) != count($options['label']) ){307 $form_fields = get_option('cwp_custom_fields'); 308 if (!empty($settings_id) && isset($form_fields['forms_types'])) { 309 $forms_types = $form_fields['forms_types']; 310 $forms = self::cubewp_email_forms(); 311 $options = isset($forms_types['options']) ? json_decode($forms_types['options'], true) : array(); 312 if (isset($options['label']) && is_array($options['label']) && isset($forms['label']) && is_array($forms['label'])) { 313 if (count($forms['label']) != count($options['label'])) { 297 314 $save_fields = true; 298 315 } 299 316 } 300 317 } 301 302 if ( $save_fields) {303 $setting_fields = $this->email_template_setting_fields( $settings_id);318 319 if ($save_fields) { 320 $setting_fields = $this->email_template_setting_fields($settings_id); 304 321 $settings_custom_fields = array(); 305 foreach ( $setting_fields as $key => $setting_field) {322 foreach ($setting_fields as $key => $setting_field) { 306 323 $settings_custom_fields[] = $key; 307 CubeWp_Custom_Fields_Processor::set_option( $key, $setting_field ); 308 } 309 update_post_meta( $settings_id, '_cwp_group_fields', implode( ',', $settings_custom_fields ) ); 310 } 311 } 312 313 private function email_template_setting_fields( $settings_id ) { 324 CubeWp_Custom_Fields_Processor::set_option($key, $setting_field); 325 } 326 update_post_meta($settings_id, '_cwp_group_fields', implode(',', $settings_custom_fields)); 327 } 328 } 329 330 private function email_template_setting_fields($settings_id) 331 { 314 332 $fields = array(); 315 $fields[' email_recipient'] = array(316 'label' => __( 'Email Recipient', 'cubewp-forms'),317 'name' => ' email_recipient',333 $fields['forms_email_recipient'] = array( 334 'label' => __('Email Recipient', 'cubewp-forms'), 335 'name' => 'forms_email_recipient', 318 336 'type' => 'dropdown', 319 337 'description' => '', 320 338 'default_value' => '', 321 339 'placeholder' => '', 322 'options' => json_encode( array(340 'options' => json_encode(array( 323 341 'label' => array( 324 esc_html__( 'Admin', 'cubewp-frontend'),325 esc_html__( 'User', 'cubewp-frontend'),342 esc_html__('Admin', 'cubewp-frontend'), 343 esc_html__('User', 'cubewp-frontend'), 326 344 ), 327 345 'value' => array( … … 329 347 'user' 330 348 ), 331 ) ),349 )), 332 350 'filter_post_types' => '', 333 351 'filter_taxonomy' => '', … … 336 354 'required' => true, 337 355 'validation_msg' => '', 338 'id' => ' email_recipient',356 'id' => 'forms_email_recipient', 339 357 'class' => '', 340 358 'container_class' => '', … … 344 362 'group_id' => $settings_id 345 363 ); 346 347 364 $forms = self::cubewp_email_forms(); 348 if( !empty($forms) ){ 349 $fields['admin_email_post_types'] = array( 350 'label' => __( 'Form Type', 'cubewp-classified' ), 351 'name' => 'admin_email_post_types', 352 'type' => 'dropdown', 353 'description' => '', 354 'default_value' => '', 355 'placeholder' => '', 356 'options' => json_encode( $forms ), 357 'filter_post_types' => '', 358 'filter_taxonomy' => '', 359 'filter_user_roles' => '', 360 'appearance' => '', 361 'required' => true, 362 'validation_msg' => '', 363 'multiple' => false, 364 'select2_ui' => true, 365 'id' => 'admin_email_post_types', 366 'class' => '', 367 'container_class' => '', 368 'conditional' => false, 369 'group_id' => $settings_id 370 ); 371 } 365 $fields['forms_types'] = array( 366 'label' => __('Form Type', 'cubewp-classified'), 367 'name' => 'forms_types', 368 'type' => 'dropdown', 369 'description' => '', 370 'default_value' => '', 371 'placeholder' => '', 372 'options' => json_encode($forms), 373 'filter_post_types' => '', 374 'filter_taxonomy' => '', 375 'filter_user_roles' => '', 376 'appearance' => '', 377 'required' => true, 378 'validation_msg' => '', 379 'multiple' => false, 380 'select2_ui' => true, 381 'id' => 'forms_types', 382 'class' => '', 383 'container_class' => '', 384 'conditional' => false, 385 'group_id' => $settings_id 386 ); 372 387 return $fields; 373 388 } 374 389 375 private static function cubewp_email_forms() { 390 private static function cubewp_email_forms() 391 { 376 392 $cwp_forms_posts = get_posts(array( 377 393 'post_type' => 'cwp_forms', … … 381 397 // Initialize an empty array to store posts with post ID as key and title as value 382 398 $cwp_forms = array(); 383 if ( !empty($cwp_forms_posts) ){399 if (!empty($cwp_forms_posts)) { 384 400 // Loop through each post 385 401 foreach ($cwp_forms_posts as $post) { … … 391 407 return $cwp_forms; 392 408 } 393 394 409 } -
cubewp-forms/trunk/cube/functions/functions.php
r3146073 r3165530 1 1 <?php 2 2 3 if ( ! function_exists( 'cwp_leads_create_database' ) ) { 4 function cwp_leads_create_database() { 5 global $wpdb; 6 $charset_collate = $wpdb->get_charset_collate(); 7 $wpdb->query("CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . "cwp_forms_leads` ( 3 if (! function_exists('cwp_leads_create_database')) { 4 function cwp_leads_create_database() 5 { 6 global $wpdb; 7 $charset_collate = $wpdb->get_charset_collate(); 8 $wpdb->query("CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . "cwp_forms_leads` ( 8 9 `id` bigint(20) unsigned NOT NULL auto_increment, 9 10 `lead_id` longtext NOT NULL, … … 17 18 PRIMARY KEY (`id`) 18 19 ) $charset_collate"); 19 } 20 add_action( 'admin_init', 'cwp_leads_create_database', 20 ); 21 } 22 23 if ( ! function_exists( 'cwp_insert_leads' ) ) { 24 function cwp_insert_leads($data = array()) { 25 global $wpdb; 26 $wpdb->insert( $wpdb->prefix . "cwp_forms_leads", array( 20 } 21 add_action('admin_init', 'cwp_leads_create_database', 20); 22 } 23 24 if (! function_exists('cwp_insert_leads')) { 25 function cwp_insert_leads($data = array()) 26 { 27 global $wpdb; 28 $wpdb->insert($wpdb->prefix . "cwp_forms_leads", array( 27 29 'lead_id' => isset($data['lead_id']) ? $data['lead_id'] : '', 28 30 'user_id' => isset($data['user_id']) ? $data['user_id'] : '', … … 32 34 'single_post' => isset($data['single_post']) ? $data['single_post'] : '', 33 35 'fields' => isset($data['fields']) ? serialize($data['fields']) : array(), 34 'dete_time' => isset($data['dete_time']) ? $data['dete_time'] : '' 35 ), array( '%s', '%d', '%d', '%s', '%d', '%s', '%s', '%d' ) ); 36 } 37 } 38 39 if ( ! function_exists( 'cwp_forms_all_leads' ) ) { 40 function cwp_forms_all_leads( ) { 41 global $wpdb; 42 $leads = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}cwp_forms_leads", ARRAY_A ); 43 if(!empty($leads) && count($leads) > 0){ 44 return $leads; 45 } 46 return array(); 47 } 48 } 49 50 if ( ! function_exists( 'cwp_forms_all_leads_by_lead_id' ) ) { 51 function cwp_forms_all_leads_by_lead_id( $leadid = '') { 52 global $wpdb; 53 $leads = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}cwp_forms_leads WHERE lead_id='{$leadid}'", ARRAY_A ); 54 if(!empty($leads) && count($leads) > 0){ 55 return $leads; 56 } 57 return array(); 58 } 59 } 60 61 if ( ! function_exists( 'cwp_forms_all_leads_by_id' ) ) { 62 function cwp_forms_all_leads_by_id( $id = '') { 63 global $wpdb; 64 $leads = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}cwp_forms_leads WHERE id={$id}", ARRAY_A ); 65 if(!empty($leads) && count($leads) > 0){ 66 return $leads; 67 } 68 return array(); 69 } 70 } 71 if ( ! function_exists( 'cwp_forms_all_leads_by_post_author' ) ) { 72 function cwp_forms_all_leads_by_post_author( $id = '') { 73 global $wpdb; 74 $leads = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}cwp_forms_leads WHERE post_author={$id}", ARRAY_A ); 75 if(!empty($leads) && count($leads) > 0){ 76 return $leads; 77 } 78 return array(); 79 } 36 'dete_time' => isset($data['dete_time']) ? $data['dete_time'] : '' 37 ), array('%s', '%d', '%d', '%s', '%d', '%s', '%s', '%d')); 38 } 39 } 40 41 if (! function_exists('cwp_forms_all_leads')) { 42 function cwp_forms_all_leads() 43 { 44 global $wpdb; 45 $leads = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}cwp_forms_leads", ARRAY_A); 46 if (!empty($leads) && count($leads) > 0) { 47 return $leads; 48 } 49 return array(); 50 } 51 } 52 53 if (! function_exists('cwp_forms_all_leads_by_lead_id')) { 54 function cwp_forms_all_leads_by_lead_id($leadid = '') 55 { 56 global $wpdb; 57 $leads = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}cwp_forms_leads WHERE lead_id='{$leadid}'", ARRAY_A); 58 if (!empty($leads) && count($leads) > 0) { 59 return $leads; 60 } 61 return array(); 62 } 63 } 64 65 if (! function_exists('cwp_forms_all_leads_by_id')) { 66 function cwp_forms_all_leads_by_id($id = '') 67 { 68 global $wpdb; 69 $leads = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}cwp_forms_leads WHERE id={$id}", ARRAY_A); 70 if (!empty($leads) && count($leads) > 0) { 71 return $leads; 72 } 73 return array(); 74 } 75 } 76 if (! function_exists('cwp_forms_all_leads_by_post_author')) { 77 function cwp_forms_all_leads_by_post_author($id = '') 78 { 79 global $wpdb; 80 $leads = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}cwp_forms_leads WHERE post_author={$id}", ARRAY_A); 81 if (!empty($leads) && count($leads) > 0) { 82 return $leads; 83 } 84 return array(); 85 } 80 86 } 81 87 /** … … 85 91 * @since 1.0.0 86 92 */ 87 if ( ! function_exists('cwp_dashboard_leads_tab')) { 88 function cwp_dashboard_leads_tab(){ 93 if (! function_exists('cwp_dashboard_leads_tab')) { 94 function cwp_dashboard_leads_tab() 95 { 89 96 return CubeWp_Forms_Dashboard::cwp_leads(); 90 97 } … … 99 106 * @since 1.0.0 100 107 */ 101 if ( ! function_exists('cwp_remove_lead_from_post')) { 102 function cwp_remove_lead_from_post($leadid = 0){ 103 if($leadid == 0) 104 return; 108 if (! function_exists('cwp_remove_lead_from_post')) { 109 function cwp_remove_lead_from_post($leadid = 0) 110 { 111 if ($leadid == 0) 112 return; 105 113 106 114 $form_id = cwp_form_id_by_lead_id($leadid); … … 120 128 * @since 1.0.0 121 129 */ 122 if ( ! function_exists('cwp_remove_lead_from_author')) { 123 function cwp_remove_lead_from_author($leadid = 0){ 124 if($leadid == 0) 125 return; 130 if (! function_exists('cwp_remove_lead_from_author')) { 131 function cwp_remove_lead_from_author($leadid = 0) 132 { 133 if ($leadid == 0) 134 return; 126 135 127 136 $author_id = cwp_author_id_by_lead_id($leadid); 128 137 $user_form_data_id = json_decode(get_user_meta($author_id, '_cwp_custom_form_data_id', true)); 129 138 unset($user_form_data_id->$leadid); 130 update_user_meta( $author_id, '_cwp_custom_form_data_id', json_encode($user_form_data_id));139 update_user_meta($author_id, '_cwp_custom_form_data_id', json_encode($user_form_data_id)); 131 140 } 132 141 } … … 140 149 * @since 1.0.0 141 150 */ 142 if ( ! function_exists('cwp_remove_lead')) { 143 function cwp_remove_lead($leadid = 0){ 144 if($leadid == 0) 145 return; 151 if (! function_exists('cwp_remove_lead')) { 152 function cwp_remove_lead($leadid = 0) 153 { 154 if ($leadid == 0) 155 return; 146 156 global $wpdb; 147 157 cwp_remove_lead_from_author($leadid); 148 158 cwp_remove_lead_from_post($leadid); 149 $wpdb->delete( $wpdb->prefix.'cwp_forms_leads', array( 'lead_id' => $leadid ), array( '%s' ));159 $wpdb->delete($wpdb->prefix . 'cwp_forms_leads', array('lead_id' => $leadid), array('%s')); 150 160 } 151 161 } … … 159 169 * @since 1.0.0 160 170 */ 161 if ( ! function_exists('cwp_form_id_by_lead_id')) { 162 function cwp_form_id_by_lead_id($leadid = 0){ 163 if($leadid == 0) 164 return; 171 if (! function_exists('cwp_form_id_by_lead_id')) { 172 function cwp_form_id_by_lead_id($leadid = 0) 173 { 174 if ($leadid == 0) 175 return; 165 176 166 177 $form_data = cwp_forms_all_leads_by_lead_id($leadid); 167 if (isset($form_data['form_id'])){178 if (isset($form_data['form_id'])) { 168 179 return $form_data['form_id']; 169 180 } … … 179 190 * @since 1.0.0 180 191 */ 181 if ( ! function_exists('cwp_post_id_by_lead_id')) { 182 function cwp_post_id_by_lead_id($leadid = 0){ 183 if($leadid == 0) 184 return; 192 if (! function_exists('cwp_post_id_by_lead_id')) { 193 function cwp_post_id_by_lead_id($leadid = 0) 194 { 195 if ($leadid == 0) 196 return; 185 197 186 198 $form_data = cwp_forms_all_leads_by_lead_id($leadid); 187 if (isset($form_data['single_post'])){199 if (isset($form_data['single_post'])) { 188 200 return $form_data['single_post']; 189 201 } … … 199 211 * @since 1.0.0 200 212 */ 201 if ( ! function_exists('cwp_author_id_by_lead_id')) { 202 function cwp_author_id_by_lead_id($leadid = 0){ 203 if($leadid == 0) 204 return; 213 if (! function_exists('cwp_author_id_by_lead_id')) { 214 function cwp_author_id_by_lead_id($leadid = 0) 215 { 216 if ($leadid == 0) 217 return; 205 218 206 219 $form_data = cwp_forms_all_leads_by_lead_id($leadid); 207 if (isset($form_data['post_author'])){220 if (isset($form_data['post_author'])) { 208 221 return $form_data['post_author']; 209 222 } … … 219 232 * @since 1.0.0 220 233 */ 221 if ( ! function_exists('cwp_lead_date_by_lead_id')) { 222 function cwp_lead_date_by_lead_id($leadid = 0){ 223 if($leadid == 0) 224 return; 234 if (! function_exists('cwp_lead_date_by_lead_id')) { 235 function cwp_lead_date_by_lead_id($leadid = 0) 236 { 237 if ($leadid == 0) 238 return; 225 239 226 240 $form_data = cwp_forms_all_leads_by_lead_id($leadid); 227 if (isset($form_data['dete_time'])){241 if (isset($form_data['dete_time'])) { 228 242 return $form_data['dete_time']; 229 243 } … … 241 255 * @since 1.0.0 242 256 */ 243 if ( ! function_exists('cwp_upload_custom_form_gallery_images')) { 244 function cwp_upload_custom_form_gallery_images( $key = '', $val = array(), $files = array(), $post_id = 0 ){ 245 257 if (! function_exists('cwp_upload_custom_form_gallery_images')) { 258 function cwp_upload_custom_form_gallery_images($key = '', $val = array(), $files = array(), $post_id = 0) 259 { 260 246 261 $attachment_ids = array(); 247 if (isset($val) && !empty($val) && is_array($val)){248 foreach ($val as $file_id){249 if (isset($files['cwp_custom_form']['name']['fields'][$key][$file_id])){262 if (isset($val) && !empty($val) && is_array($val)) { 263 foreach ($val as $file_id) { 264 if (isset($files['cwp_custom_form']['name']['fields'][$key][$file_id])) { 250 265 $file_names = $files['cwp_custom_form']['name']['fields'][$key][$file_id]; 251 foreach ($file_names as $file_key => $file_name){252 if ( $file_name != '' ){253 $file = array( 266 foreach ($file_names as $file_key => $file_name) { 267 if ($file_name != '') { 268 $file = array( 254 269 'name' => $files['cwp_custom_form']['name']['fields'][$key][$file_id][$file_key], 255 270 'type' => $files['cwp_custom_form']['type']['fields'][$key][$file_id][$file_key], 256 271 'tmp_name' => $files['cwp_custom_form']['tmp_name']['fields'][$key][$file_id][$file_key], 257 272 'error' => $files['cwp_custom_form']['error']['fields'][$key][$file_id][$file_key], 258 'size' => $files['cwp_custom_form']['size']['fields'][$key][$file_id][$file_key] 273 'size' => $files['cwp_custom_form']['size']['fields'][$key][$file_id][$file_key] 259 274 ); 260 $attachment_ids[] = cwp_handle_attachment( $file, $post_id);275 $attachment_ids[] = cwp_handle_attachment($file, $post_id); 261 276 } 262 277 } 263 } else{278 } else { 264 279 $attachment_ids[] = $file_id; 265 280 } … … 283 298 * @since 1.0.0 284 299 */ 285 if ( ! function_exists('cwp_upload_custom_form_repeating_gallery_images')) { 286 function cwp_upload_custom_form_repeating_gallery_images( $key = '',$_key = '',$field_key= '', $val = array(), $files = array(), $post_id = 0 ){ 287 300 if (! function_exists('cwp_upload_custom_form_repeating_gallery_images')) { 301 function cwp_upload_custom_form_repeating_gallery_images($key = '', $_key = '', $field_key = '', $val = array(), $files = array(), $post_id = 0) 302 { 303 288 304 $attachment_ids = array(); 289 if (isset($val) && !empty($val) && is_array($val)){290 foreach ($val as $file_id){291 if (isset($files['cwp_custom_form']['name']['fields'][$key][$_key][$field_key][$file_id])){305 if (isset($val) && !empty($val) && is_array($val)) { 306 foreach ($val as $file_id) { 307 if (isset($files['cwp_custom_form']['name']['fields'][$key][$_key][$field_key][$file_id])) { 292 308 $file_names = $files['cwp_custom_form']['name']['fields'][$key][$_key][$field_key][$file_id]; 293 foreach ($file_names as $file_key => $file_name){294 if ( $file_name != '' ){295 $file = array( 309 foreach ($file_names as $file_key => $file_name) { 310 if ($file_name != '') { 311 $file = array( 296 312 'name' => $files['cwp_custom_form']['name']['fields'][$key][$_key][$field_key][$file_id][$file_key], 297 313 'type' => $files['cwp_custom_form']['type']['fields'][$key][$_key][$field_key][$file_id][$file_key], 298 314 'tmp_name' => $files['cwp_custom_form']['tmp_name']['fields'][$key][$_key][$field_key][$file_id][$file_key], 299 315 'error' => $files['cwp_custom_form']['error']['fields'][$key][$_key][$field_key][$file_id][$file_key], 300 'size' => $files['cwp_custom_form']['size']['fields'][$key][$_key][$field_key][$file_id][$file_key] 316 'size' => $files['cwp_custom_form']['size']['fields'][$key][$_key][$field_key][$file_id][$file_key] 301 317 ); 302 $attachment_ids[] = cwp_handle_attachment( $file, $post_id);318 $attachment_ids[] = cwp_handle_attachment($file, $post_id); 303 319 } 304 320 } 305 } else{321 } else { 306 322 $attachment_ids[] = $file_id; 307 323 } … … 323 339 * @since 1.0.0 324 340 */ 325 if ( ! function_exists('cwp_upload_custom_form_file')) { 326 function cwp_upload_custom_form_file( $key = '', $val = array(), $files = array(), $post_id = 0 ){ 327 341 if (! function_exists('cwp_upload_custom_form_file')) { 342 function cwp_upload_custom_form_file($key = '', $val = array(), $files = array(), $post_id = 0) 343 { 344 328 345 $attachment_id = ''; 329 if (isset($files['cwp_custom_form']['name']['fields'][$key]) && $files['cwp_custom_form']['name']['fields'][$key] != ''){330 $file = array( 346 if (isset($files['cwp_custom_form']['name']['fields'][$key]) && $files['cwp_custom_form']['name']['fields'][$key] != '') { 347 $file = array( 331 348 'name' => $files['cwp_custom_form']['name']['fields'][$key], 332 349 'type' => $files['cwp_custom_form']['type']['fields'][$key], 333 350 'tmp_name' => $files['cwp_custom_form']['tmp_name']['fields'][$key], 334 351 'error' => $files['cwp_custom_form']['error']['fields'][$key], 335 'size' => $files['cwp_custom_form']['size']['fields'][$key] 352 'size' => $files['cwp_custom_form']['size']['fields'][$key] 336 353 ); 337 $attachment_id = cwp_handle_attachment( $file, $post_id);338 } else if(isset($val) && $val != 0){354 $attachment_id = cwp_handle_attachment($file, $post_id); 355 } else if (isset($val) && $val != 0) { 339 356 $attachment_id = $val; 340 357 } … … 342 359 } 343 360 } 344 add_filter( 'cubewp/custom_fields/custom_forms/fields', 'custom_form_fields_update', 9,2);361 add_filter('cubewp/custom_fields/custom_forms/fields', 'custom_form_fields_update', 9, 2); 345 362 346 363 /** … … 353 370 * @since 1.0.0 354 371 */ 355 function custom_form_fields_update($fields_settings = array(), $fieldData = array()) { 372 function custom_form_fields_update($fields_settings = array(), $fieldData = array()) 373 { 356 374 unset($fields_settings['field_rest_api']); 357 375 unset($fields_settings['field_admin_size']); … … 361 379 } 362 380 363 if ( ! function_exists( 'cubewp_add_recaptcha_settings_sections' ) ) { 364 function cubewp_add_recaptcha_settings_sections( $sections ) { 365 $sections['recaptcha-settings'] = array( 366 'title' => __( 'reCAPTCHA Config', 'cubewp' ), 367 'id' => 'recaptcha-settings', 368 'icon' => 'dashicons-shield', 369 'fields' => array( 370 array( 371 'id' => 'recaptcha', 372 'type' => 'switch', 373 'title' => __( 'Enable reCAPTCHA', 'cubewp-framework' ), 374 'default' => '0', 375 'desc' => __( 'Enable if you reCAPTCHA on your CubeWP forms.', 'cubewp-framework' ), 376 ), 377 array( 378 'id' => 'recaptcha_type', 379 'type' => 'select', 380 'title' => __( 'Select reCAPTCHA Type', 'cubewp-framework' ), 381 'subtitle' => '', 382 'desc' => __( 'Select the type of reCAPTCHA you want to use on to your CubeWP forms.', 'cubewp-framework' ), 383 'options' => array( 384 'google_v2' => __( 'Google reCAPTCHA v2 Checkbox', 'cubewp-framework' ), 385 ), 386 'default' => 'google_v2', 387 'required' => array( 388 array( 'recaptcha', 'equals', '1' ) 381 if (! function_exists('cubewp_add_recaptcha_settings_sections')) { 382 function cubewp_add_recaptcha_settings_sections($sections) 383 { 384 $sections['recaptcha-settings'] = array( 385 'title' => __('reCAPTCHA Config', 'cubewp'), 386 'id' => 'recaptcha-settings', 387 'icon' => 'dashicons-shield', 388 'fields' => array( 389 array( 390 'id' => 'recaptcha', 391 'type' => 'switch', 392 'title' => __('Enable reCAPTCHA', 'cubewp-framework'), 393 'default' => '0', 394 'desc' => __('Enable if you reCAPTCHA on your CubeWP forms.', 'cubewp-framework'), 395 ), 396 array( 397 'id' => 'recaptcha_type', 398 'type' => 'select', 399 'title' => __('Select reCAPTCHA Type', 'cubewp-framework'), 400 'subtitle' => '', 401 'desc' => __('Select the type of reCAPTCHA you want to use on to your CubeWP forms.', 'cubewp-framework'), 402 'options' => array( 403 'google_v2' => __('Google reCAPTCHA v2 Checkbox', 'cubewp-framework'), 404 ), 405 'default' => 'google_v2', 406 'required' => array( 407 array('recaptcha', 'equals', '1') 408 ) 409 ), 410 array( 411 'id' => 'google_recaptcha_sitekey', 412 'type' => 'text', 413 'title' => __('Site Key', 'cubewp-framework'), 414 'default' => '', 415 'desc' => __('Please enter google reCAPTCHA v2 Or v3 site key here.', 'cubewp-framework'), 416 'required' => array( 417 array('recaptcha', 'equals', '1') 418 ) 419 ), 420 array( 421 'id' => 'google_recaptcha_secretkey', 422 'type' => 'text', 423 'title' => __('Secret Key', 'cubewp-framework'), 424 'default' => '', 425 'desc' => __('Please enter google reCAPTCHA v2 Or v3 secret key here.', 'cubewp-framework'), 426 'required' => array( 427 array('recaptcha', 'equals', '1') 428 ) 429 ), 430 ) 431 ); 432 $sections['cubewp_forms_mailchimp'] = array( 433 'title' => __('Mailchimp', 'cubewp-framework'), 434 'id' => 'cubewp_forms_mailchimp', 435 'icon' => 'dashicons dashicons-images-alt2', 436 'fields' => array( 437 array( 438 'id' => 'cubewp_forms_mailchimp', 439 'title' => __('Mailchimp Integration', 'cubewp-forms'), 440 'desc' => __('Enable if you want to enable mailchimp integration with CubeWP Forms.', 'cubewp-forms'), 441 'type' => 'switch', 442 'default' => '0', 443 ), 444 array( 445 'id' => 'cubewp_forms_mailchimp_key', 446 'title' => __('Mailchimp Key', 'cubewp-forms'), 447 'desc' => __('Please enter api key you have for mailchimp account.', 'cubewp-forms'), 448 'type' => 'text', 449 'required' => array( 450 array('cubewp_forms_mailchimp', 'equals', '1') 451 ) 452 ), 453 array( 454 'id' => 'cubewp_forms_mailchimp_prefix', 455 'title' => __('Mailchimp Server Prefix', 'cubewp-forms'), 456 'desc' => __('Please enter Your Mailchimp Server Prefix of your mailchimp account.', 'cubewp-forms'), 457 'type' => 'text', 458 'placeholder' => 'us21', 459 'required' => array( 460 array('cubewp_forms_mailchimp', 'equals', '1') 461 ) 389 462 ) 390 ), 391 array( 392 'id' => 'google_recaptcha_sitekey', 393 'type' => 'text', 394 'title' => __( 'Site Key', 'cubewp-framework' ), 395 'default' => '', 396 'desc' => __( 'Please enter google reCAPTCHA v2 Or v3 site key here.', 'cubewp-framework' ), 397 'required' => array( 398 array( 'recaptcha', 'equals', '1' ) 399 ) 400 ), 401 array( 402 'id' => 'google_recaptcha_secretkey', 403 'type' => 'text', 404 'title' => __( 'Secret Key', 'cubewp-framework' ), 405 'default' => '', 406 'desc' => __( 'Please enter google reCAPTCHA v2 Or v3 secret key here.', 'cubewp-framework' ), 407 'required' => array( 408 array( 'recaptcha', 'equals', '1' ) 409 ) 410 ), 411 ) 412 ); 413 $sections['cubewp_forms_mailchimp'] = array( 414 'title' => __( 'Mailchimp', 'cubewp-framework' ), 415 'id' => 'cubewp_forms_mailchimp', 416 'icon' => 'dashicons dashicons-images-alt2', 417 'fields' => array( 418 array( 419 'id' => 'cubewp_forms_mailchimp', 420 'title' => __( 'Mailchimp Integration', 'cubewp-forms' ), 421 'desc' => __( 'Enable if you want to enable mailchimp integration with CubeWP Forms.', 'cubewp-forms' ), 422 'type' => 'switch', 423 'default' => '0', 424 ), 425 array( 426 'id' => 'cubewp_forms_mailchimp_key', 427 'title' => __( 'Mailchimp Key', 'cubewp-forms' ), 428 'desc' => __( 'Please enter api key you have for mailchimp account.', 'cubewp-forms' ), 429 'type' => 'text', 430 'required' => array( 431 array( 'cubewp_forms_mailchimp', 'equals', '1' ) 432 ) 433 ), 434 array( 435 'id' => 'cubewp_forms_mailchimp_prefix', 436 'title' => __( 'Mailchimp Server Prefix', 'cubewp-forms' ), 437 'desc' => __( 'Please enter Your Mailchimp Server Prefix of your mailchimp account.', 'cubewp-forms' ), 438 'type' => 'text', 439 'placeholder' => 'us21', 440 'required' => array( 441 array( 'cubewp_forms_mailchimp', 'equals', '1' ) 442 ) 443 ) 444 ), 445 ); 446 return $sections; 447 } 448 449 add_filter( 'cubewp/options/sections', 'cubewp_add_recaptcha_settings_sections', 9, 1 ); 450 } 451 463 ), 464 ); 465 return $sections; 466 } 467 468 add_filter('cubewp/options/sections', 'cubewp_add_recaptcha_settings_sections', 9, 1); 469 } 470 452 471 453 472 /** 454 473 * Class method, define folder path for import files 455 474 */ 456 function cwp_path_for_import_cubewp_content( $path ) { 457 $redirect_url = $path; 458 if(isset($_COOKIE['cubewp-forms-template-style'])) { 459 // Get the value of the cookie 460 $redirect_url = $_COOKIE['cubewp-forms-template-style']; 461 } 462 return $redirect_url; 463 } 464 add_filter( 'cubewp/import/content/path', 'cwp_path_for_import_cubewp_content' ); 475 function cwp_path_for_import_cubewp_content($path) 476 { 477 $redirect_url = $path; 478 if (isset($_COOKIE['cubewp-forms-template-style'])) { 479 // Get the value of the cookie 480 $redirect_url = $_COOKIE['cubewp-forms-template-style']; 481 } 482 return $redirect_url; 483 } 484 add_filter('cubewp/import/content/path', 'cwp_path_for_import_cubewp_content'); 465 485 466 486 /** 467 487 * Class method, define folder path for import files 468 488 */ 469 function cwp_redirect_after_sucess( $path ) { 470 $redirect_url = $path; 471 if(isset($_COOKIE['cubewp-forms-template-style']) ) { 472 // Get the value of the cookie 473 $redirect_url = admin_url( 'admin.php?page=cubewp-form-fields' ); 474 } 475 return $redirect_url; 476 } 477 add_filter( 'cubewp/after/import/redirect', 'cwp_redirect_after_sucess' ); 478 479 function cubewp_forms_mailchimp_cubes_fields( $fields , $cube ) { 480 global $cwpOptions; 481 if ( isset( $cwpOptions['cubewp_forms_mailchimp'] ) && $cwpOptions['cubewp_forms_mailchimp'] == '1' ) { 482 $fields['cubewp_mailchimp_field_key'] = array( 483 'class' => 'group-field field-cubewp_mailchimp_field_key mailchimp-based', 484 'name' => 'cwp[fields]['.$cube['name'].'][cubewp_mailchimp_field_key]', 485 'label' => esc_html__( 'Mailchimp Field ID', 'cubewp-forms' ), 486 'type' => 'text', 487 'id' => 'cubewp_mailchimp_field_'.$cube['id'], 488 'placeholder' => 'xxxxxxxxxx', 489 'value' => $cube['cubewp_mailchimp_field_key'] ?? '', 490 ); 491 } 492 return $fields; 493 } 494 add_filter( 'cubewp/custom_fields/custom_forms/fields', 'cubewp_forms_mailchimp_cubes_fields' , 11 , 2); 495 496 add_action( 'cubewp_forms_mailchimp_errors', 'cubewp_forms_display_errors_page' ); 497 function cubewp_forms_display_errors_page() { 498 ?> 489 function cwp_redirect_after_sucess($path) 490 { 491 $redirect_url = $path; 492 if (isset($_COOKIE['cubewp-forms-template-style'])) { 493 // Get the value of the cookie 494 $redirect_url = admin_url('admin.php?page=cubewp-form-fields'); 495 } 496 return $redirect_url; 497 } 498 add_filter('cubewp/after/import/redirect', 'cwp_redirect_after_sucess'); 499 500 function cubewp_forms_mailchimp_cubes_fields($fields, $cube) 501 { 502 global $cwpOptions; 503 if (isset($cwpOptions['cubewp_forms_mailchimp']) && $cwpOptions['cubewp_forms_mailchimp'] == '1') { 504 $fields['cubewp_mailchimp_field_key'] = array( 505 'class' => 'group-field field-cubewp_mailchimp_field_key mailchimp-based', 506 'name' => 'cwp[fields][' . $cube['name'] . '][cubewp_mailchimp_field_key]', 507 'label' => esc_html__('Mailchimp Field ID', 'cubewp-forms'), 508 'type' => 'text', 509 'id' => 'cubewp_mailchimp_field_' . $cube['id'], 510 'placeholder' => 'xxxxxxxxxx', 511 'value' => $cube['cubewp_mailchimp_field_key'] ?? '', 512 ); 513 } 514 return $fields; 515 } 516 add_filter('cubewp/custom_fields/custom_forms/fields', 'cubewp_forms_mailchimp_cubes_fields', 11, 2); 517 518 add_action('cubewp_forms_mailchimp_errors', 'cubewp_forms_display_errors_page'); 519 function cubewp_forms_display_errors_page() 520 { 521 ?> 499 522 <div class="wrap"> 500 523 <h2>Mailchimp API Errors</h2> 501 <button class="cubewp-forms-clear-mailchimp-logs" style="float:right">Clear Log</button>524 <button class="cubewp-forms-clear-mailchimp-logs" style="float:right">Clear Log</button> 502 525 <table class="widefat"> 503 526 <thead> … … 510 533 <?php 511 534 global $wpdb; 512 $table_name = $wpdb->prefix . 'cubewp_mailchimp_errors';513 514 // Check if the table exists515 $table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'");516 517 if ($table_exists) {518 // Table exists, proceed with the query519 $errors = $wpdb->get_results("SELECT * FROM $table_name ORDER BY id DESC", ARRAY_A);520 521 // Output the results522 foreach ($errors as $error) {523 echo '<tr>';524 echo '<td>' . esc_html($error['error_message']) . '</td>';525 echo '<td>' . esc_html($error['error_date']) . '</td>';526 echo '</tr>';527 }528 }535 $table_name = $wpdb->prefix . 'cubewp_mailchimp_errors'; 536 537 // Check if the table exists 538 $table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'"); 539 540 if ($table_exists) { 541 // Table exists, proceed with the query 542 $errors = $wpdb->get_results("SELECT * FROM $table_name ORDER BY id DESC", ARRAY_A); 543 544 // Output the results 545 foreach ($errors as $error) { 546 echo '<tr>'; 547 echo '<td>' . esc_html($error['error_message']) . '</td>'; 548 echo '<td>' . esc_html($error['error_date']) . '</td>'; 549 echo '</tr>'; 550 } 551 } 529 552 ?> 530 553 </tbody> … … 535 558 536 559 add_action('wp_ajax_clear_mailchimp_logs', 'clear_mailchimp_logs'); 537 function clear_mailchimp_logs() { 560 function clear_mailchimp_logs() 561 { 538 562 global $wpdb; 539 563 $table_name = $wpdb->prefix . 'cubewp_mailchimp_errors'; … … 543 567 544 568 add_action('wp_ajax_get_email_template_data', 'get_email_template_data_callback'); 545 function get_email_template_data_callback() { 546 547 $fields = array(); 569 function get_email_template_data_callback() 570 { 571 572 $fields = array(); 548 573 // Get the selected option values from the AJAX request 549 574 $selectedOptions = isset($_POST['selectedOptions']) ? $_POST['selectedOptions'] : ''; 550 if( !empty($selectedOptions) ){ 551 $groupFields = explode( ',' , get_post_meta( $selectedOptions , '_cwp_group_fields' ,true ) ); 552 $fields = array_merge( $fields , $groupFields); 553 } 554 $custom_fields = CWP()->get_custom_fields('custom_forms'); 555 556 if( !empty($fields) ){ 557 echo '<div class="cubewp-email-template-shortcode-ajax">'; 558 foreach( $fields as $field ){ 559 ?> 560 <div class="cubewp-email-template-shortcode"> 561 <span class="cubewp-email-template-shortcode-label"><?php echo esc_attr($custom_fields[$field]['label']); ?></span> 562 <span class="cubewp-email-template-shortcode-value">{<?php echo esc_attr($field); ?>}</span> 563 </div> 564 <?php 565 } 566 echo '</div>'; 567 } 575 if (!empty($selectedOptions)) { 576 $groupFields = explode(',', get_post_meta($selectedOptions, '_cwp_group_fields', true)); 577 $fields = array_merge($fields, $groupFields); 578 } 579 $custom_fields = CWP()->get_custom_fields('custom_forms'); 580 581 if (!empty($fields)) { 582 echo '<div class="cubewp-email-template-shortcode-ajax">'; 583 foreach ($fields as $field) { 584 if (isset($custom_fields[$field]['label']) && !empty($field)) { 585 ?> 586 <div class="cubewp-email-template-shortcode"> 587 <span class="cubewp-email-template-shortcode-label"><?php echo esc_attr($custom_fields[$field]['label']); ?></span> 588 <span class="cubewp-email-template-shortcode-value">{<?php echo esc_attr($field); ?>}</span> 589 </div> 590 <?php 591 } 592 } 593 echo '</div>'; 594 } 568 595 // Always remember to exit after sending the response 569 596 wp_die(); 570 597 } 571 598 572 if ( ! function_exists( 'cubewp_forms_get_email_template' ) ) { 573 function cubewp_forms_get_email_template( $recipient , $form_id ) { 574 $args = array( 575 'post_type' => CubeWp_Forms_Emails::$post_type, 576 'post_status' => 'publish', 577 'fields' => 'ids', 578 'posts_per_page' => 1, 579 'meta_query' => array( 580 'relation' => 'AND', 581 array( 582 'key' => 'email_recipient', 583 'value' => $recipient, 584 'compare' => '==' 585 ), 586 array( 587 'key' => 'admin_email_post_types', 588 'value' => $form_id, 589 'compare' => '==' 590 ), 591 ) 592 ); 593 $templates = get_posts( $args ); 594 return $templates; 595 } 596 } 597 598 if ( ! function_exists("CubeWp_Forms_Sanitize_Fields_Array")) { 599 function CubeWp_Forms_Sanitize_Fields_Array($input, $fields_of) { 600 599 if (! function_exists('cubewp_forms_get_email_template')) { 600 function cubewp_forms_get_email_template($recipient, $form_id) 601 { 602 $args = array( 603 'post_type' => CubeWp_Forms_Emails::$post_type, 604 'post_status' => 'publish', 605 'fields' => 'ids', 606 'posts_per_page' => 1, 607 'meta_query' => array( 608 'relation' => 'AND', 609 array( 610 'key' => 'email_recipient', 611 'value' => $recipient, 612 'compare' => '==' 613 ), 614 array( 615 'key' => 'admin_email_post_types', 616 'value' => $form_id, 617 'compare' => '==' 618 ), 619 ) 620 ); 621 $templates = get_posts($args); 622 return $templates; 623 } 624 } 625 626 if (! function_exists("CubeWp_Forms_Sanitize_Fields_Array")) { 627 function CubeWp_Forms_Sanitize_Fields_Array($input, $fields_of) 628 { 629 601 630 $sanitize = new CubeWp_Sanitize(); 602 631 $return = $input; -
cubewp-forms/trunk/cubewp-forms.php
r3155358 r3165530 4 4 * Plugin URI: https://cubewp.com/ 5 5 * Description: LeadGen & Contact Form by CubeWP – Drag & Drop Form Builder for WordPress 6 * Version: 1.1. 36 * Version: 1.1.4 7 7 * Author: CubeWP 8 8 * Author URI: https://CubeWp.com -
cubewp-forms/trunk/readme.txt
r3155358 r3165530 6 6 Requires PHP: 7.0 7 7 Tested up to: 6.6.1 8 Stable tag: 1.1. 38 Stable tag: 1.1.4 9 9 License: GPLv2 or later 10 10 … … 253 253 == Changelog == 254 254 255 = 1.1.4 2024-10-08 256 257 * Fixed: Invalid Nonce on Forms Template Import. 258 * Fixed: Removed extra closing div and aslo removed 1 when no leads found in CubeWP Dashboard. 259 * Fixed: Email Field shortcodes based on fields for Custom Forms. 260 255 261 = 1.1.2 2024-09-03 256 262
Note: See TracChangeset
for help on using the changeset viewer.