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

class-pum-buddypress-integration.php 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. // Exit if accessed directly
  6. if ( ! defined( 'ABSPATH' ) ) {
  7. exit;
  8. }
  9. /**
  10. * Class PUM_BuddyPress_Integration
  11. */
  12. class PUM_BuddyPress_Integration {
  13. /**
  14. *
  15. */
  16. public static function init() {
  17. add_filter( 'pum_registered_conditions', array( __CLASS__, 'registered_conditions' ) );
  18. add_filter( 'pum_condition_sort_order', array( __CLASS__, 'condition_sort_order' ) );
  19. }
  20. /**
  21. * @param array $conditions
  22. *
  23. * @return array
  24. */
  25. public static function registered_conditions( $conditions = array() ) {
  26. $conditions = array_merge( $conditions, array(
  27. // Add Additional Conditions
  28. 'is_buddypress' => array(
  29. 'group' => __( 'BuddyPress', 'buddypress' ),
  30. 'name' => __( 'BP: Is a BuddyPress Page', 'popup-maker' ),
  31. 'callback' => 'is_buddypress',
  32. ),
  33. 'bp_is_user' => array(
  34. 'group' => __( 'BuddyPress', 'buddypress' ),
  35. 'name' => __( 'BP: Is User Page', 'popup-maker' ),
  36. 'callback' => 'bp_is_user',
  37. ),
  38. 'bp_is_group' => array(
  39. 'group' => __( 'BuddyPress', 'buddypress' ),
  40. 'name' => __( 'BP: Is Group Page', 'popup-maker' ),
  41. 'callback' => 'bp_is_group',
  42. ),
  43. 'bp_is_user_messages' => array(
  44. 'group' => __( 'BuddyPress', 'buddypress' ),
  45. 'name' => __( 'BP: Is User Messages Page', 'popup-maker' ),
  46. 'callback' => 'bp_is_user_messages',
  47. ),
  48. 'bp_is_activation_page' => array(
  49. 'group' => __( 'BuddyPress', 'buddypress' ),
  50. 'name' => __( 'BP: Is Activation Page', 'popup-maker' ),
  51. 'callback' => 'bp_is_activation_page',
  52. ),
  53. 'bp_is_register_page' => array(
  54. 'group' => __( 'BuddyPress', 'buddypress' ),
  55. 'name' => __( 'BP: Is Register Page', 'popup-maker' ),
  56. 'callback' => 'bp_is_register_page',
  57. ),
  58. 'bp_is_item_admin' => array(
  59. 'group' => __( 'BuddyPress', 'buddypress' ),
  60. 'name' => __( 'BP: Is Item Admin', 'popup-maker' ),
  61. 'callback' => 'bp_is_item_admin',
  62. ),
  63. 'bp_is_item_mod' => array(
  64. 'group' => __( 'BuddyPress', 'buddypress' ),
  65. 'name' => __( 'BP: Is Item Mod', 'popup-maker' ),
  66. 'callback' => 'bp_is_item_mod',
  67. ),
  68. 'bp_is_directory' => array(
  69. 'group' => __( 'BuddyPress', 'buddypress' ),
  70. 'name' => __( 'BP: Is Directory', 'popup-maker' ),
  71. 'callback' => 'bp_is_directory',
  72. ),
  73. 'bp_is_current_component' => array(
  74. 'group' => __( 'BuddyPress', 'buddypress' ),
  75. 'name' => __( 'BP: Is Current Component', 'popup-maker' ),
  76. 'fields' => array(
  77. 'selected' => array(
  78. 'type' => 'select',
  79. 'multiple' => true,
  80. 'as_array' => true,
  81. 'select2' => true,
  82. 'options' => self::component_option_list(),
  83. 'label' => __( 'Which components?' ),
  84. ),
  85. ),
  86. 'callback' => array( __CLASS__, 'bp_is_current_component' ),
  87. ),
  88. 'bp_is_current_action' => array(
  89. 'group' => __( 'BuddyPress', 'buddypress' ),
  90. 'name' => __( 'BP: Is Current Action', 'popup-maker' ),
  91. 'fields' => array(
  92. 'selected' => array(
  93. 'type' => 'text',
  94. 'label' => __( 'Which actions?' ),
  95. ),
  96. ),
  97. 'callback' => array( __CLASS__, 'bp_is_current_action' ),
  98. ),
  99. 'bp_is_action_variable' => array(
  100. 'group' => __( 'BuddyPress', 'buddypress' ),
  101. 'name' => __( 'BP: Is Action Variable', 'popup-maker' ),
  102. 'fields' => array(
  103. 'selected' => array(
  104. 'type' => 'text',
  105. 'label' => __( 'Which action variables?' ),
  106. ),
  107. ),
  108. 'callback' => array( __CLASS__, 'bp_is_action_variable' ),
  109. ),
  110. ) );
  111. return $conditions;
  112. }
  113. /**
  114. * @return array
  115. */
  116. public static function component_option_list() {
  117. global $bp;
  118. $components = array();
  119. foreach ( $bp->active_components as $component => $key ) {
  120. $components[ $component ] = ucfirst( $component );
  121. }
  122. return $components;
  123. }
  124. /**
  125. * Checks if the current page is the selected bp components.
  126. *
  127. * @param array $settings
  128. *
  129. * @return bool
  130. */
  131. public static function bp_is_current_component( $settings = array() ) {
  132. global $bp;
  133. if ( empty ( $settings['selected'] ) ) {
  134. return false;
  135. }
  136. if ( ! is_array( $settings['selected'] ) ) {
  137. $settings['selected'] = array( $settings['selected'] );
  138. }
  139. $found = false;
  140. foreach ( $settings['selected'] as $component ) {
  141. if ( ! array_key_exists( $component, $bp->active_components ) ) {
  142. continue;
  143. }
  144. if ( bp_is_current_component( $component ) ) {
  145. $found = true;
  146. }
  147. }
  148. return $found;
  149. }
  150. /**
  151. * Checks if the current page is the selected bp action.
  152. *
  153. * @param array $settings
  154. *
  155. * @return bool
  156. */
  157. public static function bp_is_current_action( $settings = array() ) {
  158. if ( empty ( $settings['selected'] ) ) {
  159. return false;
  160. }
  161. if ( ! is_array( $settings['selected'] ) ) {
  162. $settings['selected'] = array_map( 'trim', explode( ',', $settings['selected'] ) );
  163. }
  164. $found = false;
  165. foreach ( $settings['selected'] as $action ) {
  166. if ( bp_is_current_action( $action ) ) {
  167. $found = true;
  168. }
  169. }
  170. return $found;
  171. }
  172. /**
  173. * Checks if the current page is the selected bp action variable.
  174. *
  175. * @param array $settings
  176. *
  177. * @return bool
  178. */
  179. public static function bp_is_action_variable( $settings = array() ) {
  180. if ( empty ( $settings['selected'] ) ) {
  181. return false;
  182. }
  183. if ( ! is_array( $settings['selected'] ) ) {
  184. $settings['selected'] = array_map( 'trim', explode( ',', $settings['selected'] ) );
  185. }
  186. $found = false;
  187. foreach ( $settings['selected'] as $variable ) {
  188. if ( bp_is_action_variable( $variable ) ) {
  189. $found = true;
  190. }
  191. }
  192. return $found;
  193. }
  194. /**
  195. * @param array $order
  196. *
  197. * @return array
  198. */
  199. public static function condition_sort_order( $order = array() ) {
  200. $order[ __( 'BuddyPress', 'buddypress' ) ] = 5.756;
  201. return $order;
  202. }
  203. }