Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,759 @@
<?php
class BWFAN_Pro_Rules {
private static $ins = null;
protected $rule_types = null;
protected $custom_fields = null;
private function __construct() {
add_action( 'bwfan_rules_included', [ $this, 'include_rules' ] );
add_action( 'bwfan_rules_input_included', [ $this, 'include_inputs' ] );
add_filter( 'bwfan_rules_groups', [ $this, 'add_rule_group' ] );
add_filter( 'bwfan_rule_get_rule_types', [ $this, 'add_rule_type' ] );
add_filter( 'bwfan_modify_rule_class', [ $this, 'append_contact_field_rules' ], 10, 2 );
}
public static function get_instance() {
if ( is_null( self::$ins ) ) {
self::$ins = new self();
}
return self::$ins;
}
public function add_rule_group( $group ) {
if ( class_exists( 'WFACP_Core' ) || class_exists( 'WFOCU_Common' ) ) {
$group['woofunnels'] = array(
'title' => __( 'Funnels', 'wp-marketing-automations-pro' )
);
}
if ( class_exists( 'WFOCU_Common' ) ) {
$group['upstroke_funnel'] = array(
'title' => __( 'Funnels', 'wp-marketing-automations-pro' )
);
$group['upstroke_funnel_offers'] = array(
'title' => 'Funnels',
);
}
if ( class_exists( 'WFACP_Core' ) ) {
$group['aerocheckout'] = array(
'title' => __( 'Funnels', 'wp-marketing-automations-pro' )
);
}
if ( bwfan_is_affiliatewp_active() ) {
$group['affiliatewp'] = array(
'title' => __( 'AffiliateWP', 'wp-marketing-automations-pro' ),
);
$group['affiliate_report'] = array(
'title' => __( 'AffiliateWP Digest Range', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_gforms_active() ) {
$group['gforms'] = array(
'title' => __( 'Gravity Forms', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_elementorpro_active() ) {
$group['elementor-forms'] = array(
'title' => __( 'Elementor Forms', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_tve_active() ) {
$group['thrive-forms'] = array(
'title' => __( 'Thrive Leads', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_tve_architect_active() ) {
$group['thrive-architect-forms'] = array(
'title' => __( 'Thrive Forms', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_wpforms_active() ) {
$group['wpforms'] = array(
'title' => __( 'WPForms', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_woocommerce_membership_active() ) {
$group['wc_member'] = array(
'title' => __( 'WooCommerce Memberships', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_woocommerce_subscriptions_active() ) {
$group['wc_subscription'] = array(
'title' => __( 'WooCommerce Subscriptions', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_learndash_active() ) {
$group['learndash_course'] = array(
'title' => __( 'LearnDash Course', 'wp-marketing-automations-pro' ),
);
$group['learndash_lesson'] = array(
'title' => __( 'LearnDash Lesson', 'wp-marketing-automations-pro' ),
);
$group['learndash_topic'] = array(
'title' => __( 'LearnDash Topic', 'wp-marketing-automations-pro' ),
);
$group['learndash_quiz_result'] = array(
'title' => __( 'LearnDash Quiz Result', 'wp-marketing-automations-pro' ),
);
$group['learndash_quiz'] = array(
'title' => __( 'LearnDash Quiz', 'wp-marketing-automations-pro' ),
);
$group['learndash_group'] = array(
'title' => __( 'LearnDash Group', 'wp-marketing-automations-pro' ),
);
}
/** checking ninja exists **/
if ( function_exists( 'Ninja_Forms' ) ) {
$group['ninjaforms'] = array(
'title' => __( 'Ninja Forms', 'wp-marketing-automations-pro' ),
);
}
/** checking fluent exists **/
if ( bwfan_is_fluent_forms_active() ) {
$group['fluentforms'] = array(
'title' => __( 'Fluent Forms', 'wp-marketing-automations-pro' ),
);
}
/** checking forminator exists **/
if ( bwfan_is_forminator_forms_active() ) {
$group['forminator_forms'] = array(
'title' => __( 'Forminator Forms', 'wp-marketing-automations-pro' ),
);
}
/** checking fluent exists **/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
$group['wlm_forms'] = array(
'title' => __( 'Wishlist Member Form', 'wp-marketing-automations-pro' ),
);
$group['wlm'] = array(
'title' => __( 'Wishlist Member', 'wp-marketing-automations-pro' ),
);
}
/** checking CRM list class */
if ( class_exists( 'BWFCRM_Lists' ) ) {
$group['bwfan_crm_lists'] = array(
'title' => __( 'CRM Lists', 'wp-marketing-automations-pro' ),
);
}
if ( class_exists( 'BWFCRM_Tag' ) ) {
$group['bwfan_crm_tags'] = array(
'title' => __( 'CRM Tags', 'wp-marketing-automations-pro' ),
);
}
/** checking Caldera exists **/
if ( bwfan_is_caldera_forms_active() ) {
$group['calderaforms'] = array(
'title' => __( 'Caldera Forms', 'wp-marketing-automations-pro' ),
);
}
/** checking Optin exists **/
if ( function_exists( 'bwfan_is_optin_forms_active' ) && bwfan_is_optin_forms_active() ) {
$group['optinforms'] = array(
'title' => __( 'Optin Forms', 'wp-marketing-automations-pro' ),
);
}
/** BWF_Contact Group */
$group['bwf_contact'] = array(
'title' => __( 'Contact Details', 'wp-marketing-automations-pro' )
);
$group['bwf_contact_segments'] = array(
'title' => __( 'Segments', 'wp-marketing-automations-pro' )
);
$group['bwf_contact_fields'] = array(
'title' => __( 'Contact Field', 'wp-marketing-automations-pro' )
);
$group['bwf_contact_user'] = array(
'title' => __( 'User', 'wp-marketing-automations-pro' )
);
$group['bwf_contact_wc'] = array(
'title' => __( 'WooCommerce', 'wp-marketing-automations-pro' )
);
$group['bwf_contact_geo'] = array(
'title' => __( 'Geography', 'wp-marketing-automations-pro' )
);
$group['bwf_engagement'] = array(
'title' => __( 'Engagement', 'wp-marketing-automations-pro' )
);
$group['bwf_broadcast'] = array(
'title' => __( 'Broadcast', 'wp-marketing-automations-pro' )
);
if ( bwfan_is_wc_wishlist_active() ) {
$group['wishlist_items'] = array(
'title' => __( 'Wishlist', 'wp-marketing-automations-pro' ),
);
}
if ( function_exists( 'bwfan_is_divi_forms_active' ) && bwfan_is_divi_forms_active() ) {
$group['divi_forms'] = array(
'title' => __( 'Divi Forms', 'wp-marketing-automations-pro' ),
);
}
/** Breakdance forms */
if ( function_exists( 'bwfan_is_breakdance_active' ) && bwfan_is_breakdance_active() ) {
$group['breakdance_forms'] = array(
'title' => __( 'Breakdance Form', 'wp-marketing-automations-pro' ),
);
}
if ( function_exists( 'bwfan_is_funnel_active' ) && bwfan_is_funnel_active() ) {
$group['funnel'] = array(
'title' => __( 'Funnel', 'wp-marketing-automations-pro' ),
);
}
$group['bwf_automation'] = array(
'title' => __( 'Automation', 'wp-marketing-automations-pro' )
);
if ( defined( 'BWFAN_VERSION' ) && version_compare( BWFAN_VERSION, '3.0.3', '>=' ) ) {
$group['bwf_date_time'] = array(
'title' => __( 'DateTime', 'wp-marketing-automations-pro' )
);
}
if ( BWFAN_PRO_Common::is_language_enabled() ) {
$group['languages'] = array(
'title' => __( 'Languages', 'wp-marketing-automations-pro' ),
);
}
$group['bwf_webhook'] = array(
'title' => __( 'Webhook', 'wp-marketing-automations-pro' )
);
if ( function_exists( 'bwfan_is_yith_wishlist_active' ) && bwfan_is_yith_wishlist_active() ) {
$group['yith_wishlist'] = array(
'title' => __( 'Yith Wishlist', 'wp-marketing-automations-pro' ),
);
}
if ( function_exists( 'bwfan_is_ti_wc_wishlist_active' ) && bwfan_is_ti_wc_wishlist_active() ) {
$group['ti_wc_wishlist'] = array(
'title' => __( 'TI WooCommerce Wishlist', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_woocommerce_active() && bwfan_is_funnel_active() && bwfan_is_fk_stripe_active() ) {
$group['fk_stripe_upsell'] = [
'title' => __( 'Offers', 'wp-marketing-automations-pro' ),
];
}
return $group;
}
public function add_rule_type( $types ) {
/** BWF Contact */
$types['bwf_contact'] = array(
'contact_first_name' => __( 'First Name', 'wp-marketing-automations-pro' ),
'contact_last_name' => __( 'Last Name', 'wp-marketing-automations-pro' ),
'contact_email' => __( 'Email', 'wp-marketing-automations-pro' ),
'contact_phone' => __( 'Phone', 'wp-marketing-automations-pro' ),
'contact_creation_date' => __( 'Contact Created', 'wp-marketing-automations-pro' ),
'contact_creation_days' => __( 'Contact Created (Days)', 'wp-marketing-automations-pro' ),
'contact_company' => __( 'Company', 'wp-marketing-automations-pro' ),
'contact_gender' => __( 'Gender', 'wp-marketing-automations-pro' ),
'contact_dob' => __( 'Date Of Birth is', 'wp-marketing-automations-pro' ),
);
$types['bwf_contact_segments'] = array(
'contact_tags' => __( 'Tags', 'wp-marketing-automations-pro' ),
'contact_lists' => __( 'Lists', 'wp-marketing-automations-pro' ),
'contact_audience' => __( 'Audience', 'wp-marketing-automations-pro' ),
'customer_marketing_status' => __( 'Status', 'woocommerce' ),
);
$types['bwf_contact_fields'] = array(
'customer_custom_field' => __( 'Fields', 'wp-marketing-automations-pro' ),
/** Used older customer slug to provide legacy compatibility */
);
$types = $this->add_contact_fields_rule_types( $types );
$types['bwf_contact_geo'] = array(
'contact_country' => __( 'Country', 'wp-marketing-automations-pro' ),
'contact_state' => __( 'State', 'wp-marketing-automations-pro' ),
'contact_address_1' => __( 'Address 1', 'wp-marketing-automations-pro' ),
'contact_address_2' => __( 'Address 2', 'wp-marketing-automations-pro' ),
'contact_city' => __( 'City', 'wp-marketing-automations-pro' ),
'contact_post_code' => __( 'Post Code', 'wp-marketing-automations-pro' ),
);
if ( ! isset( $types['bwf_contact_user'] ) ) {
$types['bwf_contact_user'] = [];
}
$types['bwf_contact_user'] = array_merge( $types['bwf_contact_user'], array(
'customer_is_wp_user' => __( 'Is User', 'wp-marketing-automations-pro' ),
'customer_role' => __( 'User Role', 'wp-marketing-automations-pro' ),
) );
if ( class_exists( 'WooCommerce' ) ) {
$types['bwf_contact_wc'] = array(
'customer_total_spent' => __( 'Total Revenue', 'wp-marketing-automations-pro' ),
'customer_order_count' => __( 'Total Orders Count', 'wp-marketing-automations-pro' ),
'customer_purchased_products' => __( 'Purchased Products', 'wp-marketing-automations-pro' ),
'customer_purchased_cat' => __( 'Purchased Products Categories', 'wp-marketing-automations-pro' ),
'customer_purchased_tags' => __( 'Purchased Products Tags', 'wp-marketing-automations-pro' ),
'customer_has_purchased' => __( 'Has Made A Purchase', 'wp-marketing-automations-pro' ),
'customer_has_used_coupons' => __( 'Has Used Coupons', 'wp-marketing-automations-pro' ),
'customer_first_order_date' => __( 'First order was', 'wp-marketing-automations-pro' ),
'customer_last_order_date' => __( 'Last order was', 'wp-marketing-automations-pro' ),
'customer_last_order_days' => __( 'Last order Days', 'wp-marketing-automations-pro' ),
'customer_average_order_value' => __( 'Average Order Value is', 'wp-marketing-automations-pro' ),
'customer_used_coupons' => __( 'Used Coupons', 'wp-marketing-automations-pro' ),
);
if ( bwfan_is_woocommerce_subscriptions_active() ) {
$types['bwf_contact_wc']['active_subscription'] = __( 'Has Active Subscription', 'wp-marketing-automations-pro' );
}
}
$types['bwf_engagement'] = array(
'email_opens' => __( 'Email Opens', 'wp-marketing-automations-pro' ),
'engaged' => __( 'Engaged', 'wp-marketing-automations-pro' ),
'unengaged' => __( 'Unengaged', 'wp-marketing-automations-pro' ),
'link_trigger_clicked' => __( 'Link Trigger Clicked', 'wp-marketing-automations-pro' ),
'last_login' => __( 'Last Login', 'wp-marketing-automations-pro' ),
'last_open' => __( 'Last Open', 'wp-marketing-automations-pro' ),
'last_sent' => __( 'Last Sent', 'wp-marketing-automations-pro' ),
'last_clicked' => __( 'Last Clicked', 'wp-marketing-automations-pro' ),
);
$types['bwf_broadcast'] = array(
'broadcast_sent' => __( 'Broadcast Sent', 'wp-marketing-automations-pro' ),
'broadcast_open' => __( 'Broadcast Open', 'wp-marketing-automations-pro' ),
'broadcast_clicked' => __( 'Broadcast Clicked', 'wp-marketing-automations-pro' ),
);
if ( class_exists( 'WFACP_Core' ) ) {
$types['woofunnels']['aerocheckout'] = __( 'Checkout Page', 'wp-marketing-automations-pro' );
$types['aerocheckout'] = array(
'aerocheckout' => __( 'Checkout Page', 'wp-marketing-automations-pro' ),
);
}
if ( class_exists( 'WFOCU_Common' ) ) {
$types['woofunnels']['upstroke_funnels'] = __( 'Upsell', 'wp-marketing-automations-pro' );
$types['woofunnels']['upstroke_offers'] = __( 'Upsell Offers', 'wp-marketing-automations-pro' );
$types['upstroke_funnel'] = array(
'upstroke_funnels' => __( 'Upsell', 'wp-marketing-automations-pro' ),
);
$types['upstroke_funnel_offers'] = array(
'upstroke_funnels' => __( 'Upsell', 'wp-marketing-automations-pro' ),
'upstroke_offers' => __( 'Upsell Offers', 'wp-marketing-automations-pro' ),
);
}
if ( class_exists( 'WooCommerce' ) && bwfan_is_woocommerce_subscriptions_active() ) {
$types['wc_order']['is_order_renewal'] = __( 'Is Renewal', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_status'] = __( 'Subscription Status', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_total'] = __( 'Subscription Total', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_parent_order_status'] = __( 'Subscription Parent Order Status', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_item'] = __( 'Subscription Items', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_payment_gateway'] = __( 'Subscription Payment Gateway', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_old_status'] = __( 'Subscription Old Status', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_note_text_match'] = __( 'Subscription Note Text', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_payment_count'] = __( 'Subscription Payment Count', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_coupons'] = __( 'Subscription Coupon', 'wp-marketing-automations-pro' );
$types['wc_subscription']['subscription_coupon_text_match'] = __( 'Subscription Coupon Text', 'wp-marketing-automations-pro' );
if ( 'yes' === get_option( 'woocommerce_subscriptions_enable_retry' ) ) {
$types['wc_subscription']['subscription_failed_attempt'] = __( 'Subscription Failed Attempt', 'wp-marketing-automations-pro' );
}
}
if ( class_exists( 'WooCommerce' ) ) {
$new_arr = [];
foreach ( $types['wc_order'] as $key => $rule ) {
$new_arr[ $key ] = $rule;
if ( 'product_item' === $key ) {
$new_arr['customer_past_purchased_products'] = __( 'Past Purchased Products', 'wp-marketing-automations-pro' );
}
}
$types['wc_order'] = $new_arr;
}
if ( bwfan_is_advanced_coupon_for_woocommerce_active() && bwfan_is_woocommerce_active() ) {
$types['bwf_contact']['credit_amount'] = __( 'Total Credits', 'wp-marketing-automations-pro' );
if ( bwfan_is_loyalty_program_for_woocommerce_active() ) {
$types['bwf_contact']['loyalty_points'] = __( 'Loyalty Points', 'wp-marketing-automations-pro' );
}
}
if ( bwfan_is_affiliatewp_active() ) {
$types['affiliatewp']['affiliate_total_earnings'] = __( 'Affiliate Total Earnings', 'wp-marketing-automations-pro' );
$types['affiliatewp']['affiliate_unpaid_amount'] = __( 'Affiliate Unpaid Earnings', 'wp-marketing-automations-pro' );
$types['affiliatewp']['affiliate_total_visits'] = __( 'Affiliate Total Visits', 'wp-marketing-automations-pro' );
$types['affiliate_report']['selected_range_referrals_count'] = __( 'Referral Count (Selected Frequency)', 'wp-marketing-automations-pro' );
$types['affiliate_report']['selected_range_visits'] = __( 'Referral Visits (Selected Frequency)', 'wp-marketing-automations-pro' );
$types['affiliatewp']['affiliate_rate'] = __( 'Affiliate Rate', 'wp-marketing-automations-pro' );
}
if ( bwfan_is_gforms_active() ) {
$types['gforms']['gf_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( bwfan_is_elementorpro_active() ) {
$types['elementor-forms']['elementor_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( bwfan_is_wpforms_active() ) {
$types['wpforms']['wpforms_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( bwfan_is_tve_active() ) {
$types['thrive-forms']['tve_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( bwfan_is_tve_architect_active() ) {
$types['thrive-architect-forms']['tve_architect_form_fields'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( function_exists( 'Ninja_Forms' ) ) {
$types['ninjaforms']['ninja_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( bwfan_is_fluent_forms_active() ) {
$types['fluentforms']['fluent_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( bwfan_is_caldera_forms_active() ) {
$types['calderaforms']['caldera_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( function_exists( 'bwfan_is_optin_forms_active' ) && bwfan_is_optin_forms_active() ) {
$types['optinforms']['optin_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
/** Forminator forms */
if ( function_exists( 'bwfan_is_forminator_forms_active' ) && bwfan_is_forminator_forms_active() ) {
$types['forminator_forms']['forminator_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( class_exists( 'WooCommerce' ) && bwfan_is_woocommerce_membership_active() ) {
$types['wc_member']['membership_has_status'] = __( 'Membership Has Status', 'wp-marketing-automations-pro' );
$types['wc_member']['active_membership_plans'] = __( 'Membership Has Active Plans', 'wp-marketing-automations-pro' );
}
if ( bwfan_is_learndash_active() ) {
$types['learndash_quiz_result']['learndash_quiz_percentage'] = __( 'Quiz Percentage', 'wp-marketing-automations-pro' );
$types['learndash_quiz_result']['learndash_quiz_points'] = __( 'Quiz Points', 'wp-marketing-automations-pro' );
$types['learndash_quiz_result']['learndash_quiz_score'] = __( 'Quiz Score (No. of correct answers)', 'wp-marketing-automations-pro' );
$types['learndash_quiz_result']['learndash_quiz_timespent'] = __( 'Quiz Time Spent (in seconds)', 'wp-marketing-automations-pro' );
$types['learndash_quiz_result']['learndash_quiz_result'] = __( 'User passed the Quiz', 'wp-marketing-automations-pro' );
$types['learndash_course']['learndash_course'] = __( ' Enrolled Courses', 'wp-marketing-automations-pro' );
$types['learndash_course']['learndash_course_completed'] = __( 'Courses Completed', 'wp-marketing-automations-pro' );
$types['learndash_course']['learndash_courses_started'] = __( 'Courses Started', 'wp-marketing-automations-pro' );
$types['learndash_course']['learndash_course_progress'] = __( 'Course Progress (%)', 'wp-marketing-automations-pro' );
$types['learndash_lesson']['learndash_lesson'] = __( 'Lesson', 'wp-marketing-automations-pro' );
$types['learndash_topic']['learndash_topic'] = __( 'Topic', 'wp-marketing-automations-pro' );
$types['learndash_quiz']['learndash_quiz'] = __( 'Quiz', 'wp-marketing-automations-pro' );
$types['learndash_group']['learndash_group'] = __( 'Group', 'wp-marketing-automations-pro' );
$types['learndash_course']['learndash_course_started'] = __( 'Has course started', 'wp-marketing-automations-pro' );
$types['learndash_course']['learndash_has_course_completed'] = __( 'Has Course Completed', 'wp-marketing-automations-pro' );
$group_category = get_option( 'learndash_settings_groups_taxonomies', [] );
if ( isset( $group_category['ld_group_category'] ) && 'yes' === $group_category['ld_group_category'] ) {
$types['learndash_group']['learndash_group_category'] = __( 'Group Category', 'wp-marketing-automations-pro' );
}
}
/** Wishlist rules */
if ( bwfan_is_wc_wishlist_active() ) {
$types['wishlist_items']['wishlist_item'] = __( 'Items', 'wp-marketing-automations-pro' );
}
/** Yith Wishlist rules */
if ( bwfan_is_yith_wishlist_active() ) {
$types['yith_wishlist']['yith_wishlist_item'] = __( 'Wishlist Product', 'wp-marketing-automations-pro' );
}
/** Ti Wc Wishlist rules */
if ( bwfan_is_ti_wc_wishlist_active() ) {
$types['ti_wc_wishlist']['ti_wc_wishlist_item'] = __( 'Wishlist Product', 'wp-marketing-automations-pro' );
$types['ti_wc_wishlist']['ti_wc_wishlist_item_count'] = __( 'Wishlist Product Count', 'wp-marketing-automations-pro' );
}
/** Advanced shipping rates rules */
if ( bwfan_is_woocommerce_advanced_shipping_pro_active() ) {
$types['wc_order']['advanced_shipping_rate'] = __( 'Advanced Shipping Rates', 'wp-marketing-automations-pro' );
}
/** Wishlist member rules */
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
$types['wlm_forms']['wlm_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
$types['wlm']['wlm_level'] = __( 'Membership Level', 'wp-marketing-automations-pro' );
}
/** Divi forms rules */
if ( function_exists( 'bwfan_is_divi_forms_active' ) && bwfan_is_divi_forms_active() ) {
$types['divi_forms']['divi_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
/** Break dance forms */
if ( function_exists( 'bwfan_is_breakdance_active' ) && bwfan_is_breakdance_active() ) {
$types['breakdance_forms']['breakdance_form_field'] = __( 'Form Fields', 'wp-marketing-automations-pro' );
}
if ( function_exists( 'bwfan_is_funnel_active' ) && bwfan_is_funnel_active() ) {
$types['funnel']['funnel'] = __( 'Funnel', 'wp-marketing-automations-pro' );
}
$types['bwf_automation']['ever_entered_automation'] = __( 'Has ever entered in Automation', 'wp-marketing-automations-pro' );
$types['bwf_automation']['currently_active_automation'] = __( 'Currently active in Automation', 'wp-marketing-automations-pro' );
$types['bwf_automation']['completed_automation'] = __( 'Completed the Automation', 'wp-marketing-automations-pro' );
$types['bwf_webhook']['webhook_received'] = __( 'Webhook', 'wp-marketing-automations-pro' );
if ( defined( 'BWFAN_VERSION' ) && version_compare( BWFAN_VERSION, '3.0.3', '>=' ) ) {
$types['bwf_date_time'] = array(
'current_year' => __( 'Current Year', 'wp-marketing-automations-pro' ),
'current_month' => __( 'Current Month', 'wp-marketing-automations-pro' ),
'current_day_of_month' => __( 'Current Day Of Month', 'wp-marketing-automations-pro' ),
'current_day_of_week' => __( 'Current Day Of Week', 'wp-marketing-automations-pro' ),
'current_time' => __( 'Current Time', 'wp-marketing-automations-pro' ),
'current_date_time' => __( 'Current Date Time', 'wp-marketing-automations-pro' ),
);
}
if ( BWFAN_PRO_Common::is_language_enabled() ) {
$types['languages'] = array(
'language' => __( 'Language', 'wp-marketing-automations-pro' ),
);
}
if ( bwfan_is_woocommerce_active() && bwfan_is_funnel_active() && bwfan_is_fk_stripe_active() ) {
$types['fk_stripe_upsell'] = [
'stripe_offers' => __( 'Upsell Offers', 'wp-marketing-automations-pro' ),
'stripe_bumps' => __( 'Bumps', 'wp-marketing-automations-pro' ),
];
}
return $types;
}
/**
* @param $val
* @param $rule_type
*
* @return BWFAN_Rule_Contact_Field|mixed
*/
public function append_contact_field_rules( $val, $rule_type ) {
$types = $this->rule_types;
if ( is_null( $types ) ) {
$types = apply_filters( 'bwfan_rule_get_rule_types', array() );
$this->rule_types = $types;
}
if ( ! isset( $types['bwf_contact_fields'][ $rule_type ] ) ) {
return $val;
}
$field_id = str_replace( 'bwf_contact_field_f', '', $rule_type );
$fields = $this->get_custom_fields( true );
if ( ! isset( $fields[ $field_id ] ) ) {
return $val;
}
return new BWFAN_Rule_Contact_Field( $rule_type, $fields[ $field_id ]['type'] );
}
public function add_contact_fields_rule_types( $types ) {
$fields = $this->get_custom_fields();
$page = filter_input( INPUT_GET, 'page' );
if ( 'autonami-automations' !== $page ) {
unset( $types['bwf_contact_fields']['customer_custom_field'] );
}
$data = [];
foreach ( $fields as $id => $name ) {
$data[ 'bwf_contact_field_f' . $id ] = $name;
}
$types['bwf_contact_fields'] = array_merge( $types['bwf_contact_fields'], $data );
return $types;
}
public function get_custom_fields( $more_data = false ) {
$fields = $this->custom_fields;
if ( is_null( $fields ) ) {
$fields = BWFCRM_Fields::get_custom_fields( null, null, null, null, 1, null );
$this->custom_fields = $fields;
}
$sorted_fields = BWFAN_PRO_Common::get_sorted_fields( $fields );
$fields = ! empty( $sorted_fields ) ? $sorted_fields : $fields;
if ( empty( $fields ) ) {
return [];
}
$field_data = array();
foreach ( $fields as $field ) {
if ( ! isset( $field['ID'] ) ) {
continue;
}
if ( true === $more_data ) {
$field_data[ $field['ID'] ] = $field;
continue;
}
$field_data[ $field['ID'] ] = $field['name'];
}
return $field_data;
}
public function include_rules() {
include_once __DIR__ . '/rules/bwf-customer.php';
include_once __DIR__ . '/rules/bwf-contact.php';
include_once __DIR__ . '/rules/bwf-contact-fields.php';
include_once __DIR__ . '/rules/automation.php';
include_once __DIR__ . '/rules/engagement.php';
include_once __DIR__ . '/rules/webhook-received.php';
if ( defined( 'BWFAN_VERSION' ) && version_compare( BWFAN_VERSION, '3.0.3', '>=' ) ) {
include_once __DIR__ . '/rules/bwf-date-time.php';
}
if ( bwfan_is_woocommerce_subscriptions_active() ) {
include_once __DIR__ . '/rules/subscriptions.php';
}
/** Include only if any of the woofunnel plugin activated */
if ( class_exists( 'WFACP_Core' ) || class_exists( 'WFOCU_Common' ) ) {
include_once __DIR__ . '/rules/woofunnels.php';
}
if ( bwfan_is_affiliatewp_active() ) {
include_once __DIR__ . '/rules/affiliatewp.php';
}
if ( bwfan_is_gforms_active() ) {
include_once __DIR__ . '/rules/gforms.php';
}
/** advanced shipping rates */
if ( bwfan_is_woocommerce_advanced_shipping_pro_active() ) {
include_once __DIR__ . '/rules/wc_advance_shipping.php';
}
if ( bwfan_is_elementorpro_active() ) {
include_once __DIR__ . '/rules/elementorforms.php';
}
if ( bwfan_is_wpforms_active() ) {
include_once __DIR__ . '/rules/wpforms.php';
}
if ( function_exists( 'Ninja_Forms' ) ) {
include_once __DIR__ . '/rules/ninjaforms.php';
}
if ( bwfan_is_fluent_forms_active() ) {
include_once __DIR__ . '/rules/fluentforms.php';
}
if ( bwfan_is_caldera_forms_active() ) {
include_once __DIR__ . '/rules/calderaforms.php';
}
if ( bwfan_is_tve_active() ) {
include_once __DIR__ . '/rules/thriveforms.php';
}
if ( bwfan_is_tve_architect_active() ) {
include_once __DIR__ . '/rules/thrive-architect-forms.php';
}
/** Added Forminator rule */
if ( bwfan_is_forminator_forms_active() ) {
include_once __DIR__ . '/rules/forminator.php';
}
if ( bwfan_is_woocommerce_membership_active() ) {
include_once __DIR__ . '/rules/memberships.php';
}
if ( bwfan_is_learndash_active() ) {
include_once __DIR__ . '/rules/learndash.php';
}
if ( function_exists( 'bwfan_is_optin_forms_active' ) && bwfan_is_optin_forms_active() ) {
include_once __DIR__ . '/rules/optinforms.php';
}
if ( bwfan_is_wc_wishlist_active() ) {
include_once __DIR__ . '/rules/wishlist.php';
}
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
include_once __DIR__ . '/rules/wlm.php';
}
if ( function_exists( 'bwfan_is_divi_forms_active' ) && bwfan_is_divi_forms_active() ) {
include_once __DIR__ . '/rules/divi-forms.php';
}
/** Breakdance form */
if ( function_exists( 'bwfan_is_breakdance_active' ) && bwfan_is_breakdance_active() ) {
include_once __DIR__ . '/rules/breakdance-form.php';
}
/** store credit rule */
if ( bwfan_is_advanced_coupon_for_woocommerce_active() && bwfan_is_woocommerce_active() ) {
include_once __DIR__ . '/rules/bwf-store-credit.php';
}
if ( function_exists( 'bwfan_is_funnel_active' ) && bwfan_is_funnel_active() ) {
include_once __DIR__ . '/rules/funnel.php';
}
if ( function_exists( 'bwfan_is_yith_wishlist_active' ) && bwfan_is_yith_wishlist_active() ) {
include_once __DIR__ . '/rules/bwf-yith-wishlist.php';
}
if ( function_exists( 'bwfan_is_ti_wc_wishlist_active' ) && bwfan_is_ti_wc_wishlist_active() ) {
include_once __DIR__ . '/rules/bwf-ti-wc-wishlist.php';
}
if ( BWFAN_PRO_Common::is_language_enabled() ) {
include_once __DIR__ . '/rules/languages.php';
}
if ( bwfan_is_woocommerce_active() && bwfan_is_funnel_active() && bwfan_is_fk_stripe_active() ) {
include_once BWFAN_PRO_PLUGIN_DIR . '/modules/stripe-offer/rules/upsell-offers.php';
}
}
public function include_inputs() {
if ( class_exists( 'WFOCU_Common' ) ) {
include_once __DIR__ . '/html/html-funnel-onetime.php';
include_once __DIR__ . '/html/html-funnel-products.php';
}
}
public static function make_value_as_array( $value ) {
if ( is_array( $value ) ) {
return $value;
}
/** Checking if value contains comma */
if ( strpos( $value, ',' ) !== false ) {
$value = explode( ',', $value );
$value = array_map( 'trim', $value );
} else {
$value = array( $value );
}
return $value;
}
}
BWFAN_Pro_Rules::get_instance();

View File

@@ -0,0 +1,18 @@
<?php
class bwfan_Input_Funnel_OneTime {
public function __construct() {
// vars
$this->type = 'Funnel_OneTime';
$this->defaults = array(
'default_value' => '',
'class' => '',
'placeholder' => '',
);
}
public function render( $field, $value = null ) {
echo esc_html__( 'Run this automation only if the user hasn\'t visited it yet.', 'wp-marketing-automations-pro' );
}
}

View File

@@ -0,0 +1,18 @@
<?php
class bwfan_Input_Funnel_Products {
public function __construct() {
// vars
$this->type = 'Funnel_Products';
$this->defaults = array(
'default_value' => '',
'class' => '',
'placeholder' => '',
);
}
public function render( $field, $value = null ) {
echo esc_html__( 'Run this automation only if any of automation product is not present in primary offer. ', 'wp-marketing-automations-pro' );
}
}

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.

View File

@@ -0,0 +1,784 @@
<?php
if ( bwfan_is_affiliatewp_active() ) {
class BWFAN_Rule_Affiliate_Unpaid_Amount extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'affiliate_unpaid_amount' );
}
public function get_condition_input_type() {
return 'Text';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$result = false;
$affiliate_id = isset( $automation_data['global']['affiliate_id'] ) ? $automation_data['global']['affiliate_id'] : 0;
if ( empty( $affiliate_id ) ) {
return 0;
}
$affiliate = affwp_get_affiliate( $affiliate_id );
if ( false === $affiliate ) {
return 0;
}
$total_earnings = 0;
if ( ! empty( $affiliate->unpaid_earnings ) ) {
$decimal = apply_filters( 'bwfan_get_decimal_values', 2 );
$total_earnings = round( $affiliate->unpaid_earnings, $decimal );
}
$value = (float) $rule_data['data'];
switch ( $rule_data['rule'] ) {
case '==':
$result = $total_earnings === $value;
break;
case '!=':
$result = $total_earnings !== $value;
break;
case '>':
$result = $total_earnings > $value;
break;
case '<':
$result = $total_earnings < $value;
break;
case '>=':
$result = $total_earnings >= $value;
break;
case '<=':
$result = $total_earnings <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function is_match( $rule_data ) {
$earnings = (float) $this->get_unpaid_amount();
$value = (float) $rule_data['condition'];
switch ( $rule_data['operator'] ) {
case '==':
$result = $earnings === $value;
break;
case '!=':
$result = $earnings !== $value;
break;
case '>':
$result = $earnings > $value;
break;
case '<':
$result = $earnings < $value;
break;
case '>=':
$result = $earnings >= $value;
break;
case '<=':
$result = $earnings <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function get_unpaid_amount() {
$affiliate_id = BWFAN_Core()->rules->getRulesData( 'affiliate_id' );
if ( empty( $affiliate_id ) ) {
return 0;
}
$affiliate = affwp_get_affiliate( $affiliate_id );
if ( false === $affiliate ) {
return 0;
}
$total_earnings = 0;
if ( ! empty( $affiliate->unpaid_earnings ) ) {
$decimal = apply_filters( 'bwfan_get_decimal_values', 2 );
$total_earnings = round( $affiliate->unpaid_earnings, $decimal );
}
return $total_earnings;
}
public function ui_view() {
?>
Affiliate Unpaid Earnings
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %>
<%= condition %>
<?php
}
public function get_possible_rule_operators() {
$operators = array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
return $operators;
}
}
class BWFAN_Rule_Affiliate_Total_Earnings extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'affiliate_total_earnings' );
}
public function get_condition_input_type() {
return 'Text';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$result = false;
$affiliate_id = isset( $automation_data['global']['affiliate_id'] ) ? $automation_data['global']['affiliate_id'] : 0;
if ( empty( $affiliate_id ) ) {
return 0;
}
$affiliate = affwp_get_affiliate( $affiliate_id );
if ( false === $affiliate ) {
return 0;
}
$total_earnings = 0;
$earnings = $affiliate->unpaid_earnings + $affiliate->earnings;
if ( ! empty( $earnings ) ) {
$decimal = apply_filters( 'bwfan_get_decimal_values', 2 );
$total_earnings = round( $earnings, $decimal );
}
$value = (float) $rule_data['data'];
switch ( $rule_data['rule'] ) {
case '==':
$result = $total_earnings === $value;
break;
case '!=':
$result = $total_earnings !== $value;
break;
case '>':
$result = $total_earnings > $value;
break;
case '<':
$result = $total_earnings < $value;
break;
case '>=':
$result = $total_earnings >= $value;
break;
case '<=':
$result = $total_earnings <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function is_match( $rule_data ) {
$earnings = (float) $this->get_total_earnings();
$value = (float) $rule_data['condition'];
switch ( $rule_data['operator'] ) {
case '==':
$result = $earnings === $value;
break;
case '!=':
$result = $earnings !== $value;
break;
case '>':
$result = $earnings > $value;
break;
case '<':
$result = $earnings < $value;
break;
case '>=':
$result = $earnings >= $value;
break;
case '<=':
$result = $earnings <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function get_total_earnings() {
$affiliate_id = BWFAN_Core()->rules->getRulesData( 'affiliate_id' );
if ( empty( $affiliate_id ) ) {
return 0;
}
$affiliate = affwp_get_affiliate( $affiliate_id );
if ( false === $affiliate ) {
return 0;
}
$total_earnings = 0;
$earnings = $affiliate->unpaid_earnings + $affiliate->earnings;
if ( ! empty( $earnings ) ) {
$decimal = apply_filters( 'bwfan_get_decimal_values', 2 );
$total_earnings = round( $earnings, $decimal );
}
return $total_earnings;
}
public function ui_view() {
?>
Affiliate Total Earnings
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %>
<%= condition %>
<?php
}
public function get_possible_rule_operators() {
$operators = array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
return $operators;
}
}
class BWFAN_Rule_Affiliate_Total_Visits extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'affiliate_total_visits' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Number';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$result = false;
$affiliate_id = isset( $automation_data['global']['affiliate_id'] ) ? $automation_data['global']['affiliate_id'] : 0;
if ( empty( $affiliate_id ) ) {
return 0;
}
$affiliate = affwp_get_affiliate( $affiliate_id );
if ( false === $affiliate ) {
return 0;
}
$visits = (int) $affiliate->visits;
$value = (int) $rule_data['data'];
switch ( $rule_data['rule'] ) {
case '==':
$result = $visits === $value;
break;
case '!=':
$result = $visits !== $value;
break;
case '>':
$result = $visits > $value;
break;
case '<':
$result = $visits < $value;
break;
case '>=':
$result = $visits >= $value;
break;
case '<=':
$result = $visits <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_condition_input_type() {
return 'Text';
}
public function is_match( $rule_data ) {
$visits = (int) $this->get_visits();
$value = (int) $rule_data['condition'];
switch ( $rule_data['operator'] ) {
case '==':
$result = $visits === $value;
break;
case '!=':
$result = $visits !== $value;
break;
case '>':
$result = $visits > $value;
break;
case '<':
$result = $visits < $value;
break;
case '>=':
$result = $visits >= $value;
break;
case '<=':
$result = $visits <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function get_visits() {
$affiliate_id = BWFAN_Core()->rules->getRulesData( 'affiliate_id' );
if ( empty( $affiliate_id ) ) {
return 0;
}
$affiliate = affwp_get_affiliate( $affiliate_id );
if ( false === $affiliate ) {
return 0;
}
return $affiliate->visits;
}
public function ui_view() {
?>
Affiliate Total Visits
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %>
<%= condition %>
<?php
}
public function get_possible_rule_operators() {
$operators = array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
return $operators;
}
}
class BWFAN_Rule_Selected_Range_Referrals_Count extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'selected_range_referrals_count' );
$this->description = __( 'is equal to', 'wp-marketing-automations-pro' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Number';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$referrals_count = (int) isset( $automation_data['global']['referral_count'] ) ? $automation_data['global']['referral_count'] : 0;
$value = (int) $rule_data['data'];
switch ( $rule_data['rule'] ) {
case '==':
$result = $referrals_count === $value;
break;
case '!=':
$result = $referrals_count !== $value;
break;
case '>':
$result = $referrals_count > $value;
break;
case '<':
$result = $referrals_count < $value;
break;
case '>=':
$result = $referrals_count >= $value;
break;
case '<=':
$result = $referrals_count <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_condition_input_type() {
return 'Text';
}
public function is_match( $rule_data ) {
$referrals_count = (int) BWFAN_Core()->rules->getRulesData( 'referral_count' );
$value = (int) $rule_data['condition'];
switch ( $rule_data['operator'] ) {
case '==':
$result = $referrals_count === $value;
break;
case '!=':
$result = $referrals_count !== $value;
break;
case '>':
$result = $referrals_count > $value;
break;
case '<':
$result = $referrals_count < $value;
break;
case '>=':
$result = $referrals_count >= $value;
break;
case '<=':
$result = $referrals_count <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Referral Count (Selected Frequency)
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %>
<%= condition %>
<?php
}
public function get_possible_rule_operators() {
$operators = array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
return $operators;
}
}
class BWFAN_Rule_Selected_Range_Visits extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'selected_range_visits' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Number';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$visits = (int) isset( $automation_data['global']['visits'] ) ? $automation_data['global']['visits'] : 0;
$value = (int) $rule_data['data'];
switch ( $rule_data['rule'] ) {
case '==':
$result = $visits === $value;
break;
case '!=':
$result = $visits !== $value;
break;
case '>':
$result = $visits > $value;
break;
case '<':
$result = $visits < $value;
break;
case '>=':
$result = $visits >= $value;
break;
case '<=':
$result = $visits <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_condition_input_type() {
return 'Text';
}
public function is_match( $rule_data ) {
$visits = (int) BWFAN_Core()->rules->getRulesData( 'visits' );
$value = (int) $rule_data['condition'];
switch ( $rule_data['operator'] ) {
case '==':
$result = $visits === $value;
break;
case '!=':
$result = $visits !== $value;
break;
case '>':
$result = $visits > $value;
break;
case '<':
$result = $visits < $value;
break;
case '>=':
$result = $visits >= $value;
break;
case '<=':
$result = $visits <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Referral Visits (Selected Frequency)
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %>
<%= condition %>
<?php
}
public function get_possible_rule_operators() {
$operators = array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
return $operators;
}
}
class BWFAN_Rule_Affiliate_Rate extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'affiliate_rate' );
$this->description = 'Rate Type Percentage (%) only';
}
public function get_condition_input_type() {
return 'Text';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$affiliate_id = isset( $automation_data['global']['affiliate_id'] ) ? $automation_data['global']['affiliate_id'] : 0;
if ( empty( $affiliate_id ) ) {
return false;
}
$affiliate = affwp_get_affiliate( $affiliate_id );
if ( false === $affiliate ) {
return $this->return_is_match( false, $rule_data );
}
$rate_type = affwp_get_affiliate_rate_type( $affiliate_id );
if ( 'percentage' !== $rate_type ) {
return $this->return_is_match( false, $rule_data );
}
$affiliate_rate = affwp_get_affiliate_rate( $affiliate );
if ( ! empty( $affiliate_rate ) ) {
$rate = $affiliate_rate * 100;
}
$value = (float) $rule_data['data'];
switch ( $rule_data['rule'] ) {
case '==':
$result = $rate === $value;
break;
case '!=':
$result = $rate !== $value;
break;
case '>':
$result = $rate > $value;
break;
case '<':
$result = $rate < $value;
break;
case '>=':
$result = $rate >= $value;
break;
case '<=':
$result = $rate <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function is_match( $rule_data ) {
$rate = (float) $this->get_affiliate_rate();
if ( false === $rate ) {
return false;
}
$value = (float) $rule_data['condition'];
switch ( $rule_data['operator'] ) {
case '==':
$result = $rate === $value;
break;
case '!=':
$result = $rate !== $value;
break;
case '>':
$result = $rate > $value;
break;
case '<':
$result = $rate < $value;
break;
case '>=':
$result = $rate >= $value;
break;
case '<=':
$result = $rate <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function get_affiliate_rate() {
$affiliate_id = BWFAN_Core()->rules->getRulesData( 'affiliate_id' );
if ( empty( $affiliate_id ) ) {
return false;
}
$affiliate = affwp_get_affiliate( $affiliate_id );
if ( false === $affiliate ) {
return false;
}
$rate_type = affwp_get_affiliate_rate_type( $affiliate_id );
if ( 'percentage' !== $rate_type ) {
return false;
}
$affiliate_rate = affwp_get_affiliate_rate( $affiliate );
if ( ! empty( $affiliate_rate ) ) {
return $affiliate_rate * 100;
}
return false;
}
public function ui_view() {
?>
Affiliate Rate
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %>
<%= condition %>%
<?php
}
public function get_possible_rule_operators() {
$operators = array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
return $operators;
}
}
}

View File

@@ -0,0 +1,282 @@
<?php
class BWFAN_Rule_Automation_Run_Count extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'automation_run_count' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Number';
}
/** v2 Methods: END */
public function get_condition_input_type() {
return 'Text';
}
public function is_match( $rule_data ) {
/**
* @var Woofunnels_Customer $customer
*/
$automation_id = BWFAN_Core()->rules->getRulesData( 'automation_id' );
$customer_id = BWFAN_Core()->rules->getRulesData( 'bwf_customer' );
if ( empty( $customer_id ) ) {
return $this->return_is_match( false, $rule_data );
}
$count = absint( BWFAN_Model_Contact_Automations::get_contact_automations_run_count( $customer_id, $automation_id ) );
$value = absint( $rule_data['condition'] );
switch ( $rule_data['operator'] ) {
case '==':
$result = $count === $value;
break;
case '!=':
$result = $count !== $value;
break;
case '>':
$result = $count > $value;
break;
case '<':
$result = $count < $value;
break;
case '>=':
$result = $count >= $value;
break;
case '<=':
$result = $count <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
esc_html_e( 'Automation run count', 'wp-marketing-automations-pro' );
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %>
<%= condition %>
<?php
}
public function get_possible_rule_operators() {
$operators = array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
return $operators;
}
}
class BWFAN_Rule_Ever_Entered_Automation extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'ever_entered_automation' );
}
/** v2 Methods: START */
public function get_options( $search = '' ) {
$automations = BWFAN_Common::get_automation_by_title( $search, 2 );
$prepared_data = [];
foreach ( $automations as $automation ) {
$prepared_data[ $automation['id'] ] = $automation['title'];
}
return $prepared_data;
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$contact_id = isset( $automation_data['global']['cid'] ) ? $automation_data['global']['cid'] : 0;
/** CRM contact object */
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$result = ( 'none' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
/**set automation id in active automation */
$entered_automation = $contact->get_field_by_slug( 'automation-entered' );
$entered_automation_ids = json_decode( $entered_automation, true );
$entered_automation_ids = ( ! empty( $entered_automation_ids ) && is_array( $entered_automation_ids ) ) ? $entered_automation_ids : array();
$selected_automations = $rule_data['data'];
$selected_automations = array_map( function ( $data ) {
return absint( $data['key'] );
}, $selected_automations );
$result = $this->validate_matches_set( $selected_automations, $entered_automation_ids, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'all' => __( 'matches all of ', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of ', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Currently_Active_Automation extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'currently_active_automation' );
}
/** v2 Methods: START */
public function get_options( $search = '' ) {
$automations = BWFAN_Common::get_automation_by_title( $search, 2 );
$prepared_data = [];
foreach ( $automations as $automation ) {
$prepared_data[ $automation['id'] ] = $automation['title'];
}
return $prepared_data;
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$contact_id = isset( $automation_data['global']['cid'] ) ? $automation_data['global']['cid'] : 0;
/** CRM contact object */
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$result = ( 'none' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
/**set automation id in active automation */
$active_automation = $contact->get_field_by_slug( 'automation-active' );
$active_automation_ids = json_decode( $active_automation, true );
$active_automation_ids = ( ! empty( $active_automation_ids ) && is_array( $active_automation_ids ) ) ? $active_automation_ids : array();
$selected_automations = $rule_data['data'];
$selected_automations = array_map( function ( $data ) {
return absint( $data['key'] );
}, $selected_automations );
$result = $this->validate_matches_set( $selected_automations, $active_automation_ids, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'all' => __( 'matches all of ', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of ', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Completed_Automation extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'completed_automation' );
}
/** v2 Methods: START */
public function get_options( $search = '' ) {
$automations = BWFAN_Common::get_automation_by_title( $search, 2 );
$prepared_data = [];
foreach ( $automations as $automation ) {
$prepared_data[ $automation['id'] ] = $automation['title'];
}
return $prepared_data;
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$contact_id = isset( $automation_data['global']['cid'] ) ? $automation_data['global']['cid'] : 0;
/** CRM contact object */
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$result = ( 'none' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
/**set automation id in active automation */
$completed_automation = $contact->get_field_by_slug( 'automation-completed' );
$completed_automation_ids = json_decode( $completed_automation, true );
$completed_automation_ids = ( ! empty( $completed_automation_ids ) && is_array( $completed_automation_ids ) ) ? $completed_automation_ids : array();
$selected_automations = $rule_data['data'];
$selected_automations = array_map( function ( $data ) {
return absint( $data['key'] );
}, $selected_automations );
$result = $this->validate_matches_set( $selected_automations, $completed_automation_ids, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'all' => __( 'matches all of ', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of ', 'wp-marketing-automations-pro' ),
);
}
}

View File

@@ -0,0 +1,79 @@
<?php
if ( function_exists( 'bwfan_is_breakdance_active' ) && bwfan_is_breakdance_active() ) {
if ( ! class_exists( 'BWFAN_Rule_Breakdance_Form_Field' ) ) {
class BWFAN_Rule_Breakdance_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'breakdance_form_field' );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-breakdance_form_submit_form_id'] ) ? $meta['bwfan-breakdance_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_Breakdance_Form_Submit $ins */
$ins = BWFAN_Breakdance_Form_Submit::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['fields'] ) ? $automation_data['global']['fields'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
if ( 'is_blank' === $type ) {
return $this->return_is_match( empty( $value[0] ), $rule_data );
}
if ( 'is_not_blank' === $type ) {
return $this->return_is_match( ! empty( $value[0] ), $rule_data );
}
/** Sanitize email if the key matches an email field */
if ( 'email' === $key ) {
$value = sanitize_email( $value );
}
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
}
}
}

View File

@@ -0,0 +1,396 @@
<?php
class BWFAN_Rule_Contact_Field extends BWFAN_Rule_Base {
public $slug = null;
public $type = null;
public function __construct( $slug = '', $type = '' ) {
$this->v1 = false;
$this->v2 = true;
$this->slug = $slug;
$this->type = $type;
parent::__construct( $slug );
}
/**
* @param $search
*
* @return array|string[]
*/
public function get_options( $search = '' ) {
$allowed_types = [ 4, 5 ];
$field_id = str_replace( 'bwf_contact_field_f', '', $this->slug );
$field = BWFAN_Model_Fields::get_field_by_id( $field_id );
/** If no option found */
if ( empty( $field ) || ! isset( $field['meta'] ) || ! is_object( $field['meta'] ) || ! property_exists( $field['meta'], 'options' ) ) {
return [];
}
if ( in_array( absint( $this->type ), $allowed_types ) ) {
/** For radio and dropdown field */
return $this->get_formatted_options( $field['meta']->options );
} elseif ( 6 === absint( $this->type ) ) {
/** For checkbox field */
$options = BWFAN_PRO_Common::search_srting_from_data( $field['meta']->options, $search );
return $this->get_formatted_options( $options );
}
return [];
}
public function get_formatted_options( $options ) {
if ( empty( $options ) || ! is_array( $options ) ) {
return [];
}
$formatted = [ '' => 'Select' ];
foreach ( $options as $option ) {
$formatted[ $option ] = $option;
}
return $formatted;
}
public function get_rule_type() {
$allowed_types = [ 4, 5 ];
if ( in_array( absint( $this->type ), $allowed_types, false ) ) {
return 'Select';
} elseif ( 6 === absint( $this->type ) ) {
return 'Search';
} elseif ( 7 === absint( $this->type ) ) {
return 'Date';
} elseif ( 8 === absint( $this->type ) ) {
return 'datetime';
} elseif ( 9 === absint( $this->type ) ) {
return 'time';
}
return 'Text';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$key = '';
$field = [];
$is_date_field = false;
$is_datetime_field = false;
$is_time_field = false;
$filter = isset( $rule_data['filter'] ) ? $rule_data['filter'] : '';
$field_id = ! empty( $filter ) ? str_replace( 'bwf_contact_field_f', '', $filter ) : 0;
if ( $field_id > 0 ) {
$field = BWFAN_Model_Fields::get_field_by_id( $field_id );
$key = isset( $field['slug'] ) ? $field['slug'] : '';
$is_date_field = ( BWFCRM_Fields::$TYPE_DATE === intval( $field['type'] ) );
$is_datetime_field = ( property_exists( 'BWFCRM_Fields', 'TYPE_DATETIME' ) && BWFCRM_Fields::$TYPE_DATETIME === intval( $field['type'] ) );
$is_time_field = ( property_exists( 'BWFCRM_Fields', 'TYPE_TIME' ) && BWFCRM_Fields::$TYPE_TIME === intval( $field['type'] ) );
}
$operator = $rule_data['rule'];
$value = $this->get_possible_v2_value( $key, $field, $automation_data );
/** If operator is is_blank or is_not_blank then return after value check */
if ( 'is_blank' === $operator || 'is_not_blank' === $operator ) {
return $this->return_is_match(
( 'is_blank' === $operator && empty( $value ) )
|| ( 'is_not_blank' === $operator && ! empty( $value ) ),
$rule_data
);
}
/** If field type is checkbox */
if ( ! empty( $field ) && isset( $field['type'] ) && BWFCRM_Fields::$TYPE_CHECKBOX === intval( $field['type'] ) && is_array( $rule_data['data'] ) ) {
$rule_values = array_column( $rule_data['data'], 'key' );
return $this->return_is_match( $this->validate_set( $rule_values, $value, $operator ), $rule_data );
}
/** Check if the field type is text or textarea and don't explode them */
$value = ! empty( $field ) && isset( $field['type'] ) && in_array( intval( $field['type'] ), array(
BWFCRM_Fields::$TYPE_TEXT,
BWFCRM_Fields::$TYPE_TEXTAREA
), true ) ? array( $value ) : BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
/** Between case */
if ( 'between' === $operator && is_array( $rule_data['data'] ) ) {
$value = isset( $value[0] ) && ! empty( $value[0] ) ? strtotime( $value[0] ) : '';
$from = strtotime( $rule_data['data']['from'] );
$to = strtotime( $rule_data['data']['to'] );
$result = ( ( $value >= $from ) && ( $value <= $to ) );
return $this->return_is_match( $result, $rule_data );
}
$condition_value = is_array( $rule_data['data'] ) ? $rule_data['data'] : strtolower( trim( $rule_data['data'] ) );
if ( in_array( $operator, [ 'is', 'isnot', 'is_not' ] ) ) {
switch ( $operator ) {
case 'is':
if ( true === $is_date_field ) {
$value = ! empty( $value[0] ) ? strtotime( $value[0] ) : '';
$condition_value = DateTime::createFromFormat( 'm/d/Y', trim( $rule_data['data'] ) )->format( 'Y-m-d' );
$result = ( $value === strtotime( $condition_value ) );
break;
}
$result = in_array( $condition_value, $value );
break;
case 'isnot':
case 'is_not':
$result = ! in_array( $condition_value, $value );
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** If the field type is datetime or time */
if ( true === $is_datetime_field || true === $is_time_field ) {
$format = strpos( $rule_data['data'], 'T' ) ? 'Y-m-d\TH:i:s' : 'Y-m-d H:i:s';
$format = true === $is_time_field ? 'H:i' : $format;
// Convert the contact field time into the correct format for comparison
$contact_time = new DateTime( $value[0] );
$contact_time = $contact_time->format( $format );
// Use common method to check if they match based on the operator
$result = BWFAN_DateTime_Rule_Common::is_match( $operator, $contact_time, $rule_data['data'] );
return $this->return_is_match( $result, $rule_data );
}
$value = is_array( $value ) ? $value[0] : '';
$result = false;
switch ( $operator ) {
case 'contains':
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$length = strlen( $condition_value );
$result = ( 0 === $length ) || ( substr( $value, - $length ) === $condition_value );
break;
case 'lessthan':
$result = ( $value < $condition_value );
break;
case 'morethan':
$result = ( $value > $condition_value );
break;
case 'before':
$value = ! empty( $value ) ? strtotime( $value ) : '';
$result = ( $value < strtotime( $condition_value ) );
break;
case 'after':
$value = ! empty( $value ) ? strtotime( $value ) : '';
$result = ( $value > strtotime( $condition_value ) );
break;
case 'is_blank':
$result = empty( $value );
break;
case 'is_not_blank':
$result = ! empty( $value );
break;
default:
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function validate_set( $options, $found_options, $operator ) {
if ( ! is_array( $found_options ) ) {
return false;
}
switch ( $operator ) {
case 'any':
$result = count( array_intersect( $options, $found_options ) ) > 0;
break;
case 'has':
$result = count( array_intersect( $options, $found_options ) ) === count( $options );
break;
case 'hasnot':
$result = count( array_intersect( $options, $found_options ) ) === 0;
break;
default:
$result = false;
break;
}
return $result;
}
public function get_possible_v2_value( $key, $field, $automation_data = [] ) {
$email = isset( $automation_data['global']['email'] ) ? $automation_data['global']['email'] : '';
if ( 'email' === $key && is_email( $email ) ) {
return $email;
}
$abandoned_data = isset( $automation_data['global']['abandoned_data'] ) ? $automation_data['global']['abandoned_data'] : [];
$user_id = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
$contact = '';
/** Get Contact if contact ID is available */
$contact_id = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( ! empty( $contact_id ) ) {
$contact = new WooFunnels_Contact( '', '', '', absint( $contact_id ) );
}
if ( ! $contact instanceof WooFunnels_Contact || 0 === absint( $contact->get_id() ) ) {
if ( ! is_email( $email ) && class_exists( 'WooCommerce' ) ) {
$order_id = isset( $automation_data['global']['order_id'] ) ? $automation_data['global']['order_id'] : 0;
$order = wc_get_order( $order_id );
$email = $order instanceof WC_Order ? $order->get_billing_email() : false;
}
/** get email from the user id */
if ( ! empty( $user_id ) && ! is_email( $email ) ) {
$user_data = get_userdata( $user_id );
$email = $user_data instanceof WP_User ? $user_data->user_email : false;
}
/** check with cart abandoned email */
if ( ! is_email( $email ) ) {
$email = isset( $abandoned_data['email'] ) ? $abandoned_data['email'] : false;
}
if ( ! is_email( $email ) ) {
return false;
}
$contact = new WooFunnels_Contact( '', $email );
if ( 0 === intval( $contact->get_id() ) ) {
$contact = new WooFunnels_Contact( $user_id );
}
}
if ( ! $contact instanceof WooFunnels_Contact || empty( $contact->get_id() ) ) {
return '';
}
if ( method_exists( $contact, 'get_' . $key ) ) {
$value = $contact->{'get_' . $key}();
} else {
$contact = new BWFCRM_Contact( $contact );
$value = $contact->get_field_by_slug( $key );
}
/** If field type is not checkbox then no need to decode */
if ( isset( $field['type'] ) && BWFCRM_Fields::$TYPE_CHECKBOX !== intval( $field['type'] ) ) {
return $value;
}
/** Check if the string is JSON */
$json_decoded_value = json_decode( $value, true );
if ( ! empty( $json_decoded_value ) ) {
$value = $json_decoded_value;
}
return $value;
}
public function get_possible_rule_operators() {
$operators = [];
switch ( true ) {
case ( BWFCRM_Fields::$TYPE_TEXT === absint( $this->type ) || BWFCRM_Fields::$TYPE_TEXTAREA === absint( $this->type ) ):
$operators = $this->get_possible_text_operators();
break;
case ( BWFCRM_Fields::$TYPE_SELECT === absint( $this->type ) || BWFCRM_Fields::$TYPE_RADIO === absint( $this->type ) ):
$operators = $this->get_possible_radio_operators();
break;
case ( BWFCRM_Fields::$TYPE_NUMBER === absint( $this->type ) ) :
$operators = $this->get_possible_number_operators();
break;
case ( BWFCRM_Fields::$TYPE_CHECKBOX === absint( $this->type ) ) :
$operators = $this->get_possible_checkbox_operators();
break;
case ( BWFCRM_Fields::$TYPE_DATE === absint( $this->type ) ):
$operators = $this->get_possible_date_operators();
break;
case ( property_exists( 'BWFCRM_Fields', 'TYPE_DATETIME' ) && in_array( intval( $this->type ), [ BWFCRM_Fields::$TYPE_TIME, BWFCRM_Fields::$TYPE_DATETIME ], true ) ) :
$operators = $this->get_possible_time_operators();
break;
}
return $operators;
}
public function get_possible_text_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contains', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'start with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'end with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_radio_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'isnot' => __( 'is not', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_date_operators() {
return array(
'before' => __( 'Before', 'wp-marketing-automations-pro' ),
'after' => __( 'After', 'wp-marketing-automations-pro' ),
'is' => __( 'On', 'wp-marketing-automations-pro' ),
'between' => __( 'Between', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_time_operators() {
return array(
'==' => __( 'is', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not', 'wp-marketing-automations-pro' ),
'>' => __( 'is after', 'wp-marketing-automations-pro' ),
'<' => __( 'is before', 'wp-marketing-automations-pro' ),
'>=' => __( 'is on or after', 'wp-marketing-automations-pro' ),
'<=' => __( 'is on or before', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_number_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'isnot' => __( 'is not', 'wp-marketing-automations-pro' ),
'lessthan' => __( 'Less Than', 'wp-marketing-automations-pro' ),
'morethan' => __( 'More Than', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_checkbox_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'hasnot' => __( 'matches none of', 'wp-marketing-automations-pro' ),
'has' => __( 'matches all of', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,342 @@
<?php
class BWFAN_DateTime_Rule_Common {
public static function is_match( $operator, $value, $selected_value ) {
if ( empty( $operator ) ) {
return false;
}
switch ( $operator ) {
case '==':
$result = $value === $selected_value;
break;
case '!=':
$result = $value !== $selected_value;
break;
case '>':
$result = $value > $selected_value;
break;
case '<':
$result = $value < $selected_value;
break;
case '>=':
$result = $value >= $selected_value;
break;
case '<=':
$result = $value <= $selected_value;
break;
default:
$result = false;
break;
}
return $result;
}
}
class BWFAN_Rule_Current_Year extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'current_year' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values();
}
public function get_rule_type() {
return 'Select';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$current_year = date_i18n( 'Y' );
$selected_year = $rule_data['data'];
$result = BWFAN_DateTime_Rule_Common::is_match( $rule_data['rule'], $current_year, $selected_year );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'==' => __( 'is', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not', 'wp-marketing-automations-pro' ),
'>' => __( 'is after', 'wp-marketing-automations-pro' ),
'<' => __( 'is before', 'wp-marketing-automations-pro' ),
'>=' => __( 'is on or after', 'wp-marketing-automations-pro' ),
'<=' => __( 'is on or before', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_rule_values() {
$years = array();
$current_year = date_i18n( 'Y' );
$end_year = intval( $current_year ) + 25;
for ( $year = $current_year; $year <= $end_year; $year ++ ) {
$localized_year = date_i18n( 'Y', strtotime( $year . '-01-01' ) );
$years[ $year ] = $localized_year;
}
return $years;
}
}
class BWFAN_Rule_Current_Month extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'current_month' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values();
}
public function get_rule_type() {
return 'Select';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
if ( ! isset( $rule_data['data'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$current_month = intval( date_i18n( 'n' ) );
$selected_month = intval( $rule_data['data'] );
$result = BWFAN_DateTime_Rule_Common::is_match( $rule_data['rule'], $current_month, $selected_month );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'==' => __( 'is', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not', 'wp-marketing-automations-pro' ),
'>' => __( 'is after', 'wp-marketing-automations-pro' ),
'<' => __( 'is before', 'wp-marketing-automations-pro' ),
'>=' => __( 'is on or after', 'wp-marketing-automations-pro' ),
'<=' => __( 'is on or before', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_rule_values() {
$months = range( 1, 12 );
$localized_months = array_map( function ( $month ) {
return date_i18n( 'F', mktime( 0, 0, 0, $month, 1 ) );
}, $months );
return array_combine( $months, $localized_months );
}
}
class BWFAN_Rule_Current_Day_Of_Month extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'current_day_of_month' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values();
}
public function get_rule_type() {
return 'Select';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
if ( ! isset( $rule_data['data'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$current_day = intval( date_i18n( 'j' ) );
$selected_day = intval( $rule_data['data'] );
$result = BWFAN_DateTime_Rule_Common::is_match( $rule_data['rule'], $current_day, $selected_day );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'==' => __( 'is', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not', 'wp-marketing-automations-pro' ),
'>' => __( 'is after', 'wp-marketing-automations-pro' ),
'<' => __( 'is before', 'wp-marketing-automations-pro' ),
'>=' => __( 'is on or after', 'wp-marketing-automations-pro' ),
'<=' => __( 'is on or before', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_rule_values() {
$days = range( 1, 31 );
$day_array = array_combine( $days, $days );
return $day_array;
}
}
class BWFAN_Rule_Current_Day_Of_Week extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'current_day_of_week' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values();
}
public function get_rule_type() {
return 'Select';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$current_day_of_week = date( 'l' );
$selected_day_of_week = $rule_data['data'];
$result = BWFAN_DateTime_Rule_Common::is_match( $rule_data['rule'], $current_day_of_week, $selected_day_of_week );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'==' => __( 'is', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_rule_values() {
$days_of_week = array(
'Sunday' => __( 'Sunday', 'wp-marketing-automations-pro' ),
'Monday' => __( 'Monday', 'wp-marketing-automations-pro' ),
'Tuesday' => __( 'Tuesday', 'wp-marketing-automations-pro' ),
'Wednesday' => __( 'Wednesday', 'wp-marketing-automations-pro' ),
'Thursday' => __( 'Thursday', 'wp-marketing-automations-pro' ),
'Friday' => __( 'Friday', 'wp-marketing-automations-pro' ),
'Saturday' => __( 'Saturday', 'wp-marketing-automations-pro' )
);
return $days_of_week;
}
}
class BWFAN_Rule_Current_Time extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'current_time' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'time';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
if ( empty( $rule_data['data'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$current_time = strtotime( date_i18n( 'H:i' ) );
$selected_time = strtotime( $rule_data['data'] );
$result = BWFAN_DateTime_Rule_Common::is_match( $rule_data['rule'], $current_time, $selected_time );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'==' => __( 'is', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not', 'wp-marketing-automations-pro' ),
'>' => __( 'is after', 'wp-marketing-automations-pro' ),
'<' => __( 'is before', 'wp-marketing-automations-pro' ),
'>=' => __( 'is on or after', 'wp-marketing-automations-pro' ),
'<=' => __( 'is on or before', 'wp-marketing-automations-pro' )
);
}
}
class BWFAN_Rule_Current_Date_Time extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'current_date_time' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'datetime';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
if ( empty( $rule_data['data'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$current_datetime = date_i18n( 'Y-m-d\TH:i' );
$datetime = new DateTime( $rule_data['data'] );
$selected_datetime = $datetime->format( 'Y-m-d\TH:i' );
$result = BWFAN_DateTime_Rule_Common::is_match( $rule_data['rule'], $current_datetime, $selected_datetime );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'==' => __( 'is', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not', 'wp-marketing-automations-pro' ),
'>' => __( 'is after', 'wp-marketing-automations-pro' ),
'<' => __( 'is before', 'wp-marketing-automations-pro' ),
'>=' => __( 'is on or after', 'wp-marketing-automations-pro' ),
'<=' => __( 'is on or before', 'wp-marketing-automations-pro' )
);
}
}

View File

@@ -0,0 +1,274 @@
<?php
class BWFAN_Rule_Credit_Amount extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
parent::__construct( 'credit_amount' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Number';
}
/** v2 Methods: START */
public function is_match_v2( $automation_data, $rule_data ) {
$total_credits = isset( $automation_data['global']['amount'] ) ? $automation_data['global']['amount'] : null;
$value = (float) $rule_data['data'];
/** If total credits amount is set using Adv coupons events */
if ( ! is_null( $total_credits ) ) {
$result = $this->quick_match( $total_credits, $value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
/** If user id */
$user_id = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : '';
if ( ! empty( $user_id ) ) {
$total_credits = BWFAN_ADV_Coupon_Source::fetch_user_total_credit( $user_id );
$result = $this->quick_match( $total_credits, $value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
/** If CID */
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : '';
if ( ! empty( $cid ) ) {
$contact = new BWFCRM_Contact( $cid );
if ( $contact instanceof BWFCRM_Contact && $contact->is_contact_exists() && ! empty( $contact->contact->get_wpid() ) ) {
$total_credits = BWFAN_ADV_Coupon_Source::fetch_user_total_credit( $contact->contact->get_wpid() );
$result = $this->quick_match( $total_credits, $value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
}
/** If email */
$email = isset( $automation_data['global']['email'] ) ? $automation_data['global']['email'] : '';
if ( ! empty( $email ) && is_email( $email ) ) {
$user = get_user_by( 'email', $email );
if ( $user instanceof WP_USER ) {
$total_credits = BWFAN_ADV_Coupon_Source::fetch_user_total_credit( $user->ID );
$result = $this->quick_match( $total_credits, $value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
}
/** WC order cases */
$order_id = isset( $automation_data['global']['order_id'] ) ? $automation_data['global']['order_id'] : '';
if ( empty( $order_id ) ) {
return $this->return_is_match( 0, $rule_data );
}
$order = wc_get_order( $order_id );
if ( ! $order instanceof WC_Order ) {
return $this->return_is_match( 0, $rule_data );
}
$user_id = $order->get_user_id();
if ( ! empty( $user_id ) ) {
$total_credits = BWFAN_ADV_Coupon_Source::fetch_user_total_credit( $user_id );
$result = $this->quick_match( $total_credits, $value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
$email = $order->get_billing_email();
if ( ! empty( $email ) ) {
$user = get_user_by( 'email', $email );
if ( $user instanceof WP_USER ) {
$total_credits = BWFAN_ADV_Coupon_Source::fetch_user_total_credit( $user_id );
$result = $this->quick_match( $total_credits, $value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
}
return $this->return_is_match( 0, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
}
protected function quick_match( $amount, $value, $operator ) {
$amount = empty( $amount ) ? 0 : $amount;
$amount = (float) $amount;
$result = false;
switch ( $operator ) {
case '==':
$result = $amount === $value;
break;
case '!=':
$result = $amount !== $value;
break;
case '>':
$result = $amount > $value;
break;
case '<':
$result = $amount < $value;
break;
case '>=':
$result = $amount >= $value;
break;
case '<=':
$result = $amount <= $value;
break;
default:
break;
}
return $result;
}
}
if ( bwfan_is_loyalty_program_for_woocommerce_active() ) {
class BWFAN_Rule_Loyalty_Points extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
parent::__construct( 'loyalty_points' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Number';
}
/** v2 Methods: START */
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$saved_value = (float) $rule_data['data'];
/** If user id */
$user_id = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
if ( ! empty( $user_id ) ) {
$result = $this->quick_match( $user_id, $saved_value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
/** If CID */
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : '';
if ( ! empty( $cid ) ) {
$contact = new BWFCRM_Contact( $cid );
if ( $contact instanceof BWFCRM_Contact && $contact->is_contact_exists() && ! empty( $contact->contact->get_wpid() ) ) {
$result = $this->quick_match( $contact->contact->get_wpid(), $saved_value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
}
/** If email */
$email = isset( $automation_data['global']['email'] ) ? $automation_data['global']['email'] : '';
if ( ! empty( $email ) && is_email( $email ) ) {
$user = get_user_by( 'email', $email );
if ( $user instanceof WP_USER ) {
$result = $this->quick_match( $user->ID, $saved_value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
}
/** WC order cases */
$order_id = isset( $automation_data['global']['order_id'] ) ? $automation_data['global']['order_id'] : '';
if ( empty( $order_id ) ) {
return $this->return_is_match( 0, $rule_data );
}
$order = wc_get_order( $order_id );
if ( ! $order instanceof WC_Order ) {
return $this->return_is_match( 0, $rule_data );
}
$user_id = $order->get_user_id();
if ( ! empty( $user_id ) ) {
$result = $this->quick_match( $user_id, $saved_value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
$email = $order->get_billing_email();
if ( ! empty( $email ) ) {
$user = get_user_by( 'email', $email );
if ( $user instanceof WP_USER ) {
$result = $this->quick_match( $user->ID, $saved_value, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
}
return $this->return_is_match( 0, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
}
protected function quick_match( $user_id, $value, $operator ) {
if ( empty( $user_id ) ) {
return false;
}
$points = get_user_meta( $user_id, '_acfw_loyalprog_user_total_points', true );
$points = (float) $points;
$result = false;
switch ( $operator ) {
case '==':
$result = $points === $value;
break;
case '!=':
$result = $points !== $value;
break;
case '>':
$result = $points > $value;
break;
case '<':
$result = $points < $value;
break;
case '>=':
$result = $points >= $value;
break;
case '<=':
$result = $points <= $value;
break;
default:
break;
}
return $result;
}
}
}

View File

@@ -0,0 +1,195 @@
<?php
if ( bwfan_is_woocommerce_active() && bwfan_is_ti_wc_wishlist_active() ) {
class BWFAN_Rule_Ti_Wc_wishlist_Item extends BWFAN_Rule_Products {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'ti_wc_wishlist_item' );
}
/**
* Common function for v1 and v2 to define the rule operators
* @return array
*/
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'all' => __( 'matches all of ', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
}
/**
* @param $term
*
* Getting the field options for the view
*
* @return array
*/
public function get_options( $term = '' ) {
return $this->get_search_results( $term, true );
}
public function get_rule_type() {
return 'Search';
}
/**
* @param $automation_data
* @param $rule_data
*
* Processing the conditions for v2
*
* @return bool
*/
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$data = $rule_data['data'];
if ( ! is_array( $data ) && empty( $data ) ) {
return false;
}
$wishlist_id = isset( $automation_data['global']['wishlist_id'] ) ? $automation_data['global']['wishlist_id'] : '';
if ( empty( $wishlist_id ) ) {
return $this->return_is_match( false, $rule_data );
}
// Fetch wishlist data using the function
$wishlist_data = BWFAN_PRO_Common::get_ti_wc_wishlist_data_by_id( $wishlist_id );
if ( ! $wishlist_data ) {
return $this->return_is_match( false, $rule_data );
}
$wishlist_product = isset( $wishlist_data['product_ids'] ) ? $wishlist_data['product_ids'] : [];
if ( empty( $wishlist_product ) ) {
return $this->return_is_match( false, $rule_data );
}
$saved_ids = array_column( $rule_data['data'], 'key' );
$result = $this->validate_set( $saved_ids, $wishlist_product, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
public function validate_set( $saved_products, $product_found, $operator ) {
$result = false;
switch ( $operator ) {
case 'any':
$result = count( array_intersect( $saved_products, $product_found ) ) > 0;
break;
case 'all':
$result = count( array_intersect( $saved_products, $product_found ) ) === count( $saved_products );
break;
case 'none':
$result = count( array_intersect( $saved_products, $product_found ) ) === 0;
break;
}
return $result;
}
}
class BWFAN_Rule_Ti_Wc_wishlist_Item_Count extends BWFAN_Rule_Products {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'ti_wc_wishlist_item_count' );
}
/**
* Common function for v1 and v2 to define the rule operators
* @return array
*/
public function get_possible_rule_operators() {
return array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'is greater or equal to', 'wp-marketing-automations-pro' ),
'<=' => __( 'is less or equal to', 'wp-marketing-automations-pro' ),
);
}
/**
* @param $term
*
* Getting the field options for the view
*
* @return array
*/
public function get_options( $term = '' ) {
return $this->get_search_results( $term, true );
}
public function get_rule_type() {
return 'Number';
}
/**
* @param $automation_data
* @param $rule_data
*
* Processing the conditions for v2
*
* @return bool
*/
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$data = $rule_data['data'];
if ( ! is_array( $data ) && empty( $data ) ) {
return false;
}
$wishlist_id = isset( $automation_data['global']['wishlist_id'] ) ? $automation_data['global']['wishlist_id'] : '';
if ( empty( $wishlist_id ) ) {
return $this->return_is_match( false, $rule_data );
}
$wishlist_data = BWFAN_PRO_Common::get_ti_wc_wishlist_data_by_id( $wishlist_id );
if ( ! $wishlist_data ) {
return $this->return_is_match( false, $rule_data );
}
$product_ids = isset( $wishlist_data['product_ids'] ) ? $wishlist_data['product_ids'] : [];
$count = is_array( $product_ids ) ? count( $product_ids ) : 0;
$value = absint( $rule_data['data'] );
switch ( $rule_data['rule'] ) {
case '==':
$result = $count === $value;
break;
case '!=':
$result = $count !== $value;
break;
case '>':
$result = $count > $value;
break;
case '<':
$result = $count < $value;
break;
case '>=':
$result = $count >= $value;
break;
case '<=':
$result = $count <= $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function get_condition_input_type() {
return 'Text';
}
}
}

View File

@@ -0,0 +1,103 @@
<?php
if ( bwfan_is_woocommerce_active() && bwfan_is_yith_wishlist_active() ) {
class BWFAN_Rule_Yith_wishlist_Item extends BWFAN_Rule_Products {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'yith_wishlist_item' );
}
/**
* common function for v1 and v2 to define the rule operators
* @return array
*/
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'all' => __( 'matches all of ', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
}
/**
* @param $term
*
* getting the field options for the view
*
* @return array
*/
public function get_options( $term = '' ) {
return $this->get_search_results( $term, true );
}
public function get_rule_type() {
return 'Search';
}
/**
* @param $automation_data
* @param $rule_data
*
* processing the conditions for v2
*
* @return bool
*/
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$data = $rule_data['data'];
if ( ! is_array( $data ) && empty( $data ) ) {
return false;
}
$wishlist_id = isset( $automation_data['global']['wishlist_id'] ) ? $automation_data['global']['wishlist_id'] : '';
if ( empty( $wishlist_id ) ) {
return $this->return_is_match( false, $rule_data );
}
global $wpdb;
$table_name = $wpdb->prefix . 'yith_wcwl';
$query = $wpdb->prepare( "SELECT * FROM $table_name WHERE wishlist_id = %d", $wishlist_id );
$wishlist_items = $wpdb->get_results( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $wishlist_items ) ) {
return $this->return_is_match( false, $rule_data );
}
$wishlist_product = array_map( function ( $item ) {
return $item->prod_id;
}, $wishlist_items );
if ( empty( $wishlist_product ) ) {
return $this->return_is_match( false, $rule_data );
}
$saved_ids = array_column( $rule_data['data'], 'key' );
$result = $this->validate_set( $saved_ids, $wishlist_product, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
public function validate_set( $saved_products, $product_found, $operator ) {
$result = false;
/** Get product ids with parent */
switch ( $operator ) {
case 'any':
$result = count( array_intersect( $saved_products, $product_found ) ) > 0;
break;
case 'all':
$result = count( array_intersect( $saved_products, $product_found ) ) === count( $saved_products );
break;
case 'none':
$result = count( array_intersect( $saved_products, $product_found ) ) === 0;
break;
}
return $result;
}
}
}

View File

@@ -0,0 +1,171 @@
<?php
if ( bwfan_is_caldera_forms_active() ) {
class BWFAN_Rule_Caldera_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'caldera_form_field' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-caldera_form_submit_form_id'] ) ? $meta['bwfan-caldera_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_Caldera_Form_Submit $ins */
$ins = BWFAN_Caldera_Form_Submit::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['fields'] ) ? $automation_data['global']['fields'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( $saved_value );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
public function conditions_view() {
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => 'select',
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][key]',
'choices' => $values,
'class' => 'bwfan_field_one_half bwfan_caldera_form_fields',
'placeholder' => __( 'Field', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][value]',
'choices' => $values,
'class' => 'bwfan_field_one_half',
'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$fields = BWFAN_Core()->rules->getRulesData( 'fields' );
$type = $rule_data['operator'];
$value = isset( $fields[ $rule_data['condition']['key'] ] ) ? $fields[ $rule_data['condition']['key'] ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $rule_data['condition']['value'] ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
switch ( $type ) {
case 'is':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) > 0;
} else {
$result = in_array( $condition_value, $value );
}
break;
case 'is_not':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) === 0;
} else {
$result = ! in_array( $condition_value, $value );
}
break;
case 'contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
if ( 0 === $length ) {
$result = true;
} else {
$result = substr( $value, - $length ) === $condition_value;
}
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Form Field
'<%= bwfan_events_js_data["caldera_form_submit"]["selected_form_fields"][condition['key']] %>' <% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> '<%= condition['value'] %>'
<?php
}
}
}

View File

@@ -0,0 +1,101 @@
<?php
if ( function_exists( 'bwfan_is_divi_forms_active' ) && bwfan_is_divi_forms_active() ) {
class BWFAN_Rule_Divi_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'divi_form_field' );
}
/**
* common function for v1 and v2 to define the rule operators
* @return array
*/
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
/** v2 Methods: START */
/**
* @param $term
*
* getting the field options for the view
*
* @return array
*/
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-divi_form_submit_form_id'] ) ? $meta['bwfan-divi_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
if ( ! isset( BWFAN_Divi_Forms_Common::extract_forms_and_fields()[ $form_id ] ) ) {
return array();
}
/** @var BWFAN_Divi_Form_Submit $ins */
$ins = BWFAN_Divi_Form_Submit::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
/**
* @param $automation_data
* @param $rule_data
*
* processing the conditions for v2
*
* @return bool
*/
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['entry'] ) ? $automation_data['global']['entry'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', array_map( 'trim', $value ) );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
}
}

View File

@@ -0,0 +1,196 @@
<?php
if ( bwfan_is_elementorpro_active() ) {
class BWFAN_Rule_Elementor_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'elementor_form_field' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$page_id = isset( $meta['elementor_popup_submit_page_id'] ) ? $meta['elementor_popup_submit_page_id'] : 0;
$form_id = isset( $meta['elementor_submit_form_id'] ) ? $meta['elementor_submit_form_id'] : 0;
$form_id = empty( $form_id ) && isset( $meta['elementor_popup_submit_form_id'] ) ? $meta['elementor_popup_submit_form_id'] : $form_id;
/** @var BWFAN_Elementor_Form_Submit $ins */
$ins = BWFAN_Elementor_Form_Submit::get_instance();
$fields = $ins->get_form_fields( $form_id, $page_id );
if ( empty( $fields ) ) {
return [];
}
$formatted_fields = [];
foreach ( $fields[ $form_id ] as $field ) {
$formatted_fields[ $field['field_slug'] ] = $field['field_label'];
}
return $formatted_fields;
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['entry'] ) ? $automation_data['global']['entry'] : [];
$form_id = isset( $automation_data['global']['form_id'] ) ? $automation_data['global']['form_id'] : '';
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
/**
* handling for popup form submit
*/
if ( 'elementor_popup_form_submit' === $automation_data['event_data']['event_slug'] ) {
$field_slugs = empty( $automation_data['global']['fields'][ $form_id ] ) ? [] : array_column( $automation_data['global']['fields'][ $form_id ], 'field_slug' );
$key_index = array_search( $key, $field_slugs );
$value = ( false !== $key_index && isset( $entry[ $key ] ) ) ? $entry[ $key ] : $value;
}
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', array_map( 'trim', $value ) );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
public function conditions_view() {
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => 'select',
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][key]',
'choices' => $values,
'class' => 'bwfan_field_one_half bwfan_elementor_form_fields',
'placeholder' => __( 'Field', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][value]',
'choices' => $values,
'class' => 'bwfan_field_one_half',
'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$entry = BWFAN_Core()->rules->getRulesData( 'entry' );
$type = $rule_data['operator'];
$value = isset( $entry[ $rule_data['condition']['key'] ] ) ? $entry[ $rule_data['condition']['key'] ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $rule_data['condition']['value'] ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
switch ( $type ) {
case 'is':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) > 0;
} else {
$result = in_array( $condition_value, $value );
}
break;
case 'is_not':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) === 0;
} else {
$result = ! in_array( $condition_value, $value );
}
break;
case 'contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
if ( 0 === $length ) {
$result = true;
} else {
$result = substr( $value, - $length ) === $condition_value;
}
break;
case 'is_blank':
$result = empty( $value[0] );
break;
case 'is_not_blank':
$result = ! empty( $value[0] );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Form Field
<% var event = (_.has(BWFAN_Auto, 'uiDataDetail') && _.has(BWFAN_Auto.uiDataDetail, 'trigger') && _.has(BWFAN_Auto.uiDataDetail.trigger, 'event')) ? BWFAN_Auto.uiDataDetail.trigger.event : ''; %>
'<%= bwfan_events_js_data[event]["selected_form_fields"][condition['key']] %>' <% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> '<%= condition['value'] %>'
<?php
}
}
}

View File

@@ -0,0 +1,749 @@
<?php
class BWFAN_Rule_Link_Trigger_Clicked extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
parent::__construct( 'link_trigger_clicked' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_search_results( $term, true );
}
public function get_search_results( $term, $v2 = false ) {
$link_triggers = BWFAN_Model_Link_Triggers::get_link_triggers( $term );
if ( $v2 ) {
$return = array();
foreach ( $link_triggers['links'] as $link ) {
$return[ $link['ID'] ] = $link['title'];
}
return $return;
}
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
$result = ( 'none' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
$result = ( 'none' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$link_cliked = $contact->get_field_by_slug( 'link-trigger-click' ) ? json_decode( $contact->get_field_by_slug( 'link-trigger-click' ) ) : array();
if ( empty( $link_cliked ) ) {
$result = ( 'none' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$link_cliked = array_values( $link_cliked );
$selected_link = array_map( function ( $link ) {
return $link['key'];
}, $rule_data['data'] );
$type = $rule_data['rule'];
$result = $this->validate_matches_set( $selected_link, $link_cliked, $type );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'any' => __( 'Matches any of', 'wp-marketing-automations-pro' ),
'none' => __( 'Matches none of', 'wp-marketing-automations-pro' ),
'all' => __( 'Matches all of', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Last_Login extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
parent::__construct( 'last_login' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Days';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
return $this->return_is_match( $result, $rule_data );
}
$last_login = $contact->get_field_by_slug( 'last-login' ) ? strtotime( $contact->get_field_by_slug( 'last-login' ) ) : '';
if ( empty( $last_login ) ) {
return $this->return_is_match( $result, $rule_data );
}
$type = $rule_data['rule'];
$result = $this->validate_matches_duration_set( $last_login, $rule_data, $type );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'over' => __( 'Before', 'wp-marketing-automations-pro' ),
'past' => __( 'In the last', 'wp-marketing-automations-pro' ),
'between' => __( 'In between', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Last_Open extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
parent::__construct( 'last_open' );
}
public function get_rule_type() {
return 'Days';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
return $this->return_is_match( $result, $rule_data );
}
$last_open = $contact->get_field_by_slug( 'last-open' ) ? strtotime( $contact->get_field_by_slug( 'last-open' ) ) : '';
if ( empty( $last_open ) ) {
return $this->return_is_match( $result, $rule_data );
}
$type = $rule_data['rule'];
$result = $this->validate_matches_duration_set( $last_open, $rule_data, $type );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'over' => __( 'Before', 'wp-marketing-automations-pro' ),
'past' => __( 'In the last', 'wp-marketing-automations-pro' ),
'between' => __( 'In between', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Last_Sent extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
parent::__construct( 'last_sent' );
}
public function get_rule_type() {
return 'Days';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
return $this->return_is_match( false, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
return $this->return_is_match( false, $rule_data );
}
$last_sent = $contact->get_field_by_slug( 'last-sent' ) ? strtotime( $contact->get_field_by_slug( 'last-sent' ) ) : '';
if ( empty( $last_sent ) ) {
return $this->return_is_match( false, $rule_data );
}
$type = $rule_data['rule'];
$result = $this->validate_matches_duration_set( $last_sent, $rule_data, $type );
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'over' => __( 'Before', 'wp-marketing-automations-pro' ),
'past' => __( 'In the last', 'wp-marketing-automations-pro' ),
'between' => __( 'In between', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Last_Clicked extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
parent::__construct( 'last_clicked' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Days';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
return $this->return_is_match( $result, $rule_data );
}
$last_click = $contact->get_field_by_slug( 'last-click' ) ? strtotime( $contact->get_field_by_slug( 'last-click' ) ) : '';
if ( empty( $last_click ) ) {
return $this->return_is_match( $result, $rule_data );
}
$type = $rule_data['rule'];
$result = $this->validate_matches_duration_set( $last_click, $rule_data, $type );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'over' => __( 'Before', 'wp-marketing-automations-pro' ),
'past' => __( 'In the last', 'wp-marketing-automations-pro' ),
'between' => __( 'In between', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Engaged extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
parent::__construct( 'engaged' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Days';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
return $this->return_is_match( $result, $rule_data );
}
$type = $rule_data['rule'];
$current_time = current_time( 'timestamp' );
if ( ! is_array( $rule_data['data'] ) ) {
$data = date( 'Y-m-d', $current_time - ( DAY_IN_SECONDS * absint( $rule_data['data'] ) ) );// excluding time
} else {
$from = absint( $rule_data['data']['from'] );
$date = new DateTime( 'now', wp_timezone() );
$date->modify( "-$from days" );
$from = $date->format( 'Y-m-d' );
$to = absint( $rule_data['data']['to'] );
$date = new DateTime( 'now', wp_timezone() );
$date->modify( "-$to days" );
$to = $date->format( 'Y-m-d' );
}
$filter_rule = '';
switch ( $type ) {
case 'over':
$filter_rule = '<';
break;
case 'past':
$filter_rule = '>=';
break;
case 'between':
$filter_rule = 'between';
break;
default:
break;
}
/** Get Last Sent & Last Open */
$last_sent = BWFAN_Model_Fields::get_field_by_slug( 'last-sent' );
$last_open = BWFAN_Model_Fields::get_field_by_slug( 'last-open' );
$last_click = BWFAN_Model_Fields::get_field_by_slug( 'last-click' );
$last_sent = 'f' . $last_sent['ID'];
$last_open = 'f' . $last_open['ID'];
$last_click = 'f' . $last_click['ID'];
if ( 'between' === $filter_rule ) {
$where = " AND ( cm.$last_sent IS NULL OR ( ( cm.$last_open >= '$to' AND cm.$last_open <= '$from') OR ( cm.$last_click >= '$to' AND cm.$last_click <= '$from') ) )";
} else {
$where = " AND ( cm.$last_sent IS NULL OR ( cm.$last_open $filter_rule '$data' OR cm.$last_click $filter_rule '$data' ) )";
}
$engaged_count = BWFAN_Pro_Common::get_engaged_or_unengaged_data_count( $where, $cid );
if ( ! empty( $engaged_count ) && $engaged_count > 0 ) {
$result = true;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'over' => __( 'Before', 'wp-marketing-automations-pro' ),
'past' => __( 'In the last', 'wp-marketing-automations-pro' ),
'between' => __( 'In between', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Unengaged extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
parent::__construct( 'unengaged' );
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Days';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
return $this->return_is_match( $result, $rule_data );
}
/** Get Last Sent & Last Open */
$last_sent = BWFAN_Model_Fields::get_field_by_slug( 'last-sent' );
$last_open = BWFAN_Model_Fields::get_field_by_slug( 'last-open' );
$last_sent = 'f' . $last_sent['ID'];
$last_open = 'f' . $last_open['ID'];
$current_time = current_time( 'timestamp' );
$data = date( 'Y-m-d', $current_time - ( DAY_IN_SECONDS * absint( $rule_data['data'] ) ) ); // excluding time
$where = " AND ( cm.$last_sent IS NOT NULL AND (cm.$last_open IS NULL OR cm.$last_open < '$data') )";
$unengaged_count = BWFAN_Pro_Common::get_engaged_or_unengaged_data_count( $where, $cid );
if ( ! empty( $unengaged_count ) && $unengaged_count > 0 ) {
$result = true;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'from' => __( 'from', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Broadcast_Sent extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
$this->title = 'Broadcast';
parent::__construct( 'broadcast_sent' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return BWFAN_PRO_Common::get_broadcasts_by_term( $term );
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$data = $rule_data['data'][0]['key'];
$broadcast_sent = BWFAN_PRO_Common::get_contacts_from_broadcast( $data, '' );
if ( empty( $broadcast_sent ) ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$broadcast_sent = array_map( function ( $user_ids ) {
return $user_ids['id'];
}, $broadcast_sent );
$type = $rule_data['rule'];
switch ( $type ) {
case 'is':
$result = in_array( $cid, $broadcast_sent );
break;
case 'isnot':
case 'is_not':
$result = ! in_array( $cid, $broadcast_sent );
break;
default:
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'is' => __( 'is sent', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not sent', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Broadcast_Open extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
$this->title = 'Broadcast';
parent::__construct( 'broadcast_open' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return BWFAN_PRO_Common::get_broadcasts_by_term( $term );
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$data = $rule_data['data'][0]['key'];
$broadcast_open = BWFAN_PRO_Common::get_contacts_from_broadcast( $data, 'open' );
if ( empty( $broadcast_open ) ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$broadcast_open = array_map( function ( $user_ids ) {
return $user_ids['id'];
}, $broadcast_open );
$type = $rule_data['rule'];
switch ( $type ) {
case 'is':
$result = in_array( $cid, $broadcast_open );
break;
case 'isnot':
case 'is_not':
$result = ! in_array( $cid, $broadcast_open );
break;
default:
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'is' => __( 'has opened', 'wp-marketing-automations-pro' ),
'is_not' => __( 'has not opened', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Broadcast_Clicked extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
$this->title = 'Broadcast';
parent::__construct( 'broadcast_clicked' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return BWFAN_PRO_Common::get_broadcasts_by_term( $term );
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$data = $rule_data['data'][0]['key'];
$broadcast_clicked = BWFAN_PRO_Common::get_contacts_from_broadcast( $data, 'click' );
if ( empty( $broadcast_clicked ) ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$broadcast_clicked = array_map( function ( $user_ids ) {
return $user_ids['id'];
}, $broadcast_clicked );
$type = $rule_data['rule'];
switch ( $type ) {
case 'is':
$result = in_array( $cid, $broadcast_clicked );
break;
case 'isnot':
case 'is_not':
$result = ! in_array( $cid, $broadcast_clicked );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'is' => __( 'has clicked', 'wp-marketing-automations-pro' ),
'is_not' => __( 'has not clicked', 'wp-marketing-automations-pro' ),
);
}
}
class BWFAN_Rule_Email_Opens extends BWFAN_Rule_Base {
public function __construct() {
$this->v1 = false;
$this->v2 = true;
$this->title = 'Email';
parent::__construct( 'email_opens' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_search_results( $term );
}
public function get_search_results( $term, $v = 2 ) {
return BWFAN_PRO_Common::get_emails_by_subject_in_data( $term, $v );
}
public function get_rule_type() {
return 'search-list';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$cid = isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : 0;
if ( 0 === absint( $cid ) ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$contact = new BWFCRM_Contact( $cid );
if ( ! $contact->is_contact_exists() ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$step_ids = empty( $rule_data['data'] ) ? [] : array_column( $rule_data['data'], 'id' );
$emails_open = BWFAN_PRO_Common::get_contacts_engagement( $cid, $step_ids, 1, 1 );
if ( ! empty( $emails_open ) ) {
$result = true;
}
$type = $rule_data['rule'];
switch ( $type ) {
case 'is':
break;
case 'is_not':
$result = ! $result;
break;
default:
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'is' => __( 'has opened', 'wp-marketing-automations-pro' ),
'is_not' => __( 'has not opened', 'wp-marketing-automations-pro' ),
);
}
}

View File

@@ -0,0 +1,195 @@
<?php
if ( bwfan_is_fluent_forms_active() ) {
class BWFAN_Rule_Fluent_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'fluent_form_field' );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-fluent_form_submit_form_id'] ) ? $meta['bwfan-fluent_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_Fluent_Form_Submit $ins */
$ins = BWFAN_Fluent_Form_Submit::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['fields'] ) ? $automation_data['global']['fields'] : [];
$names = [ 'names:first_name', 'names:last_name' ];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
if ( in_array( $key, $names, true ) ) {
$fields = explode( ':', $key );
$value = isset( $entry['names'][ $fields[1] ] ) ? $entry['names'][ $fields[1] ] : '';
}
$value = empty( $value ) && isset( $entry[ $key ] ) ? $entry[ $key ] : $value;
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function conditions_view() {
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => 'select',
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][key]',
'choices' => $values,
'class' => 'bwfan_field_one_half bwfan_fluent_form_fields',
'placeholder' => __( 'Field', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][value]',
'choices' => $values,
'class' => 'bwfan_field_one_half',
'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$entry = BWFAN_Core()->rules->getRulesData( 'fields' );
$type = $rule_data['operator'];
$value = isset( $entry[ $rule_data['condition']['key'] ] ) ? $entry[ $rule_data['condition']['key'] ] : '';
$rule_key = $rule_data['condition']['key'];
if ( strpos( $rule_key, ':' ) !== false ) {
$fieldsgroup = explode( ':', $rule_key );
$field_name = $fieldsgroup[1];
$field_group_data = isset( $entry[ $fieldsgroup[0] ] ) ? $entry[ $fieldsgroup[0] ] : array();
$value = isset( $field_group_data[ $field_name ] ) ? $field_group_data[ $field_name ] : '';
}
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $rule_data['condition']['value'] ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
switch ( $type ) {
case 'is':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) > 0;
} else {
$result = in_array( $condition_value, $value );
}
break;
case 'is_not':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) === 0;
} else {
$result = ! in_array( $condition_value, $value );
}
break;
case 'contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
if ( 0 === $length ) {
$result = true;
} else {
$result = substr( $value, - $length ) === $condition_value;
}
break;
case 'is_blank':
$result = empty( $value[0] );
break;
case 'is_not_blank':
$result = ! empty( $value[0] );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Form Field
'<%= bwfan_events_js_data["fluent_form_submit"]["selected_form_fields"][condition['key']] %>' <% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> '<%= condition['value'] %>'
<?php
}
}
}

View File

@@ -0,0 +1,85 @@
<?php
if ( function_exists( 'bwfan_is_forminator_forms_active' ) && bwfan_is_forminator_forms_active() ) {
if ( ! class_exists( 'BWFAN_Rule_Forminator_Form_Field' ) ) {
class BWFAN_Rule_Forminator_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'forminator_form_field' );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$finalarr = [];
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-forminator_form_submit_form_id'] ) ? $meta['bwfan-forminator_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_Forminator_Form_Submit $ins */
$ins = BWFAN_Forminator_Form_Submit::get_instance();
$fields = $ins->get_form_fields( $form_id );
foreach ( $fields as $value ) {
$finalarr[ $value->__get( 'element_id' ) ] = $value->__get( 'field_label' );
}
return $finalarr;
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['entry'] ) ? $automation_data['global']['entry'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
}
}
}

View File

@@ -0,0 +1,72 @@
<?php
class BWFAN_Rule_funnel extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'funnel' );
}
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
}
/** v2 Methods: START */
public function get_rule_type() {
return 'Search';
}
public function get_options( $term = '' ) {
$results = array();
$args = array( 's' => $term );
$funnels = WFFN_Core()->admin->get_funnels( $args );
foreach ( $funnels['items'] as $funnel ) {
$results[ $funnel['id'] ] = $funnel['title'];
}
return $results;
}
public function is_match_v2( $automation_data, $rule_data ) {
$funnel_ids = array();
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$funnel_id = isset( $automation_data['global']['funnel_id'] ) ? $automation_data['global']['funnel_id'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$saved_ids = array_column( $rule_data['data'], 'key' );
$funnel_ids[] = $funnel_id;
$data = $rule_data['data'];
if ( ! is_array( $data ) && empty( $data ) ) {
return false;
}
$result = $this->validate_set( $saved_ids, $funnel_ids, $rule_data['rule'] );
return $this->return_is_match( $result, $rule_data );
}
public function validate_set( $saved_ids, $funnel_ids, $operator ) {
switch ( $operator ) {
case 'any':
$result = count( array_intersect( $saved_ids, $funnel_ids ) ) > 0;
break;
case 'none':
$result = count( array_intersect( $saved_ids, $funnel_ids ) ) === 0;
break;
default:
$result = false;
break;
}
return $result;
}
}

View File

@@ -0,0 +1,181 @@
<?php
if ( bwfan_is_gforms_active() ) {
class BWFAN_Rule_GF_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'gf_form_field' );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-gf_form_submit_form_id'] ) ? $meta['bwfan-gf_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_GF_Form_Submit $ins */
$ins = BWFAN_GF_Form_Submit::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['entry'] ) ? $automation_data['global']['entry'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', array_map( 'trim', $value ) );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: End */
public function conditions_view() {
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => 'select',
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][key]',
'choices' => $values,
'class' => 'bwfan_field_one_half bwfan_gform_form_fields',
'placeholder' => __( 'Field', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][value]',
'choices' => $values,
'class' => 'bwfan_field_one_half',
'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$entry = BWFAN_Core()->rules->getRulesData( 'entry' );
$type = $rule_data['operator'];
$value = isset( $entry[ $rule_data['condition']['key'] ] ) ? $entry[ $rule_data['condition']['key'] ] : '';
$value_json_decoded = json_decode( $value, true );
$value = empty( $value_json_decoded ) ? $value : $value_json_decoded;
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $rule_data['condition']['value'] ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
switch ( $type ) {
case 'is':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) > 0;
} else {
$result = in_array( $condition_value, $value );
}
break;
case 'is_not':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) === 0;
} else {
$result = ! in_array( $condition_value, $value );
}
break;
case 'contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
if ( 0 === $length ) {
$result = true;
} else {
$result = substr( $value, - $length ) === $condition_value;
}
break;
case 'is_blank':
$result = empty( $value[0] );
break;
case 'is_not_blank':
$result = ! empty( $value[0] );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Form Field
'<%= bwfan_events_js_data["gf_form_submit"]["selected_form_fields"][condition['key']] %>' <% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> '<%= condition['value'] %>'
<?php
}
}
}

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.

View File

@@ -0,0 +1,69 @@
<?php
class BWFAN_Rule_Language extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'language' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values();
}
public function get_rule_type() {
return 'Select';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) || ! isset( $automation_data['global']['language'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
$language = $automation_data['global']['language'];
if ( empty( $language ) ) {
$result = ( 'is_not' === $rule_data['rule'] ) ? true : $result;
return $this->return_is_match( $result, $rule_data );
}
$value = strval( $rule_data['data'] );
$language = strval( $language );
switch ( $rule_data['rule'] ) {
case 'is':
$result = $language === $value;
break;
case 'is_not':
$result = $language !== $value;
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_rule_values() {
$lang_options = [];
$language_data = BWFAN_PRO_Common::get_language_settings();
if ( is_array( $language_data ) && isset( $language_data['lang_options'] ) && ! empty( $language_data['lang_options'] ) ) {
$lang_options = array_replace( [ '' => 'Select' ], $language_data['lang_options'] );
}
return $lang_options;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,272 @@
<?php
if ( bwfan_is_woocommerce_active() && bwfan_is_woocommerce_membership_active() ) {
class BWFAN_Rule_Membership_Has_Status extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'membership_has_status' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values();
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
/** @var WC_Memberships_User_Membership $membership */
$membership = isset( $automation_data['global']['wc_user_membership_id'] ) && ! empty( $automation_data['global']['wc_user_membership_id'] ) ? wc_memberships_get_user_membership( $automation_data['global']['wc_user_membership_id'] ) : null;
if ( ! $membership instanceof WC_Memberships_User_Membership ) {
return $this->return_is_match( $result, $rule_data );
}
$status = $membership->get_status();
$selected_status = array_map( function ( $status ) {
return $status['key'];
}, $rule_data['data'] );
switch ( $rule_data['rule'] ) {
case 'is':
if ( is_array( $selected_status ) ) {
$result = in_array( $status, $selected_status, true ) ? true : false;
}
break;
case 'is_not':
if ( is_array( $selected_status ) ) {
$result = ! in_array( $status, $selected_status, true ) ? true : false;
}
break;
default:
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Chosen_Select';
}
public function get_possible_rule_values() {
$statuses = wc_memberships_get_user_membership_statuses( false, false );
$statuses_to_return = array();
foreach ( $statuses as $status ) {
$statuses_to_return[ $status ] = wc_memberships_get_user_membership_status_name( $status );
}
return $statuses_to_return;
}
public function is_match( $rule_data ) {
$result = false;
$status = BWFAN_Core()->rules->getRulesData( 'wc_user_membership_status' );
if ( empty( $status ) ) {
$membership_id = BWFAN_Core()->rules->getRulesData( 'wc_user_membership_id' );
/** @var WC_Memberships_User_Membership $membership */
$membership = ! empty( $membership_id ) ? wc_memberships_get_user_membership( $membership_id ) : '';
if ( empty( $membership ) ) {
return $this->return_is_match( $result, $rule_data );
}
$status = $membership->get_status();
}
$type = $rule_data['operator'];
switch ( $type ) {
case 'is':
if ( is_array( $rule_data['condition'] ) ) {
$result = in_array( $status, $rule_data['condition'], true ) ? true : false;
}
break;
case 'is_not':
if ( is_array( $rule_data['condition'] ) ) {
$result = ! in_array( $status, $rule_data['condition'], true ) ? true : false;
}
break;
default:
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
esc_html_e( 'Membership status ', 'wp-marketing-automations-pro' )
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %>
<%= condition %>
<?php
}
}
class BWFAN_Rule_Active_Membership_Plans extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'active_membership_plans' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values( $term );
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
$result = false;
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( $result, $rule_data );
}
/** @var $memberships get user all memberships instead of membership object with active status */
$memberships = wc_memberships_get_user_memberships( $automation_data['global']['user_id'], array( 'status' => 'wcm-active' ) );
/** empty $memberships then return false **/
if ( empty( $memberships ) ) {
return $this->return_is_match( $result, $rule_data );
}
$plans = array();
foreach ( $memberships as $membership ) {
/** @var WC_Memberships_User_Membership $membership */
if ( ! $membership instanceof WC_Memberships_User_Membership ) {
continue;
}
$plan = $membership->get_plan();
if ( ! $plan instanceof WC_Memberships_Membership_Plan ) {
continue;
}
$plans[] = $plan->get_id();
}
/** empty $plans then return false **/
if ( empty( $plans ) ) {
return $this->return_is_match( $result, $rule_data );
}
$selected_plans = array_map( function ( $plan ) {
return absint( $plan['key'] );
}, $rule_data['data'] );
switch ( $rule_data['rule'] ) {
case 'is':
if ( is_array( $selected_plans ) && is_array( $plans ) ) {
$result = count( array_intersect( $plans, $selected_plans ) ) === count( $selected_plans );
}
break;
case 'is_not':
if ( is_array( $selected_plans ) && is_array( $plans ) ) {
$result = count( array_intersect( $plans, $selected_plans ) ) === 0;
}
break;
default:
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Chosen_Select';
}
public function get_possible_rule_values( $term = '' ) {
$args = array();
if ( ! empty( $term ) ) {
$args['s'] = sanitize_text_field( $term );
}
$plans = wc_memberships_get_membership_plans( $args );
$plans_to_return = array();
foreach ( $plans as $plan ) {
$plans_to_return[ $plan->get_id() ] = $plan->get_name();
}
return $plans_to_return;
}
public function is_match( $rule_data ) {
$result = false;
$plan_id = BWFAN_Core()->rules->getRulesData( 'wc_membership_plan_id' );
$plan = ! empty( $plan_id ) ? wc_memberships_get_membership_plan( $plan_id ) : '';
if ( empty( $plan ) ) {
$membership_id = BWFAN_Core()->rules->getRulesData( 'wc_user_membership_id' );
/** @var WC_Memberships_User_Membership $membership */
$membership = ! empty( $membership_id ) ? wc_memberships_get_user_membership( $membership_id ) : '';
if ( empty( $membership ) ) {
return $this->return_is_match( $result, $rule_data );
}
$plan = $membership->get_plan();
}
$plan = $plan->get_id();
$type = $rule_data['operator'];
switch ( $type ) {
case 'is':
if ( is_array( $rule_data['condition'] ) ) {
$condition = array_map( 'absint', $rule_data['condition'] );
$result = in_array( absint( $plan ), $condition, true ) ? true : false;
}
break;
case 'is_not':
if ( is_array( $rule_data['condition'] ) ) {
$result = ! in_array( $plan, $rule_data['condition'], true ) ? true : false;
}
break;
default:
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
esc_html_e( 'Membership plan ', 'wp-marketing-automations-pro' )
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %>
<%= condition %>
<?php
}
}
}

View File

@@ -0,0 +1,178 @@
<?php
if ( bwfan_is_ninja_forms_active() ) {
class BWFAN_Rule_Ninja_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'ninja_form_field' );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['ninja_form_submit_form_id'] ) ? $meta['ninja_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_Ninja_Form_Submit $ins */
$ins = BWFAN_Ninja_Form_Submit::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['fields'] ) ? $automation_data['global']['fields'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', array_map( 'trim', $value ) );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function conditions_view() {
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => 'select',
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][key]',
'choices' => $values,
'class' => 'bwfan_field_one_half bwfan_ninja_form_fields',
'placeholder' => __( 'Field', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][value]',
'choices' => $values,
'class' => 'bwfan_field_one_half',
'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$fields = BWFAN_Core()->rules->getRulesData( 'fields' );
$type = $rule_data['operator'];
$value = isset( $fields[ $rule_data['condition']['key'] ] ) ? $fields[ $rule_data['condition']['key'] ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $rule_data['condition']['value'] ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
switch ( $type ) {
case 'is':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) > 0;
} else {
$result = in_array( $condition_value, $value );
}
break;
case 'is_not':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) === 0;
} else {
$result = ! in_array( $condition_value, $value );
}
break;
case 'contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
if ( 0 === $length ) {
$result = true;
} else {
$result = substr( $value, - $length ) === $condition_value;
}
break;
case 'is_blank':
$result = empty( $value[0] );
break;
case 'is_not_blank':
$result = ! empty( $value[0] );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Form Field
'<%= bwfan_events_js_data["ninja_form_submit"]["selected_form_fields"][condition['key']] %>' <% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> '<%= condition['value'] %>'
<?php
}
}
}

View File

@@ -0,0 +1,178 @@
<?php
if ( function_exists( 'bwfan_is_optin_forms_active' ) && bwfan_is_optin_forms_active() ) {
class BWFAN_Rule_Optin_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'optin_form_field' );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-optin_form_submit_form_id'] ) ? $meta['bwfan-optin_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_Funnel_Optin_Form_Submit $ins */
$ins = BWFAN_Funnel_Optin_Form_Submit::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['fields'] ) ? $automation_data['global']['fields'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', array_map( 'trim', $value ) );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function conditions_view() {
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => 'select',
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][key]',
'choices' => $values,
'class' => 'bwfan_field_one_half bwfan_optin_form_fields',
'placeholder' => __( 'Field', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][value]',
'choices' => $values,
'class' => 'bwfan_field_one_half',
'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$fields = BWFAN_Core()->rules->getRulesData( 'fields' );
$type = $rule_data['operator'];
$value = isset( $fields[ $rule_data['condition']['key'] ] ) ? $fields[ $rule_data['condition']['key'] ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $rule_data['condition']['value'] ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
switch ( $type ) {
case 'is':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) > 0;
} else {
$result = in_array( $condition_value, $value );
}
break;
case 'is_not':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) === 0;
} else {
$result = ! in_array( $condition_value, $value );
}
break;
case 'contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
if ( 0 === $length ) {
$result = true;
} else {
$result = substr( $value, - $length ) === $condition_value;
}
break;
case 'is_blank':
$result = empty( $value[0] );
break;
case 'is_not_blank':
$result = ! empty( $value[0] );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Form Field
'<%= bwfan_events_js_data["funnel_optin_form_submit"]["selected_form_fields"][condition['key']] %>' <% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> '<%= condition['value'] %>'
<?php
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,89 @@
<?php
if ( bwfan_is_tve_architect_active() ) {
class BWFAN_Rule_TVE_Architect_Form_Fields extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v21 = false;
parent::__construct( 'tve_architect_form_fields' );
}
/**
* @return array
*/
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-thrive_form_id'] ) ? $meta['bwfan-thrive_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_TVE_Lead_Form_Submit $ins */
$ins = BWFAN_TVE_Architect_Form_Submit::get_instance();
$fields = $ins->get_form_fields( $form_id );
$transformed = array();
foreach ( $fields as $field ) {
if ( isset( $field['key'] ) && isset( $field['value'] ) ) {
$transformed[ $field['key'] ] = $field['value'];
}
}
return $transformed;
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['fields'] ) ? $automation_data['global']['fields'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', array_map( 'trim', $value ) );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
}
}

View File

@@ -0,0 +1,180 @@
<?php
if ( bwfan_is_tve_active() ) {
class BWFAN_Rule_TVE_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'tve_form_field' );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-tve_form_submit_form_id'] ) ? $meta['bwfan-tve_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_TVE_Lead_Form_Submit $ins */
$ins = BWFAN_TVE_Lead_Form_Submit::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['entry'] ) ? $automation_data['global']['entry'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', array_map( 'trim', $value ) );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function conditions_view() {
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => 'select',
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][key]',
'choices' => $values,
'class' => 'bwfan_field_one_half bwfan_tve_form_fields',
'placeholder' => __( 'Field', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][value]',
'choices' => $values,
'class' => 'bwfan_field_one_half',
'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$entry = BWFAN_Core()->rules->getRulesData( 'entry' );
$type = $rule_data['operator'];
$value = isset( $entry[ $rule_data['condition']['key'] ] ) ? $entry[ $rule_data['condition']['key'] ] : '';
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $rule_data['condition']['value'] ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
switch ( $type ) {
case 'is':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) > 0;
} else {
$result = in_array( $condition_value, $value );
}
break;
case 'is_not':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) === 0;
} else {
$result = ! in_array( $condition_value, $value );
}
break;
case 'contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
if ( 0 === $length ) {
$result = true;
} else {
$result = substr( $value, - $length ) === $condition_value;
}
break;
case 'is_blank':
$result = empty( $value[0] );
break;
case 'is_not_blank':
$result = ! empty( $value[0] );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Form Field
'<%= bwfan_events_js_data["tve_lead_form_submit"]["selected_form_fields"][condition['key']] %>' <% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> '<%= condition['value'] %>'
<?php
}
}
}

View File

@@ -0,0 +1,122 @@
<?php
class BWFAN_Rule_Advanced_Shipping_Rate extends BWFAN_Dynamic_Option_Base {
public function __construct() {
parent::__construct( 'advanced_shipping_rate' );
}
public function get_condition_values_nice_names( $values ) {
$return = [];
if ( 0 === count( $values ) ) {
return $return;
}
foreach ( $values as $shipping_rate_id ) {
$return[ $shipping_rate_id ] = get_the_title( $shipping_rate_id );
}
return $return;
}
public function get_search_type_name() {
return 'shipping_rate_rule';
}
public function get_search_results( $term ) {
$array = array();
if ( empty( $term ) ) {
wp_send_json( array(
'results' => $array,
) );
}
$args = array(
'post_type' => 'was',
'numberposts' => 5,
'paged' => 1,
's' => $term,
);
$posts = get_posts( $args );
if ( is_array( $posts ) && count( $posts ) > 0 ) {
foreach ( $posts as $post ) {
if ( ! $post instanceof WP_Post ) {
continue;
}
$array[] = array(
'id' => (string) $post->ID,
'text' => $post->post_title,
);
}
}
wp_send_json( array(
'results' => $array,
) );
}
public function is_match( $rule_data ) {
global $wpdb;
$type = $rule_data['operator'];
$order = BWFAN_Core()->rules->getRulesData( 'wc_order' );
if ( ! $order instanceof WC_Order ) {
return $this->return_is_match( false, $rule_data );
}
$shipping = $order->get_items( 'shipping' );
if ( empty( $shipping ) ) {
return $this->return_is_match( false, $rule_data );
}
$shipping_ids = [];
foreach ( $shipping as $item ) {
$shipping_ids[] = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'was' AND post_status = 'publish' LIMIT 1;", $item->get_name() ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
$result = false;
switch ( $type ) {
case 'all':
if ( is_array( $rule_data['condition'] ) && is_array( $shipping_ids ) ) {
$result = count( array_intersect( $rule_data['condition'], $shipping_ids ) ) === count( $rule_data['condition'] );
}
break;
case 'any':
if ( is_array( $rule_data['condition'] ) && is_array( $shipping_ids ) ) {
$result = count( array_intersect( $rule_data['condition'], $shipping_ids ) ) >= 1;
}
break;
case 'none':
if ( is_array( $rule_data['condition'] ) && is_array( $shipping_ids ) ) {
$result = count( array_intersect( $rule_data['condition'], $shipping_ids ) ) === 0;
}
break;
default:
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
esc_html_e( 'Order Shipping Rate', 'wp-marketing-automations-pro' );
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> <% var chosen = []; %>
<% _.each(condition, function( value, key ){ %>
<% chosen.push(uiData[value]); %>
<% }); %>
<%= chosen.join("/ ") %>
<?php
}
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'all' => __( 'matches all of ', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
}
}

View File

@@ -0,0 +1,192 @@
<?php
class BWFAN_Rule_Webhook_Received extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'webhook_received' );
}
public function get_possible_rule_operators() {
$operators = array_merge( $this->operator_matches(), $this->get_number_operators() );
$operators['is_blank'] = __( 'is blank', 'wp-marketing-automations-pro' );
$operators['is_not_blank'] = __( 'is not blank', 'wp-marketing-automations-pro' );
return $operators;
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
if ( ! isset( $meta['webhook_data'] ) ) {
return array();
}
$webhook_fields = is_array( $meta['webhook_data'] ) ? $meta['webhook_data'] : [];
return $this->get_webhook_fields( $webhook_fields );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = $this->get_field_value( $key, $automation_data );
if ( in_array( $type, array_keys( $this->get_number_operators() ), true ) ) {
if ( ! is_numeric( $value ) || ! is_numeric( $saved_value ) ) {
return $this->return_is_match( false, $rule_data );
}
$result = $this->is_match_number( $value, $type, $saved_value );
return $this->return_is_match( $result, $rule_data );
}
/** If type is is_blank or is_not_blank */
if ( 'is_blank' === $type || 'is_not_blank' === $type ) {
return ( 'is_blank' === $type ) ? empty( $value ) : ! empty( $value );
}
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = false;
switch ( $type ) {
case 'is':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) > 0;
} else {
$result = in_array( $condition_value, $value );
}
break;
case 'is_not':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) === 0;
} else {
$result = ! in_array( $condition_value, $value );
}
break;
case 'contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
if ( 0 === $length ) {
$result = true;
} else {
$result = substr( $value, - $length ) === $condition_value;
}
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function is_match_number( $value, $operator, $saved_value ) {
$value = (float) $value;
$saved_value = (float) $saved_value;
$result = false;
switch ( $operator ) {
case '==':
$result = $value === $saved_value;
break;
case '!=':
$result = $value !== $saved_value;
break;
case '>':
$result = $value > $saved_value;
break;
case '<':
$result = $value < $saved_value;
break;
case '>=':
$result = $value >= $saved_value;
break;
case '<=':
$result = $value <= $saved_value;
break;
}
return $result;
}
/**
* @param $field_key
* @param $automation_data
*
* @return mixed|string
*/
public function get_field_value( $field_key, $automation_data ) {
$keys = explode( '.', $field_key );
$data = isset( $automation_data['global']['webhook_data'] ) ? $automation_data['global']['webhook_data'] : [];
foreach ( $keys as $val ) {
if ( isset( $data[ $val ] ) ) {
$data = $data[ $val ];
}
}
return ! is_array( $data ) ? $data : '';
}
/**
* Get webhook fields
*
* @param $webhook_fields
*
* @return array
*/
public function get_webhook_fields( $webhook_fields ) {
$field_keys = [];
foreach ( $webhook_fields as $key => $value ) {
if ( is_array( $value ) ) {
$keys = $this->get_webhook_fields( $value );
foreach ( $keys as $k ) {
$field_keys[ $key . '.' . $k ] = $key . '.' . $k;
}
continue;
}
$field_keys[ $key ] = $key;
}
return ! empty( $field_keys ) ? $field_keys : [];
}
public function get_number_operators() {
return array(
'==' => __( 'is equal to', 'wp-marketing-automations-pro' ),
'!=' => __( 'is not equal to', 'wp-marketing-automations-pro' ),
'>' => __( 'is greater than', 'wp-marketing-automations-pro' ),
'<' => __( 'is less than', 'wp-marketing-automations-pro' ),
'>=' => __( 'at least', 'wp-marketing-automations-pro' ),
'<=' => __( 'at most', 'wp-marketing-automations-pro' ),
);
}
}

View File

@@ -0,0 +1,143 @@
<?php
if ( bwfan_is_wc_wishlist_active() && bwfan_is_woocommerce_active() ) {
class BWFAN_Rule_Wishlist_Item extends BWFAN_Rule_Products {
public $supports = array( 'cart', 'order' );
public function __construct() {
$this->v2 = true;
parent::__construct( 'wishlist_item' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_search_results( $term, true );
}
public function get_rule_type() {
return 'Search';
}
/** v2 Methods: END */
public function get_products( $automation_data = [] ) {
if ( isset( $automation_data['global'] ) && is_array( $automation_data['global'] ) ) {
$wishlist_items = isset( $automation_data['global']['wishlist_items'] ) ? $automation_data['global']['wishlist_items'] : [];
} else {
$wishlist_items = BWFAN_Core()->rules->getRulesData( 'wishlist_items' );
}
$result = false;
$found_ids = [];
if ( empty( $wishlist_items ) ) {
return [];
}
return $wishlist_items;
}
public function ui_view() {
esc_html_e( 'Wishlist Items ', 'wp-marketing-automations-pro' );
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> <% var chosen = []; %>
<% _.each(condition, function( value, key ){ %>
<%
if(_.has(uiData, value)) {
chosen.push(uiData[value]);
}
%>
<% }); %>
<%= chosen.join("/ ") %>
<?php
}
public function get_possible_rule_operators() {
$operators = array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'all' => __( 'matches exactly', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
return $operators;
}
}
class BWFAN_Rule_Wishlist_Item_Category extends BWFAN_Rule_Term_Taxonomy {
public $taxonomy_name = 'product_cat';
public function __construct() {
$this->v2 = true;
parent::__construct( 'wishlist_item_category' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_search_results( $term, true );
}
public function get_rule_type() {
return 'Search';
}
/** v2 Methods: END */
public function get_term_ids( $automation_data = [] ) {
if ( isset( $automation_data['global'] ) && is_array( $automation_data['global'] ) ) {
$wishlist_items = isset( $automation_data['global']['wishlist_items'] ) ? $automation_data['global']['wishlist_items'] : [];
} else {
$wishlist_items = BWFAN_Core()->rules->getRulesData( 'wishlist_items' );
}
if ( empty( $wishlist_items ) ) {
return [];
}
$all_terms = [];
foreach ( $wishlist_items as $item_id ) {
$all_terms = $this->get_wishlist_item_terms( $all_terms, $item_id );
}
return $all_terms;
}
public function get_wishlist_item_terms( $all_terms, $item_id ) {
$terms = wp_get_object_terms( $item_id, $this->taxonomy_name, array(
'fields' => 'ids',
) );
$all_terms = array_merge( $all_terms, $terms );
return $all_terms;
}
public function ui_view() {
esc_html_e( 'Wishlist Item\'s category ', 'wp-marketing-automations-pro' );
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %><% var chosen = []; %>
<% _.each(condition, function( value, key ){ %>
<% chosen.push(uiData[value]); %>
<% }); %>
<%= chosen.join("/ ") %>
<?php
}
public function get_possible_rule_operators() {
$operators = array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
return $operators;
}
}
}

View File

@@ -0,0 +1,235 @@
<?php
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
class BWFAN_Rule_WLM_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
parent::__construct( 'wlm_form_field' );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-wlm_form_submit_form_id'] ) ? $meta['bwfan-wlm_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_WLM_User_Registration $ins */
$ins = BWFAN_WLM_User_Registration::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$result = false;
$entry = isset( $automation_data['global']['entry'] ) ? $automation_data['global']['entry'] : [];
$data = $rule_data['data'];
if ( ! is_array( $data ) && empty( $data ) ) {
return $this->return_is_match( false, $rule_data );
}
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
switch ( $rule_data['rule'] ) {
case 'is':
$result = ( strtolower( $value ) === strtolower( $saved_value ) );
break;
case 'is_not':
$result = ( strtolower( $value ) !== strtolower( $saved_value ) );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function conditions_view() {
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => 'select',
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][key]',
'choices' => $values,
'class' => 'bwfan_field_one_half bwfan_wlm_form_fields',
'placeholder' => __( 'Field', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][value]',
'choices' => $values,
'class' => 'bwfan_field_one_half',
'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$entry = BWFAN_Core()->rules->getRulesData( 'entry' );
$type = $rule_data['operator'];
$value = isset( $entry[ $rule_data['condition']['key'] ] ) ? $entry[ $rule_data['condition']['key'] ] : '';
switch ( $type ) {
case 'is':
$result = ( strtolower( $value ) === strtolower( $rule_data['condition']['value'] ) );
break;
case 'is_not':
$result = ( strtolower( $value ) !== strtolower( $rule_data['condition']['value'] ) );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Form Field
'<%= bwfan_events_js_data["wlm_user_registration"]["selected_form_fields"][condition['key']] %>' <% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> '<%= condition['value'] %>'
<?php
}
}
class BWFAN_Rule_WLM_Level extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'wlm_level' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values();
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$level_id = isset( $automation_data['global']['level_id'] ) ? $automation_data['global']['level_id'] : 0;
$result = false;
/** for wishlist member events to check for membership level */
$in = false;
$rule_data['condition'] = array_map( 'intval', $rule_data['condition'] );
$selected_level = array_map( function ( $level ) {
return absint( $level['key'] );
}, $rule_data['data'] );
if ( in_array( absint( $level_id ), $selected_level, true ) ) {
$in = true;
}
$result = 'in' === $rule_data['rule'] ? $in : ! $in;
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'in' => __( 'is', 'wp-marketing-automations-pro' ),
'notin' => __( 'is not', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_rule_values() {
$result = array();
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
public function get_condition_input_type() {
return 'Chosen_Select';
}
/**
* @param $rule_data
*
* @return bool
*/
public function is_match( $rule_data ) {
$result = false;
if ( isset( $rule_data['condition'] ) && isset( $rule_data['operator'] ) ) {
/** for wishlist member events to check for membership level */
$level_id = BWFAN_Core()->rules->getRulesData( 'level_id' );
$in = false;
$rule_data['condition'] = array_map( 'intval', $rule_data['condition'] );
if ( in_array( intval( $level_id ), $rule_data['condition'], true ) ) {
$in = true;
}
$result = 'in' === $rule_data['operator'] ? $in : ! $in;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
echo esc_html__( 'Membership Level ', 'wp-marketing-automations-pro' );
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> <% var chosen = []; %>
<% _.each(condition, function( value, key ){ %>
<% chosen.push(uiData[value]); %>
<% }); %>
<%= chosen.join("/") %>
<?php
}
}
}

View File

@@ -0,0 +1,454 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'WFACP_Common' ) ) {
class BWFAN_Rule_Aerocheckout extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'aerocheckout' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values( $term );
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$abandoned_data = isset( $automation_data['global']['cart_details'] ) ? $automation_data['global']['cart_details'] : [];
$order_id = isset( $automation_data['global']['order_id'] ) ? $automation_data['global']['order_id'] : 0;
/** could be abandonment event or order created event */
$order = wc_get_order( $order_id );
$aero_id = false;
if ( isset( $abandoned_data['checkout_data'] ) ) {
/** Abandonment event */
$checkout_data = json_decode( $abandoned_data['checkout_data'] );
$aero_id = ( isset( $checkout_data->aerocheckout_page_id ) && ! empty( $checkout_data->aerocheckout_page_id ) ) ? $checkout_data->aerocheckout_page_id : false;
} elseif ( $order instanceof WC_Order ) {
/** Order created event */
$aero_id = $order->get_meta( '_wfacp_post_id', true );
}
if ( empty( $aero_id ) ) {
$result = 'in' === $rule_data['rule'] ? false : true;
return $this->return_is_match( $result, $rule_data );
}
$in = false;
$selected_checkouts = array_map( function ( $wfacp ) {
return absint( $wfacp['key'] );
}, $rule_data['data'] );
if ( in_array( intval( $aero_id ), $selected_checkouts, true ) ) {
$in = true;
}
$result = 'in' === $rule_data['rule'] ? $in : ! $in;
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'in' => __( 'is', 'wp-marketing-automations-pro' ),
'notin' => __( 'is not', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_rule_values( $term = '' ) {
$result = array();
$args = array(
'post_type' => 'wfacp_checkout',
'fields' => 'ids',
'posts_per_page' => 10,
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC'
);
if ( ! empty( $term ) ) {
$args['s'] = $term;
}
if ( ! empty( $term ) && is_numeric( $term ) ) {
unset( $args['s'] );
$args['post__in'] = array( $term );
}
$query = new WP_Query( $args );
$checkout_pages = $query->posts;
if ( is_array( $checkout_pages ) && count( $checkout_pages ) > 0 ) {
foreach ( $checkout_pages as $page_id ) {
$result[ $page_id ] = get_the_title( $page_id ) . " (#{$page_id})";
}
}
return $result;
}
public function get_condition_input_type() {
return 'Chosen_Select';
}
/**
* @param $rule_data
*
* @return bool
*/
public function is_match( $rule_data ) {
$result = false;
if ( isset( $rule_data['condition'] ) && isset( $rule_data['operator'] ) ) {
/** could be abandonment event or order created event */
$abandoned_data = BWFAN_Core()->rules->getRulesData( 'abandoned_data' );
$order = BWFAN_Core()->rules->getRulesData( 'wc_order' );
$aero_id = false;
if ( isset( $abandoned_data['checkout_data'] ) ) {
/** Abandonment event */
$checkout_data = json_decode( $abandoned_data['checkout_data'] );
$aero_id = ( isset( $checkout_data->aerocheckout_page_id ) && ! empty( $checkout_data->aerocheckout_page_id ) ) ? $checkout_data->aerocheckout_page_id : false;
} elseif ( $order instanceof WC_Order ) {
/** Order created event */
$aero_id = $order->get_meta( '_wfacp_post_id', true );
}
if ( empty( $aero_id ) ) {
return $this->return_is_match( $result, $rule_data );
}
$in = false;
$rule_data['condition'] = array_map( 'intval', $rule_data['condition'] );
if ( in_array( intval( $aero_id ), $rule_data['condition'], true ) ) {
$in = true;
}
$result = 'in' === $rule_data['operator'] ? $in : ! $in;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
echo esc_html__( 'Checkout Page', 'wp-marketing-automations-pro' );
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> <% var chosen = []; %>
<% _.each(condition, function( value, key ){ %>
<% chosen.push(uiData[value]); %>
<% }); %>
<%= chosen.join("/") %>
<?php
}
}
}
if ( class_exists( 'WFOCU_Common' ) ) {
class BWFAN_Rule_Upstroke_Funnels extends BWFAN_Dynamic_Option_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'upstroke_funnels' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values( $term );
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$upstroke_funnel_id = isset( $automation_data['global']['funnel_id'] ) ? $automation_data['global']['funnel_id'] : 0;
$upstroke_funnel_ids = array( $upstroke_funnel_id );
$selected_upstroke = array_map( function ( $upstroke ) {
return $upstroke['key'];
}, $rule_data['data'] );
$result = false;
switch ( $rule_data['rule'] ) {
case 'any':
if ( is_array( $selected_upstroke ) && is_array( $upstroke_funnel_ids ) ) {
$result = count( array_intersect( $selected_upstroke, $upstroke_funnel_ids ) ) >= 1;
}
break;
case 'none':
if ( is_array( $selected_upstroke ) && is_array( $upstroke_funnel_ids ) ) {
$result = count( array_intersect( $selected_upstroke, $upstroke_funnel_ids ) ) === 0;
}
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_rule_values( $term = '' ) {
$data = BWFAN_PRO_Common::get_upstroke_funnels( $term );
if ( empty( $data ) || ! is_array( $data ) ) {
return [];
}
$result = array();
foreach ( $data as $v ) {
$result[ $v['id'] ] = $v['post_title'];
}
return $result;
}
public function get_condition_input_type() {
return 'Chosen_Select';
}
public function conditions_view() {
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition]',
'choices' => $values,
'search_type' => $this->get_search_type_name(),
'rule_type' => $this->rule_type,
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$type = $rule_data['operator'];
$upstroke_funnel_id = BWFAN_Core()->rules->getRulesData( 'upstroke_funnel_id' );
$upstroke_funnel_ids = array( $upstroke_funnel_id );
switch ( $type ) {
case 'any':
if ( is_array( $rule_data['condition'] ) && is_array( $upstroke_funnel_ids ) ) {
$result = count( array_intersect( $rule_data['condition'], $upstroke_funnel_ids ) ) >= 1;
}
break;
case 'none':
if ( is_array( $rule_data['condition'] ) && is_array( $upstroke_funnel_ids ) ) {
$result = count( array_intersect( $rule_data['condition'], $upstroke_funnel_ids ) ) === 0;
}
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
echo esc_html__( 'Funnels', 'wp-marketing-automations-pro' );
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> <% var chosen = []; %>
<% _.each(condition, function( value, key ){ %>
<% chosen.push(uiData[value]); %>
<% }); %>
<%= chosen.join("/") %>
<?php
}
public function get_condition_values_nice_names( $values ) {
$return = [];
if ( count( $values ) > 0 ) {
$return = BWFAN_PRO_Common::get_upstroke_funnel_nice_name( $values );
}
return $return;
}
}
class BWFAN_Rule_Upstroke_Offers extends BWFAN_Dynamic_Option_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'upstroke_offers' );
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
return $this->get_possible_rule_values( $term );
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$upstroke_offer_id = isset( $automation_data['global']['offer_id'] ) ? $automation_data['global']['offer_id'] : 0;
$upstroke_offer_ids = array( $upstroke_offer_id );
$selected_upstroke = array_map( function ( $upstroke ) {
return $upstroke['key'];
}, $rule_data['data'] );
$upstroke_offer_ids = array( $upstroke_offer_id );
switch ( $rule_data['rule'] ) {
case 'any':
if ( is_array( $selected_upstroke ) && is_array( $upstroke_offer_ids ) ) {
$result = count( array_intersect( $selected_upstroke, $upstroke_offer_ids ) ) >= 1;
}
break;
case 'none':
if ( is_array( $selected_upstroke ) && is_array( $upstroke_offer_ids ) ) {
$result = count( array_intersect( $selected_upstroke, $upstroke_offer_ids ) ) === 0;
}
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
}
public function get_possible_rule_values( $term = '' ) {
$data = BWFAN_PRO_Common::get_upstroke_offers( $term );
if ( empty( $data ) || ! is_array( $data ) ) {
return [];
}
$result = array();
foreach ( $data as $v ) {
$result[ $v['id'] ] = $v['post_title'];
}
return $result;
}
public function get_condition_input_type() {
return 'Chosen_Select';
}
public function conditions_view() {
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition]',
'choices' => $values,
'search_type' => $this->get_search_type_name(),
'rule_type' => $this->rule_type,
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$type = $rule_data['operator'];
$upstroke_offer_id = BWFAN_Core()->rules->getRulesData( 'upstroke_offer_id' );
$upstroke_offer_ids = array( $upstroke_offer_id );
switch ( $type ) {
case 'any':
if ( is_array( $rule_data['condition'] ) && is_array( $upstroke_offer_ids ) ) {
$result = count( array_intersect( $rule_data['condition'], $upstroke_offer_ids ) ) >= 1;
}
break;
case 'none':
if ( is_array( $rule_data['condition'] ) && is_array( $upstroke_offer_ids ) ) {
$result = count( array_intersect( $rule_data['condition'], $upstroke_offer_ids ) ) === 0;
}
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
echo esc_html__( 'Offer', 'wp-marketing-automations-pro' );
?>
<% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<% var possible_values = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_values() ); ?>'); %>
<%= ops[operator] %> <% var chosen = []; %>
<% _.each(condition, function( value, key ){ %>
<% chosen.push("'"+possible_values[value]+"'"); %>
<% }); %>
<%= chosen.join(", ") %>
<?php
}
public function get_condition_values_nice_names( $values ) {
$return = [];
if ( count( $values ) > 0 ) {
$return = BWFAN_PRO_Common::get_upstroke_offer_nice_name( $values );
}
return $return;
}
}
}

View File

@@ -0,0 +1,183 @@
<?php
if ( bwfan_is_wpforms_active() ) {
class BWFAN_Rule_WPFORMS_Form_Field extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
parent::__construct( 'wpforms_form_field' );
}
public function get_possible_rule_operators() {
return array(
'is' => __( 'is', 'wp-marketing-automations-pro' ),
'is_not' => __( 'is not', 'wp-marketing-automations-pro' ),
'contains' => __( 'contains', 'wp-marketing-automations-pro' ),
'not_contains' => __( 'does not contain', 'wp-marketing-automations-pro' ),
'starts_with' => __( 'starts with', 'wp-marketing-automations-pro' ),
'ends_with' => __( 'ends with', 'wp-marketing-automations-pro' ),
'is_blank' => __( 'is blank', 'wp-marketing-automations-pro' ),
'is_not_blank' => __( 'is not blank', 'wp-marketing-automations-pro' ),
);
}
public function get_condition_input_type() {
return 'Text';
}
/** v2 Methods: START */
public function get_options( $term = '' ) {
$meta = $this->event_automation_meta;
$form_id = isset( $meta['bwfan-wpforms_form_submit_form_id'] ) ? $meta['bwfan-wpforms_form_submit_form_id'] : 0;
if ( empty( $form_id ) ) {
return array();
}
/** @var BWFAN_WPFORMS_Form_Submit $ins */
$ins = BWFAN_WPFORMS_Form_Submit::get_instance();
return $ins->get_form_fields( $form_id );
}
public function get_rule_type() {
return 'key-value';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$entry = isset( $automation_data['global']['entry']['fields'] ) ? $automation_data['global']['entry']['fields'] : [];
$type = $rule_data['rule'];
$data = $rule_data['data'];
$key = isset( $data[0] ) ? $data[0] : '';
$saved_value = isset( $data[1] ) ? $data[1] : '';
$value = isset( $entry[ $key ] ) ? $entry[ $key ] : '';
if ( is_array( $value ) ) {
$value = isset( $value['first'] ) ? $value['first'] : ( isset( $value['primary'] ) ? $value['primary'] : implode( ', ', $value ) );
}
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', array_map( 'trim', $value ) );
$condition_value = strtolower( trim( $saved_value ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
$result = BWFAN_PRO_Common::forms_fields_rules( $type, $condition_value, $value );
return $this->return_is_match( $result, $rule_data );
}
/** v2 Methods: END */
public function conditions_view() {
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => 'select',
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][key]',
'choices' => $values,
'class' => 'bwfan_field_one_half bwfan_wpforms_form_fields',
'placeholder' => __( 'Field', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
$condition_input_type = $this->get_condition_input_type();
$values = $this->get_possible_rule_values();
$value_args = array(
'input' => $condition_input_type,
'name' => 'bwfan_rule[<%= groupId %>][<%= ruleId %>][condition][value]',
'choices' => $values,
'class' => 'bwfan_field_one_half',
'placeholder' => __( 'Value', 'wp-marketing-automations-pro' ),
);
bwfan_Input_Builder::create_input_field( $value_args );
}
public function is_match( $rule_data ) {
$entry = BWFAN_Core()->rules->getRulesData( 'entry' );
$type = $rule_data['operator'];
$value = isset( $entry['fields'][ $rule_data['condition']['key'] ] ) ? $entry['fields'][ $rule_data['condition']['key'] ] : '';
if ( is_array( $value ) ) {
$value = isset( $value['first'] ) ? $value['first'] : ( isset( $value['primary'] ) ? $value['primary'] : implode( ', ', $value ) );
}
$value = BWFAN_Pro_Rules::make_value_as_array( $value );
$value = array_map( 'strtolower', $value );
$condition_value = strtolower( trim( $rule_data['condition']['value'] ) );
/** checking if condition value contains comma */
if ( strpos( $condition_value, ',' ) !== false ) {
$condition_value = explode( ',', $condition_value );
$condition_value = array_map( 'trim', $condition_value );
}
switch ( $type ) {
case 'is':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) > 0;
} else {
$result = in_array( $condition_value, $value );
}
break;
case 'is_not':
if ( is_array( $condition_value ) && is_array( $value ) ) {
$result = count( array_intersect( $condition_value, $value ) ) === 0;
} else {
$result = ! in_array( $condition_value, $value );
}
break;
case 'contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) !== false;
break;
case 'not_contains':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$result = strpos( $value, $condition_value ) === false;
break;
case 'starts_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
$result = substr( $value, 0, $length ) === $condition_value;
break;
case 'ends_with':
$value = isset( $value[0] ) && ! empty( $value[0] ) ? $value[0] : '';
$length = strlen( $condition_value );
if ( 0 === $length ) {
$result = true;
} else {
$result = substr( $value, - $length ) === $condition_value;
}
break;
case 'is_blank':
$result = empty( $value[0] );
break;
case 'is_not_blank':
$result = ! empty( $value[0] );
break;
default:
$result = false;
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function ui_view() {
?>
Form Field
'<%= bwfan_events_js_data["wpforms_form_submit"]["selected_form_fields"][condition['key']] %>' <% var ops = JSON.parse('<?php echo wp_json_encode( $this->get_possible_rule_operators() ); ?>'); %>
<%= ops[operator] %> '<%= condition['value'] %>'
<?php
}
}
}