Advertisement
blackimpala

Index Plugin Form

Mar 29th, 2021
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. // Our callback to create the contact form page.
  2. function gym_contact_create_form() {
  3.   $form = array(
  4.     'post_title'    => wp_strip_all_tags( 'Gym Contact Page' ),
  5.     'post_name'    => 'gym-contact-form',
  6.     'post_status'   => 'publish',
  7.     'post_author'   => 1,
  8.     'post_type'     => 'page',
  9.   );
  10.   // Check if page exists
  11.   $page = get_page_by_path('gym-contact-form');
  12.   if ($page == NULL) {
  13.     // Create a page upon creation.
  14.     wp_insert_post( $form );
  15.   }
  16. }
  17.  
  18. // Mock data
  19. function gym_contact_install_data() {
  20.   global $wpdb;
  21.   $table_name = $wpdb->prefix . 'contact';
  22.  
  23.   $test_name = 'Michael Williams';
  24.   $test_email = 'mikew@monarchdigital.com';
  25.   $test_phone = '(719)344-2118';
  26.   $test_message = 'This is my test message. My heater needs repair.';
  27.  
  28.     $wpdb->insert(
  29.         $table_name,
  30.         array(
  31.             'name' => $test_name,
  32.             'email' => $test_email,
  33.             'phone' => $test_phone,
  34.             'message' => $test_message,
  35.             'time' => current_time( 'mysql' )
  36.         )
  37.     );
  38. }
  39.  
  40. // Hook up our template file for the contact form - https://codex.wordpress.org/Plugin_API/Filter_Reference/page_template
  41. add_filter( 'page_template', 'gym_contact_form_template' );
  42. function gym_contact_form_template( $page_template ) {
  43.   if ( is_page( 'Gym Contact Page' ) ) {
  44.     $page_template = dirname( __FILE__ ) . '/includes/gym_contact_form.php';
  45.   }
  46.   return $page_template;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement