Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Gatesc bine
  4. Description: Genereaza si afiseaza retete pentru gatit
  5. Version: 0.1.1
  6. Author: Gatesc Bine development team
  7. Text Domain: gatescbine
  8. Domain Path: /languages
  9. */
  10.  
  11.  
  12. function myplugin_activate() {
  13. $servername = "localhost";
  14. $username = "root";
  15. $password = "";
  16. $dbname = "gatescbine";
  17.  
  18. try {
  19. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  20. // set the PDO error mode to exception
  21. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  22.  
  23. // sql to create table
  24. $sql = "CREATE TABLE retete (
  25. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  26. nume VARCHAR(50)
  27. )";
  28.  
  29. // use exec() because no results are returned
  30. $conn->exec($sql);
  31. //echo "Table MyGuests created successfully";
  32. }
  33. catch(PDOException $e)
  34. {
  35. echo $sql . "<br>" . $e->getMessage();
  36. }
  37.  
  38. $conn = null;
  39. }
  40. register_activation_hook( __FILE__, 'myplugin_activate' );
  41.  
  42.  
  43.  
  44. function pippin_show_fruits() {
  45. $fruits = array(
  46. 'apples',
  47. 'oranges',
  48. 'kumkwats',
  49. 'dragon fruit',
  50. 'peaches',
  51. 'durians'
  52. );
  53. $list = '<ul>';
  54.  
  55. foreach($fruits as $fruit) :
  56. $list .= '<li>' . $fruit . '</li>';
  57. endforeach;
  58.  
  59. $list .= '</ul>';
  60.  
  61. return $list;
  62. }
  63. add_shortcode( 'foobar', 'pippin_show_fruits' );
  64.  
  65.  
  66.  
  67. function gatescbine_form(){
  68. $msg = '
  69. <div id="content">
  70. <form action="';
  71. $msg = $msg . esc_url( admin_url('admin-post.php') );
  72. $msg = $msg . '" method="post">
  73. <label for="message">Nume reteta</label>
  74. <textarea name="nume" id="message"></textarea>
  75. <input type="hidden" name="action" value="gatesc_contact_form">
  76. <input type="hidden" id="txtUrl" name="txtUrl" value="" />
  77. <script>
  78. document.getElementById(\'txtUrl\').value = window.location.href;
  79. </script>
  80. <input type="submit" value="Send My Message">
  81. </form>
  82. </div>';
  83. return $msg;
  84. }
  85. add_shortcode( 'gatescbine_form', 'gatescbine_form' );
  86.  
  87. function gatescbine_form_callback(){
  88. $servername = "localhost";
  89. $username = "root";
  90. $password = "";
  91. $dbname = "gatescbine";
  92.  
  93. try {
  94. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  95. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  96. $stmt = $conn->prepare("INSERT INTO `retete`(`nume`) VALUES ( :nume)");
  97. $stmt->bindParam(':nume', $_POST["nume"]);
  98.  
  99. $stmt->execute();
  100. }
  101. catch(PDOException $e)
  102. {
  103. echo $sql . "<br>" . $e->getMessage();
  104. }
  105.  
  106. $conn = null;
  107.  
  108. header("Location: " . $_POST["txtUrl"]);
  109. die();
  110. }
  111.  
  112. add_action( 'admin_post_nopriv_gatesc_contact_form', 'gatescbine_form_callback' );
  113. add_action( 'admin_post_gatesc_contact_form', 'gatescbine_form_callback' );
  114.  
  115.  
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement