NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

storage.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Handles various db-related tasks
  4. */
  5. class P2P_Storage {
  6. static $version = 4;
  7. static function init() {
  8. scb_register_table( 'p2p' );
  9. scb_register_table( 'p2pmeta' );
  10. add_action( 'deleted_post', array( __CLASS__, 'deleted_object' ) );
  11. add_action( 'deleted_user', array( __CLASS__, 'deleted_object' ) );
  12. }
  13. static function install() {
  14. scb_install_table( 'p2p', "
  15. p2p_id bigint(20) unsigned NOT NULL auto_increment,
  16. p2p_from bigint(20) unsigned NOT NULL,
  17. p2p_to bigint(20) unsigned NOT NULL,
  18. p2p_type varchar(44) NOT NULL default '',
  19. PRIMARY KEY (p2p_id),
  20. KEY p2p_from (p2p_from),
  21. KEY p2p_to (p2p_to),
  22. KEY p2p_type (p2p_type)
  23. " );
  24. scb_install_table( 'p2pmeta', "
  25. meta_id bigint(20) unsigned NOT NULL auto_increment,
  26. p2p_id bigint(20) unsigned NOT NULL default '0',
  27. meta_key varchar(255) default NULL,
  28. meta_value longtext,
  29. PRIMARY KEY (meta_id),
  30. KEY p2p_id (p2p_id),
  31. KEY meta_key (meta_key)
  32. " );
  33. }
  34. static function uninstall() {
  35. scb_uninstall_table( 'p2p' );
  36. scb_uninstall_table( 'p2pmeta' );
  37. delete_option( 'p2p_storage' );
  38. }
  39. static function deleted_object( $object_id ) {
  40. $object_type = str_replace( 'deleted_', '', current_filter() );
  41. foreach ( P2P_Connection_Type_Factory::get_all_instances() as $p2p_type => $ctype ) {
  42. foreach ( array( 'from', 'to' ) as $direction ) {
  43. if ( $object_type == $ctype->side[ $direction ]->get_object_type() ) {
  44. p2p_delete_connections( $p2p_type, array(
  45. $direction => $object_id,
  46. ) );
  47. }
  48. }
  49. }
  50. }
  51. }