edit-contact-form.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. // don't load directly
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. die( '-1' );
  5. }
  6. function wpcf7_admin_save_button( $post_id ) {
  7. static $button = '';
  8. if ( ! empty( $button ) ) {
  9. echo $button;
  10. return;
  11. }
  12. $nonce = wp_create_nonce( 'wpcf7-save-contact-form_' . $post_id );
  13. $onclick = sprintf(
  14. "this.form._wpnonce.value = '%s';"
  15. . " this.form.action.value = 'save';"
  16. . " return true;",
  17. $nonce );
  18. $button = sprintf(
  19. '<input type="submit" class="button-primary" name="wpcf7-save" value="%1$s" onclick="%2$s" />',
  20. esc_attr( __( 'Save', 'contact-form-7' ) ),
  21. $onclick );
  22. echo $button;
  23. }
  24. ?><div class="wrap" id="wpcf7-contact-form-editor">
  25. <h1 class="wp-heading-inline"><?php
  26. if ( $post->initial() ) {
  27. echo esc_html( __( 'Add New Contact Form', 'contact-form-7' ) );
  28. } else {
  29. echo esc_html( __( 'Edit Contact Form', 'contact-form-7' ) );
  30. }
  31. ?></h1>
  32. <?php
  33. if ( ! $post->initial()
  34. and current_user_can( 'wpcf7_edit_contact_forms' ) ) {
  35. echo wpcf7_link(
  36. menu_page_url( 'wpcf7-new', false ),
  37. __( 'Add New', 'contact-form-7' ),
  38. array( 'class' => 'page-title-action' )
  39. );
  40. }
  41. ?>
  42. <hr class="wp-header-end">
  43. <?php
  44. do_action( 'wpcf7_admin_warnings',
  45. $post->initial() ? 'wpcf7-new' : 'wpcf7',
  46. wpcf7_current_action(),
  47. $post
  48. );
  49. do_action( 'wpcf7_admin_notices',
  50. $post->initial() ? 'wpcf7-new' : 'wpcf7',
  51. wpcf7_current_action(),
  52. $post
  53. );
  54. ?>
  55. <?php
  56. if ( $post ) :
  57. if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) {
  58. $disabled = '';
  59. } else {
  60. $disabled = ' disabled="disabled"';
  61. }
  62. ?>
  63. <form method="post" action="<?php echo esc_url( add_query_arg( array( 'post' => $post_id ), menu_page_url( 'wpcf7', false ) ) ); ?>" id="wpcf7-admin-form-element"<?php do_action( 'wpcf7_post_edit_form_tag' ); ?>>
  64. <?php
  65. if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) {
  66. wp_nonce_field( 'wpcf7-save-contact-form_' . $post_id );
  67. }
  68. ?>
  69. <input type="hidden" id="post_ID" name="post_ID" value="<?php echo (int) $post_id; ?>" />
  70. <input type="hidden" id="wpcf7-locale" name="wpcf7-locale" value="<?php echo esc_attr( $post->locale() ); ?>" />
  71. <input type="hidden" id="hiddenaction" name="action" value="save" />
  72. <input type="hidden" id="active-tab" name="active-tab" value="<?php echo isset( $_GET['active-tab'] ) ? (int) $_GET['active-tab'] : '0'; ?>" />
  73. <div id="poststuff">
  74. <div id="post-body" class="metabox-holder columns-2">
  75. <div id="post-body-content">
  76. <div id="titlediv">
  77. <div id="titlewrap">
  78. <label class="screen-reader-text" id="title-prompt-text" for="title"><?php echo esc_html( __( 'Enter title here', 'contact-form-7' ) ); ?></label>
  79. <?php
  80. $posttitle_atts = array(
  81. 'type' => 'text',
  82. 'name' => 'post_title',
  83. 'size' => 30,
  84. 'value' => $post->initial() ? '' : $post->title(),
  85. 'id' => 'title',
  86. 'spellcheck' => 'true',
  87. 'autocomplete' => 'off',
  88. 'disabled' =>
  89. current_user_can( 'wpcf7_edit_contact_form', $post_id ) ? '' : 'disabled',
  90. );
  91. echo sprintf( '<input %s />', wpcf7_format_atts( $posttitle_atts ) );
  92. ?>
  93. </div><!-- #titlewrap -->
  94. <div class="inside">
  95. <?php
  96. if ( ! $post->initial() ) :
  97. ?>
  98. <p class="description">
  99. <label for="wpcf7-shortcode"><?php echo esc_html( __( "Copy this shortcode and paste it into your post, page, or text widget content:", 'contact-form-7' ) ); ?></label>
  100. <span class="shortcode wp-ui-highlight"><input type="text" id="wpcf7-shortcode" onfocus="this.select();" readonly="readonly" class="large-text code" value="<?php echo esc_attr( $post->shortcode() ); ?>" /></span>
  101. </p>
  102. <?php
  103. if ( $old_shortcode = $post->shortcode( array( 'use_old_format' => true ) ) ) :
  104. ?>
  105. <p class="description">
  106. <label for="wpcf7-shortcode-old"><?php echo esc_html( __( "You can also use this old-style shortcode:", 'contact-form-7' ) ); ?></label>
  107. <span class="shortcode old"><input type="text" id="wpcf7-shortcode-old" onfocus="this.select();" readonly="readonly" class="large-text code" value="<?php echo esc_attr( $old_shortcode ); ?>" /></span>
  108. </p>
  109. <?php
  110. endif;
  111. endif;
  112. ?>
  113. </div>
  114. </div><!-- #titlediv -->
  115. </div><!-- #post-body-content -->
  116. <div id="postbox-container-1" class="postbox-container">
  117. <?php if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) : ?>
  118. <div id="submitdiv" class="postbox">
  119. <h3><?php echo esc_html( __( 'Status', 'contact-form-7' ) ); ?></h3>
  120. <div class="inside">
  121. <div class="submitbox" id="submitpost">
  122. <div id="minor-publishing-actions">
  123. <div class="hidden">
  124. <input type="submit" class="button-primary" name="wpcf7-save" value="<?php echo esc_attr( __( 'Save', 'contact-form-7' ) ); ?>" />
  125. </div>
  126. <?php
  127. if ( ! $post->initial() ) :
  128. $copy_nonce = wp_create_nonce( 'wpcf7-copy-contact-form_' . $post_id );
  129. ?>
  130. <input type="submit" name="wpcf7-copy" class="copy button" value="<?php echo esc_attr( __( 'Duplicate', 'contact-form-7' ) ); ?>" <?php echo "onclick=\"this.form._wpnonce.value = '$copy_nonce'; this.form.action.value = 'copy'; return true;\""; ?> />
  131. <?php endif; ?>
  132. </div><!-- #minor-publishing-actions -->
  133. <div id="misc-publishing-actions">
  134. <?php do_action( 'wpcf7_admin_misc_pub_section', $post_id ); ?>
  135. </div><!-- #misc-publishing-actions -->
  136. <div id="major-publishing-actions">
  137. <?php
  138. if ( ! $post->initial() ) :
  139. $delete_nonce = wp_create_nonce( 'wpcf7-delete-contact-form_' . $post_id );
  140. ?>
  141. <div id="delete-action">
  142. <input type="submit" name="wpcf7-delete" class="delete submitdelete" value="<?php echo esc_attr( __( 'Delete', 'contact-form-7' ) ); ?>" <?php echo "onclick=\"if (confirm('" . esc_js( __( "You are about to delete this contact form.\n 'Cancel' to stop, 'OK' to delete.", 'contact-form-7' ) ) . "')) {this.form._wpnonce.value = '$delete_nonce'; this.form.action.value = 'delete'; return true;} return false;\""; ?> />
  143. </div><!-- #delete-action -->
  144. <?php endif; ?>
  145. <div id="publishing-action">
  146. <span class="spinner"></span>
  147. <?php wpcf7_admin_save_button( $post_id ); ?>
  148. </div>
  149. <div class="clear"></div>
  150. </div><!-- #major-publishing-actions -->
  151. </div><!-- #submitpost -->
  152. </div>
  153. </div><!-- #submitdiv -->
  154. <?php endif; ?>
  155. <div id="informationdiv" class="postbox">
  156. <h3><?php echo esc_html( __( "Do you need help?", 'contact-form-7' ) ); ?></h3>
  157. <div class="inside">
  158. <p><?php echo esc_html( __( "Here are some available options to help solve your problems.", 'contact-form-7' ) ); ?></p>
  159. <ol>
  160. <li><?php echo sprintf(
  161. /* translators: 1: FAQ, 2: Docs ("FAQ & Docs") */
  162. __( '%1$s &#38; %2$s', 'contact-form-7' ),
  163. wpcf7_link(
  164. __( 'https://contactform7.com/faq/', 'contact-form-7' ),
  165. __( 'FAQ', 'contact-form-7' )
  166. ),
  167. wpcf7_link(
  168. __( 'https://contactform7.com/docs/', 'contact-form-7' ),
  169. __( 'Docs', 'contact-form-7' )
  170. )
  171. ); ?></li>
  172. <li><?php echo wpcf7_link(
  173. __( 'https://wordpress.org/support/plugin/contact-form-7/', 'contact-form-7' ),
  174. __( 'Support Forums', 'contact-form-7' )
  175. ); ?></li>
  176. <li><?php echo wpcf7_link(
  177. __( 'https://contactform7.com/custom-development/', 'contact-form-7' ),
  178. __( 'Professional Services', 'contact-form-7' )
  179. ); ?></li>
  180. </ol>
  181. </div>
  182. </div><!-- #informationdiv -->
  183. </div><!-- #postbox-container-1 -->
  184. <div id="postbox-container-2" class="postbox-container">
  185. <div id="contact-form-editor">
  186. <div class="keyboard-interaction"><?php
  187. echo sprintf(
  188. /* translators: 1: ◀ ▶ dashicon, 2: screen reader text for the dashicon */
  189. esc_html( __( '%1$s %2$s keys switch panels', 'contact-form-7' ) ),
  190. '<span class="dashicons dashicons-leftright" aria-hidden="true"></span>',
  191. sprintf(
  192. '<span class="screen-reader-text">%s</span>',
  193. /* translators: screen reader text */
  194. esc_html( __( '(left and right arrow)', 'contact-form-7' ) )
  195. )
  196. );
  197. ?></div>
  198. <?php
  199. $editor = new WPCF7_Editor( $post );
  200. $panels = array();
  201. if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) {
  202. $panels = array(
  203. 'form-panel' => array(
  204. 'title' => __( 'Form', 'contact-form-7' ),
  205. 'callback' => 'wpcf7_editor_panel_form',
  206. ),
  207. 'mail-panel' => array(
  208. 'title' => __( 'Mail', 'contact-form-7' ),
  209. 'callback' => 'wpcf7_editor_panel_mail',
  210. ),
  211. 'messages-panel' => array(
  212. 'title' => __( 'Messages', 'contact-form-7' ),
  213. 'callback' => 'wpcf7_editor_panel_messages',
  214. ),
  215. );
  216. $additional_settings = trim( $post->prop( 'additional_settings' ) );
  217. $additional_settings = explode( "\n", $additional_settings );
  218. $additional_settings = array_filter( $additional_settings );
  219. $additional_settings = count( $additional_settings );
  220. $panels['additional-settings-panel'] = array(
  221. 'title' => $additional_settings
  222. ? sprintf(
  223. /* translators: %d: number of additional settings */
  224. __( 'Additional Settings (%d)', 'contact-form-7' ),
  225. $additional_settings )
  226. : __( 'Additional Settings', 'contact-form-7' ),
  227. 'callback' => 'wpcf7_editor_panel_additional_settings',
  228. );
  229. }
  230. $panels = apply_filters( 'wpcf7_editor_panels', $panels );
  231. foreach ( $panels as $id => $panel ) {
  232. $editor->add_panel( $id, $panel['title'], $panel['callback'] );
  233. }
  234. $editor->display();
  235. ?>
  236. </div><!-- #contact-form-editor -->
  237. <?php if ( current_user_can( 'wpcf7_edit_contact_form', $post_id ) ) : ?>
  238. <p class="submit"><?php wpcf7_admin_save_button( $post_id ); ?></p>
  239. <?php endif; ?>
  240. </div><!-- #postbox-container-2 -->
  241. </div><!-- #post-body -->
  242. <br class="clear" />
  243. </div><!-- #poststuff -->
  244. </form>
  245. <?php endif; ?>
  246. </div><!-- .wrap -->
  247. <?php
  248. $tag_generator = WPCF7_TagGenerator::get_instance();
  249. $tag_generator->print_panels( $post );
  250. do_action( 'wpcf7_admin_footer', $post );