edit-contact-form.php
491 lines
| 1 | <?php |
| 2 | |
| 3 | // don't load directly |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | die( '-1' ); |
| 6 | } |
| 7 | |
| 8 | $save_button = sprintf( |
| 9 | '<input %s />', |
| 10 | wpcf7_format_atts( array( |
| 11 | 'type' => 'submit', |
| 12 | 'class' => 'button-primary', |
| 13 | 'name' => 'wpcf7-save', |
| 14 | 'value' => __( 'Save', 'contact-form-7' ), |
| 15 | ) ) |
| 16 | ); |
| 17 | |
| 18 | $formatter = new WPCF7_HTMLFormatter( array( |
| 19 | 'allowed_html' => array_merge( wpcf7_kses_allowed_html(), array( |
| 20 | 'form' => array( |
| 21 | 'method' => true, |
| 22 | 'action' => true, |
| 23 | 'id' => true, |
| 24 | 'class' => true, |
| 25 | 'disabled' => true, |
| 26 | ), |
| 27 | ) ), |
| 28 | ) ); |
| 29 | |
| 30 | $formatter->append_start_tag( 'div', array( |
| 31 | 'class' => 'wrap', |
| 32 | 'id' => 'wpcf7-contact-form-editor', |
| 33 | ) ); |
| 34 | |
| 35 | $formatter->append_start_tag( 'h1', array( |
| 36 | 'class' => 'wp-heading-inline', |
| 37 | ) ); |
| 38 | |
| 39 | $formatter->append_preformatted( |
| 40 | esc_html( $post->initial() |
| 41 | ? __( 'Add Contact Form', 'contact-form-7' ) |
| 42 | : __( 'Edit Contact Form', 'contact-form-7' ) |
| 43 | ) |
| 44 | ); |
| 45 | |
| 46 | $formatter->end_tag( 'h1' ); |
| 47 | |
| 48 | if ( ! $post->initial() and current_user_can( 'wpcf7_edit_contact_forms' ) ) { |
| 49 | $formatter->append_whitespace(); |
| 50 | |
| 51 | $formatter->append_preformatted( |
| 52 | wpcf7_link( |
| 53 | menu_page_url( 'wpcf7-new', false ), |
| 54 | __( 'Add Contact Form', 'contact-form-7' ), |
| 55 | array( 'class' => 'page-title-action' ) |
| 56 | ) |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | $formatter->append_start_tag( 'hr', array( |
| 61 | 'class' => 'wp-header-end', |
| 62 | ) ); |
| 63 | |
| 64 | $formatter->call_user_func( static function () use ( $post ) { |
| 65 | do_action( 'wpcf7_admin_warnings', |
| 66 | $post->initial() ? 'wpcf7-new' : 'wpcf7', |
| 67 | wpcf7_current_action(), |
| 68 | $post |
| 69 | ); |
| 70 | |
| 71 | do_action( 'wpcf7_admin_notices', |
| 72 | $post->initial() ? 'wpcf7-new' : 'wpcf7', |
| 73 | wpcf7_current_action(), |
| 74 | $post |
| 75 | ); |
| 76 | } ); |
| 77 | |
| 78 | if ( $post ) { |
| 79 | $formatter->append_start_tag( 'form', array( |
| 80 | 'method' => 'post', |
| 81 | 'action' => esc_url( add_query_arg( |
| 82 | array( 'post' => $post_id ), |
| 83 | menu_page_url( 'wpcf7', false ) |
| 84 | ) ), |
| 85 | 'id' => 'wpcf7-admin-form-element', |
| 86 | 'disabled' => ! current_user_can( 'wpcf7_edit_contact_form', $post_id ), |
| 87 | ) ); |
| 88 | |
| 89 | if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) { |
| 90 | $formatter->call_user_func( static function () use ( $post_id ) { |
| 91 | wp_nonce_field( 'wpcf7-save-contact-form_' . $post_id ); |
| 92 | } ); |
| 93 | } |
| 94 | |
| 95 | $formatter->append_start_tag( 'input', array( |
| 96 | 'type' => 'hidden', |
| 97 | 'id' => 'post_ID', |
| 98 | 'name' => 'post_ID', |
| 99 | 'value' => (int) $post_id, |
| 100 | ) ); |
| 101 | |
| 102 | $formatter->append_start_tag( 'input', array( |
| 103 | 'type' => 'hidden', |
| 104 | 'id' => 'wpcf7-locale', |
| 105 | 'name' => 'wpcf7-locale', |
| 106 | 'value' => $post->locale(), |
| 107 | ) ); |
| 108 | |
| 109 | $formatter->append_start_tag( 'input', array( |
| 110 | 'type' => 'hidden', |
| 111 | 'id' => 'hiddenaction', |
| 112 | 'name' => 'action', |
| 113 | 'value' => 'save', |
| 114 | ) ); |
| 115 | |
| 116 | $formatter->append_start_tag( 'input', array( |
| 117 | 'type' => 'hidden', |
| 118 | 'id' => 'active-tab', |
| 119 | 'name' => 'active-tab', |
| 120 | 'value' => wpcf7_superglobal_get( 'active-tab' ), |
| 121 | ) ); |
| 122 | |
| 123 | $formatter->append_start_tag( 'div', array( |
| 124 | 'id' => 'poststuff', |
| 125 | ) ); |
| 126 | |
| 127 | $formatter->append_start_tag( 'div', array( |
| 128 | 'id' => 'post-body', |
| 129 | 'class' => 'metabox-holder columns-2 wp-clearfix', |
| 130 | ) ); |
| 131 | |
| 132 | $formatter->append_start_tag( 'div', array( |
| 133 | 'id' => 'post-body-content', |
| 134 | ) ); |
| 135 | |
| 136 | $formatter->append_start_tag( 'div', array( |
| 137 | 'id' => 'titlediv', |
| 138 | ) ); |
| 139 | |
| 140 | $formatter->append_start_tag( 'div', array( |
| 141 | 'id' => 'titlewrap', |
| 142 | ) ); |
| 143 | |
| 144 | $formatter->append_start_tag( 'input', array( |
| 145 | 'type' => 'text', |
| 146 | 'name' => 'post_title', |
| 147 | 'value' => $post->initial() ? '' : $post->title(), |
| 148 | 'id' => 'title', |
| 149 | 'spellcheck' => 'true', |
| 150 | 'autocomplete' => 'off', |
| 151 | 'disabled' => ! current_user_can( 'wpcf7_edit_contact_form', $post_id ), |
| 152 | 'placeholder' => __( 'Enter title here', 'contact-form-7' ), |
| 153 | 'aria-label' => __( 'Enter title here', 'contact-form-7' ), |
| 154 | ) ); |
| 155 | |
| 156 | $formatter->end_tag( 'div' ); // #titlewrap |
| 157 | |
| 158 | $formatter->append_start_tag( 'div', array( |
| 159 | 'class' => 'inside', |
| 160 | ) ); |
| 161 | |
| 162 | if ( ! $post->initial() ) { |
| 163 | if ( $shortcode = $post->shortcode() ) { |
| 164 | $formatter->append_start_tag( 'p', array( |
| 165 | 'class' => 'description', |
| 166 | ) ); |
| 167 | |
| 168 | $formatter->append_start_tag( 'label', array( |
| 169 | 'for' => 'wpcf7-shortcode', |
| 170 | ) ); |
| 171 | |
| 172 | $formatter->append_preformatted( |
| 173 | esc_html( __( 'Copy this shortcode and paste it into your post, page, or text widget content:', 'contact-form-7' ) ) |
| 174 | ); |
| 175 | |
| 176 | $formatter->end_tag( 'label' ); |
| 177 | |
| 178 | $formatter->append_whitespace(); |
| 179 | |
| 180 | $formatter->append_start_tag( 'span', array( |
| 181 | 'class' => 'shortcode wp-ui-highlight', |
| 182 | ) ); |
| 183 | |
| 184 | $formatter->append_start_tag( 'input', array( |
| 185 | 'type' => 'text', |
| 186 | 'id' => 'wpcf7-shortcode', |
| 187 | 'readonly' => true, |
| 188 | 'class' => 'large-text code selectable', |
| 189 | 'value' => $shortcode, |
| 190 | ) ); |
| 191 | |
| 192 | $formatter->end_tag( 'p' ); |
| 193 | } |
| 194 | |
| 195 | if ( $shortcode = $post->shortcode( array( 'use_old_format' => true ) ) ) { |
| 196 | $formatter->append_start_tag( 'p', array( |
| 197 | 'class' => 'description', |
| 198 | ) ); |
| 199 | |
| 200 | $formatter->append_start_tag( 'label', array( |
| 201 | 'for' => 'wpcf7-shortcode-old', |
| 202 | ) ); |
| 203 | |
| 204 | $formatter->append_preformatted( |
| 205 | esc_html( __( 'You can also use this old-style shortcode:', 'contact-form-7' ) ) |
| 206 | ); |
| 207 | |
| 208 | $formatter->end_tag( 'label' ); |
| 209 | |
| 210 | $formatter->append_whitespace(); |
| 211 | |
| 212 | $formatter->append_start_tag( 'span', array( |
| 213 | 'class' => 'shortcode old', |
| 214 | ) ); |
| 215 | |
| 216 | $formatter->append_start_tag( 'input', array( |
| 217 | 'type' => 'text', |
| 218 | 'id' => 'wpcf7-shortcode-old', |
| 219 | 'readonly' => true, |
| 220 | 'class' => 'large-text code selectable', |
| 221 | 'value' => $shortcode, |
| 222 | ) ); |
| 223 | |
| 224 | $formatter->end_tag( 'p' ); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | $formatter->end_tag( 'div' ); // .inside |
| 229 | $formatter->end_tag( 'div' ); // #titlediv |
| 230 | $formatter->end_tag( 'div' ); // #post-body-content |
| 231 | |
| 232 | $formatter->append_start_tag( 'div', array( |
| 233 | 'id' => 'postbox-container-1', |
| 234 | 'class' => 'postbox-container', |
| 235 | ) ); |
| 236 | |
| 237 | if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) { |
| 238 | $formatter->append_start_tag( 'section', array( |
| 239 | 'id' => 'submitdiv', |
| 240 | 'class' => 'postbox', |
| 241 | ) ); |
| 242 | |
| 243 | $formatter->append_start_tag( 'h2' ); |
| 244 | |
| 245 | $formatter->append_preformatted( |
| 246 | esc_html( __( 'Status', 'contact-form-7' ) ) |
| 247 | ); |
| 248 | |
| 249 | $formatter->end_tag( 'h2' ); |
| 250 | |
| 251 | $formatter->append_start_tag( 'div', array( |
| 252 | 'class' => 'inside', |
| 253 | ) ); |
| 254 | |
| 255 | $formatter->append_start_tag( 'div', array( |
| 256 | 'class' => 'submitbox', |
| 257 | 'id' => 'submitpost', |
| 258 | ) ); |
| 259 | |
| 260 | $formatter->append_start_tag( 'div', array( |
| 261 | 'id' => 'minor-publishing-actions', |
| 262 | ) ); |
| 263 | |
| 264 | $formatter->append_start_tag( 'div', array( |
| 265 | 'class' => 'hidden', |
| 266 | ) ); |
| 267 | |
| 268 | $formatter->append_start_tag( 'input', array( |
| 269 | 'type' => 'submit', |
| 270 | 'class' => 'button-primary', |
| 271 | 'name' => 'wpcf7-save', |
| 272 | 'value' => __( 'Save', 'contact-form-7' ), |
| 273 | ) ); |
| 274 | |
| 275 | $formatter->end_tag( 'div' ); // .hidden |
| 276 | |
| 277 | if ( ! $post->initial() ) { |
| 278 | $formatter->append_start_tag( 'input', array( |
| 279 | 'type' => 'submit', |
| 280 | 'name' => 'wpcf7-copy', |
| 281 | 'class' => 'copy button', |
| 282 | 'value' => __( 'Duplicate', 'contact-form-7' ), |
| 283 | ) ); |
| 284 | } |
| 285 | |
| 286 | $formatter->end_tag( 'div' ); // #minor-publishing-actions |
| 287 | |
| 288 | $formatter->append_start_tag( 'div', array( |
| 289 | 'id' => 'misc-publishing-actions', |
| 290 | ) ); |
| 291 | |
| 292 | $formatter->call_user_func( static function () use ( $post_id ) { |
| 293 | do_action( 'wpcf7_admin_misc_pub_section', $post_id ); |
| 294 | } ); |
| 295 | |
| 296 | $formatter->end_tag( 'div' ); // #misc-publishing-actions |
| 297 | |
| 298 | $formatter->append_start_tag( 'div', array( |
| 299 | 'id' => 'major-publishing-actions', |
| 300 | ) ); |
| 301 | |
| 302 | if ( ! $post->initial() ) { |
| 303 | $formatter->append_start_tag( 'div', array( |
| 304 | 'id' => 'delete-action', |
| 305 | ) ); |
| 306 | |
| 307 | $formatter->append_start_tag( 'input', array( |
| 308 | 'type' => 'submit', |
| 309 | 'name' => 'wpcf7-delete', |
| 310 | 'class' => 'delete submitdelete', |
| 311 | 'value' => __( 'Delete', 'contact-form-7' ), |
| 312 | ) ); |
| 313 | |
| 314 | $formatter->end_tag( 'div' ); // #delete-action |
| 315 | } |
| 316 | |
| 317 | $formatter->append_start_tag( 'div', array( |
| 318 | 'id' => 'publishing-action', |
| 319 | ) ); |
| 320 | |
| 321 | $formatter->append_preformatted( '<span class="spinner"></span>' ); |
| 322 | $formatter->append_preformatted( $save_button ); |
| 323 | |
| 324 | $formatter->end_tag( 'div' ); // #publishing-action |
| 325 | |
| 326 | $formatter->append_preformatted( '<div class="clear"></div>' ); |
| 327 | |
| 328 | $formatter->end_tag( 'div' ); // #major-publishing-actions |
| 329 | $formatter->end_tag( 'div' ); // #submitpost |
| 330 | $formatter->end_tag( 'div' ); // .inside |
| 331 | $formatter->end_tag( 'section' ); // #submitdiv |
| 332 | } |
| 333 | |
| 334 | $formatter->append_start_tag( 'section', array( |
| 335 | 'id' => 'informationdiv', |
| 336 | 'class' => 'postbox', |
| 337 | ) ); |
| 338 | |
| 339 | $formatter->append_start_tag( 'h2' ); |
| 340 | |
| 341 | $formatter->append_preformatted( |
| 342 | esc_html( __( 'Do you need help?', 'contact-form-7' ) ) |
| 343 | ); |
| 344 | |
| 345 | $formatter->end_tag( 'h2' ); |
| 346 | |
| 347 | $formatter->append_start_tag( 'div', array( |
| 348 | 'class' => 'inside', |
| 349 | ) ); |
| 350 | |
| 351 | $formatter->append_start_tag( 'p' ); |
| 352 | |
| 353 | $formatter->append_preformatted( |
| 354 | esc_html( __( 'Here are some available options to help solve your problems.', 'contact-form-7' ) ) |
| 355 | ); |
| 356 | |
| 357 | $formatter->end_tag( 'p' ); |
| 358 | |
| 359 | $formatter->append_start_tag( 'ol' ); |
| 360 | |
| 361 | $formatter->append_start_tag( 'li' ); |
| 362 | |
| 363 | $formatter->append_preformatted( |
| 364 | sprintf( |
| 365 | /* translators: 1: FAQ, 2: Docs ("FAQ & Docs") */ |
| 366 | __( '%1$s and %2$s', 'contact-form-7' ), |
| 367 | wpcf7_link( |
| 368 | __( 'https://contactform7.com/faq/', 'contact-form-7' ), |
| 369 | __( 'FAQ', 'contact-form-7' ) |
| 370 | ), |
| 371 | wpcf7_link( |
| 372 | __( 'https://contactform7.com/docs/', 'contact-form-7' ), |
| 373 | __( 'docs', 'contact-form-7' ) |
| 374 | ) |
| 375 | ) |
| 376 | ); |
| 377 | |
| 378 | $formatter->append_start_tag( 'li' ); |
| 379 | |
| 380 | $formatter->append_preformatted( |
| 381 | wpcf7_link( |
| 382 | __( 'https://wordpress.org/support/plugin/contact-form-7/', 'contact-form-7' ), |
| 383 | __( 'Support forums', 'contact-form-7' ) |
| 384 | ) |
| 385 | ); |
| 386 | |
| 387 | $formatter->append_start_tag( 'li' ); |
| 388 | |
| 389 | $formatter->append_preformatted( |
| 390 | wpcf7_link( |
| 391 | __( 'https://contactform7.com/custom-development/', 'contact-form-7' ), |
| 392 | __( 'Professional services', 'contact-form-7' ) |
| 393 | ) |
| 394 | ); |
| 395 | |
| 396 | $formatter->end_tag( 'ol' ); |
| 397 | $formatter->end_tag( 'div' ); // .inside |
| 398 | $formatter->end_tag( 'section' ); // #informationdiv |
| 399 | $formatter->end_tag( 'div' ); // #postbox-container-1 |
| 400 | |
| 401 | $formatter->append_start_tag( 'div', array( |
| 402 | 'id' => 'postbox-container-2', |
| 403 | 'class' => 'postbox-container', |
| 404 | ) ); |
| 405 | |
| 406 | $formatter->append_start_tag( 'div', array( |
| 407 | 'id' => 'contact-form-editor', |
| 408 | ) ); |
| 409 | |
| 410 | $formatter->call_user_func( static function () use ( $post, $post_id ) { |
| 411 | $editor = new WPCF7_Editor( $post ); |
| 412 | $panels = array(); |
| 413 | |
| 414 | if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) { |
| 415 | $panels = array( |
| 416 | 'form-panel' => array( |
| 417 | 'title' => __( 'Form', 'contact-form-7' ), |
| 418 | 'callback' => 'wpcf7_editor_panel_form', |
| 419 | ), |
| 420 | 'mail-panel' => array( |
| 421 | 'title' => __( 'Mail', 'contact-form-7' ), |
| 422 | 'callback' => 'wpcf7_editor_panel_mail', |
| 423 | ), |
| 424 | 'messages-panel' => array( |
| 425 | 'title' => __( 'Messages', 'contact-form-7' ), |
| 426 | 'callback' => 'wpcf7_editor_panel_messages', |
| 427 | ), |
| 428 | ); |
| 429 | |
| 430 | $additional_settings = $post->prop( 'additional_settings' ); |
| 431 | |
| 432 | if ( ! is_scalar( $additional_settings ) ) { |
| 433 | $additional_settings = ''; |
| 434 | } |
| 435 | |
| 436 | $additional_settings = trim( $additional_settings ); |
| 437 | $additional_settings = explode( "\n", $additional_settings ); |
| 438 | $additional_settings = array_filter( $additional_settings ); |
| 439 | $additional_settings = count( $additional_settings ); |
| 440 | |
| 441 | $panels['additional-settings-panel'] = array( |
| 442 | 'title' => $additional_settings |
| 443 | ? sprintf( |
| 444 | /* translators: %d: number of additional settings */ |
| 445 | __( 'Additional Settings (%d)', 'contact-form-7' ), |
| 446 | $additional_settings |
| 447 | ) |
| 448 | : __( 'Additional Settings', 'contact-form-7' ), |
| 449 | 'callback' => 'wpcf7_editor_panel_additional_settings', |
| 450 | ); |
| 451 | } |
| 452 | |
| 453 | $panels = apply_filters( 'wpcf7_editor_panels', $panels ); |
| 454 | |
| 455 | foreach ( $panels as $id => $panel ) { |
| 456 | $editor->add_panel( $id, $panel['title'], $panel['callback'] ); |
| 457 | } |
| 458 | |
| 459 | $editor->display(); |
| 460 | } ); |
| 461 | |
| 462 | $formatter->end_tag( 'div' ); // #contact-form-editor |
| 463 | |
| 464 | if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) { |
| 465 | $formatter->append_start_tag( 'p', array( |
| 466 | 'class' => 'submit', |
| 467 | ) ); |
| 468 | |
| 469 | $formatter->append_preformatted( $save_button ); |
| 470 | |
| 471 | $formatter->end_tag( 'p' ); |
| 472 | } |
| 473 | |
| 474 | $formatter->end_tag( 'div' ); // #postbox-container-2 |
| 475 | $formatter->end_tag( 'div' ); // #post-body |
| 476 | |
| 477 | $formatter->append_preformatted( '<br class="clear" />' ); |
| 478 | |
| 479 | $formatter->end_tag( 'div' ); // #poststuff |
| 480 | $formatter->end_tag( 'form' ); |
| 481 | } |
| 482 | |
| 483 | $formatter->end_tag( 'div' ); // .wrap |
| 484 | |
| 485 | $formatter->print(); |
| 486 | |
| 487 | $tag_generator = WPCF7_TagGenerator::get_instance(); |
| 488 | $tag_generator->print_panels( $post ); |
| 489 | |
| 490 | do_action( 'wpcf7_admin_footer', $post ); |
| 491 |