get_id(); if ( isset( $this->conditions[ $id ] ) ) { throw new Exception( 'Condition with ID ' . esc_html( $id ) . ' is already registered.' ); } $this->conditions[ $id ] = $condition; } /** * Gets a registered condition by its ID. * * @param string $id ID of the condition to retrieve. * * @return ConditionInterface|null The condition if found, null otherwise. */ public function get_condition( string $id ): ?ConditionInterface { return $this->conditions[ $id ] ?? null; } /** * Define Pro conditions for upselling. * * @return array[] */ private function get_pro_conditions( ): array { return [ 'post_content' => [ 'label' => __( 'Keywords', 'adpresso' ), 'group' => 'Pro', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'referrer_url' => [ 'label' => __( 'Referrer URL', 'adpresso' ), 'group' => 'Pro', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'url_parameters' => [ 'label' => __( 'URL Parameters', 'adpresso' ), 'group' => 'Pro', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'user_role' => [ 'label' => __( 'User Role', 'adpresso' ), 'group' => 'Pro', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'max_impressions' => [ 'label' => __( 'Impression Limit', 'adpresso' ), 'group' => 'Pro', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'adblocker' => [ 'label' => __( 'Ad Blocker', 'adpresso' ), 'group' => 'Pro', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'browser_width' => [ 'label' => __( 'Browser Width', 'adpresso' ), 'group' => 'Pro', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'cookie' => [ 'label' => __( 'Cookie', 'adpresso' ), 'group' => 'Pro', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'logged_in' => [ 'label' => __( 'Logged-in Visitor', 'adpresso' ), 'group' => 'Pro', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'wpml_language' => [ 'label' => __( 'Language (WPML)', 'adpresso' ), 'group' => 'Integrations', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'pmp_membership_level' => [ 'label' => __( 'Membership Level (Paid Memberships Pro)', 'adpresso' ), 'group' => 'Integrations', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'pmp_page_level' => [ 'label' => __( 'Page Level (Paid Memberships Pro)', 'adpresso' ), 'group' => 'Integrations', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'gamipress_points' => [ 'label' => __( 'Points (GamiPress)', 'adpresso' ), 'group' => 'Integrations', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'gamipress_rank' => [ 'label' => __( 'Rank (GamiPress)', 'adpresso' ), 'group' => 'Integrations', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'gamipress_achievement' => [ 'label' => __( 'Achievement (GamiPress)', 'adpresso' ), 'group' => 'Integrations', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'buddypress_group' => [ 'label' => __( 'Group (BuddyPress)', 'adpresso' ), 'group' => 'Integrations', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], 'buddypress_profile_field' => [ 'label' => __( 'Profile Field (BuddyPress)', 'adpresso' ), 'group' => 'Integrations', 'operators' => [], 'valueField' => [], 'premium' => true, 'disabled' => true, ], ]; } /** * Returns all registered conditions. * * @return ConditionInterface[] Array of registered conditions. */ public function get_all_conditions(): array { return $this->conditions; } /** * Gathers the configuration for all registered conditions for the JS app. * * @return array */ public function get_all_condition_configs(): array { $configs = []; foreach ( $this->get_all_conditions() as $condition ) { $configs[ $condition->get_id() ] = [ 'label' => $condition->get_label(), 'group' => $condition->get_group(), 'operators' => $condition->get_supported_operators(), 'valueField' => $condition->get_value_config(), 'headlessCompatible' => $condition->is_headless_compatible(), ]; } // A locked teaser is only shown for a Pro condition that isn't ALREADY genuinely registered foreach ( $this->get_pro_conditions() as $id => $teaser ) { if ( ! isset( $configs[ $id ] ) ) { $configs[ $id ] = $teaser; } } return $configs; } }