| @@ -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 | */ |
| @@ -138,12 +154,15 @@ | ||
| 138 | 154 | wp_enqueue_style( "codemirror-matchesonscrollbar-css", $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.css', array(), $this->version, 'all' ); |
| 139 | 155 | wp_enqueue_style( 'smart-grid-css', $plugin_dir . 'assets/css.gs/smart-grid.admin.css', array(), $this->version, 'all'); |
| 140 | 156 | wp_enqueue_style('dashicons'); |
| 141 | 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'); | |
| 142 | 160 | break; |
| 143 | 161 | case 'edit': //table. |
| 144 | 162 | wp_enqueue_style( $this->plugin_name, $plugin_dir . 'admin/css/cf7-grid-layout-admin.css', array(), $this->version, 'all' ); |
| 145 | - | |
| 163 | + /** @since 4.4.0 Enabled user style enqueue */ | |
| 164 | + do_action('cf7sg_enqueue_admin_table_styles'); | |
| 146 | 165 | break; |
| 147 | 166 | } |
| 148 | 167 | |
| 149 | 168 | } |
| @@ -186,9 +205,9 @@ | ||
| 186 | 205 | ); |
| 187 | 206 | /** @since 3.1.2 initialise codemirror after library load and parse as attribute to anonymous functtion in cf7-grid-codemirror.js */ |
| 188 | 207 | wp_add_inline_script('cf7-codemirror-js', |
| 189 | 208 | 'const cmInitialSettings = { |
| 190 | - value:"",matchTags: {bothTags: true},autoCloseTags:true, | |
| 209 | + value:"",autoCloseTags:true, | |
| 191 | 210 | extraKeys: {"Ctrl-Space": "autocomplete", "Ctrl-/": "toggleComment", "Ctrl-J": "toMatchingTag"}, |
| 192 | 211 | lineNumbers: true, styleActiveLine: true, |
| 193 | 212 | matchBrackets: true, tabSize:2, lineWrapping: true, addModeClass: true, |
| 194 | 213 | foldGutter: true, autofocus:false, |
| @@ -197,12 +216,8 @@ | ||
| 197 | 216 | const codeMirror_5_32 = CodeMirror(document.getElementById("cf7-codemirror"),cmInitialSettings); |
| 198 | 217 | const cssCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-css-codemirror"),cmInitialSettings); |
| 199 | 218 | const jsCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-js-codemirror"),cmInitialSettings);'); |
| 200 | 219 | //matchtags. |
| 201 | - wp_enqueue_script( 'codemirror-matchtag-js', | |
| 202 | - $plugin_dir . 'assets/codemirror/edit/matchtags.js', | |
| 203 | - array('cf7-codemirror-js'), $this->version, true | |
| 204 | - ); | |
| 205 | 220 | wp_enqueue_script( 'codemirror-closetag-js', |
| 206 | 221 | $plugin_dir . 'assets/codemirror/edit/closetag.js', |
| 207 | 222 | array('cf7-codemirror-js'), $this->version, true |
| 208 | 223 | ); |
| @@ -222,8 +237,12 @@ | ||
| 222 | 237 | wp_enqueue_script( 'codemirror-xml-fold-js', |
| 223 | 238 | $plugin_dir . 'assets/codemirror/addon/fold/xml-fold.js', |
| 224 | 239 | array('cf7-codemirror-js'), $this->version, true |
| 225 | 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 | + ); | |
| 226 | 245 | wp_enqueue_script( 'codemirror-brace-fold-js', |
| 227 | 246 | $plugin_dir . 'assets/codemirror/addon/fold/brace-fold.js', |
| 228 | 247 | array('cf7-codemirror-js'), $this->version, true |
| 229 | 248 | ); |
| @@ -356,9 +375,11 @@ | ||
| 356 | 375 | 'csstheme' => array( |
| 357 | 376 | 'light'=>'paraiso-light', |
| 358 | 377 | 'dark'=>'material-ocean', |
| 359 | 378 | 'user'=>$user_css_theme |
| 360 | - ) | |
| 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'), | |
| 361 | 382 | ) |
| 362 | 383 | ); |
| 363 | 384 | global $post; |
| 364 | 385 | |
| @@ -388,9 +409,10 @@ | ||
| 388 | 409 | do_action('cf7sg_enqueue_admin_editor_scripts'); |
| 389 | 410 | break; |
| 390 | 411 | case 'edit': |
| 391 | 412 | //wp_enqueue_script( $this->plugin_name.'-quick-edit', plugin_dir_url( __FILE__ ) . 'js/cf7-grid-layout-quick-edit.js', false, $this->version, true ); |
| 392 | - | |
| 413 | + /** @since 4.4.0 Enabled user script enqueue */ | |
| 414 | + do_action('cf7sg_enqueue_admin_table_scripts'); | |
| 393 | 415 | break; |
| 394 | 416 | } |
| 395 | 417 | } |
| 396 | 418 | |
| @@ -408,9 +430,9 @@ | ||
| 408 | 430 | 'wpcf7_edit_contact_forms', |
| 409 | 431 | 'post-new.php?post_type=wpcf7_contact_form' |
| 410 | 432 | ); |
| 411 | 433 | //initial cf7 object when creating new form |
| 412 | - add_action( 'load-' . $hook, array($this, 'setup_cf7_object')); | |
| 434 | + //add_action( 'load-' . $hook, array($this, 'setup_cf7_object')); | |
| 413 | 435 | //remove_submenu_page( $menu_slug, $submenu_slug ); |
| 414 | 436 | remove_submenu_page( 'wpcf7', 'wpcf7-new' ); |
| 415 | 437 | remove_meta_box('slugdiv', $this->cf7_post_type(), 'normal'); |
| 416 | 438 | } |
| @@ -547,38 +569,9 @@ | ||
| 547 | 569 | 'high' |
| 548 | 570 | ); |
| 549 | 571 | } |
| 550 | 572 | } |
| 551 | - /** | |
| 552 | - * Function called on page load when new form is created | |
| 553 | - * hooked to 'load-{page-hook}' | |
| 554 | - * @since 1.0.0 | |
| 555 | - **/ | |
| 556 | - public function setup_cf7_object(){ | |
| 557 | - $args = array(); | |
| 558 | - /** | |
| 559 | - * Fix locale setup for new forms using polylang. | |
| 560 | - * @since 2.1.4 | |
| 561 | - */ | |
| 562 | - if(isset($_GET['locale'])){ | |
| 563 | - $args['locale'] = $_GET['locale']; | |
| 564 | - }else if(isset($_GET['new_lang'])){ | |
| 565 | - //check for polylang | |
| 566 | - $locale = $_GET['new_lang']; | |
| 567 | - if(function_exists('pll_languages_list')){ | |
| 568 | - $langs = pll_languages_list(); | |
| 569 | - $locales = pll_languages_list(array('fields'=>'locale')); | |
| 570 | - foreach($langs as $idx => $lang){ | |
| 571 | - if($lang == $locale){ | |
| 572 | - $locale = $locales[$idx]; | |
| 573 | - } | |
| 574 | - } | |
| 575 | - } | |
| 576 | - $args['locale'] =$locale; | |
| 577 | - }else $args['locale'] = get_locale(); | |
| 578 | 573 | |
| 579 | - WPCF7_ContactForm::get_template( $args); | |
| 580 | - } | |
| 581 | 574 | /** |
| 582 | 575 | * Callback function to disolay the main editor meta box |
| 583 | 576 | * @since 1.0.0 |
| 584 | 577 | */ |
| @@ -587,11 +580,11 @@ | ||
| 587 | 580 | wpcf7_contact_form($post); //set the post |
| 588 | 581 | } |
| 589 | 582 | $post_id = $post->ID; |
| 590 | 583 | $cf7_form = wpcf7_get_current_contact_form(); |
| 591 | - | |
| 592 | 584 | if ( ! $cf7_form ) { |
| 593 | - $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); | |
| 594 | 587 | } |
| 595 | 588 | |
| 596 | 589 | // if(empty($post)){ |
| 597 | 590 | // $post_id = -1; |
| @@ -671,8 +664,21 @@ | ||
| 671 | 664 | public function grid_editor_panel($form_post){ |
| 672 | 665 | require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php'; |
| 673 | 666 | } |
| 674 | 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 | + /** | |
| 675 | 681 | * Save cf7 post using ajax |
| 676 | 682 | * Hooked to 'save_post_wpcf7_contact_form' |
| 677 | 683 | * @since 1.0.0 |
| 678 | 684 | **/ |
| @@ -712,9 +718,9 @@ | ||
| 712 | 718 | 'value'=>1, |
| 713 | 719 | 'data-*'=>1, |
| 714 | 720 | ); |
| 715 | 721 | $allowed_tags['script']=array('type'=>1); |
| 716 | - $cf7_key = sanitize_text_field($_POST['post_name']); | |
| 722 | + $cf7_key = $post->post_name; | |
| 717 | 723 | $allowed_tags = apply_filters('cf7sg_kses_allowed_html',$allowed_tags, $cf7_key); |
| 718 | 724 | if(isset( $_POST['wpcf7-form'] )){ |
| 719 | 725 | $args['form'] = wp_kses($_POST['wpcf7-form'], $allowed_tags); |
| 720 | 726 | } |
| @@ -809,12 +815,12 @@ | ||
| 809 | 815 | update_post_meta($post_id, '_cf7sg_has_tables', $has_tables); |
| 810 | 816 | $has_toggles = ( 'true' === $_POST['cf7sg-has-toggles']) ? true : false; |
| 811 | 817 | update_post_meta($post_id, '_cf7sg_has_toggles', $has_toggles); |
| 812 | 818 | /** @since 3.3.5 track toggles in tabs */ |
| 813 | - $toggle_in_tabs = json_decode(stripslashes($_POST['cf7sg-toggle-in-tabs'])); | |
| 814 | - if(empty($toggle_in_tabs)) $toggle_in_tabs = array(); | |
| 815 | - if(!is_array($toggle_in_tabs)) $toggle_in_tabs = array($toggle_in_tabs); | |
| 816 | - 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); | |
| 817 | 823 | /** |
| 818 | 824 | * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms. |
| 819 | 825 | */ |
| 820 | 826 | $is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false; |
| @@ -860,8 +866,27 @@ | ||
| 860 | 866 | } |
| 861 | 867 | //jstags comments. |
| 862 | 868 | if(empty($_POST['cf7sg_jstags_comments'])) update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',1); |
| 863 | 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 | + } | |
| 864 | 889 | } |
| 865 | 890 | /** |
| 866 | 891 | * Print default js template, |
| 867 | 892 | * Hooked to 'cf7sg_default_custom_js_template' |
| @@ -1250,9 +1275,14 @@ | ||
| 1250 | 1275 | /* tutorials */ |
| 1251 | 1276 | ob_clean(); |
| 1252 | 1277 | include_once 'partials/pointers/cf7sg-pointer-tutorials.php'; |
| 1253 | 1278 | $content =ob_get_contents(); |
| 1254 | - $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"]'); | |
| 1255 | 1285 | /* shortcodes */ |
| 1256 | 1286 | ob_clean(); |
| 1257 | 1287 | include_once 'partials/pointers/cf7sg-pointer-shortcodes.php'; |
| 1258 | 1288 | $content = ob_get_clean(); |
| @@ -1284,8 +1314,16 @@ | ||
| 1284 | 1314 | if(!empty($content)){ |
| 1285 | 1315 | $pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls'); |
| 1286 | 1316 | ob_clean(); |
| 1287 | 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 | + } | |
| 1288 | 1326 | include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php'; |
| 1289 | 1327 | $content = ob_get_contents(); |
| 1290 | 1328 | if(!empty($content)){ |
| 1291 | 1329 | $pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code'); |
| @@ -1422,13 +1460,17 @@ | ||
| 1422 | 1460 | /** |
| 1423 | 1461 | * Funciton to to initialise admin notices. |
| 1424 | 1462 | * hooked on 'admin_init' |
| 1425 | 1463 | *@since 4.1.0 |
| 1426 | - *@param boolean $init initiliase notices or not | |
| 1427 | 1464 | */ |
| 1428 | 1465 | public function init_notices(){ |
| 1429 | - $grid_settings = get_option('cf7sg-plugin-version', array()); | |
| 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 | + | |
| 1430 | 1470 | $warning = false; |
| 1471 | + $notices = array(); | |
| 1472 | + | |
| 1431 | 1473 | if(isset($grid_settings['update']) and CF7SG_VERSION_FORM_UPDATE==CF7_GRID_VERSION){ |
| 1432 | 1474 | $warning = true; |
| 1433 | 1475 | }else if(isset($grid_settings['fv']) ) { |
| 1434 | 1476 | if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true; |
| @@ -1433,37 +1475,46 @@ | ||
| 1433 | 1475 | }else if(isset($grid_settings['fv']) ) { |
| 1434 | 1476 | if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true; |
| 1435 | 1477 | }else{ //check the forms directly |
| 1436 | 1478 | global $wpdb; |
| 1479 | + $post_type = $this->cf7_post_type(); | |
| 1437 | 1480 | $result = $wpdb->get_col("SELECT pm.meta_value FROM {$wpdb->postmeta} as pm |
| 1438 | 1481 | INNER JOIN {$wpdb->posts} as p on p.ID = pm.post_id |
| 1439 | - WHERE p.post_type = 'wpcf7_contact_form' | |
| 1482 | + WHERE p.post_type = '{$post_type}' | |
| 1440 | 1483 | AND pm.meta_key = '_cf7sg_version' |
| 1441 | 1484 | ORDER BY pm.meta_key |
| 1442 | 1485 | "); |
| 1443 | 1486 | if(!empty($result) and version_compare($result[0], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true; |
| 1444 | 1487 | } |
| 1488 | + | |
| 1445 | 1489 | if($warning){ |
| 1446 | - $notices= array( | |
| 1447 | - 'admin.php'=>array(), | |
| 1448 | - 'plugins.php'=>array(), | |
| 1449 | - 'post.php'=>array(), | |
| 1450 | - 'edit.php'=>array(), | |
| 1451 | - ); | |
| 1452 | - $nonce = wp_create_nonce( 'cf7sg_notice-'.CF7_GRID_VERSION ); //unique. | |
| 1453 | 1490 | $link = admin_url('edit.php?post_type=wpcf7_contact_form'); |
| 1454 | 1491 | /* translators: %s is the url to the forms admin table */ |
| 1455 | 1492 | $msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout'); |
| 1456 | - $notice = array( | |
| 1457 | - 'nonce'=>$nonce, | |
| 1493 | + $notices['cf7sg_notice-'.CF7_GRID_VERSION] = array( | |
| 1458 | 1494 | 'type'=>'notice-warning', //[notice-update|notice-error] |
| 1459 | - 'msg'=>sprintf($msg , $link) | |
| 1495 | + 'msg'=>sprintf($msg , $link), | |
| 1496 | + 'pages'=>array('plugins.php','edit.php') | |
| 1460 | 1497 | ); |
| 1461 | - $notices['plugins.php']['cf7sg']=$notice; | |
| 1462 | - $notices['edit.php']['post_type=wpcf7_contact_form']=$notice; | |
| 1463 | - | |
| 1464 | - update_option('cf7sg-admin-notices', $notices); | |
| 1465 | 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); | |
| 1466 | 1517 | |
| 1467 | 1518 | update_option('cf7sg-plugin-version', array( |
| 1468 | 1519 | 'gv'=>CF7_GRID_VERSION, |
| 1469 | 1520 | 'fv'=>CF7SG_VERSION_FORM_UPDATE |
| @@ -1472,10 +1523,8 @@ | ||
| 1472 | 1523 | /** |
| 1473 | 1524 | * Display admin notices |
| 1474 | 1525 | * Hooked on 'admin_notices' |
| 1475 | 1526 | *@since 4.1.0 |
| 1476 | - *@param string $param text_description | |
| 1477 | - *@return string text_description | |
| 1478 | 1527 | */ |
| 1479 | 1528 | public function admin_notices(){ |
| 1480 | 1529 | //check if we have any notices. |
| 1481 | 1530 | global $pagenow; |
| @@ -1481,29 +1530,39 @@ | ||
| 1481 | 1530 | global $pagenow; |
| 1482 | 1531 | $notices = get_option('cf7sg-admin-notices', array()); |
| 1483 | 1532 | if(empty($notices)) return; |
| 1484 | 1533 | |
| 1485 | - if(!isset($notices[$pagenow])) return; | |
| 1534 | + if(!isset(self::$admin_notice_pages[$pagenow])) return; | |
| 1486 | 1535 | |
| 1487 | - // debug_msg($notices[$pagenow], $pagenow); | |
| 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. | |
| 1488 | 1547 | |
| 1489 | - foreach($notices[$pagenow] as $key=>$notice){ | |
| 1490 | - switch(true){ | |
| 1491 | - case strpos($key, 'page=') !== false && isset($_GET['page']) && $_GET['page'] === str_replace('page=','',$key): | |
| 1492 | - case strpos($key, 'post_type=') !== false && isset($_GET['post_type']) && $_GET['post_type'] === str_replace('post_type=','',$key): | |
| 1493 | - case $key==='any': | |
| 1494 | - case $key==='cf7sg': | |
| 1495 | - $dismiss = $notice['nonce'].'-forever'; | |
| 1496 | - if ( ! PAnD::is_admin_notice_active( $dismiss ) ) { | |
| 1497 | - unset($notices[$pagenow]); | |
| 1498 | - update_option('cf7sg-admin-notices', $notices); | |
| 1499 | - continue 2; //continue foreach loop. | |
| 1500 | - } | |
| 1501 | - ?> | |
| 1502 | - <div data-dismissible="<?=$dismiss?>" class="notice <?=$notice['type']?> is-dismissible"><p><?=$notice['msg']?></p></div> | |
| 1503 | - <?php | |
| 1504 | - break; | |
| 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. | |
| 1505 | 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 | |
| 1506 | 1565 | } |
| 1507 | 1566 | } |
| 1508 | 1567 | /** |
| 1509 | 1568 | * ajax request to validate plugin update. |
| @@ -1550,6 +1609,70 @@ | ||
| 1550 | 1609 | $grid_settings['update'] = true; |
| 1551 | 1610 | update_option('cf7sg-plugin-version', $grid_settings); |
| 1552 | 1611 | } |
| 1553 | 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; | |
| 1554 | 1677 | } |
| 1555 | 1678 | } |