Нет описания

upgrades.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit;
  7. }
  8. /**
  9. * Adds an upgrade action to the completed upgrades array
  10. *
  11. * @since 1.7.0
  12. *
  13. * @see PUM_Utils_Upgrades::set_upgrade_complete
  14. *
  15. * @param string $upgrade_id The action to add to the competed upgrades array
  16. *
  17. * @return bool If the function was successfully added
  18. */
  19. function pum_set_upgrade_complete( $upgrade_id = '' ) {
  20. return PUM_Utils_Upgrades::instance()->set_upgrade_complete( $upgrade_id );
  21. }
  22. /**
  23. * Get's the array of completed upgrade actions
  24. *
  25. * @since 1.7.0
  26. *
  27. * @return array The array of completed upgrades
  28. */
  29. function pum_get_completed_upgrades() {
  30. return PUM_Utils_Upgrades::instance()->get_completed_upgrades();
  31. }
  32. /**
  33. * Check if the upgrade routine has been run for a specific action
  34. *
  35. * @since 1.7.0
  36. *
  37. * @param string $upgrade_id The upgrade action to check completion for
  38. *
  39. * @return bool If the action has been added to the completed actions array
  40. */
  41. function pum_has_completed_upgrade( $upgrade_id = '' ) {
  42. return PUM_Utils_Upgrades::instance()->has_completed_upgrade( $upgrade_id );
  43. }
  44. /**
  45. * Clean up postmeta by removing all keys from the given post_id.
  46. *
  47. * @param int $post_id
  48. * @param array $keys_to_delete
  49. */
  50. function pum_cleanup_post_meta_keys( $post_id = 0, $keys_to_delete = array() ) {
  51. /**
  52. * Clean up automatically.
  53. */
  54. if ( ! empty( $keys_to_delete ) ) {
  55. global $wpdb;
  56. $keys_to_delete = array_map( 'esc_sql', (array) $keys_to_delete );
  57. $meta_keys = implode( "','", $keys_to_delete );
  58. $query = $wpdb->prepare( "DELETE FROM `$wpdb->postmeta` WHERE `post_id` = %d AND `meta_key` IN ('{$meta_keys}')", $post_id );
  59. $wpdb->query( $query );
  60. wp_cache_delete( $post_id, 'post_meta' );
  61. }
  62. }