wpcf7_load_contact_form_admin

The Contact Form 7 wpcf7 load contact form admin function.

Description

wpcf7_load_contact_form_admin(); 

Usage

  1. if ( !function_exists( 'wpcf7_load_contact_form_admin' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/admin/admin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wpcf7_load_contact_form_admin(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/admin/admin.php  
  1. function wpcf7_load_contact_form_admin() { 
  2. global $plugin_page; 
  3.  
  4. $action = wpcf7_current_action(); 
  5.  
  6. if ( 'save' == $action ) { 
  7. $id = isset( $_POST['post_ID'] ) ? $_POST['post_ID'] : '-1'; 
  8. check_admin_referer( 'wpcf7-save-contact-form_' . $id ); 
  9.  
  10. if ( ! current_user_can( 'wpcf7_edit_contact_form', $id ) ) { 
  11. wp_die( __( 'You are not allowed to edit this item.', 'contact-form-7' ) ); 
  12.  
  13. $args = $_REQUEST; 
  14. $args['id'] = $id; 
  15.  
  16. $args['title'] = isset( $_POST['post_title'] ) 
  17. ? $_POST['post_title'] : null; 
  18.  
  19. $args['locale'] = isset( $_POST['wpcf7-locale'] ) 
  20. ? $_POST['wpcf7-locale'] : null; 
  21.  
  22. $args['form'] = isset( $_POST['wpcf7-form'] ) 
  23. ? $_POST['wpcf7-form'] : ''; 
  24.  
  25. $args['mail'] = isset( $_POST['wpcf7-mail'] ) 
  26. ? wpcf7_sanitize_mail( $_POST['wpcf7-mail'] ) 
  27. : array(); 
  28.  
  29. $args['mail_2'] = isset( $_POST['wpcf7-mail-2'] ) 
  30. ? wpcf7_sanitize_mail( $_POST['wpcf7-mail-2'] ) 
  31. : array(); 
  32.  
  33. $args['messages'] = isset( $_POST['wpcf7-messages'] ) 
  34. ? $_POST['wpcf7-messages'] : array(); 
  35.  
  36. $args['additional_settings'] = isset( $_POST['wpcf7-additional-settings'] ) 
  37. ? $_POST['wpcf7-additional-settings'] : ''; 
  38.  
  39. $contact_form = wpcf7_save_contact_form( $args ); 
  40.  
  41. if ( $contact_form && wpcf7_validate_configuration() ) { 
  42. $config_validator = new WPCF7_ConfigValidator( $contact_form ); 
  43. $config_validator->validate(); 
  44. $config_validator->save(); 
  45.  
  46. $query = array( 
  47. 'post' => $contact_form ? $contact_form->id() : 0,  
  48. 'active-tab' => isset( $_POST['active-tab'] ) 
  49. ? (int) $_POST['active-tab'] : 0,  
  50. ); 
  51.  
  52. if ( ! $contact_form ) { 
  53. $query['message'] = 'failed'; 
  54. } elseif ( -1 == $id ) { 
  55. $query['message'] = 'created'; 
  56. } else { 
  57. $query['message'] = 'saved'; 
  58.  
  59. $redirect_to = add_query_arg( $query, menu_page_url( wpcf7, false ) ); 
  60. wp_safe_redirect( $redirect_to ); 
  61. exit(); 
  62.  
  63. if ( 'copy' == $action ) { 
  64. $id = empty( $_POST['post_ID'] ) 
  65. ? absint( $_REQUEST['post'] ) 
  66. : absint( $_POST['post_ID'] ); 
  67.  
  68. check_admin_referer( 'wpcf7-copy-contact-form_' . $id ); 
  69.  
  70. if ( ! current_user_can( 'wpcf7_edit_contact_form', $id ) ) { 
  71. wp_die( __( 'You are not allowed to edit this item.', 'contact-form-7' ) ); 
  72.  
  73. $query = array(); 
  74.  
  75. if ( $contact_form = wpcf7_contact_form( $id ) ) { 
  76. $new_contact_form = $contact_form->copy(); 
  77. $new_contact_form->save(); 
  78.  
  79. $query['post'] = $new_contact_form->id(); 
  80. $query['message'] = 'created'; 
  81.  
  82. $redirect_to = add_query_arg( $query, menu_page_url( wpcf7, false ) ); 
  83.  
  84. wp_safe_redirect( $redirect_to ); 
  85. exit(); 
  86.  
  87. if ( 'delete' == $action ) { 
  88. if ( ! empty( $_POST['post_ID'] ) ) { 
  89. check_admin_referer( 'wpcf7-delete-contact-form_' . $_POST['post_ID'] ); 
  90. } elseif ( ! is_array( $_REQUEST['post'] ) ) { 
  91. check_admin_referer( 'wpcf7-delete-contact-form_' . $_REQUEST['post'] ); 
  92. } else { 
  93. check_admin_referer( 'bulk-posts' ); 
  94.  
  95. $posts = empty( $_POST['post_ID'] ) 
  96. ? (array) $_REQUEST['post'] 
  97. : (array) $_POST['post_ID']; 
  98.  
  99. $deleted = 0; 
  100.  
  101. foreach ( $posts as $post ) { 
  102. $post = WPCF7_ContactForm::get_instance( $post ); 
  103.  
  104. if ( empty( $post ) ) { 
  105. continue; 
  106.  
  107. if ( ! current_user_can( 'wpcf7_delete_contact_form', $post->id() ) ) { 
  108. wp_die( __( 'You are not allowed to delete this item.', 'contact-form-7' ) ); 
  109.  
  110. if ( ! $post->delete() ) { 
  111. wp_die( __( 'Error in deleting.', 'contact-form-7' ) ); 
  112.  
  113. $deleted += 1; 
  114.  
  115. $query = array(); 
  116.  
  117. if ( ! empty( $deleted ) ) { 
  118. $query['message'] = 'deleted'; 
  119.  
  120. $redirect_to = add_query_arg( $query, menu_page_url( wpcf7, false ) ); 
  121.  
  122. wp_safe_redirect( $redirect_to ); 
  123. exit(); 
  124.  
  125. if ( 'validate' == $action && wpcf7_validate_configuration() ) { 
  126. if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) { 
  127. check_admin_referer( 'wpcf7-bulk-validate' ); 
  128.  
  129. if ( ! current_user_can( 'wpcf7_edit_contact_forms' ) ) { 
  130. wp_die( __( "You are not allowed to validate configuration.", 'contact-form-7' ) ); 
  131.  
  132. $contact_forms = WPCF7_ContactForm::find(); 
  133.  
  134. $result = array( 
  135. 'timestamp' => current_time( 'timestamp' ),  
  136. 'version' => WPCF7_VERSION,  
  137. 'count_valid' => 0,  
  138. 'count_invalid' => 0,  
  139. ); 
  140.  
  141. foreach ( $contact_forms as $contact_form ) { 
  142. $config_validator = new WPCF7_ConfigValidator( $contact_form ); 
  143. $config_validator->validate(); 
  144. $config_validator->save(); 
  145.  
  146. if ( $config_validator->is_valid() ) { 
  147. $result['count_valid'] += 1; 
  148. } else { 
  149. $result['count_invalid'] += 1; 
  150.  
  151. WPCF7::update_option( 'bulk_validate', $result ); 
  152.  
  153. $query = array( 
  154. 'message' => 'validated' ); 
  155.  
  156. $redirect_to = add_query_arg( $query, menu_page_url( wpcf7, false ) ); 
  157. wp_safe_redirect( $redirect_to ); 
  158. exit(); 
  159.  
  160. $_GET['post'] = isset( $_GET['post'] ) ? $_GET['post'] : ''; 
  161.  
  162. $post = null; 
  163.  
  164. if ( 'wpcf7-new' == $plugin_page ) { 
  165. $post = WPCF7_ContactForm::get_template( array( 
  166. 'locale' => isset( $_GET['locale'] ) ? $_GET['locale'] : null ) ); 
  167. } elseif ( ! empty( $_GET['post'] ) ) { 
  168. $post = WPCF7_ContactForm::get_instance( $_GET['post'] ); 
  169.  
  170. $current_screen = get_current_screen(); 
  171.  
  172. $help_tabs = new WPCF7_Help_Tabs( $current_screen ); 
  173.  
  174. if ( $post && current_user_can( 'wpcf7_edit_contact_form', $post->id() ) ) { 
  175. $help_tabs->set_help_tabs( 'edit' ); 
  176. } else { 
  177. $help_tabs->set_help_tabs( 'list' ); 
  178.  
  179. if ( ! class_exists( 'WPCF7_Contact_Form_List_Table' ) ) { 
  180. require_once WPCF7_PLUGIN_DIR . '/admin/includes/class-contact-forms-list-table.php'; 
  181.  
  182. add_filter( 'manage_' . $current_screen->id . '_columns',  
  183. array( 'WPCF7_Contact_Form_List_Table', 'define_columns' ) ); 
  184.  
  185. add_screen_option( 'per_page', array( 
  186. 'default' => 20,  
  187. 'option' => 'cfseven_contact_forms_per_page' ) );