| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php
- /*******************************************************************************
- * Copyright (c) 2019, Code Atlantic LLC
- ******************************************************************************/
- // Exit if accessed directly
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- /**
- * Class PUM_BuddyPress_Integration
- */
- class PUM_BuddyPress_Integration {
- /**
- *
- */
- public static function init() {
- add_filter( 'pum_registered_conditions', array( __CLASS__, 'registered_conditions' ) );
- add_filter( 'pum_condition_sort_order', array( __CLASS__, 'condition_sort_order' ) );
- }
- /**
- * @param array $conditions
- *
- * @return array
- */
- public static function registered_conditions( $conditions = array() ) {
- $conditions = array_merge( $conditions, array(
- // Add Additional Conditions
- 'is_buddypress' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is a BuddyPress Page', 'popup-maker' ),
- 'callback' => 'is_buddypress',
- ),
- 'bp_is_user' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is User Page', 'popup-maker' ),
- 'callback' => 'bp_is_user',
- ),
- 'bp_is_group' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is Group Page', 'popup-maker' ),
- 'callback' => 'bp_is_group',
- ),
- 'bp_is_user_messages' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is User Messages Page', 'popup-maker' ),
- 'callback' => 'bp_is_user_messages',
- ),
- 'bp_is_activation_page' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is Activation Page', 'popup-maker' ),
- 'callback' => 'bp_is_activation_page',
- ),
- 'bp_is_register_page' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is Register Page', 'popup-maker' ),
- 'callback' => 'bp_is_register_page',
- ),
- 'bp_is_item_admin' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is Item Admin', 'popup-maker' ),
- 'callback' => 'bp_is_item_admin',
- ),
- 'bp_is_item_mod' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is Item Mod', 'popup-maker' ),
- 'callback' => 'bp_is_item_mod',
- ),
- 'bp_is_directory' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is Directory', 'popup-maker' ),
- 'callback' => 'bp_is_directory',
- ),
- 'bp_is_current_component' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is Current Component', 'popup-maker' ),
- 'fields' => array(
- 'selected' => array(
- 'type' => 'select',
- 'multiple' => true,
- 'as_array' => true,
- 'select2' => true,
- 'options' => self::component_option_list(),
- 'label' => __( 'Which components?' ),
- ),
- ),
- 'callback' => array( __CLASS__, 'bp_is_current_component' ),
- ),
- 'bp_is_current_action' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is Current Action', 'popup-maker' ),
- 'fields' => array(
- 'selected' => array(
- 'type' => 'text',
- 'label' => __( 'Which actions?' ),
- ),
- ),
- 'callback' => array( __CLASS__, 'bp_is_current_action' ),
- ),
- 'bp_is_action_variable' => array(
- 'group' => __( 'BuddyPress', 'buddypress' ),
- 'name' => __( 'BP: Is Action Variable', 'popup-maker' ),
- 'fields' => array(
- 'selected' => array(
- 'type' => 'text',
- 'label' => __( 'Which action variables?' ),
- ),
- ),
- 'callback' => array( __CLASS__, 'bp_is_action_variable' ),
- ),
- ) );
- return $conditions;
- }
- /**
- * @return array
- */
- public static function component_option_list() {
- global $bp;
- $components = array();
- foreach ( $bp->active_components as $component => $key ) {
- $components[ $component ] = ucfirst( $component );
- }
- return $components;
- }
- /**
- * Checks if the current page is the selected bp components.
- *
- * @param array $settings
- *
- * @return bool
- */
- public static function bp_is_current_component( $settings = array() ) {
- global $bp;
- if ( empty ( $settings['selected'] ) ) {
- return false;
- }
- if ( ! is_array( $settings['selected'] ) ) {
- $settings['selected'] = array( $settings['selected'] );
- }
- $found = false;
- foreach ( $settings['selected'] as $component ) {
- if ( ! array_key_exists( $component, $bp->active_components ) ) {
- continue;
- }
- if ( bp_is_current_component( $component ) ) {
- $found = true;
- }
- }
- return $found;
- }
- /**
- * Checks if the current page is the selected bp action.
- *
- * @param array $settings
- *
- * @return bool
- */
- public static function bp_is_current_action( $settings = array() ) {
- if ( empty ( $settings['selected'] ) ) {
- return false;
- }
- if ( ! is_array( $settings['selected'] ) ) {
- $settings['selected'] = array_map( 'trim', explode( ',', $settings['selected'] ) );
- }
- $found = false;
- foreach ( $settings['selected'] as $action ) {
- if ( bp_is_current_action( $action ) ) {
- $found = true;
- }
- }
- return $found;
- }
- /**
- * Checks if the current page is the selected bp action variable.
- *
- * @param array $settings
- *
- * @return bool
- */
- public static function bp_is_action_variable( $settings = array() ) {
- if ( empty ( $settings['selected'] ) ) {
- return false;
- }
- if ( ! is_array( $settings['selected'] ) ) {
- $settings['selected'] = array_map( 'trim', explode( ',', $settings['selected'] ) );
- }
- $found = false;
- foreach ( $settings['selected'] as $variable ) {
- if ( bp_is_action_variable( $variable ) ) {
- $found = true;
- }
- }
- return $found;
- }
- /**
- * @param array $order
- *
- * @return array
- */
- public static function condition_sort_order( $order = array() ) {
- $order[ __( 'BuddyPress', 'buddypress' ) ] = 5.756;
- return $order;
- }
- }
|