Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: CRUD
  4. **/
  5.  
  6. function create_address_database_table() {
  7. global $wpdb;
  8. $table_name = $wpdb->prefix . 'afaddresss';
  9. $sql = "CREATE TABLE $table_name (
  10. id mediumint(9) unsigned NOT NULL AUTO_INCREMENT,
  11. name varchar(50) NOT NULL,
  12. email longtext NOT NULL,
  13. phone_no longtext NOT NULL,
  14. address longtext NOT NULL,
  15. photo longtext NOT NULL,
  16. PRIMARY KEY (id)
  17. );";
  18. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  19. dbDelta( $sql );
  20. }
  21.  
  22. register_activation_hook( __FILE__, 'create_address_database_table' );
  23.  
  24.  
  25. add_action('admin_menu', 'addMenu');
  26.  
  27. function addMenu() {
  28. add_menu_page( 'Addresses', 'Addresses', 'manage_options', 'addresses', 'addressPage', 'dashicons-media-spreadsheet', 26 );
  29. add_submenu_page( 'addresses', 'Addresses', 'All Addresses', 'manage_options', 'addressPage', 'addressPage' );
  30. add_submenu_page( 'addresses', 'Add New Address', 'Add New', 'manage_options', 'newAddress', 'newAddress' );
  31. remove_submenu_page('addresses','addresses');
  32. }
  33.  
  34. function addressPage() {
  35. include __DIR__.'/addressTable.php';
  36. $addressTable = new addressTable();
  37. $addressTable->prepare_items();
  38. echo '<form method="get">
  39. <input type="hidden" name="page" value="'.$_REQUEST['page'].'" />';
  40. echo '<div class="wrap"><h1 class="wp-heading-inline">Addresses</h1>
  41. <a href="http://127.0.0.1/wordpress1/wp-admin/post-new.php?post_type=page" class="page-title-action">Add New</a>';
  42. $addressTable->search_box('search', 'search_id');
  43. echo '</div></form>';
  44. $addressTable->display();
  45. }
  46.  
  47. function newAddress() {
  48. include __DIR__.'/newAddress.php';
  49. }
  50.  
  51. add_action('admin_post_my_action', 'my_callback_fn');
  52.  
  53. function my_callback_fn() {
  54. ?>
  55. <!DOCTYPE html>
  56. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
  57. <head>
  58. <meta charset="utf-8" />
  59. <meta name="viewport" content="width=device-width, initial-scale=1">
  60. <title>Conversion Result</title>
  61. </head>
  62. <body>
  63. <h1>Conversion Results</h1>
  64. <?php
  65. echo 'Hello world!';
  66. ?>
  67. </body>
  68. </html>
  69. <?php
  70. exit;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement