Няма описание

queries.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit; // Exit if accessed directly
  7. }
  8. /**
  9. * Get a popup model instance.
  10. *
  11. * @param int $popup_id
  12. *
  13. * @return PUM_Model_Popup
  14. */
  15. function pum_get_popup( $popup_id = null ) {
  16. if ( ( is_null( $popup_id ) || 0 === $popup_id ) && pum_is_popup( pum()->current_popup ) ) {
  17. return pum()->current_popup;
  18. }
  19. /** @var int $popup_id filtered $popup_id */
  20. $popup_id = pum_get_popup_id( $popup_id );
  21. try {
  22. return pum()->popups->get_item( $popup_id );
  23. } catch ( InvalidArgumentException $e ) {
  24. // Return empty object
  25. return new PUM_Model_Popup( $popup_id );
  26. }
  27. }
  28. /**
  29. * Queries popups and returns them in a specific format.
  30. *
  31. * @param array $args
  32. *
  33. * @return PUM_Model_Popup[]
  34. */
  35. function pum_get_popups( $args = array() ) {
  36. return pum()->popups->get_items( $args );
  37. }
  38. /**
  39. * Queries popups and returns them in a specific format.
  40. *
  41. * @param array $args
  42. *
  43. * @return PUM_Model_Popup[]
  44. */
  45. function pum_get_all_popups( $args = array() ) {
  46. $args['posts_per_page'] = -1;
  47. return pum_get_popups( $args );
  48. }
  49. /**
  50. * Gets a count popups with specified args.
  51. *
  52. * @param array $args
  53. *
  54. * @return int
  55. */
  56. function pum_count_popups( $args = array() ) {
  57. $args = wp_parse_args( $args, array(
  58. 'post_status' => 'publish',
  59. ) );
  60. return pum()->popups->count_items( $args );
  61. }