Advertisement
tareq1988

WP insert plugin test

Apr 4th, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Test wpdb insert plugin
  4. Description: Test wpdb insert plugin
  5. Version: 0.1
  6. Author: Tareq Hasan
  7. Author URI: http://tareq.wedevs.com
  8. */
  9.  
  10. function test_plugin_menu() {
  11.     add_options_page('Test wpdb insert plugin', 'Test wpdb insert plugin', 9, 'test-wpdb-insert', 'test_wpdb_insert');
  12. }
  13. add_action('admin_menu', 'test_plugin_menu');
  14.  
  15. function test_wpdb_insert() {
  16.     global $wpdb;
  17.    
  18.     if( isset( $_POST['test_submit'] ) ) {
  19.         $name = $_POST['test_name'];
  20.         $mail = $_POST['test_mail'];
  21.        
  22.         $result = $wpdb->insert('test', array('name' => $name, 'email' => $mail), array( '%s', '%s' ) );
  23.         if( $result ) {
  24.             echo '<div class="updated fade" id="message"><p><strong>Inserted.</strong></p></div>';
  25.         } else {
  26.             echo 'something went wrong';
  27.         }
  28.     }
  29. ?>
  30.  
  31. <div class="wrap">
  32.     <h2>Test</h2>
  33.    
  34.     <form method="post" action="">
  35.         <table class="form-table">
  36.             <tr valign="top">
  37.                 <th scope="row">Name</th>
  38.                 <td> <input type="text" name="test_name" value="" />
  39.                     <span class="description">Enter name</span>
  40.                 </td>
  41.             </tr>
  42.             <tr valign="top">
  43.                 <th scope="row">Email</th>
  44.                 <td>
  45.                     <input type="text" name="test_mail" value="" />
  46.                     <span class="description">Enter your mail</span>
  47.                 </td>
  48.             </tr>
  49.         </table
  50.         <p class="submit">
  51.             <input name="test_submit" type="submit" class="button-primary" value="<?php _e('Add') ?>" />
  52.         </p>
  53.     </form>
  54.    
  55. </div>
  56.     <?php
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement