Brak opisu

conditionals.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit; // Exit if accessed directly
  7. }
  8. /**
  9. * Determines whether the current page is an popup maker admin page.
  10. *
  11. * @since 1.7.0
  12. *
  13. * @return bool
  14. */
  15. function pum_is_admin_page() {
  16. if ( ! is_admin() || ! did_action( 'wp_loaded' ) ) {
  17. return false;
  18. }
  19. $typenow = pum_typenow();
  20. $tests = array(
  21. 'popup' == $typenow,
  22. 'popup_theme' == $typenow,
  23. ! empty( $GLOBALS['hook_suffix'] ) && in_array( $GLOBALS['hook_suffix'], PUM_Admin_Pages::$pages ),
  24. );
  25. return in_array( true, $tests );
  26. }
  27. /**
  28. * Determines whether the current admin page is the All Popups page.
  29. *
  30. * @since 1.12
  31. * @return bool True if current page is All Popups page.
  32. */
  33. function pum_is_all_popups_page() {
  34. $screen = get_current_screen();
  35. $tests = array(
  36. pum_is_admin_page(),
  37. 'edit-popup' === $screen->id,
  38. pum_typenow() === 'popup',
  39. );
  40. return ! in_array( false, $tests, true );
  41. }
  42. /**
  43. * Determines whether the current admin page is the popup editor.
  44. *
  45. * @since 1.7.0
  46. *
  47. * @return bool
  48. */
  49. function pum_is_popup_editor() {
  50. global $pagenow;
  51. $tests = array(
  52. is_admin(),
  53. pum_is_admin_page(),
  54. 'popup' == pum_typenow(),
  55. in_array( $pagenow, array( 'post-new.php', 'post.php' ) ),
  56. );
  57. return ! in_array( false, $tests );
  58. }
  59. /**
  60. * Determines whether the current admin page is the popup theme editor.
  61. *
  62. * @since 1.7.0
  63. *
  64. * @return bool
  65. */
  66. function pum_is_popup_theme_editor() {
  67. global $pagenow;
  68. $tests = array(
  69. is_admin(),
  70. pum_is_admin_page(),
  71. 'popup_theme' == pum_typenow(),
  72. in_array( $pagenow, array( 'post-new.php', 'post.php' ) ),
  73. );
  74. return ! in_array( false, $tests );
  75. }
  76. /**
  77. * Determines whether the current admin page is the extensions page.
  78. *
  79. * @since 1.7.0
  80. *
  81. * @param null|string $key
  82. *
  83. * @return bool
  84. */
  85. function pum_is_submenu_page( $key = null ) {
  86. $tests = array(
  87. is_admin(),
  88. pum_is_admin_page(),
  89. ! pum_is_popup_editor(),
  90. ! pum_is_popup_theme_editor(),
  91. $key && ! empty( $GLOBALS['hook_suffix'] ) ? $GLOBALS['hook_suffix'] == PUM_Admin_Pages::get_page( $key ) : true,
  92. ! isset( $key ) && ! empty( $GLOBALS['hook_suffix'] ) ? in_array( $GLOBALS['hook_suffix'], PUM_Admin_Pages::$pages ) : true,
  93. );
  94. return ! in_array( false, $tests );
  95. }
  96. /**
  97. * Determines whether the current admin page is the subscriptions page.
  98. *
  99. * @since 1.7.0
  100. *
  101. * @return bool
  102. */
  103. function pum_is_subscriptions_page() {
  104. return pum_is_submenu_page( 'subscriptions' );
  105. }
  106. /**
  107. * Determines whether the current admin page is the extensions page.
  108. *
  109. * @since 1.7.0
  110. *
  111. * @return bool
  112. */
  113. function pum_is_extensions_page() {
  114. return pum_is_submenu_page( 'extensions' );
  115. }
  116. /**
  117. * Determines whether the current admin page is the settings page.
  118. *
  119. * @since 1.7.0
  120. *
  121. * @return bool
  122. */
  123. function pum_is_settings_page() {
  124. return pum_is_submenu_page( 'settings' );
  125. }
  126. /**
  127. * Determines whether the current admin page is the tools page.
  128. *
  129. * @since 1.7.0
  130. *
  131. * @return bool
  132. */
  133. function pum_is_tools_page() {
  134. return pum_is_submenu_page( 'tools' );
  135. }
  136. /**
  137. * Determines whether the current admin page is the support page.
  138. *
  139. * @since 1.7.0
  140. *
  141. * @return bool
  142. */
  143. function pum_is_support_page() {
  144. return pum_is_submenu_page( 'support' );
  145. }