暂无描述

queries.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 theme model instance.
  10. *
  11. * @param int $theme_id
  12. *
  13. * @return PUM_Model_Theme
  14. */
  15. function pum_get_theme( $theme_id = 0 ) {
  16. if ( ! $theme_id ) {
  17. $theme_id = pum_get_theme_id();
  18. }
  19. try {
  20. return pum()->themes->get_item( $theme_id );
  21. } catch ( InvalidArgumentException $e ) {
  22. // Return empty object
  23. return new PUM_Model_Theme( $theme_id );
  24. }
  25. }
  26. /**
  27. * Queries themes and returns them in a specific format.
  28. *
  29. * @param array $args
  30. *
  31. * @return PUM_Model_Theme[]
  32. */
  33. function pum_get_themes( $args = array() ) {
  34. return pum()->themes->get_items( $args );
  35. }
  36. /**
  37. * Queries themes and returns them in a specific format.
  38. *
  39. * @param array $args
  40. *
  41. * @return PUM_Model_Theme[]
  42. */
  43. function pum_get_all_themes( $args = array() ) {
  44. $args['posts_per_page'] = -1;
  45. return pum_get_themes( $args );
  46. }
  47. /**
  48. * Gets a count themes with specified args.
  49. *
  50. * @param array $args
  51. *
  52. * @return int
  53. */
  54. function pum_count_themes( $args = array() ) {
  55. $args = wp_parse_args( $args, array(
  56. 'post_status' => 'publish',
  57. ) );
  58. return pum()->themes->count_items( $args );
  59. }