NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Table.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Takes care of creating, updating and deleting database tables.
  4. */
  5. class scbTable {
  6. /**
  7. * The table name.
  8. * @var string
  9. */
  10. protected $name;
  11. /**
  12. * The table columns.
  13. * @var string
  14. */
  15. protected $columns;
  16. /**
  17. * The upgrade method.
  18. * @var string
  19. */
  20. protected $upgrade_method;
  21. /**
  22. * Sets up table.
  23. *
  24. * @param string $name Table name.
  25. * @param string $file Reference to main plugin file.
  26. * @param string $columns The SQL columns for the CREATE TABLE statement.
  27. * @param array $upgrade_method (optional)
  28. *
  29. * @return void
  30. */
  31. public function __construct( $name, $file, $columns, $upgrade_method = 'dbDelta' ) {
  32. $this->name = $name;
  33. $this->columns = $columns;
  34. $this->upgrade_method = $upgrade_method;
  35. scb_register_table( $name );
  36. if ( $file ) {
  37. scbUtil::add_activation_hook( $file, array( $this, 'install' ) );
  38. scbUtil::add_uninstall_hook( $file, array( $this, 'uninstall' ) );
  39. }
  40. }
  41. /**
  42. * Installs table.
  43. *
  44. * @return void
  45. */
  46. public function install() {
  47. scb_install_table( $this->name, $this->columns, $this->upgrade_method );
  48. }
  49. /**
  50. * Uninstalls table.
  51. *
  52. * @return void
  53. */
  54. public function uninstall() {
  55. scb_uninstall_table( $this->name );
  56. }
  57. }