| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The admin-specific functionality of the plugin. |
| 5 |
* |
| 6 |
* @link http://syllogic.in |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package Cf7_Grid_Layout |
| 10 |
* @subpackage Cf7_Grid_Layout/admin |
| 11 |
*/ |
| 12 |
|
| 13 |
/** |
| 14 |
* The admin-specific functionality of the plugin. |
| 15 |
* |
| 16 |
* Defines the plugin name, version, and two examples hooks for how to |
| 17 |
* enqueue the admin-specific stylesheet and JavaScript. |
| 18 |
* |
| 19 |
* @package Cf7_Grid_Layout |
| 20 |
* @subpackage Cf7_Grid_Layout/admin |
| 21 |
* @author Aurovrata V. <vrata@syllogic.in> |
| 22 |
*/ |
| 23 |
class Cf7_Grid_Layout_Admin { |
| 24 |
/** |
| 25 |
* The ID of this plugin. |
| 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 |
* |
| 43 |
* @since 1.0.0 |
| 44 |
* @access private |
| 45 |
* @var string $plugin_name The ID of this plugin. |
| 46 |
*/ |
| 47 |
private $plugin_name; |
| 48 |
/** |
| 49 |
* The version of this plugin. |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* @access private |
| 53 |
* @var string $version The current version of this plugin. |
| 54 |
*/ |
| 55 |
private $version; |
| 56 |
/** |
| 57 |
* Initialize the class and set its properties. |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* @param string $plugin_name The name of this plugin. |
| 61 |
* @param string $version The version of this plugin. |
| 62 |
*/ |
| 63 |
public function __construct( $plugin_name, $version ) { |
| 64 |
$this->plugin_name = $plugin_name; |
| 65 |
$this->version = $version; |
| 66 |
} |
| 67 |
/** |
| 68 |
* get cf7 post type set by cf7 plugin. |
| 69 |
* |
| 70 |
*@since 3.0.0 |
| 71 |
*@return string post type. |
| 72 |
*/ |
| 73 |
private function cf7_post_type(){ |
| 74 |
$type = 'wpcf7_post_type_notset'; |
| 75 |
if(class_exists('WPCF7_ContactForm') ) { |
| 76 |
$type = WPCF7_ContactForm::post_type; |
| 77 |
} |
| 78 |
return $type; |
| 79 |
} |
| 80 |
/** |
| 81 |
* Hack to add scripts/styles to edit page. |
| 82 |
* Hooked on 'admin_enqueue_scripts'. |
| 83 |
*@since 1.5.0 |
| 84 |
*/ |
| 85 |
public function popular_extentions_scripts(){ |
| 86 |
$screen = get_current_screen(); |
| 87 |
if (empty($screen) || $this->cf7_post_type() != $screen->post_type){ |
| 88 |
return; |
| 89 |
} |
| 90 |
$plugin_dir = plugin_dir_url( __DIR__ ); |
| 91 |
switch( $screen->base ){ |
| 92 |
case 'post': |
| 93 |
$page_hook = ''; |
| 94 |
if('add' == $screen->action) $page_hook = 'contact_page_wpcf7-new'; |
| 95 |
else $page_hook = 'toplevel_page_wpcf7'; |
| 96 |
//unhook this function. |
| 97 |
remove_action('admin_enqueue_scripts', array($this, 'popular_extentions_scripts'),999,0); |
| 98 |
do_action('admin_enqueue_scripts', $page_hook); |
| 99 |
$plugin_page =''; |
| 100 |
add_action('admin_enqueue_scripts', array($this, 'popular_extentions_scripts'),999,0); |
| 101 |
break; |
| 102 |
case 'edit': //table. |
| 103 |
break; |
| 104 |
} |
| 105 |
} |
| 106 |
/** |
| 107 |
* Function to spoof the wpcf7 plugin admin scripts loading for extensions |
| 108 |
* Hooked on 'admin_print_scripts' and used to fix the issue with the mailchimp ext. |
| 109 |
*@since 1.5.1 |
| 110 |
*/ |
| 111 |
public function print_extentions_scripts(){ |
| 112 |
$screen = get_current_screen(); |
| 113 |
if (empty($screen) || $this->cf7_post_type() != $screen->post_type){ |
| 114 |
return; |
| 115 |
} |
| 116 |
global $plugin_page; |
| 117 |
$plugin_page = 'wpcf7'; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
/** |
| 122 |
* Register the stylesheets for the admin area. |
| 123 |
* |
| 124 |
* @since 1.0.0 |
| 125 |
*/ |
| 126 |
public function enqueue_styles($page) { |
| 127 |
|
| 128 |
if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ) return; |
| 129 |
|
| 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 |
} |
| 137 |
if (empty($screen) || $this->cf7_post_type() != $screen->post_type){ |
| 138 |
return; |
| 139 |
} |
| 140 |
switch( $screen->base ){ |
| 141 |
case 'post': |
| 142 |
wp_enqueue_style( "cf7-grid-post-css", $plugin_dir . 'admin/css/cf7-grid-layout-post.css', array(), $this->version, 'all' ); |
| 143 |
//dynamic tag |
| 144 |
wp_enqueue_style('cf7sg-dynamic-tag-css', $plugin_dir . 'admin/css/cf7sg-dynamic-tag.css', array(), $this->version, 'all' ); |
| 145 |
//benchmark tag |
| 146 |
wp_enqueue_style('cf7sg-benchmark-tag-css', $plugin_dir . 'admin/css/cf7sg-benchmark-tag.css', array(), $this->version, 'all' ); |
| 147 |
//codemirror |
| 148 |
wp_enqueue_style( "codemirror-css", $plugin_dir . 'assets/codemirror/codemirror.css', array(), $this->version, 'all' ); |
| 149 |
/** @since 4.0 enable dark theme */ |
| 150 |
wp_enqueue_style( "codemirror-theme-light-css", $plugin_dir . 'assets/codemirror/theme/paraiso-light.css', array(), $this->version, 'all' ); |
| 151 |
wp_enqueue_style( "codemirror-theme-dark-css", $plugin_dir . 'assets/codemirror/theme/material-ocean.css', array(), $this->version, 'all' ); |
| 152 |
wp_enqueue_style( "codemirror-foldgutter-css", $plugin_dir . 'assets/codemirror/addon/fold/foldgutter.css', array(), $this->version, 'all' ); |
| 153 |
wp_enqueue_style( "codemirror-dialog-css", $plugin_dir . 'assets/codemirror/addon/dialog/dialog.css', array(), $this->version, 'all' ); |
| 154 |
wp_enqueue_style( "codemirror-matchesonscrollbar-css", $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.css', array(), $this->version, 'all' ); |
| 155 |
wp_enqueue_style( 'smart-grid-css', $plugin_dir . 'assets/css.gs/smart-grid.admin.css', array(), $this->version, 'all'); |
| 156 |
wp_enqueue_style('dashicons'); |
| 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'); |
| 160 |
break; |
| 161 |
case 'edit': //table. |
| 162 |
wp_enqueue_style( $this->plugin_name, $plugin_dir . 'admin/css/cf7-grid-layout-admin.css', array(), $this->version, 'all' ); |
| 163 |
/** @since 4.4.0 Enabled user style enqueue */ |
| 164 |
do_action('cf7sg_enqueue_admin_table_styles'); |
| 165 |
break; |
| 166 |
} |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Register the JavaScript for the admin area. |
| 172 |
* |
| 173 |
* @since 1.0.0 |
| 174 |
*/ |
| 175 |
public function enqueue_scripts($page) { |
| 176 |
|
| 177 |
$plugin_dir = plugin_dir_url( __DIR__ ); |
| 178 |
if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ){ |
| 179 |
wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array( 'jquery' ), $this->version, true ); |
| 180 |
return; |
| 181 |
} |
| 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 |
} |
| 194 |
if ($this->cf7_post_type() != $screen->post_type){ |
| 195 |
return; |
| 196 |
} |
| 197 |
|
| 198 |
switch( $screen->base ){ |
| 199 |
case 'post': |
| 200 |
/* register codemirror editor & addons. */ |
| 201 |
//codemirror script |
| 202 |
wp_register_script( 'cf7-codemirror-js', |
| 203 |
$plugin_dir . 'assets/codemirror/codemirror.js', |
| 204 |
null, "5.32", true |
| 205 |
); |
| 206 |
/** @since 3.1.2 initialise codemirror after library load and parse as attribute to anonymous functtion in cf7-grid-codemirror.js */ |
| 207 |
wp_add_inline_script('cf7-codemirror-js', |
| 208 |
'const cmInitialSettings = { |
| 209 |
value:"",autoCloseTags:true, |
| 210 |
extraKeys: {"Ctrl-Space": "autocomplete", "Ctrl-/": "toggleComment", "Ctrl-J": "toMatchingTag"}, |
| 211 |
lineNumbers: true, styleActiveLine: true, |
| 212 |
matchBrackets: true, tabSize:2, lineWrapping: true, addModeClass: true, |
| 213 |
foldGutter: true, autofocus:false, |
| 214 |
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"] |
| 215 |
} |
| 216 |
const codeMirror_5_32 = CodeMirror(document.getElementById("cf7-codemirror"),cmInitialSettings); |
| 217 |
const cssCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-css-codemirror"),cmInitialSettings); |
| 218 |
const jsCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-js-codemirror"),cmInitialSettings);'); |
| 219 |
//matchtags. |
| 220 |
wp_enqueue_script( 'codemirror-closetag-js', |
| 221 |
$plugin_dir . 'assets/codemirror/edit/closetag.js', |
| 222 |
array('cf7-codemirror-js'), $this->version, true |
| 223 |
); |
| 224 |
//fold code |
| 225 |
wp_enqueue_script( 'codemirror-foldcode-js', |
| 226 |
$plugin_dir . 'assets/codemirror/addon/fold/foldcode.js', |
| 227 |
array('cf7-codemirror-js'), $this->version, true |
| 228 |
); |
| 229 |
wp_enqueue_script( 'codemirror-foldgutter-js', |
| 230 |
$plugin_dir . 'assets/codemirror/addon/fold/foldgutter.js', |
| 231 |
array('cf7-codemirror-js'), $this->version, true |
| 232 |
); |
| 233 |
wp_enqueue_script( 'codemirror-indent-fold-js', |
| 234 |
$plugin_dir . 'assets/codemirror/addon/fold/indent-fold.js', |
| 235 |
array('cf7-codemirror-js'), $this->version, true |
| 236 |
); |
| 237 |
wp_enqueue_script( 'codemirror-xml-fold-js', |
| 238 |
$plugin_dir . 'assets/codemirror/addon/fold/xml-fold.js', |
| 239 |
array('cf7-codemirror-js'), $this->version, true |
| 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 |
); |
| 245 |
wp_enqueue_script( 'codemirror-brace-fold-js', |
| 246 |
$plugin_dir . 'assets/codemirror/addon/fold/brace-fold.js', |
| 247 |
array('cf7-codemirror-js'), $this->version, true |
| 248 |
); |
| 249 |
wp_enqueue_script( 'codemirror-comment-fold-js', |
| 250 |
$plugin_dir . 'assets/codemirror/addon/fold/comment-fold.js', |
| 251 |
array('cf7-codemirror-js'), $this->version, true |
| 252 |
); |
| 253 |
wp_enqueue_script( 'codemirror-mixed-js', |
| 254 |
$plugin_dir . 'assets/codemirror/mode/htmlmixed/htmlmixed.js', |
| 255 |
array('cf7-codemirror-js'), $this->version, true |
| 256 |
); |
| 257 |
wp_enqueue_script( 'codemirror-javascript-js', |
| 258 |
$plugin_dir . 'assets/codemirror/mode/javascript/javascript.js', |
| 259 |
array('cf7-codemirror-js'), $this->version, true |
| 260 |
); |
| 261 |
wp_enqueue_script( 'codemirror-xml-js', |
| 262 |
$plugin_dir . 'assets/codemirror/mode/xml/xml.js', |
| 263 |
array('cf7-codemirror-js'), $this->version, true |
| 264 |
); |
| 265 |
wp_enqueue_script( 'codemirror-css-js', |
| 266 |
$plugin_dir . 'assets/codemirror/mode/css/css.js', |
| 267 |
array('cf7-codemirror-js'), $this->version, true |
| 268 |
); |
| 269 |
//overlay for shortcode highligh |
| 270 |
wp_enqueue_script( 'codemirror-overlay-js', |
| 271 |
$plugin_dir . 'assets/codemirror/addon/mode/overlay.js', |
| 272 |
array('cf7-codemirror-js'), $this->version, true |
| 273 |
); |
| 274 |
/** |
| 275 |
* @since 1.3.0 enable search codemirror |
| 276 |
*/ |
| 277 |
//overlay for shortcode highligh |
| 278 |
wp_enqueue_script( 'codemirror-search-js', |
| 279 |
$plugin_dir . 'assets/codemirror/addon/search/search.js', |
| 280 |
array('cf7-codemirror-js'), $this->version, true |
| 281 |
); |
| 282 |
wp_enqueue_script( 'codemirror-jumptoline-js', |
| 283 |
$plugin_dir . 'assets/codemirror/addon/search/jump-to-line.js', |
| 284 |
array('cf7-codemirror-js'), $this->version, true |
| 285 |
); |
| 286 |
wp_enqueue_script( 'codemirror-matchesonscrollbar-js', |
| 287 |
$plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.js', |
| 288 |
array('cf7-codemirror-js'), $this->version, true |
| 289 |
); |
| 290 |
wp_enqueue_script( 'codemirror-searchcursor-js', |
| 291 |
$plugin_dir . 'assets/codemirror/addon/search/searchcursor.js', |
| 292 |
array('cf7-codemirror-js'), $this->version, true |
| 293 |
); |
| 294 |
wp_enqueue_script( 'codemirror-annotatescrollbar-js', |
| 295 |
$plugin_dir . 'assets/codemirror/addon/scroll/annotatescrollbar.js', |
| 296 |
array('cf7-codemirror-js'), $this->version, true |
| 297 |
); |
| 298 |
wp_enqueue_script( 'codemirror-dialog-js', |
| 299 |
$plugin_dir . 'assets/codemirror/addon/dialog/dialog.js', |
| 300 |
array('cf7-codemirror-js'), $this->version, true |
| 301 |
); |
| 302 |
|
| 303 |
//js beautify |
| 304 |
wp_enqueue_script( 'beautify-js', |
| 305 |
$plugin_dir . 'assets/beautify/beautify.js', |
| 306 |
array('jquery'), $this->version, true |
| 307 |
); |
| 308 |
wp_enqueue_script( 'beautify-html-js', |
| 309 |
$plugin_dir . 'assets/beautify/beautify-html.js', |
| 310 |
array('beautify-js'), $this->version, true |
| 311 |
); |
| 312 |
wp_enqueue_script('jquery-select2', $plugin_dir . 'assets/select2/js/select2.min.js', array( 'jquery' ), $this->version, true ); |
| 313 |
/** @since 4.0 enable dark theme */ |
| 314 |
$cm_light = apply_filters('cf7sg_admin_editor_theme', ''); |
| 315 |
$user_theme = get_user_meta(get_current_user_id(),'_cf7sg_cm_theme', true); |
| 316 |
if(!empty($cm_light) && file_exists(get_stylesheet_directory().'/'.$cm_light) ){ |
| 317 |
wp_enqueue_style( "codemirror-theme-css", get_stylesheet_directory_uri().'/'.$cm_light, array(), $this->version, 'all' ); |
| 318 |
$user_theme = basename($cm_light, '.css'); |
| 319 |
update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', ''); |
| 320 |
}else{ |
| 321 |
if(empty($user_theme)){ |
| 322 |
$user_theme = 'paraiso-light'; |
| 323 |
update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', 'light'); |
| 324 |
}else{ |
| 325 |
$user_theme = ('light'==$user_theme ? 'paraiso-light' : 'material-ocean'); |
| 326 |
} |
| 327 |
} |
| 328 |
$cm_js_light = apply_filters('cf7sg_admin_js_editor_theme', ''); |
| 329 |
$user_js_theme = get_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', true); |
| 330 |
if(!empty($cm_js_light) && file_exists(get_stylesheet_directory().'/'.$cm_js_light) ){ |
| 331 |
wp_enqueue_style( "codemirror-js-theme-css", get_stylesheet_directory_uri().'/'.$cm_js_light, array(), $this->version, 'all' ); |
| 332 |
$user_js_theme = basename($cm_js_light, '.css'); |
| 333 |
update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', ''); |
| 334 |
}else{ |
| 335 |
if(empty($user_js_theme)){ |
| 336 |
$user_js_theme = 'paraiso-light'; |
| 337 |
update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', 'light'); |
| 338 |
}else{ |
| 339 |
$user_js_theme = ('light'==$user_js_theme ? 'paraiso-light' : 'material-ocean'); |
| 340 |
} |
| 341 |
} |
| 342 |
$cm_css_light = apply_filters('cf7sg_admin_css_editor_theme', ''); |
| 343 |
$user_css_theme = get_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', true); |
| 344 |
if(!empty($cm_css_light) && file_exists(get_stylesheet_directory().'/'.$cm_css_light) ){ |
| 345 |
wp_enqueue_style( "codemirror-css-theme-css", get_stylesheet_directory_uri().'/'.$cm_css_light, array(), $this->version, 'all' ); |
| 346 |
$user_css_theme = basename($cm_css_light, '.css'); |
| 347 |
update_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', ''); |
| 348 |
}else{ |
| 349 |
if(empty($user_css_theme)){ |
| 350 |
$user_css_theme = 'paraiso-light'; |
| 351 |
update_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', 'light'); |
| 352 |
}else{ |
| 353 |
$user_css_theme = ('light'==$user_css_theme ? 'paraiso-light' : 'material-ocean'); |
| 354 |
} |
| 355 |
} |
| 356 |
//enqueue the cf7 scripts. |
| 357 |
wpcf7_admin_enqueue_scripts( 'wpcf7' ); |
| 358 |
wp_enqueue_script('jquery-clibboard', $plugin_dir . 'assets/clipboard/clipboard.min.js', array('jquery'),$this->version,true); |
| 359 |
wp_enqueue_script( 'cf7-grid-codemirror-js', $plugin_dir . 'admin/js/cf7-grid-codemirror.js', array( 'jquery', 'jquery-ui-tabs', 'cf7-codemirror-js' ), $this->version, true ); |
| 360 |
wp_localize_script( |
| 361 |
'cf7-grid-codemirror-js', |
| 362 |
'cf7sgeditor', |
| 363 |
array( |
| 364 |
'mode' => 'shortcode', |
| 365 |
'theme' => array( |
| 366 |
'light'=>'paraiso-light', |
| 367 |
'dark'=>'material-ocean', |
| 368 |
'user'=>$user_theme |
| 369 |
), |
| 370 |
'jstheme' => array( |
| 371 |
'light'=>'paraiso-light', |
| 372 |
'dark'=>'material-ocean', |
| 373 |
'user'=>$user_js_theme |
| 374 |
), |
| 375 |
'csstheme' => array( |
| 376 |
'light'=>'paraiso-light', |
| 377 |
'dark'=>'material-ocean', |
| 378 |
'user'=>$user_css_theme |
| 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'), |
| 382 |
) |
| 383 |
); |
| 384 |
global $post; |
| 385 |
|
| 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 ); |
| 387 |
wp_localize_script( |
| 388 |
$this->plugin_name, |
| 389 |
'cf7grid', |
| 390 |
array( |
| 391 |
'preHTML' => apply_filters('cf7sg_pre_cf7_field_html', '<div class="field"><label></label>', $post->post_name), |
| 392 |
'postHTML' => apply_filters('cf7sg_post_cf7_field_html', '<p class="info-tip"></p></div>', $post->post_name), |
| 393 |
'requiredHTML' => apply_filters('cf7sg_required_cf7_field_html', '<em>*</em>', $post->post_name), |
| 394 |
'ui' => apply_filters('cf7sg_grid_ui', true, $post->post_name) |
| 395 |
) |
| 396 |
); |
| 397 |
wp_enqueue_script( 'cf7sg-dynamic-tag-js', $plugin_dir . 'admin/js/cf7sg-dynamic-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true ); |
| 398 |
wp_enqueue_script( 'cf7-benchmark-tag-js', $plugin_dir . 'admin/js/cf7-benchmark-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true ); |
| 399 |
/** @since 3.2.0 */ |
| 400 |
wp_enqueue_script('cf7sg-mail-tag-js', $plugin_dir.'admin/js/mail-tag-helper.js', array('jquery','jquery-clibboard')); |
| 401 |
wp_localize_script('cf7sg-mail-tag-js','mailTagHelper', |
| 402 |
array( |
| 403 |
'msg'=>__('Click to copy!','cf7-grid-layout'), |
| 404 |
'filter'=> __('Filter mailTag %s', 'cf7-grid-layout') |
| 405 |
) |
| 406 |
); |
| 407 |
/** @since 3.3.0 enqueue ui-grid helpers js */ |
| 408 |
wp_enqueue_script('ui-grid-helpers-js', $plugin_dir.'admin/js/ui-custom-helper.js', array('jquery')); |
| 409 |
do_action('cf7sg_enqueue_admin_editor_scripts'); |
| 410 |
break; |
| 411 |
case 'edit': |
| 412 |
//wp_enqueue_script( $this->plugin_name.'-quick-edit', plugin_dir_url( __FILE__ ) . 'js/cf7-grid-layout-quick-edit.js', false, $this->version, true ); |
| 413 |
/** @since 4.4.0 Enabled user script enqueue */ |
| 414 |
do_action('cf7sg_enqueue_admin_table_scripts'); |
| 415 |
break; |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
/** |
| 420 |
* Adds a new sub-menu to replace the 'Add New' CF7 menu |
| 421 |
* Add a new sub-menu to the Contact main menu, as well as remove the current default |
| 422 |
* |
| 423 |
*/ |
| 424 |
public function add_cf7_sub_menu(){ |
| 425 |
|
| 426 |
$hook = add_submenu_page( |
| 427 |
'wpcf7', |
| 428 |
__cf7sg( 'Edit Contact Form'), |
| 429 |
__cf7sg( 'Add New'), |
| 430 |
'wpcf7_edit_contact_forms', |
| 431 |
'post-new.php?post_type=wpcf7_contact_form' |
| 432 |
); |
| 433 |
//initial cf7 object when creating new form |
| 434 |
//add_action( 'load-' . $hook, array($this, 'setup_cf7_object')); |
| 435 |
//remove_submenu_page( $menu_slug, $submenu_slug ); |
| 436 |
remove_submenu_page( 'wpcf7', 'wpcf7-new' ); |
| 437 |
remove_meta_box('slugdiv', $this->cf7_post_type(), 'normal'); |
| 438 |
} |
| 439 |
/** |
| 440 |
* Change the submenu order |
| 441 |
* @since 1.0.0 |
| 442 |
*/ |
| 443 |
public function change_cf7_submenu_order( $menu_ord ) { |
| 444 |
global $submenu; |
| 445 |
// Enable the next line to see all menu orders |
| 446 |
if(!isset($submenu['wpcf7']) ){ |
| 447 |
return $menu_ord; |
| 448 |
} |
| 449 |
if( is_network_admin() ){ |
| 450 |
return $menu_ord; |
| 451 |
} |
| 452 |
$arr = array(); |
| 453 |
foreach($submenu['wpcf7'] as $menu){ |
| 454 |
switch($menu[2]){ |
| 455 |
case 'post-new.php?post_type=wpcf7_contact_form': |
| 456 |
//push to the front |
| 457 |
array_unshift($arr, $menu); |
| 458 |
break; |
| 459 |
default: |
| 460 |
$arr[]=$menu; |
| 461 |
break; |
| 462 |
} |
| 463 |
} |
| 464 |
$submenu['wpcf7'] = $arr; |
| 465 |
return $menu_ord; |
| 466 |
} |
| 467 |
/** |
| 468 |
* Modify the regsitered cf7 post tppe |
| 469 |
* THis function enables public capability and amind UI visibility for the cf7 post type. Hooked late on `register_post_type_args` |
| 470 |
* @since 1.0.0 |
| 471 |
* @param Array $args array of post parameters being registered |
| 472 |
* @param String $post_type post type breing resgistered |
| 473 |
*/ |
| 474 |
|
| 475 |
public function modify_cf7_post_type_args($args, $post_type){ |
| 476 |
if($post_type === $this->cf7_post_type() ) { |
| 477 |
// debug_msg($args, 'pre-args'); |
| 478 |
// $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array()); |
| 479 |
/** @since 2.8.3 add wpcf7_type (registered in assets/cf7-table.php) taxonomy to cf7 post type */ |
| 480 |
$system_taxonomy = array('wpcf7_type'); |
| 481 |
// if(!empty($system_dropdowns)){ |
| 482 |
// foreach($system_dropdowns as $id=>$list){ |
| 483 |
// $system_taxonomy = array_merge($system_taxonomy, $list); |
| 484 |
// } |
| 485 |
// } |
| 486 |
if(!empty($args['taxonomies'])){ |
| 487 |
$system_taxonomy = array_merge($args['taxonomies'], $system_taxonomy); |
| 488 |
$system_taxonomy = array_unique($system_taxonomy); |
| 489 |
} |
| 490 |
$args['taxonomies'] = $system_taxonomy; |
| 491 |
|
| 492 |
$args['public'] = false; |
| 493 |
$args['show_ui']= true; |
| 494 |
$args['show_in_menu']= 'wpcf7'; |
| 495 |
$args['supports'] = array('title', 'author'); |
| 496 |
$args['labels']['add_new_item'] = 'Add New Form'; |
| 497 |
$args['labels']['edit_item'] = 'Edit Form'; |
| 498 |
$args['labels']['new_item'] = 'New Form'; |
| 499 |
$args['labels']['view_item'] = 'View Form'; |
| 500 |
$args['labels']['view_items'] = 'View Forms'; |
| 501 |
$args['labels']['search_items'] = 'Search Forms'; |
| 502 |
$args['labels']['not_found'] = 'No forms found.'; |
| 503 |
$args['labels']['not_found_in_trash'] = 'No forms found in Trash.'; |
| 504 |
$args['labels']['parent_item_colon'] = ''; |
| 505 |
$args['labels']['attributes'] = 'Form Attributes'; |
| 506 |
$args['labels']['insert_into_item'] = 'Insert into form'; |
| 507 |
$args['labels']['uploaded_to_this_item'] = 'Uploaded to this form'; |
| 508 |
$args['labels']['filter_items_list'] = 'Filter forms list'; |
| 509 |
$args['labels']['items_list_navigation'] = 'Forms list navigation'; |
| 510 |
$args['labels']['items_list'] = 'Forms list'; |
| 511 |
/** @since 2.8.1 fix missing delete_posts notices*/ |
| 512 |
// $args['capabilities']['delete_posts']= 'wpcf7_delete_posts'; |
| 513 |
/** @since 3.0.0 enable better capability management */ |
| 514 |
// $args['capability_type'] = 'page'; |
| 515 |
|
| 516 |
$args['map_meta_cap']=true; //allow finer capability mapping. |
| 517 |
$args['capabilities']['edit_post'] = 'wpcf7_edit_contact_form'; |
| 518 |
$args['capabilities']['read_post'] = 'wpcf7_read_contact_form'; |
| 519 |
$args['capabilities']['delete_post'] = 'wpcf7_delete_contact_form'; |
| 520 |
$args['capabilities']['edit_posts'] = 'wpcf7_edit_contact_forms'; |
| 521 |
$args['capabilities']['edit_others_posts']= 'wpcf7_edit_others_contact_forms'; |
| 522 |
$args['capabilities']['edit_published_posts']= 'wpcf7_edit_published_contact_forms'; |
| 523 |
$args['capabilities']['delete_posts']= 'wpcf7_delete_contact_forms'; |
| 524 |
$args['capabilities']['delete_published_posts']= 'wpcf7_delete_published_contact_forms'; |
| 525 |
$args['capabilities']['delete_others_posts']= 'wpcf7_delete_others_contact_forms'; |
| 526 |
$args['capabilities']['publish_posts']= 'wpcf7_publish_contact_forms'; |
| 527 |
$args['capabilities']['read_private_posts']= 'wpcf7_publish_contact_forms'; |
| 528 |
|
| 529 |
// debug_msg($args); |
| 530 |
} |
| 531 |
return $args; |
| 532 |
} |
| 533 |
/** |
| 534 |
* Register custom taxonomy for dynamic dropdown lists |
| 535 |
* Hooked on 'init' |
| 536 |
* @since 1.0.0 |
| 537 |
* |
| 538 |
**/ |
| 539 |
public function register_dynamic_dropdown_taxonomy(){ |
| 540 |
//register the dynamic dropdown taxonomies. |
| 541 |
$dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array()); |
| 542 |
//debug_msg($dropdowns); |
| 543 |
$created = array(); |
| 544 |
foreach($dropdowns as $post_lists){ |
| 545 |
foreach($post_lists as $slug=>$taxonomy){ |
| 546 |
if(!isset($created[$slug])){ |
| 547 |
if(is_array($taxonomy)){ |
| 548 |
$this->register_dynamic_dropdown($taxonomy); |
| 549 |
$created[$slug] = $slug; |
| 550 |
} |
| 551 |
} |
| 552 |
} |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
/** |
| 557 |
* Function to add the metabox to the cf7 post edit screen |
| 558 |
* This adds the main editor, hooked on 'add_meta_boxes' |
| 559 |
* @since 1.0.0 |
| 560 |
*/ |
| 561 |
public function main_editor_meta_box() { |
| 562 |
//add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args) |
| 563 |
if( post_type_exists( $this->cf7_post_type() ) ) { |
| 564 |
add_meta_box( 'meta-box-main-cf7-editor', |
| 565 |
__cf7sg( 'Edit Contact Form' ), |
| 566 |
array($this , 'main_editor_metabox_display'), |
| 567 |
$this->cf7_post_type(), |
| 568 |
'normal', |
| 569 |
'high' |
| 570 |
); |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
/** |
| 575 |
* Callback function to disolay the main editor meta box |
| 576 |
* @since 1.0.0 |
| 577 |
*/ |
| 578 |
public function main_editor_metabox_display($post){ |
| 579 |
if('auto-draft' !== $post->post_status){ |
| 580 |
wpcf7_contact_form($post); //set the post |
| 581 |
} |
| 582 |
$post_id = $post->ID; |
| 583 |
$cf7_form = wpcf7_get_current_contact_form(); |
| 584 |
if ( ! $cf7_form ) { |
| 585 |
$args = apply_filters('cf7sg_new_cf7_form_template_arguments', array()); |
| 586 |
$cf7_form = WPCF7_ContactForm::get_template($args); |
| 587 |
} |
| 588 |
|
| 589 |
// if(empty($post)){ |
| 590 |
// $post_id = -1; |
| 591 |
// }else{ |
| 592 |
// $post_id = $post->ID; |
| 593 |
// } |
| 594 |
require_once WPCF7_PLUGIN_DIR . '/admin/includes/editor.php'; |
| 595 |
require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-admin-editor-display.php'; |
| 596 |
} |
| 597 |
|
| 598 |
/** |
| 599 |
* Function to add the metabox to the cf7 post edit screen |
| 600 |
* This adds the main editor, hooked on 'add_meta_boxes' |
| 601 |
* @since 1.0.0 |
| 602 |
*/ |
| 603 |
public function info_meta_box() { |
| 604 |
//add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args) |
| 605 |
if(post_type_exists( $this->cf7_post_type() ) ) { |
| 606 |
add_meta_box( 'meta-box-cf7-info', |
| 607 |
__cf7sg( 'Information' ), |
| 608 |
array($this , 'info_metabox_display'), |
| 609 |
$this->cf7_post_type(), |
| 610 |
'side', |
| 611 |
'high' |
| 612 |
); |
| 613 |
} |
| 614 |
} |
| 615 |
/** |
| 616 |
* Re-introduces the wordpress 'wpcf7_admin_misc_pub_section' for plugins to add their fields for submission |
| 617 |
* Hooked to 'post_submitbox_misc_actions' which fires after post dat/time parameters are printed |
| 618 |
* @since 1.0.0 |
| 619 |
* @param WP_Post $post post object being edited/created. |
| 620 |
**/ |
| 621 |
public function cf7_post_submit_action($post){ |
| 622 |
if($this->cf7_post_type() == $post->post_type){ |
| 623 |
do_action( 'wpcf7_admin_misc_pub_section', $post->ID ); |
| 624 |
} |
| 625 |
} |
| 626 |
/** |
| 627 |
* Callback function to disolay the main editor meta box |
| 628 |
* @since 1.0.0 |
| 629 |
*/ |
| 630 |
public function info_metabox_display($post){ |
| 631 |
require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-info-metabox-display.php'; |
| 632 |
} |
| 633 |
/** |
| 634 |
* Function to add the metabox to the cf7 post edit screen |
| 635 |
* This adds the helper, hooked on 'add_meta_boxes' |
| 636 |
* @since 1.1.0 |
| 637 |
*/ |
| 638 |
public function helper_meta_box() { |
| 639 |
//add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args). |
| 640 |
if(post_type_exists( $this->cf7_post_type() ) ) { |
| 641 |
add_meta_box( 'meta-box-cf7sg-helper', |
| 642 |
__( 'Actions & Filters', 'cf7-grid-layout' ), |
| 643 |
array($this , 'helper_metabox_display'), |
| 644 |
$this->cf7_post_type(), |
| 645 |
'side', |
| 646 |
'low' |
| 647 |
); |
| 648 |
} |
| 649 |
} |
| 650 |
/** |
| 651 |
* Callback function to disolay the helper meta box |
| 652 |
* @since 1.0.0 |
| 653 |
*/ |
| 654 |
public function helper_metabox_display($post){ |
| 655 |
require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-helper-metabox-display.php'; |
| 656 |
} |
| 657 |
/** |
| 658 |
* Display the editor panels (wpcf7 / codemirror / grid) |
| 659 |
* |
| 660 |
* @since 1.0.0 |
| 661 |
* @param string $p1 . |
| 662 |
* @return string $p2 . |
| 663 |
**/ |
| 664 |
public function grid_editor_panel($form_post){ |
| 665 |
require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php'; |
| 666 |
} |
| 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 |
/** |
| 681 |
* Save cf7 post using ajax |
| 682 |
* Hooked to 'save_post_wpcf7_contact_form' |
| 683 |
* @since 1.0.0 |
| 684 |
**/ |
| 685 |
public function save_post($post_id, $post, $update){ |
| 686 |
//make sure this is the edit page and not a quick-edit. |
| 687 |
if( !isset($_POST['_wpcf7nonce']) ){ |
| 688 |
return; |
| 689 |
} |
| 690 |
//validate the nonce. |
| 691 |
check_admin_referer( 'wpcf7-save-contact-form_' . $post_id, '_wpcf7nonce'); |
| 692 |
|
| 693 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){ |
| 694 |
return; |
| 695 |
} |
| 696 |
|
| 697 |
switch($post->post_status){ |
| 698 |
case 'auto-draft': |
| 699 |
case 'trash': |
| 700 |
return; |
| 701 |
default: |
| 702 |
break; |
| 703 |
} |
| 704 |
|
| 705 |
// debug_msg($_POST, 'submitted '); |
| 706 |
$args = $_REQUEST; |
| 707 |
$args['id'] = $post_id; |
| 708 |
|
| 709 |
$args['title'] = isset( $_POST['post_title'] ) ? sanitize_text_field($_POST['post_title'], 'Contact Form', 'save') : null; |
| 710 |
$args['locale'] = isset( $_POST['wpcf7-locale'] ) ? sanitize_text_field($_POST['wpcf7-locale']) : null; |
| 711 |
$args['form'] = ''; |
| 712 |
$allowed_tags = wp_kses_allowed_html( 'post' ); //filtered in function below. |
| 713 |
/** @since 2.10.0 alllow custom input html*/ |
| 714 |
$allowed_tags['input']=array( //add additional input html elements |
| 715 |
'type'=>1, |
| 716 |
'class'=>1, |
| 717 |
'id'=>1, |
| 718 |
'value'=>1, |
| 719 |
'data-*'=>1, |
| 720 |
); |
| 721 |
$allowed_tags['script']=array('type'=>1); |
| 722 |
$cf7_key = $post->post_name; |
| 723 |
$allowed_tags = apply_filters('cf7sg_kses_allowed_html',$allowed_tags, $cf7_key); |
| 724 |
if(isset( $_POST['wpcf7-form'] )){ |
| 725 |
$args['form'] = wp_kses($_POST['wpcf7-form'], $allowed_tags); |
| 726 |
} |
| 727 |
$args['mail'] = isset( $_POST['wpcf7-mail'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail'] ): array(); |
| 728 |
$args['mail_2'] = isset( $_POST['wpcf7-mail-2'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail-2'] ): array(); |
| 729 |
$args['messages'] = isset( $_POST['wpcf7-messages'] ) ? $_POST['wpcf7-messages'] : array(); |
| 730 |
foreach($args['messages'] as $key=>$value){ |
| 731 |
$args['messages'][$key] = sanitize_text_field($value); |
| 732 |
} |
| 733 |
$args['additional_settings'] = isset( $_POST['wpcf7-additional-settings'] ) ? sanitize_textarea_field($_POST['wpcf7-additional-settings']) : ''; |
| 734 |
|
| 735 |
//need to unhook this function so as not to loop infinitely |
| 736 |
//debug_msg($args, 'saving cf7 posts'); |
| 737 |
remove_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3); |
| 738 |
$contact_form = wpcf7_save_contact_form( $args ); |
| 739 |
add_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3); |
| 740 |
//flag as a grid form |
| 741 |
//update_post_meta($post_id, 'cf7_grid_form', true); removed since v2.3 as not used. |
| 742 |
//save sub-forms if any |
| 743 |
$sub_forms = json_decode(stripslashes($_POST['cf7sg-embeded-forms'])); |
| 744 |
if(empty($sub_forms)) $sub_forms = array(); |
| 745 |
if(!is_array($sub_forms)) $sub_forms = array($sub_forms); |
| 746 |
$sanitised_sub_forms = array(); |
| 747 |
foreach($sub_forms as $field){ |
| 748 |
$sanitised_sub_forms[] = sanitize_text_field($field); |
| 749 |
} |
| 750 |
update_post_meta($post_id, '_cf7sg_sub_forms', $sanitised_sub_forms); |
| 751 |
//save form fields which are in tabs or tables. |
| 752 |
$tt_fields = json_decode(stripslashes($_POST['cf7sg-table-fields'])); |
| 753 |
if(empty($tt_fields)) $tt_fields = array(); |
| 754 |
if(!is_array($tt_fields)) $tt_fields = array($tt_fields); |
| 755 |
$sanitised_table_fields = array(); |
| 756 |
foreach($tt_fields as $table_fields){ |
| 757 |
if(is_object($table_fields)){ /** @since 2.4.2 track fields in each tables. */ |
| 758 |
$table_fields = get_object_vars($table_fields); /*convert to array*/ |
| 759 |
$table = array_keys($table_fields); |
| 760 |
$table = sanitize_text_field($table[0]); |
| 761 |
$table_fields = $table_fields[$table]; |
| 762 |
$sanitised_table_fields[$table]=array(); |
| 763 |
foreach($table_fields as $field) $sanitised_table_fields[$table][] = sanitize_text_field($field); |
| 764 |
}else $sanitised_table_fields[] = sanitize_text_field($table_fields); |
| 765 |
} |
| 766 |
update_post_meta($post_id, '_cf7sg_grid_table_names', $sanitised_table_fields); |
| 767 |
//tabs |
| 768 |
$tt_fields = json_decode(stripslashes($_POST['cf7sg-tabs-fields'])); |
| 769 |
if(empty($tt_fields)) $tt_fields = array(); |
| 770 |
if(!is_array($tt_fields)) $tt_fields = array($tt_fields); |
| 771 |
$sanitised_tab_fields = array(); |
| 772 |
foreach($tt_fields as $tab_field){ |
| 773 |
if(is_object($tab_field)){ /** @since 2.4.2 track fields in each tabs. */ |
| 774 |
$tab_field = get_object_vars($tab_field); /*convert to array*/ |
| 775 |
$tab = array_keys($tab_field); |
| 776 |
$tab = sanitize_text_field($tab[0]); |
| 777 |
$tab_field = $tab_field[$tab]; |
| 778 |
$sanitised_tab_fields[$tab]=array(); |
| 779 |
foreach($tab_field as $field) $sanitised_tab_fields[$tab][] = sanitize_text_field($field); |
| 780 |
}else $sanitised_tab_fields[] = sanitize_text_field($tab_field); |
| 781 |
} |
| 782 |
update_post_meta($post_id, '_cf7sg_grid_tabs_names', $sanitised_tab_fields); |
| 783 |
/** track toggled fields. |
| 784 |
* @since 2.5*/ |
| 785 |
$tt_fields = json_decode(stripslashes($_POST['cf7sg-toggle-fields'])); |
| 786 |
if(empty($tt_fields)) $tt_fields = array(); |
| 787 |
if(!is_array($tt_fields)) $tt_fields = array($tt_fields); |
| 788 |
$sanitised_toggled_fields = array(); |
| 789 |
foreach($tt_fields as $tgg_field){ |
| 790 |
if(is_object($tgg_field)){ |
| 791 |
$tgg_field = get_object_vars($tgg_field); /*convert to array*/ |
| 792 |
$tgg = array_keys($tgg_field); |
| 793 |
$tgg = sanitize_text_field($tgg[0]); |
| 794 |
$tgg_field = $tgg_field[$tgg]; |
| 795 |
$sanitised_toggled_fields[$tgg]=array(); |
| 796 |
foreach($tgg_field as $field) $sanitised_toggled_fields[$tgg][] = sanitize_text_field($field); |
| 797 |
}else $sanitised_toggled_fields[] = sanitize_text_field($tgg_field); |
| 798 |
} |
| 799 |
update_post_meta($post_id, '_cf7sg_grid_toggled_names', $sanitised_toggled_fields); |
| 800 |
/** @since 4.0.0 track tabbed toggles */ |
| 801 |
$ttgls = json_decode(stripslashes($_POST['cf7sg-tabbed-toggles'])); |
| 802 |
if(empty($ttgls)) $ttgls = array(); |
| 803 |
if(!is_array($ttgls)) $ttgls = array($ttgls); |
| 804 |
update_post_meta($post_id, '_cf7sg_grid_tabbed_toggles', $ttgls); |
| 805 |
/** @since 4.0.0 track grouped toggles */ |
| 806 |
$ttgls = json_decode(stripslashes($_POST['cf7sg-grouped-toggles'])); |
| 807 |
if(empty($ttgls)) $ttgls = array(); |
| 808 |
if(is_object($ttgls)) $ttgls = get_object_vars($ttgls); //convert to array. |
| 809 |
else $ttgls = array(); |
| 810 |
update_post_meta($post_id, '_cf7sg_grid_grouped_toggles', $ttgls); |
| 811 |
//flag tab & tables for more efficient front-end display. |
| 812 |
$has_tabs = ( 'true' === $_POST['cf7sg-has-tabs']) ? true : false; |
| 813 |
update_post_meta($post_id, '_cf7sg_has_tabs', $has_tabs); |
| 814 |
$has_tables = ( 'true' === $_POST['cf7sg-has-tables']) ? true : false; |
| 815 |
update_post_meta($post_id, '_cf7sg_has_tables', $has_tables); |
| 816 |
$has_toggles = ( 'true' === $_POST['cf7sg-has-toggles']) ? true : false; |
| 817 |
update_post_meta($post_id, '_cf7sg_has_toggles', $has_toggles); |
| 818 |
/** @since 3.3.5 track toggles 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); |
| 823 |
/** |
| 824 |
* @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms. |
| 825 |
*/ |
| 826 |
$is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false; |
| 827 |
update_post_meta($post_id, '_cf7sg_managed_form', $is_cf7sg); |
| 828 |
update_post_meta($post_id, '_cf7sg_version', $this->version); |
| 829 |
/** @since 3.0.0 track script classes for loading for js/css in front-end */ |
| 830 |
$classes = sanitize_text_field($_POST['cf7sg-script-classes']); |
| 831 |
$classes = explode(',', trim($classes, ',')); |
| 832 |
// debug_msg($classes, 'script classes'); |
| 833 |
update_post_meta($post_id, '_cf7sg_script_classes', $classes); |
| 834 |
/** |
| 835 |
*@since 2.3.0 the duplicate functionality has been instored and therefore any new meta fields added to this plugin needs to be added to the duplication properties too. |
| 836 |
*/ |
| 837 |
/** @since 4.0.0 save user theme pref */ |
| 838 |
if(isset($_POST['cf7sg_codemirror_theme'])){ |
| 839 |
update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', $_POST['cf7sg_codemirror_theme']); |
| 840 |
} |
| 841 |
if(isset($_POST['cf7sg_js_codemirror_theme'])){ |
| 842 |
update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', $_POST['cf7sg_js_codemirror_theme']); |
| 843 |
} |
| 844 |
//save js file if used. |
| 845 |
$path = get_stylesheet_directory(); |
| 846 |
if(!empty($_POST['cf7sg_js_file'])){ |
| 847 |
//check if the file name is changed. |
| 848 |
if(!empty($_POST['cf7sg_prev_js_file']) && file_exists(ABSPATH. $_POST['cf7sg_prev_js_file'])){ |
| 849 |
if( !unlink(ABSPATH.$_POST['cf7sg_prev_js_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_js_file']); |
| 850 |
} |
| 851 |
if( !is_dir("$path/js/") ) mkdir("$path/js/"); |
| 852 |
file_put_contents( "$path/js/{$cf7_key}.js", stripslashes($_POST['cf7sg_js_file']) ); |
| 853 |
}else if( isset($_POST['cf7sg_js_file']) && file_exists("$path/js/{$cf7_key}.js") ) { //delete file. |
| 854 |
if( !unlink("$path/js/{$cf7_key}.js") ) debug_msg("CF7SG ADMIN: unable to delete file $path/js/{$cf7_key}.js"); |
| 855 |
} |
| 856 |
//save css file. |
| 857 |
if(!empty($_POST['cf7sg_css_file'])){ |
| 858 |
//check if the file is changed. |
| 859 |
if(!empty($_POST['cf7sg_prev_css_file']) && file_exists(ABSPATH.$_POST['cf7sg_prev_css_file'])){ |
| 860 |
if( !unlink(ABSPATH.$_POST['cf7sg_prev_css_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_css_file']); |
| 861 |
} |
| 862 |
if( !is_dir("$path/css/") ) mkdir("$path/css/"); |
| 863 |
file_put_contents( $path."/css/{$cf7_key}.css", stripslashes($_POST['cf7sg_css_file'])); |
| 864 |
}else if( isset($_POST['cf7sg_css_file']) && file_exists("$path/css/{$cf7_key}.css") ) { //delete file. |
| 865 |
if( !unlink("$path/css/{$cf7_key}.css") ) debug_msg("CF7SG ADMIN: unable to delete file $path/css/{$cf7_key}.css"); |
| 866 |
} |
| 867 |
//jstags comments. |
| 868 |
if(empty($_POST['cf7sg_jstags_comments'])) update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',1); |
| 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 |
} |
| 889 |
} |
| 890 |
/** |
| 891 |
* Print default js template, |
| 892 |
* Hooked to 'cf7sg_default_custom_js_template' |
| 893 |
*@since 4.0.0 |
| 894 |
*@param string $form_key form key. |
| 895 |
*/ |
| 896 |
public function print_default_js($form_key){ |
| 897 |
$js_file = str_replace(ABSPATH, '', get_stylesheet_directory()."/js/{$form_key}.js"); |
| 898 |
include_once 'partials/cf7-default-js.php'; |
| 899 |
} |
| 900 |
/** |
| 901 |
* |
| 902 |
* |
| 903 |
*@since 2.3.0 |
| 904 |
*@param string $new_form_id new form id to duplciate to. |
| 905 |
*@param string $form_id form id to duplciate. |
| 906 |
*/ |
| 907 |
public function duplicate_form_properties($new_form_id, $form_id){ |
| 908 |
//these properties will be preceded with an '_' by the cf7 plugin before being duplicated. |
| 909 |
$properties = array('_cf7sg_sub_forms', '_cf7sg_grid_table_names', '_cf7sg_grid_tabs_names', '_cf7sg_has_tabs', '_cf7sg_has_tables', '_cf7sg_managed_form','_cf7sg_script_classes', '_cf7sg_version'); |
| 910 |
$properties = apply_filters('cf7sg_duplicate_form_properties', $properties); |
| 911 |
foreach($properties as $field){ |
| 912 |
$value = get_post_meta($form_id, $field, true); |
| 913 |
if(!empty($value)) update_post_meta($new_form_id,$field, $value); |
| 914 |
} |
| 915 |
} |
| 916 |
/** |
| 917 |
* Duplicate form. |
| 918 |
* |
| 919 |
*@since 2.3.0 |
| 920 |
*@param string $param text_description |
| 921 |
*@return string text_description |
| 922 |
*/ |
| 923 |
public function duplicate_cf7_form(){ |
| 924 |
global $pagenow; |
| 925 |
if($pagenow != 'post.php') return; |
| 926 |
if(isset($_GET['action']) && 'cf7copy' == $_GET['action']){ |
| 927 |
$action = 'wpcf7-copy-contact-form_' . $_GET['post']; |
| 928 |
if( !wp_verify_nonce( $_GET['_wpnonce'], $action )){ |
| 929 |
die( 'Security check error: Try to reload the page and try again.' ); |
| 930 |
} |
| 931 |
if ( $form = wpcf7_contact_form( $_GET['post'] ) ) { |
| 932 |
$new_form = $form->copy(); |
| 933 |
$new_form->save(); |
| 934 |
$this->duplicate_form_properties($new_form->id(), $_GET['post']); |
| 935 |
wp_safe_redirect( admin_url( '/post.php?post='.$new_form->id().'&action=edit' )); |
| 936 |
exit; |
| 937 |
} |
| 938 |
} |
| 939 |
} |
| 940 |
/** |
| 941 |
* Filtered allowed html tags & attributes, add data-button to div tags to ensure forms are saved properly. |
| 942 |
* Hooked on 'wp_kses_allowed_html' |
| 943 |
*@since 1.0.0 |
| 944 |
*@param array $allowed array of allowed tags and attributes. |
| 945 |
*@param mixed $context context in which content is filtered. |
| 946 |
*@return array allowed tags and ttribtues. |
| 947 |
*/ |
| 948 |
public function custom_kses_rules($allowed, $context){ |
| 949 |
if(is_array($context)){ |
| 950 |
return $allowed; |
| 951 |
} |
| 952 |
if('post'===$context){ |
| 953 |
$allowed['div']['data-button'] = true; //table buttons. |
| 954 |
$allowed['div']['data-form'] = true; //sub-forms. |
| 955 |
$allowed['div']['data-on'] = true; //toggles. |
| 956 |
$allowed['div']['data-off'] = true; //toggles. |
| 957 |
$allowed['div']['data-open'] = true; //accordion. |
| 958 |
$allowed['div']['data-group'] = true; //accordion. |
| 959 |
$allowed['div']['data-config-field'] = true; //cf7 plugin. |
| 960 |
} |
| 961 |
return $allowed; |
| 962 |
} |
| 963 |
/** |
| 964 |
* Filters the default form loaded when a new CF7 form is created |
| 965 |
* Hooked on 'wpcf7_default_template' |
| 966 |
* @since 1.0 |
| 967 |
* @param string $template the html string for the form tempalte |
| 968 |
* @param string $prop the template property required. |
| 969 |
*/ |
| 970 |
public function default_cf7_form($template, $prop){ |
| 971 |
if($prop !== 'form') return $template; |
| 972 |
include( plugin_dir_path( __FILE__ ) . '/partials/cf7-default-form.php'); |
| 973 |
return $template; |
| 974 |
} |
| 975 |
/** |
| 976 |
* Ajax function to return the content of a cf7 form |
| 977 |
* Hooked on 'wp_ajax_get_cf7_content' |
| 978 |
* @since 1.0.0 |
| 979 |
* @return String cf7 form content. |
| 980 |
**/ |
| 981 |
public function get_cf7_content(){ |
| 982 |
if( !isset($_POST['nonce']) ){ |
| 983 |
echo 'error, nonce failed, try to reload the page.'; |
| 984 |
wp_die(); |
| 985 |
} |
| 986 |
if(!wp_verify_nonce($_POST['nonce'], 'wpcf7-save-contact-form_' . $_POST['id'], '_wpcf7nonce')){ |
| 987 |
echo 'error, nonce failed, try to reload the page.'; |
| 988 |
wp_die(); |
| 989 |
} |
| 990 |
$cf7_key = sanitize_text_field($_POST['cf7_key']); |
| 991 |
$sub_forms = get_posts(array( |
| 992 |
'post_type' => $this->cf7_post_type(), |
| 993 |
'post_name__in' => array($cf7_key) |
| 994 |
)); |
| 995 |
$form=''; |
| 996 |
if(!empty($sub_forms)){ |
| 997 |
$form = get_post_meta($sub_forms[0]->ID, '_form', true); |
| 998 |
echo $form; |
| 999 |
}else{ |
| 1000 |
echo 'unable to find form '.$cf7_key; |
| 1001 |
} |
| 1002 |
wp_die(); |
| 1003 |
} |
| 1004 |
/** |
| 1005 |
* Adds a [taxonomy] tag to cf7 forms |
| 1006 |
* Hooked on 'wpcf7_admin_init' |
| 1007 |
* @since 1.0.0 |
| 1008 |
**/ |
| 1009 |
public function cf7_shortcode_tags(){ |
| 1010 |
if ( class_exists( 'WPCF7_TagGenerator' ) ) { |
| 1011 |
$tag_generator = WPCF7_TagGenerator::get_instance(); |
| 1012 |
$tag_generator->add( |
| 1013 |
'dynamic_select', //tag id |
| 1014 |
__( 'dynamic-dropdown', 'cf7_2_post' ), //tag button label |
| 1015 |
array($this,'dynamic_tag_generator') //callback |
| 1016 |
); |
| 1017 |
$tag_generator->add( |
| 1018 |
'benchmark', //tag id |
| 1019 |
__( 'benchmark', 'cf7_2_post' ), //tag button label |
| 1020 |
array($this,'benchmark_tag_generator') //callback |
| 1021 |
); |
| 1022 |
} |
| 1023 |
} |
| 1024 |
/** |
| 1025 |
* Dynamic select screen displayt. |
| 1026 |
* |
| 1027 |
* This function is called by cf7 plugin, and is registered with a hooked function above |
| 1028 |
* |
| 1029 |
* @since 1.0.0 |
| 1030 |
* @param WPCF7_ContactForm $contact_form the cf7 form object |
| 1031 |
* @param array $args arguments for this form. |
| 1032 |
*/ |
| 1033 |
function dynamic_tag_generator( $contact_form, $args = '' ) { |
| 1034 |
$args = wp_parse_args( $args, array() ); |
| 1035 |
include( plugin_dir_path( __FILE__ ) . '/partials/cf7-dynamic-tag-display.php'); |
| 1036 |
} |
| 1037 |
/** |
| 1038 |
* Benchmark input screen displayt. |
| 1039 |
* |
| 1040 |
* This function is called by cf7 plugin, and is registered with a hooked function above |
| 1041 |
* |
| 1042 |
* @since 1.0.0 |
| 1043 |
* @param WPCF7_ContactForm $contact_form the cf7 form object |
| 1044 |
* @param array $args arguments for this form. |
| 1045 |
*/ |
| 1046 |
function benchmark_tag_generator( $contact_form, $args = '' ) { |
| 1047 |
$args = wp_parse_args( $args, array() ); |
| 1048 |
include( plugin_dir_path( __FILE__ ) . '/partials/cf7-benchmark-tag.php'); |
| 1049 |
} |
| 1050 |
/** |
| 1051 |
* Print hiddend field on cf7 post submit box |
| 1052 |
* Hooked on 'wpcf7_admin_misc_pub_section' |
| 1053 |
* @since 1.0.0 |
| 1054 |
* @param string $post_id cf7 form post id . |
| 1055 |
**/ |
| 1056 |
public function dynamic_select_choices($post_id){ |
| 1057 |
echo '<input id="cf72post-dynamic-select" type="hidden" name="cf72post_dynamic_select_taxonomies" />'; |
| 1058 |
} |
| 1059 |
/** |
| 1060 |
* CF7 Form saved from backend, check if dynamic-select are used |
| 1061 |
* Hooked on 'wpcf7_save_contact_form' |
| 1062 |
* @since 1.0.0 |
| 1063 |
* @param WPCF7_Contact_Form $cf7_form cf7 form object |
| 1064 |
*/ |
| 1065 |
public function save_factory_metas($cf7_form){ |
| 1066 |
$cf7_post_id = $cf7_form->id(); |
| 1067 |
//get the tags used in this form |
| 1068 |
if( isset($_POST['cf72post_dynamic_select_taxonomies']) ){ |
| 1069 |
$created_taxonomies = array(); |
| 1070 |
$taxonomies = json_decode(str_replace('\"','"',$_POST['cf72post_dynamic_select_taxonomies']), true); |
| 1071 |
if(empty($taxonomies)){ |
| 1072 |
$taxonomies = array(); |
| 1073 |
} |
| 1074 |
foreach($taxonomies as $taxonomy){ |
| 1075 |
//sanitize fields before saving into the DB. |
| 1076 |
foreach($taxonomy as $key=>$value){ |
| 1077 |
$key = sanitize_key($key); |
| 1078 |
$taxonomy[$key] = sanitize_text_field($value); |
| 1079 |
} |
| 1080 |
$created_taxonomies[$taxonomy['slug']] = $taxonomy; |
| 1081 |
} |
| 1082 |
//debug_msg($created_taxonomies); |
| 1083 |
$tags = $cf7_form->scan_form_tags(); //get your form tags |
| 1084 |
$post_lists = $saved_lists = $system_list = array(); |
| 1085 |
|
| 1086 |
$dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array()); |
| 1087 |
foreach($dropdowns as $id => $lists){ |
| 1088 |
$saved_lists = array_merge($saved_lists, $lists); |
| 1089 |
} |
| 1090 |
foreach($tags as $tag){ |
| 1091 |
if('dynamic_select' == $tag['basetype']){ |
| 1092 |
if(isset($tag['values'])){ |
| 1093 |
$slug=''; |
| 1094 |
foreach($tag['values'] as $values){ |
| 1095 |
if(0 == strpos($values, 'slug:') ){ |
| 1096 |
$slug = str_replace('slug:', '', $values); |
| 1097 |
break; |
| 1098 |
} |
| 1099 |
} |
| 1100 |
if(empty($slug)) continue; //not a taxonomy list. |
| 1101 |
//is slug newly created? |
| 1102 |
if(isset($created_taxonomies[$slug])){ |
| 1103 |
//store this taxonomy. |
| 1104 |
$post_lists[$slug] = $created_taxonomies[$slug]; |
| 1105 |
}else if(isset($saved_lists[$slug])){ |
| 1106 |
//retain previously saved list if we are stil using it. |
| 1107 |
$post_lists[$slug] = $saved_lists[$slug]; |
| 1108 |
}else{ //system taxonomy. |
| 1109 |
$system_list[] = $slug; |
| 1110 |
} |
| 1111 |
//store the taxonomy slug in the cf7 metas. |
| 1112 |
//$post_lists[$slug] = null; |
| 1113 |
} |
| 1114 |
} |
| 1115 |
} |
| 1116 |
//list of taxonomy to register. |
| 1117 |
//unset the old value. |
| 1118 |
unset($dropdowns[$cf7_post_id]); |
| 1119 |
//unshift new value to top of array. |
| 1120 |
$dropdowns = array($cf7_post_id => $post_lists) + $dropdowns ; |
| 1121 |
|
| 1122 |
update_option('_cf7sg_dynamic_dropdown_taxonomy', $dropdowns); |
| 1123 |
//list of system taxonomy to register |
| 1124 |
$system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array()); |
| 1125 |
$system_dropdowns[$cf7_post_id] = $system_list; |
| 1126 |
update_option('_cf7sg_dynamic_dropdown_system_taxonomy', $system_dropdowns); |
| 1127 |
|
| 1128 |
} |
| 1129 |
} |
| 1130 |
|
| 1131 |
/** |
| 1132 |
* function to regsiter dyanmic dropdown taxonomies |
| 1133 |
* |
| 1134 |
* @since 1.0.0 |
| 1135 |
* @param Object $taxonomy_object std object with parameters $taxonomy_object->slug, $taxonomy_object->singular, $taxonomy_object->plural, $taxonomy_object->hierarchical . |
| 1136 |
**/ |
| 1137 |
protected function register_dynamic_dropdown($taxonomy_array){ |
| 1138 |
$slug = $taxonomy_array['slug']; |
| 1139 |
$name = $taxonomy_array['singular']; |
| 1140 |
$plural = $taxonomy_array['plural']; |
| 1141 |
$is_hierarchical = $taxonomy_array['hierarchical']; |
| 1142 |
|
| 1143 |
$labels = array( |
| 1144 |
'name' => $plural, |
| 1145 |
'singular_name' => $name, |
| 1146 |
'menu_name' => $plural, |
| 1147 |
'all_items' => 'All '.$plural, |
| 1148 |
'parent_item' => 'Parent '.$name, |
| 1149 |
'parent_item_colon' => 'Parent '.$name.':', |
| 1150 |
'new_item_name' => 'New '.$name.' Name', |
| 1151 |
'add_new_item' => 'Add New '.$name, |
| 1152 |
'edit_item' => 'Edit '.$name, |
| 1153 |
'update_item' => 'Update '.$name, |
| 1154 |
'view_item' => 'View '.$name, |
| 1155 |
'separate_items_with_commas' => 'Separate '.$plural.' with commas', |
| 1156 |
'add_or_remove_items' => 'Add or remove '.$plural, |
| 1157 |
'choose_from_most_used' => 'Choose from the most used', |
| 1158 |
'popular_items' => 'Popular '.$plural, |
| 1159 |
'search_items' => 'Search '.$plural, |
| 1160 |
'not_found' => 'Not Found', |
| 1161 |
'no_terms' => 'No '.$plural, |
| 1162 |
'items_list' => $plural.' list', |
| 1163 |
'items_list_navigation' => $plural.' list navigation', |
| 1164 |
); |
| 1165 |
//labels can be modified post registration |
| 1166 |
$args = array( |
| 1167 |
'labels' => $labels, |
| 1168 |
'hierarchical' => $is_hierarchical, |
| 1169 |
'public' => false, |
| 1170 |
'show_ui' => true, |
| 1171 |
'show_admin_column' => false, |
| 1172 |
'show_in_nav_menus' => false, |
| 1173 |
'show_tagcloud' => false, |
| 1174 |
'show_in_quick_edit' => false, |
| 1175 |
'description' => 'Contact Form 7 dynamic dropdown taxonomy list', |
| 1176 |
); |
| 1177 |
|
| 1178 |
register_taxonomy( $slug, $this->cf7_post_type(), $args ); |
| 1179 |
} |
| 1180 |
/** |
| 1181 |
* Deactivate this plugin if CF7 plugin is deactivated. |
| 1182 |
* Hooks on action 'admin_init' |
| 1183 |
* @since 2.1 |
| 1184 |
*/ |
| 1185 |
//public function deactivate_cf7_polylang( $plugin, $network_deactivating ) { |
| 1186 |
public function check_plugin_dependency() { |
| 1187 |
//if either the polylang for the cf7 plugin is not active anymore, deactive this extension |
| 1188 |
if( !is_plugin_active("contact-form-7/wp-contact-form-7.php") ){ |
| 1189 |
deactivate_plugins( "cf7-grid-layout/cf7-grid-layout.php" ); |
| 1190 |
debug_msg("Deactivating Smart Grid"); |
| 1191 |
|
| 1192 |
$button = '<a href="'.network_admin_url('plugins.php').'">Return to Plugins</a></a>'; |
| 1193 |
wp_die( '<p><strong>CF7 smart Grid-layout Extension</strong> requires <strong>Contact Form 7</strong> plugin, and has therefore been deactivated!</p>'.$button ); |
| 1194 |
|
| 1195 |
return false; |
| 1196 |
} |
| 1197 |
return true; |
| 1198 |
} |
| 1199 |
/** |
| 1200 |
* Add disabled button message on hover to cf7 messages. |
| 1201 |
* Hooked to 'wpcf7_messages', see file contact-form-7/includes/contact-form-template.php fn messages(). |
| 1202 |
*@since 2.6.0 |
| 1203 |
*@param array $messages array of messages to filter. |
| 1204 |
*@return array array of cf7 messages. |
| 1205 |
*/ |
| 1206 |
public function disabled_message($messages){ |
| 1207 |
$messages['submit_disabled'] = array( |
| 1208 |
'description' |
| 1209 |
=> __( "Hover message for disabled submit/save button", 'cf7-grid-layout' ), |
| 1210 |
'default' |
| 1211 |
=> __( "Disabled! To enable, check the acceptance field.", 'cf7-grid-layout' ), |
| 1212 |
); |
| 1213 |
/** @sicne 2.8.0 */ |
| 1214 |
$messages['max_table_rows'] = array( |
| 1215 |
'description' |
| 1216 |
=> __( "Message displayed when max tables rows reached.", 'cf7-grid-layout' ), |
| 1217 |
'default' |
| 1218 |
=> __( "You have reached the maximum number of rows.", 'cf7-grid-layout' ), |
| 1219 |
); |
| 1220 |
return $messages; |
| 1221 |
} |
| 1222 |
/** |
| 1223 |
* Adds pretty pointers to help users. |
| 1224 |
* Hooked on 'admin_enqueue_scripts' |
| 1225 |
*@since 2.6.0 |
| 1226 |
*@param string $hook_suffix current page. |
| 1227 |
*/ |
| 1228 |
public function pretty_admin_pointers($hook_suffix){ |
| 1229 |
$screen = get_current_screen(); |
| 1230 |
if (!isset($screen) || $this->cf7_post_type() != $screen->post_type || in_array( $hook_suffix, array('post.php', 'post-new.php'), true)){ |
| 1231 |
return; |
| 1232 |
} |
| 1233 |
$enqueue_pointer = false; |
| 1234 |
// Get array list of dismissed pointers for current user and convert it to array |
| 1235 |
$user_id = get_current_user_id(); |
| 1236 |
$dismissed_pointers = explode( ',', get_user_meta( $user_id, 'dismissed_wp_pointers', true ) ); |
| 1237 |
$pointers = array(); |
| 1238 |
/** |
| 1239 |
* Filter to add custom pointers for user iterface. |
| 1240 |
* @var array $pointers an array of $pointer_id=>array($content, $arrow, $valign) key/value pairs to filter. The key is the pointer id to identify which ones the user has dismissed. The value is an array with the message $content, the position of the $arrow (left|right|top|bottom), the vertical alignment ($valign) of the box (center|top|bottom). |
| 1241 |
* @return array an array of pointers, which will be checked agains the current user. |
| 1242 |
*/ |
| 1243 |
$filter_pointers = apply_filters('cf7sg_plugin_pointers-'.$screen->id, array()); |
| 1244 |
foreach($filter_pointers as $id=>$pointer){ |
| 1245 |
// Check if our pointer is not among dismissed ones |
| 1246 |
if( !in_array( $id, $dismissed_pointers ) ) { |
| 1247 |
$enqueue_pointer = true; |
| 1248 |
$pointers[$id] = array($pointer[0], $pointer[1], $pointer[2], $pointer[3]); |
| 1249 |
} |
| 1250 |
} |
| 1251 |
// Enqueue pointer CSS and JS files, if needed |
| 1252 |
if( $enqueue_pointer ) { |
| 1253 |
wp_enqueue_style( 'wp-pointer' ); |
| 1254 |
wp_enqueue_script( 'wp-pointer' ); |
| 1255 |
wp_enqueue_script('cf7sg-pointer-js', plugin_dir_url( __DIR__ ).'admin/js/cf7sg-pointers.js', array('jquery'), $this->version, true); |
| 1256 |
wp_localize_script('cf7sg-pointer-js', 'cf7sg_pointers', |
| 1257 |
array('pointers'=>$pointers, 'next'=>__('Next', 'cf7-grid-layout')) |
| 1258 |
); |
| 1259 |
// Add footer scripts using callback function |
| 1260 |
//add_action( 'admin_print_footer_scripts', array($this, 'pretty_pointer_script') ); |
| 1261 |
} |
| 1262 |
} |
| 1263 |
/** |
| 1264 |
* CF7 Table pointer notices. |
| 1265 |
* Hooked on 'cf7sg_plugin_pointers-edit-wpcf7_contact_form' |
| 1266 |
*@since 2.6.0 |
| 1267 |
*@param array $pointers array of pointers to suplement |
| 1268 |
*@return array array of pointers element-id=>hmtl to display key value pairs. |
| 1269 |
*/ |
| 1270 |
public function edit_pointers($pointers){ |
| 1271 |
ob_start(); |
| 1272 |
include_once 'partials/pointers/cf7sg-pointer-update-forms.php'; |
| 1273 |
$content =ob_get_contents(); |
| 1274 |
$pointers['update_forms_pointer'] = array($content, 'left', 'center',''); |
| 1275 |
/* tutorials */ |
| 1276 |
ob_clean(); |
| 1277 |
include_once 'partials/pointers/cf7sg-pointer-tutorials.php'; |
| 1278 |
$content =ob_get_contents(); |
| 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"]'); |
| 1285 |
/* shortcodes */ |
| 1286 |
ob_clean(); |
| 1287 |
include_once 'partials/pointers/cf7sg-pointer-shortcodes.php'; |
| 1288 |
$content = ob_get_clean(); |
| 1289 |
$pointers['cf7sg_shortcodes'] = array($content, 'top', 'top',''); |
| 1290 |
return $pointers; |
| 1291 |
} |
| 1292 |
/** |
| 1293 |
* CF7 Edit pointer notices. |
| 1294 |
* Hooked on 'cf7sg_plugin_pointers-wpcf7_contact_form' |
| 1295 |
*@since 2.6.0 |
| 1296 |
*@param array $pointers array of pointers to suplement |
| 1297 |
*@return array array of pointers element-id=>hmtl to display key value pairs. |
| 1298 |
*/ |
| 1299 |
public function post_pointers($pointers){ |
| 1300 |
ob_start(); |
| 1301 |
include_once 'partials/pointers/cf7sg-pointer-editor-full-screen.php'; |
| 1302 |
$content =ob_get_contents(); |
| 1303 |
//content / arrow [top,bottom,left,right] / box align [top,bottom,center] / css selector. |
| 1304 |
$pointers['full_screen'] = array($content, 'left', 'center','#full-screen-cf7'); |
| 1305 |
/* shortcodes */ |
| 1306 |
ob_clean(); |
| 1307 |
include_once 'partials/pointers/cf7sg-pointer-editor-tabs.php'; |
| 1308 |
$content =ob_get_contents(); |
| 1309 |
$pointers['editor_tabs'] = array($content, 'right', 'center','#form-editor-tabs>ul>li.ui-tabs-active'); |
| 1310 |
/* shortcodes */ |
| 1311 |
ob_clean(); |
| 1312 |
include_once 'partials/pointers/cf7sg-pointer-editor-rows-control.php'; |
| 1313 |
$content = ob_get_contents(); |
| 1314 |
if(!empty($content)){ |
| 1315 |
$pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls'); |
| 1316 |
ob_clean(); |
| 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 |
} |
| 1326 |
include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php'; |
| 1327 |
$content = ob_get_contents(); |
| 1328 |
if(!empty($content)){ |
| 1329 |
$pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code'); |
| 1330 |
ob_clean(); |
| 1331 |
} |
| 1332 |
include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php'; |
| 1333 |
$content = ob_get_contents(); |
| 1334 |
$pointers['dynamic_dropdown'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-dropdown"]'); |
| 1335 |
ob_clean(); |
| 1336 |
/* #optional-editors */ |
| 1337 |
include_once 'partials/pointers/cf7sg-pointers-editor-optional-js-css.php'; |
| 1338 |
$content = ob_get_contents(); |
| 1339 |
$pointers['js_css_editors'] = array($content, 'left', 'center','#optional-editors'); |
| 1340 |
ob_clean(); |
| 1341 |
include_once 'partials/pointers/cf7sg-pointer-tag-benchmark.php'; |
| 1342 |
$content = ob_get_clean(); |
| 1343 |
$pointers['benchmark'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="benchmark"]'); |
| 1344 |
return $pointers; |
| 1345 |
} |
| 1346 |
/** |
| 1347 |
* Rest meta_caps for better fine tuning of user caps. |
| 1348 |
* hooked to 'wpcf7_map_meta_cap'. |
| 1349 |
*@since 3.0.0 |
| 1350 |
*@param array $caps key->value pairs of capabilities. |
| 1351 |
*@return array key->value pairs of capabilities. |
| 1352 |
*/ |
| 1353 |
public function reset_meta_cap($caps){ |
| 1354 |
return array( |
| 1355 |
'wpcf7_read_contact_form'=>'read_post', |
| 1356 |
'wpcf7_edit_contact_form' =>'edit_post', |
| 1357 |
'wpcf7_edit_contact_forms' => 'edit_posts', |
| 1358 |
'wpcf7_edit_others_contact_forms'=>'edit_others_posts', |
| 1359 |
'wpcf7_edit_published_contact_forms'=>'edit_published_posts', |
| 1360 |
'wpcf7_delete_contact_form'=>'delete_post', |
| 1361 |
'wpcf7_delete_contact_forms'=>'delete_posts', |
| 1362 |
'wpcf7_delete_published_contact_forms'=>'delete_published_posts', |
| 1363 |
'wpcf7_delete_others_contact_forms'=>'delete_others_posts', |
| 1364 |
'wpcf7_publish_contact_forms'=>'publish_posts', |
| 1365 |
'wpcf7_publish_contact_forms'=>'read_private_posts', |
| 1366 |
'wpcf7_submit'=>'read', /** @since 3.2.1 to fix subscribers_only. */ |
| 1367 |
); |
| 1368 |
} |
| 1369 |
/** |
| 1370 |
* CF7 plugin by default sets form post status to 'publish' regardless of user capability. |
| 1371 |
* This functions rectifies this. Hooked to 'wp_insert_post_data'. |
| 1372 |
*@since 3.0.0 |
| 1373 |
*@param array $data sanitised post data. |
| 1374 |
*@return array post data. |
| 1375 |
*/ |
| 1376 |
public function pending_for_review($data){ |
| 1377 |
if($this->cf7_post_type() != $data['post_type']) return $data; |
| 1378 |
|
| 1379 |
$post_type_object = get_post_type_object( $this->cf7_post_type() ); |
| 1380 |
//check if user can publish. |
| 1381 |
if(!current_user_can($post_type_object->cap->publish_posts) && $data['post_status']=='publish'){ |
| 1382 |
$data['post_status']='pending'; |
| 1383 |
} |
| 1384 |
// debug_msg('post status '.$data['post_status']); |
| 1385 |
return $data; |
| 1386 |
} |
| 1387 |
/** |
| 1388 |
* Enable all cf7 capabilites for editors. |
| 1389 |
* Hooked to action 'admin_init'. |
| 1390 |
*@since 3.0.0 |
| 1391 |
*/ |
| 1392 |
public function enable_cf7_editor_role(){ |
| 1393 |
global $wp_roles; |
| 1394 |
if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); |
| 1395 |
$caps=array('wpcf7_edit_contact_forms','wpcf7_edit_others_contact_forms','wpcf7_edit_published_contact_forms','wpcf7_read_contact_forms','wpcf7_publish_contact_forms','wpcf7_delete_contact_forms','wpcf7_delete_published_contact_forms','wpcf7_delete_others_contact_forms'); |
| 1396 |
$fe = $wp_roles->get_role('editor'); |
| 1397 |
if(!empty($fe)){ /** @since 3.0.3 in case editor role is deleted */ |
| 1398 |
foreach($caps as $cap) $fe->add_cap($cap); |
| 1399 |
} |
| 1400 |
$caps[]='wpcf7_manage_integration'; |
| 1401 |
$ad = $wp_roles->get_role('administrator'); |
| 1402 |
if(!empty($ad)){ /** @since 3.0.3 in case admin role is deleted */ |
| 1403 |
foreach($caps as $cap) $ad->add_cap($cap); |
| 1404 |
} |
| 1405 |
|
| 1406 |
/** @since 3.1.3 redirect cf7 plugin pages*/ |
| 1407 |
global $pagenow; |
| 1408 |
if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) ) { |
| 1409 |
$url = ''; |
| 1410 |
switch($_GET['page']){ |
| 1411 |
case 'wpcf7-new': |
| 1412 |
$url = "post-new.php?post_type=wpcf7_contact_form" ; |
| 1413 |
break; |
| 1414 |
case 'wpcf7': |
| 1415 |
if(isset($_GET['post'])) $url = "post.php?post={$_GET['post']}&action=edit&classic-editor"; |
| 1416 |
else $url = "edit.php?post_type=wpcf7_contact_form"; |
| 1417 |
break; |
| 1418 |
} |
| 1419 |
if(!empty($url)){ |
| 1420 |
wp_redirect( admin_url( $url )); |
| 1421 |
exit; |
| 1422 |
} |
| 1423 |
} |
| 1424 |
} |
| 1425 |
/** |
| 1426 |
* Add grid helper hooks for individual tags. |
| 1427 |
* Hooked to action 'cf7sg_ui_grid_helper_hooks'. |
| 1428 |
*@since 3.3.0 |
| 1429 |
*/ |
| 1430 |
public function print_helper_hooks(){ |
| 1431 |
require_once plugin_dir_path( __FILE__ ) .'partials/helpers/cf7sg-form-fields.php'; |
| 1432 |
} |
| 1433 |
/** |
| 1434 |
* Setup mailtags or toggles. |
| 1435 |
* |
| 1436 |
*@since 4.0.0 |
| 1437 |
*@param string $param text_description |
| 1438 |
*@return string text_description |
| 1439 |
*/ |
| 1440 |
public function setup_cf7_mailtags($mailtags = array()){ |
| 1441 |
// return $mailtags; |
| 1442 |
$contact_form = WPCF7_ContactForm::get_current(); |
| 1443 |
$fields = get_post_meta($contact_form->id(), '_cf7sg_grid_toggled_names', true); |
| 1444 |
//update_post_meta($post_id, '_cf7sg_grid_tabbed_toggles', $ttgls); |
| 1445 |
if(!empty($fields)){ |
| 1446 |
$toggles = array_keys($fields); |
| 1447 |
$groups = get_post_meta($contact_form->id(), '_cf7sg_grid_grouped_toggles', true); |
| 1448 |
if(!empty($groups)){ |
| 1449 |
foreach($groups as $group=>$grp_toggles){ |
| 1450 |
$toggles = array_diff($toggles, $grp_toggles); |
| 1451 |
array_push($toggles, $group); |
| 1452 |
} |
| 1453 |
} |
| 1454 |
foreach($toggles as $tgl) $mailtags[]= 'cf7sg-toggle-'.$tgl; |
| 1455 |
} |
| 1456 |
//add a general form tag. |
| 1457 |
$mailtags[]= 'cf7sg-form-'.get_cf7form_key($contact_form->id()); |
| 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; |
| 1677 |
} |
| 1678 |
} |
| 1679 |
|