/var/www/html_uk/wp-content/plugins/automatewoo/includes/Communication_Page.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php

namespace AutomateWoo;

defined'ABSPATH' ) || exit;

/**
 * Communication_Page
 *
 * @since 4.0
 */
class Communication_Page {

    
/** @var string $using_customer_key True if the customer is retreived using a customer key */
    
private static $using_customer_key false;

    
/**
     * Init runs when on the communication preferences page
     */
    
public static function init() {
        
aw_no_page_cache();
    }

    
/**
     * Get the contents of the communication preferences shortcode
     *
     * @return string
     */
    
public static function output_preferences_shortcode() {
        
$customer     false;
        
$customer_key Clean::stringaw_request'customer_key' ) );

        if ( 
$customer_key ) {
            
self::$using_customer_key true;
            
$customer                 Customer_Factory::get_by_key$customer_key );
        } elseif ( 
is_user_logged_in() ) {
            
$customer Customer_Factory::get_by_user_idget_current_user_id() );
        }

        
ob_start();
        
self::output_preferences_form$customer );
        return 
ob_get_clean();
    }

    
/**
     * Output the communication preferences page
     *
     * @param Customer $customer
     */
    
public static function output_preferences_form$customer ) {
        
$data = [];

        
wp_enqueue_style'automatewoo-communication-page' );

        
$data['intent'] = Clean::stringaw_request'intent' ) );

        if ( ! 
$customer ) {
            
aw_get_template'communication-preferences/communication-form-no-customer.php'$data );
        } else {
            
$data['customer'] = $customer;

            if ( 
self::$using_customer_key && 'unsubscribe' === $data['intent'] && ! aw_request'automatewoo_save_changes' ) ) {
                
$customer->opt_out();
                
wc_add_notice__"Saved successfully! You won't receive marketing communications from us."'automatewoo' ) );
            }

            
aw_get_template'communication-preferences/communication-form.php'$data );
        }
    }

    
/**
     * Get the contents of the communication preferences signup form
     *
     * @return string
     */
    
public static function output_signup_form() {
        
wp_enqueue_style'automatewoo-communication-page' );
        
ob_start();
        
aw_get_template'communication-preferences/signup-form.php' );
        return 
ob_get_clean();
    }
}