| @@ -23,8 +23,24 @@ | ||
| 23 | 23 | class Cf7_Grid_Layout_Admin { |
| 24 | 24 | /** |
| 25 | 25 | * The ID of this plugin. |
| 26 | 26 | * |
| 27 | + * @since 4.2.1 | |
| 28 | + * @access private | |
| 29 | + * @var string $plugin_name The ID of this plugin. | |
| 30 | + */ | |
| 31 | + private static $admin_notice_pages = array( | |
| 32 | + 'admin.php'=>array('cf7sg_help'=>'page'), | |
| 33 | + 'edit.php'=>array('wpcf7_contact_form'=>'post_type'), | |
| 34 | + 'post.php'=> 'wpcf7_contact_form', | |
| 35 | + 'edit-tags.php'=>array('wpcf7_contact_form'=>'post_type'), | |
| 36 | + 'index.php'=>'',//dashboard , | |
| 37 | + 'plugins.php'=>'', | |
| 38 | + //'options-general.php'=>'page=', | |
| 39 | + ); | |
| 40 | + /** | |
| 41 | + * The ID of this plugin. | |
| 42 | + * | |
| 27 | 43 | * @since 1.0.0 |
| 28 | 44 | * @access private |
| 29 | 45 | * @var string $plugin_name The ID of this plugin. |
| 30 | 46 | */ |
| @@ -107,15 +123,21 @@ | ||
| 107 | 123 | * |
| 108 | 124 | * @since 1.0.0 |
| 109 | 125 | */ |
| 110 | 126 | public function enqueue_styles($page) { |
| 127 | + | |
| 111 | 128 | if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ) return; |
| 112 | 129 | |
| 113 | 130 | $screen = get_current_screen(); |
| 131 | + $plugin_dir = plugin_dir_url( __DIR__ ); | |
| 132 | + if('plugins'==$screen->base){ | |
| 133 | + /** @since 4.1.0 */ | |
| 134 | + wp_enqueue_style('plugin-update',$plugin_dir . 'admin/css/cf7sg-plugin-update.css', array(), $this->version, 'all'); | |
| 135 | + return; | |
| 136 | + } | |
| 114 | 137 | if (empty($screen) || $this->cf7_post_type() != $screen->post_type){ |
| 115 | 138 | return; |
| 116 | 139 | } |
| 117 | - $plugin_dir = plugin_dir_url( __DIR__ ); | |
| 118 | 140 | switch( $screen->base ){ |
| 119 | 141 | case 'post': |
| 120 | 142 | wp_enqueue_style( "cf7-grid-post-css", $plugin_dir . 'admin/css/cf7-grid-layout-post.css', array(), $this->version, 'all' ); |
| 121 | 143 | //dynamic tag |
| @@ -132,12 +154,15 @@ | ||
| 132 | 154 | wp_enqueue_style( "codemirror-matchesonscrollbar-css", $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.css', array(), $this->version, 'all' ); |
| 133 | 155 | wp_enqueue_style( 'smart-grid-css', $plugin_dir . 'assets/css.gs/smart-grid.admin.css', array(), $this->version, 'all'); |
| 134 | 156 | wp_enqueue_style('dashicons'); |
| 135 | 157 | wp_enqueue_style('select2-style', $plugin_dir . 'assets/select2/css/select2.min.css', array(), $this->version, 'all' ); |
| 158 | + /** @since 4.4.0 Enabled user style enqueue */ | |
| 159 | + do_action('cf7sg_enqueue_admin_editor_styles'); | |
| 136 | 160 | break; |
| 137 | 161 | case 'edit': //table. |
| 138 | 162 | wp_enqueue_style( $this->plugin_name, $plugin_dir . 'admin/css/cf7-grid-layout-admin.css', array(), $this->version, 'all' ); |
| 139 | - | |
| 163 | + /** @since 4.4.0 Enabled user style enqueue */ | |
| 164 | + do_action('cf7sg_enqueue_admin_table_styles'); | |
| 140 | 165 | break; |
| 141 | 166 | } |
| 142 | 167 | |
| 143 | 168 | } |
| @@ -147,10 +172,9 @@ | ||
| 147 | 172 | * |
| 148 | 173 | * @since 1.0.0 |
| 149 | 174 | */ |
| 150 | 175 | public function enqueue_scripts($page) { |
| 151 | - global $post; | |
| 152 | - //debug_msg($screen, $this->custom_type ); | |
| 176 | + | |
| 153 | 177 | $plugin_dir = plugin_dir_url( __DIR__ ); |
| 154 | 178 | if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ){ |
| 155 | 179 | wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array( 'jquery' ), $this->version, true ); |
| 156 | 180 | return; |
| @@ -155,11 +179,23 @@ | ||
| 155 | 179 | wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array( 'jquery' ), $this->version, true ); |
| 156 | 180 | return; |
| 157 | 181 | } |
| 158 | 182 | $screen = get_current_screen(); |
| 183 | + if('plugins'==$screen->base){ | |
| 184 | + /** @since 4.1.0 */ | |
| 185 | + wp_enqueue_script('cf7sg-plugin-update', $plugin_dir . 'admin/js/cf7sg-plugin-update.js', array('jquery')); | |
| 186 | + /* translators: message displayed when succesful update to validate new version */ | |
| 187 | + wp_localize_script('cf7sg-plugin-update', 'cf7sg',array( | |
| 188 | + 'msg'=> __('Validating your update...','cf7-grid-layout'), | |
| 189 | + 'nonce'=> wp_create_nonce( 'cf7sg_udpate_plugin' ), | |
| 190 | + 'error'=>__('Unable to validate, please reload!', 'cf7-grid-layout') | |
| 191 | + )); | |
| 192 | + return; | |
| 193 | + } | |
| 159 | 194 | if ($this->cf7_post_type() != $screen->post_type){ |
| 160 | 195 | return; |
| 161 | 196 | } |
| 197 | + | |
| 162 | 198 | switch( $screen->base ){ |
| 163 | 199 | case 'post': |
| 164 | 200 | /* register codemirror editor & addons. */ |
| 165 | 201 | //codemirror script |
| @@ -169,9 +205,9 @@ | ||
| 169 | 205 | ); |
| 170 | 206 | /** @since 3.1.2 initialise codemirror after library load and parse as attribute to anonymous functtion in cf7-grid-codemirror.js */ |
| 171 | 207 | wp_add_inline_script('cf7-codemirror-js', |
| 172 | 208 | 'const cmInitialSettings = { |
| 173 | - value:"",matchTags: {bothTags: true},autoCloseTags:true, | |
| 209 | + value:"",autoCloseTags:true, | |
| 174 | 210 | extraKeys: {"Ctrl-Space": "autocomplete", "Ctrl-/": "toggleComment", "Ctrl-J": "toMatchingTag"}, |
| 175 | 211 | lineNumbers: true, styleActiveLine: true, |
| 176 | 212 | matchBrackets: true, tabSize:2, lineWrapping: true, addModeClass: true, |
| 177 | 213 | foldGutter: true, autofocus:false, |
| @@ -180,12 +216,8 @@ | ||
| 180 | 216 | const codeMirror_5_32 = CodeMirror(document.getElementById("cf7-codemirror"),cmInitialSettings); |
| 181 | 217 | const cssCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-css-codemirror"),cmInitialSettings); |
| 182 | 218 | const jsCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-js-codemirror"),cmInitialSettings);'); |
| 183 | 219 | //matchtags. |
| 184 | - wp_enqueue_script( 'codemirror-matchtag-js', | |
| 185 | - $plugin_dir . 'assets/codemirror/edit/matchtags.js', | |
| 186 | - array('cf7-codemirror-js'), $this->version, true | |
| 187 | - ); | |
| 188 | 220 | wp_enqueue_script( 'codemirror-closetag-js', |
| 189 | 221 | $plugin_dir . 'assets/codemirror/edit/closetag.js', |
| 190 | 222 | array('cf7-codemirror-js'), $this->version, true |
| 191 | 223 | ); |
| @@ -205,8 +237,12 @@ | ||
| 205 | 237 | wp_enqueue_script( 'codemirror-xml-fold-js', |
| 206 | 238 | $plugin_dir . 'assets/codemirror/addon/fold/xml-fold.js', |
| 207 | 239 | array('cf7-codemirror-js'), $this->version, true |
| 208 | 240 | ); |
| 241 | + wp_enqueue_script( 'codemirror-matchtag-js', | |
| 242 | + $plugin_dir . 'assets/codemirror/addon/edit/matchtags.js', | |
| 243 | + array('cf7-codemirror-js','codemirror-xml-fold-js'), $this->version, true | |
| 244 | + ); | |
| 209 | 245 | wp_enqueue_script( 'codemirror-brace-fold-js', |
| 210 | 246 | $plugin_dir . 'assets/codemirror/addon/fold/brace-fold.js', |
| 211 | 247 | array('cf7-codemirror-js'), $this->version, true |
| 212 | 248 | ); |
| @@ -324,9 +360,9 @@ | ||
| 324 | 360 | wp_localize_script( |
| 325 | 361 | 'cf7-grid-codemirror-js', |
| 326 | 362 | 'cf7sgeditor', |
| 327 | 363 | array( |
| 328 | - 'mode' => apply_filters('cf7sg_admin_editor_mode', 'shortcode', $post->post_name), | |
| 364 | + 'mode' => 'shortcode', | |
| 329 | 365 | 'theme' => array( |
| 330 | 366 | 'light'=>'paraiso-light', |
| 331 | 367 | 'dark'=>'material-ocean', |
| 332 | 368 | 'user'=>$user_theme |
| @@ -339,11 +375,14 @@ | ||
| 339 | 375 | 'csstheme' => array( |
| 340 | 376 | 'light'=>'paraiso-light', |
| 341 | 377 | 'dark'=>'material-ocean', |
| 342 | 378 | 'user'=>$user_css_theme |
| 343 | - ) | |
| 379 | + ), | |
| 380 | + 'jserror'=>__('There is a <strong>Javascript error on the page</strong> which prevents the editor from loading properly.', 'cf7-grid-layout'), | |
| 381 | + 'fixhtmlform'=>__('The editor failed to load. You may recover your form by copying it into a new form editor, do you wish to continue?', 'cf7-grid-layout'), | |
| 344 | 382 | ) |
| 345 | 383 | ); |
| 384 | + global $post; | |
| 346 | 385 | |
| 347 | 386 | wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array('cf7-grid-codemirror-js', 'jquery-ui-sortable' ), $this->version, true ); |
| 348 | 387 | wp_localize_script( |
| 349 | 388 | $this->plugin_name, |
| @@ -364,15 +403,16 @@ | ||
| 364 | 403 | 'msg'=>__('Click to copy!','cf7-grid-layout'), |
| 365 | 404 | 'filter'=> __('Filter mailTag %s', 'cf7-grid-layout') |
| 366 | 405 | ) |
| 367 | 406 | ); |
| 368 | - /** @since 3.3.0enqueue ui-grid helpers js */ | |
| 407 | + /** @since 3.3.0 enqueue ui-grid helpers js */ | |
| 369 | 408 | wp_enqueue_script('ui-grid-helpers-js', $plugin_dir.'admin/js/ui-custom-helper.js', array('jquery')); |
| 370 | 409 | do_action('cf7sg_enqueue_admin_editor_scripts'); |
| 371 | 410 | break; |
| 372 | 411 | case 'edit': |
| 373 | 412 | //wp_enqueue_script( $this->plugin_name.'-quick-edit', plugin_dir_url( __FILE__ ) . 'js/cf7-grid-layout-quick-edit.js', false, $this->version, true ); |
| 374 | - | |
| 413 | + /** @since 4.4.0 Enabled user script enqueue */ | |
| 414 | + do_action('cf7sg_enqueue_admin_table_scripts'); | |
| 375 | 415 | break; |
| 376 | 416 | } |
| 377 | 417 | } |
| 378 | 418 | |
| @@ -390,9 +430,9 @@ | ||
| 390 | 430 | 'wpcf7_edit_contact_forms', |
| 391 | 431 | 'post-new.php?post_type=wpcf7_contact_form' |
| 392 | 432 | ); |
| 393 | 433 | //initial cf7 object when creating new form |
| 394 | - add_action( 'load-' . $hook, array($this, 'setup_cf7_object')); | |
| 434 | + //add_action( 'load-' . $hook, array($this, 'setup_cf7_object')); | |
| 395 | 435 | //remove_submenu_page( $menu_slug, $submenu_slug ); |
| 396 | 436 | remove_submenu_page( 'wpcf7', 'wpcf7-new' ); |
| 397 | 437 | remove_meta_box('slugdiv', $this->cf7_post_type(), 'normal'); |
| 398 | 438 | } |
| @@ -529,38 +569,9 @@ | ||
| 529 | 569 | 'high' |
| 530 | 570 | ); |
| 531 | 571 | } |
| 532 | 572 | } |
| 533 | - /** | |
| 534 | - * Function called on page load when new form is created | |
| 535 | - * hooked to 'load-{page-hook}' | |
| 536 | - * @since 1.0.0 | |
| 537 | - **/ | |
| 538 | - public function setup_cf7_object(){ | |
| 539 | - $args = array(); | |
| 540 | - /** | |
| 541 | - * Fix locale setup for new forms using polylang. | |
| 542 | - * @since 2.1.4 | |
| 543 | - */ | |
| 544 | - if(isset($_GET['locale'])){ | |
| 545 | - $args['locale'] = $_GET['locale']; | |
| 546 | - }else if(isset($_GET['new_lang'])){ | |
| 547 | - //check for polylang | |
| 548 | - $locale = $_GET['new_lang']; | |
| 549 | - if(function_exists('pll_languages_list')){ | |
| 550 | - $langs = pll_languages_list(); | |
| 551 | - $locales = pll_languages_list(array('fields'=>'locale')); | |
| 552 | - foreach($langs as $idx => $lang){ | |
| 553 | - if($lang == $locale){ | |
| 554 | - $locale = $locales[$idx]; | |
| 555 | - } | |
| 556 | - } | |
| 557 | - } | |
| 558 | - $args['locale'] =$locale; | |
| 559 | - }else $args['locale'] = get_locale(); | |
| 560 | 573 | |
| 561 | - WPCF7_ContactForm::get_template( $args); | |
| 562 | - } | |
| 563 | 574 | /** |
| 564 | 575 | * Callback function to disolay the main editor meta box |
| 565 | 576 | * @since 1.0.0 |
| 566 | 577 | */ |
| @@ -569,11 +580,11 @@ | ||
| 569 | 580 | wpcf7_contact_form($post); //set the post |
| 570 | 581 | } |
| 571 | 582 | $post_id = $post->ID; |
| 572 | 583 | $cf7_form = wpcf7_get_current_contact_form(); |
| 573 | - | |
| 574 | 584 | if ( ! $cf7_form ) { |
| 575 | - $cf7_form = WPCF7_ContactForm::get_template(); | |
| 585 | + $args = apply_filters('cf7sg_new_cf7_form_template_arguments', array()); | |
| 586 | + $cf7_form = WPCF7_ContactForm::get_template($args); | |
| 576 | 587 | } |
| 577 | 588 | |
| 578 | 589 | // if(empty($post)){ |
| 579 | 590 | // $post_id = -1; |
| @@ -653,8 +664,21 @@ | ||
| 653 | 664 | public function grid_editor_panel($form_post){ |
| 654 | 665 | require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php'; |
| 655 | 666 | } |
| 656 | 667 | /** |
| 668 | + * Clean up post meta, delete sgcf7 corresponding view post. | |
| 669 | + * Hooked to action 'before_delete_post'. | |
| 670 | + *@since 4.3.0 | |
| 671 | + *@param int $post_id post ID. | |
| 672 | + *@param WP_Post post object. | |
| 673 | + */ | |
| 674 | + public function delete_post($post_id){ | |
| 675 | + if(get_post_type($post_id) != WPCF7_ContactForm::post_type) return; | |
| 676 | + //remove viwing post. | |
| 677 | + $preview_id = get_post_meta($post_id, '_cf7sg_form_page',true); | |
| 678 | + if(!empty($preview_id)) wp_delete_post($preview_id); | |
| 679 | + } | |
| 680 | + /** | |
| 657 | 681 | * Save cf7 post using ajax |
| 658 | 682 | * Hooked to 'save_post_wpcf7_contact_form' |
| 659 | 683 | * @since 1.0.0 |
| 660 | 684 | **/ |
| @@ -694,9 +718,9 @@ | ||
| 694 | 718 | 'value'=>1, |
| 695 | 719 | 'data-*'=>1, |
| 696 | 720 | ); |
| 697 | 721 | $allowed_tags['script']=array('type'=>1); |
| 698 | - $cf7_key = sanitize_text_field($_POST['post_name']); | |
| 722 | + $cf7_key = $post->post_name; | |
| 699 | 723 | $allowed_tags = apply_filters('cf7sg_kses_allowed_html',$allowed_tags, $cf7_key); |
| 700 | 724 | if(isset( $_POST['wpcf7-form'] )){ |
| 701 | 725 | $args['form'] = wp_kses($_POST['wpcf7-form'], $allowed_tags); |
| 702 | 726 | } |
| @@ -791,12 +815,12 @@ | ||
| 791 | 815 | update_post_meta($post_id, '_cf7sg_has_tables', $has_tables); |
| 792 | 816 | $has_toggles = ( 'true' === $_POST['cf7sg-has-toggles']) ? true : false; |
| 793 | 817 | update_post_meta($post_id, '_cf7sg_has_toggles', $has_toggles); |
| 794 | 818 | /** @since 3.3.5 track toggles in tabs */ |
| 795 | - $toggle_in_tabs = json_decode(stripslashes($_POST['cf7sg-toggle-in-tabs'])); | |
| 796 | - if(empty($toggle_in_tabs)) $toggle_in_tabs = array(); | |
| 797 | - if(!is_array($toggle_in_tabs)) $toggle_in_tabs = array($toggle_in_tabs); | |
| 798 | - update_post_meta($post_id, '_cf7sg_grid_toggle_in_tabs', $toggle_in_tabs); | |
| 819 | + // $toggle_in_tabs = json_decode(stripslashes($_POST['cf7sg-toggle-in-tabs'])); | |
| 820 | + // if(empty($toggle_in_tabs)) $toggle_in_tabs = array(); | |
| 821 | + // if(!is_array($toggle_in_tabs)) $toggle_in_tabs = array($toggle_in_tabs); | |
| 822 | + // update_post_meta($post_id, '_cf7sg_grid_toggle_in_tabs', $toggle_in_tabs); | |
| 799 | 823 | /** |
| 800 | 824 | * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms. |
| 801 | 825 | */ |
| 802 | 826 | $is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false; |
| @@ -823,9 +847,9 @@ | ||
| 823 | 847 | //check if the file name is changed. |
| 824 | 848 | if(!empty($_POST['cf7sg_prev_js_file']) && file_exists(ABSPATH. $_POST['cf7sg_prev_js_file'])){ |
| 825 | 849 | if( !unlink(ABSPATH.$_POST['cf7sg_prev_js_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_js_file']); |
| 826 | 850 | } |
| 827 | - if (!is_dir($path)) mkdir($path); | |
| 851 | + if( !is_dir("$path/js/") ) mkdir("$path/js/"); | |
| 828 | 852 | file_put_contents( "$path/js/{$cf7_key}.js", stripslashes($_POST['cf7sg_js_file']) ); |
| 829 | 853 | }else if( isset($_POST['cf7sg_js_file']) && file_exists("$path/js/{$cf7_key}.js") ) { //delete file. |
| 830 | 854 | if( !unlink("$path/js/{$cf7_key}.js") ) debug_msg("CF7SG ADMIN: unable to delete file $path/js/{$cf7_key}.js"); |
| 831 | 855 | } |
| @@ -834,9 +858,9 @@ | ||
| 834 | 858 | //check if the file is changed. |
| 835 | 859 | if(!empty($_POST['cf7sg_prev_css_file']) && file_exists(ABSPATH.$_POST['cf7sg_prev_css_file'])){ |
| 836 | 860 | if( !unlink(ABSPATH.$_POST['cf7sg_prev_css_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_css_file']); |
| 837 | 861 | } |
| 838 | - if (!is_dir($path)) mkdir($path); | |
| 862 | + if( !is_dir("$path/css/") ) mkdir("$path/css/"); | |
| 839 | 863 | file_put_contents( $path."/css/{$cf7_key}.css", stripslashes($_POST['cf7sg_css_file'])); |
| 840 | 864 | }else if( isset($_POST['cf7sg_css_file']) && file_exists("$path/css/{$cf7_key}.css") ) { //delete file. |
| 841 | 865 | if( !unlink("$path/css/{$cf7_key}.css") ) debug_msg("CF7SG ADMIN: unable to delete file $path/css/{$cf7_key}.css"); |
| 842 | 866 | } |
| @@ -842,8 +866,27 @@ | ||
| 842 | 866 | } |
| 843 | 867 | //jstags comments. |
| 844 | 868 | if(empty($_POST['cf7sg_jstags_comments'])) update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',1); |
| 845 | 869 | else update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',0); |
| 870 | + /** @since 4.3.0 create/update a preview form post for this form */ | |
| 871 | + $preview_id = get_post_meta($post->ID, '_cf7sg_form_page',true); | |
| 872 | + $content = '[cf7form cf7key="'.$cf7_key.'"'; | |
| 873 | + $content .= isset($_POST['post_lang_choice']) ? ' lang="'.$_POST['post_lang_choice'].'"]':']'; | |
| 874 | + $prev_page = array( | |
| 875 | + 'post_title'=>sanitize_text_field($_POST['post_title']), | |
| 876 | + 'post_content'=>$content, | |
| 877 | + 'post_status'=>'draft', | |
| 878 | + 'post_type'=>'cf7sg_page', | |
| 879 | + // 'post_name' => sanitize_title( $title ), | |
| 880 | + ); | |
| 881 | + if(empty($cf7_key)) $prev_page['post_content'] = '[contact-form-7 id="'.$post->ID.'"]'; | |
| 882 | + if( !empty($preview_id) ){ | |
| 883 | + $prev_page['ID'] = $preview_id; | |
| 884 | + } | |
| 885 | + $preview_id = wp_insert_post($prev_page, true); | |
| 886 | + if(!is_wp_error($preview_id)){ | |
| 887 | + update_post_meta($post->ID, '_cf7sg_form_page',$preview_id); | |
| 888 | + } | |
| 846 | 889 | } |
| 847 | 890 | /** |
| 848 | 891 | * Print default js template, |
| 849 | 892 | * Hooked to 'cf7sg_default_custom_js_template' |
| @@ -1232,9 +1275,14 @@ | ||
| 1232 | 1275 | /* tutorials */ |
| 1233 | 1276 | ob_clean(); |
| 1234 | 1277 | include_once 'partials/pointers/cf7sg-pointer-tutorials.php'; |
| 1235 | 1278 | $content =ob_get_contents(); |
| 1236 | - $pointers['tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=admin.php?page=cf7sg_help"]'); | |
| 1279 | + $pointers['tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]'); | |
| 1280 | + /* new tutorials */ | |
| 1281 | + ob_clean(); | |
| 1282 | + include_once 'partials/pointers/cf7sg-pointer-tutorial-advance.php'; | |
| 1283 | + $content =ob_get_contents(); | |
| 1284 | + $pointers['new_tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]'); | |
| 1237 | 1285 | /* shortcodes */ |
| 1238 | 1286 | ob_clean(); |
| 1239 | 1287 | include_once 'partials/pointers/cf7sg-pointer-shortcodes.php'; |
| 1240 | 1288 | $content = ob_get_clean(); |
| @@ -1266,8 +1314,16 @@ | ||
| 1266 | 1314 | if(!empty($content)){ |
| 1267 | 1315 | $pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls'); |
| 1268 | 1316 | ob_clean(); |
| 1269 | 1317 | } |
| 1318 | + /* preview form */ | |
| 1319 | + ob_clean(); | |
| 1320 | + include_once 'partials/pointers/cf7sg-pointer-editor-preview-form.php'; | |
| 1321 | + $content = ob_get_contents(); | |
| 1322 | + if(!empty($content)){ | |
| 1323 | + $pointers['preview_form'] = array($content, 'right', 'center','#preview-form-link'); | |
| 1324 | + ob_clean(); | |
| 1325 | + } | |
| 1270 | 1326 | include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php'; |
| 1271 | 1327 | $content = ob_get_contents(); |
| 1272 | 1328 | if(!empty($content)){ |
| 1273 | 1329 | $pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code'); |
| @@ -1399,6 +1455,224 @@ | ||
| 1399 | 1455 | } |
| 1400 | 1456 | //add a general form tag. |
| 1401 | 1457 | $mailtags[]= 'cf7sg-form-'.get_cf7form_key($contact_form->id()); |
| 1402 | 1458 | return $mailtags; |
| 1459 | + } | |
| 1460 | + /** | |
| 1461 | + * Funciton to to initialise admin notices. | |
| 1462 | + * hooked on 'admin_init' | |
| 1463 | + *@since 4.1.0 | |
| 1464 | + */ | |
| 1465 | + public function init_notices(){ | |
| 1466 | + $grid_settings = get_option( 'cf7sg-plugin-version', array()); | |
| 1467 | + //if plugin settings exists and this is not an update, then no need to run. | |
| 1468 | + if( !empty($grid_settings) and !isset($grid_settings['update']) ) return; | |
| 1469 | + | |
| 1470 | + $warning = false; | |
| 1471 | + $notices = array(); | |
| 1472 | + | |
| 1473 | + if(isset($grid_settings['update']) and CF7SG_VERSION_FORM_UPDATE==CF7_GRID_VERSION){ | |
| 1474 | + $warning = true; | |
| 1475 | + }else if(isset($grid_settings['fv']) ) { | |
| 1476 | + if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true; | |
| 1477 | + }else{ //check the forms directly | |
| 1478 | + global $wpdb; | |
| 1479 | + $post_type = $this->cf7_post_type(); | |
| 1480 | + $result = $wpdb->get_col("SELECT pm.meta_value FROM {$wpdb->postmeta} as pm | |
| 1481 | + INNER JOIN {$wpdb->posts} as p on p.ID = pm.post_id | |
| 1482 | + WHERE p.post_type = '{$post_type}' | |
| 1483 | + AND pm.meta_key = '_cf7sg_version' | |
| 1484 | + ORDER BY pm.meta_key | |
| 1485 | + "); | |
| 1486 | + if(!empty($result) and version_compare($result[0], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true; | |
| 1487 | + } | |
| 1488 | + | |
| 1489 | + if($warning){ | |
| 1490 | + $link = admin_url('edit.php?post_type=wpcf7_contact_form'); | |
| 1491 | + /* translators: %s is the url to the forms admin table */ | |
| 1492 | + $msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout'); | |
| 1493 | + $notices['cf7sg_notice-'.CF7_GRID_VERSION] = array( | |
| 1494 | + 'type'=>'notice-warning', //[notice-update|notice-error] | |
| 1495 | + 'msg'=>sprintf($msg , $link), | |
| 1496 | + 'pages'=>array('plugins.php','edit.php') | |
| 1497 | + ); | |
| 1498 | + } | |
| 1499 | + /** @since 4.2.0 new sliders tutorial */ | |
| 1500 | + if( isset($grid_settings['update']) ){ | |
| 1501 | + $notices['cf7sg_sliders_tutorial'] = array( | |
| 1502 | + 'type'=>'notice-update', //[notice-update|notice-error] | |
| 1503 | + /* translators: %s is the link to the tuorial page*/ | |
| 1504 | + 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">multistep slider forms</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')), | |
| 1505 | + 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/WiweQRhOr0g" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to create multi-step multi-slide CF7 forms using a slider construct functionality of the Smart Grid-layout extension plugin.</strong></div>', | |
| 1506 | + 'pages'=>array('plugins.php','edit.php') | |
| 1507 | + ); | |
| 1508 | + $notices['cf7sg_modular_tutorial'] = array( | |
| 1509 | + 'type'=>'notice-update', //[notice-update|notice-error] | |
| 1510 | + /* translators: %s is the link to the tuorial page*/ | |
| 1511 | + 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">modular form construct</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')), | |
| 1512 | + 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/vPc3M5Emro4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to use modular form construct functionality allowing complex forms to be assembled from other child forms.</strong></div>', | |
| 1513 | + 'pages'=>array('plugins.php','edit.php') | |
| 1514 | + ); | |
| 1515 | + } | |
| 1516 | + if(!empty($notices)) update_option('cf7sg-admin-notices', $notices); | |
| 1517 | + | |
| 1518 | + update_option('cf7sg-plugin-version', array( | |
| 1519 | + 'gv'=>CF7_GRID_VERSION, | |
| 1520 | + 'fv'=>CF7SG_VERSION_FORM_UPDATE | |
| 1521 | + )); | |
| 1522 | + } | |
| 1523 | + /** | |
| 1524 | + * Display admin notices | |
| 1525 | + * Hooked on 'admin_notices' | |
| 1526 | + *@since 4.1.0 | |
| 1527 | + */ | |
| 1528 | + public function admin_notices(){ | |
| 1529 | + //check if we have any notices. | |
| 1530 | + global $pagenow; | |
| 1531 | + $notices = get_option('cf7sg-admin-notices', array()); | |
| 1532 | + if(empty($notices)) return; | |
| 1533 | + | |
| 1534 | + if(!isset(self::$admin_notice_pages[$pagenow])) return; | |
| 1535 | + | |
| 1536 | + $notify=false; | |
| 1537 | + $rule = self::$admin_notice_pages[$pagenow]; | |
| 1538 | + // debug_msg($rule, 'notice rules '); | |
| 1539 | + if($pagenow=='post.php'){ | |
| 1540 | + $screen = get_current_screen(); | |
| 1541 | + if($this->cf7_post_type() == $screen->post_type) $notify=true; | |
| 1542 | + }else if( !empty($rule) and is_array($rule) ){ | |
| 1543 | + foreach($rule as $key=>$type){ | |
| 1544 | + if( isset($_GET[$type]) and $_GET[$type]==$key ) $notify=true; | |
| 1545 | + } | |
| 1546 | + }else $notify = true; //default. | |
| 1547 | + | |
| 1548 | + if(!$notify) return; //rules don't match; | |
| 1549 | + | |
| 1550 | + //do we have any notices to display? | |
| 1551 | + foreach($notices as $id=>$notice){ | |
| 1552 | + if( isset($notice['pages']) and !in_array($pagenow, $notice['pages'])) continue; | |
| 1553 | + $time = isset($notice['time']) ? $notice['time']: 'forever'; | |
| 1554 | + $dismiss = "$id-$time"; | |
| 1555 | + if ( ! PAnD::is_admin_notice_active( $dismiss ) ) { | |
| 1556 | + unset($notices[$id]); | |
| 1557 | + update_option('cf7sg-admin-notices', $notices); | |
| 1558 | + continue ; //continue foreach loop. | |
| 1559 | + } | |
| 1560 | + if(!isset($notice['html'])) $notice['html'] = ''; | |
| 1561 | + ?> | |
| 1562 | + <style>.notice .inline-top{display: inline-block;vertical-align: top;margin-right: 10px;max-width: 300px;}</style> | |
| 1563 | + <div data-dismissible="<?=$dismiss?>" class="notice <?=$notice['type']?> is-dismissible"><p><?=$notice['msg']?></p><?=$notice['html']?></div> | |
| 1564 | + <?php | |
| 1565 | + } | |
| 1566 | + } | |
| 1567 | + /** | |
| 1568 | + * ajax request to validate plugin update. | |
| 1569 | + * Hooked on 'wp_ajax_validate_cf7sg_version_update' | |
| 1570 | + * @since 4.1.0 | |
| 1571 | + */ | |
| 1572 | + public function validate_cf7sg_version_update(){ | |
| 1573 | + if( !isset($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], 'cf7sg_udpate_plugin') ){ | |
| 1574 | + echo 'error, nonce failed, try to reload the page.'; | |
| 1575 | + wp_die(); | |
| 1576 | + } | |
| 1577 | + $grid_settings = get_option('cf7sg-plugin-version', array()); | |
| 1578 | + $warning = false; | |
| 1579 | + if(isset($grid_settings['fv']) ) { | |
| 1580 | + if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true; | |
| 1581 | + } | |
| 1582 | + $grid_settings['fv'] = CF7SG_VERSION_FORM_UPDATE; | |
| 1583 | + $grid_settings['gv'] = CF7_GRID_VERSION; | |
| 1584 | + $grid_settings['update'] = true; | |
| 1585 | + update_option('cf7sg-plugin-version', $grid_settings); | |
| 1586 | + $update_msg = __('Version validated, thank you!','cf7-grid-layout'); | |
| 1587 | + if($warning){ | |
| 1588 | + $link = admin_url('edit.php?post_type=wpcf7_contact_form'); | |
| 1589 | + /* translators: %s link to form table */ | |
| 1590 | + $update_msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout'); | |
| 1591 | + $update_msg = sprintf( $update_msg, $link); | |
| 1592 | + } | |
| 1593 | + echo $update_msg; | |
| 1594 | + wp_die(); | |
| 1595 | + } | |
| 1596 | + /** | |
| 1597 | + * Check if plugin is getting updated. | |
| 1598 | + * Hooked to 'upgrader_post_install'. | |
| 1599 | + *@since 4.1.0 | |
| 1600 | + *@param array $param text_description | |
| 1601 | + *@param array $extras text_description | |
| 1602 | + *@param array $result text_description | |
| 1603 | + *@return array responses for the upgrade process | |
| 1604 | + */ | |
| 1605 | + public function post_plugin_upgrade($response, $extras, $result){ | |
| 1606 | + if( ( isset($response['destination_name']) and 'cf7-grid-layout' == $response['destination_name'] ) | |
| 1607 | + or ( isset($extras['plugin']) and 'cf7-grid-layout/cf7-grid-layout.php' == $extras['plugin'] ) ){ | |
| 1608 | + $grid_settings = get_option('cf7sg-plugin-version', array()); | |
| 1609 | + $grid_settings['update'] = true; | |
| 1610 | + update_option('cf7sg-plugin-version', $grid_settings); | |
| 1611 | + } | |
| 1612 | + return $response; | |
| 1613 | + } | |
| 1614 | + /** | |
| 1615 | + * Preview form post type creation. | |
| 1616 | + * hooked on action 'init'. | |
| 1617 | + *@since 4.3.0 | |
| 1618 | + *@param string $param text_description | |
| 1619 | + *@return string text_description | |
| 1620 | + */ | |
| 1621 | + // Register Custom Post Type | |
| 1622 | + function register_form_preview_posttype() { | |
| 1623 | + | |
| 1624 | + $labels = array( | |
| 1625 | + 'name' => _x( 'CF7 Forms', 'Post Type General Name', 'cf7-grid-layout' ), | |
| 1626 | + 'singular_name' => _x( 'CF7 Form', 'Post Type Singular Name', 'cf7-grid-layout' ), | |
| 1627 | + 'menu_name' => __( 'CF7 Forms', 'cf7-grid-layout' ), | |
| 1628 | + 'name_admin_bar' => __( 'CF7 Form', 'cf7-grid-layout' ), | |
| 1629 | + 'parent_item_colon' => __( 'Parent Item:', 'cf7-grid-layout' ), | |
| 1630 | + 'all_items' => __( 'All Form Pages', 'cf7-grid-layout' ), | |
| 1631 | + 'add_new_item' => __( 'Add New Form Page', 'cf7-grid-layout' ), | |
| 1632 | + 'add_new' => __( 'Add New', 'cf7-grid-layout' ), | |
| 1633 | + 'new_item' => __( 'New Form Page', 'cf7-grid-layout' ), | |
| 1634 | + 'edit_item' => __( 'Edit Form Page', 'cf7-grid-layout' ), | |
| 1635 | + 'update_item' => __( 'Update Form Page', 'cf7-grid-layout' ), | |
| 1636 | + 'view_item' => __( 'View Form Page', 'cf7-grid-layout' ), | |
| 1637 | + 'view_items' => __( 'View Form Pages', 'cf7-grid-layout' ), | |
| 1638 | + 'search_items' => __( 'Search Form Page', 'cf7-grid-layout' ), | |
| 1639 | + 'not_found' => __( 'Not found', 'cf7-grid-layout' ), | |
| 1640 | + 'not_found_in_trash' => __( 'Not found in Trash', 'cf7-grid-layout' ), | |
| 1641 | + ); | |
| 1642 | + $rewrite = array( | |
| 1643 | + 'slug' => 'sgform', | |
| 1644 | + 'with_front' => true, | |
| 1645 | + 'pages' => true, | |
| 1646 | + 'feeds' => false, | |
| 1647 | + ); | |
| 1648 | + $args = array( | |
| 1649 | + 'label' => __( 'CF7 Form', 'cf7-grid-layout' ), | |
| 1650 | + 'description' => __( 'Preview/View CF7 forms on the front-end', 'cf7-grid-layout' ), | |
| 1651 | + 'labels' => $labels, | |
| 1652 | + 'public' => true, | |
| 1653 | + 'show_ui' => false, | |
| 1654 | + 'show_in_menu' => false, | |
| 1655 | + 'show_in_admin_bar' => false, | |
| 1656 | + 'show_in_nav_menus' => false, | |
| 1657 | + 'can_export' => false, | |
| 1658 | + 'has_archive' => false, | |
| 1659 | + 'exclude_from_search' => true, | |
| 1660 | + 'publicly_queryable' => true, | |
| 1661 | + // 'query_var' => 'sgcf7', | |
| 1662 | + 'rewrite' => $rewrite, | |
| 1663 | + ); | |
| 1664 | + register_post_type( 'cf7sg_page', $args ); | |
| 1665 | + | |
| 1666 | + } | |
| 1667 | + /** | |
| 1668 | + * Load translation files for the CF7 Polylang extension. | |
| 1669 | + * Hoooked to '' | |
| 1670 | + *@since 4.4.0 | |
| 1671 | + *@param string $param text_description | |
| 1672 | + *@return string text_description | |
| 1673 | + */ | |
| 1674 | + public function load_translation_files($trans){ | |
| 1675 | + $trans[$this->plugin_name]=CF7SG_TRANSLATED_VERSION; | |
| 1676 | + return $trans; | |
| 1403 | 1677 | } |
| 1404 | 1678 | } |