/var/www/html_us/wp-content/plugins/checkout-for-woocommerce/includes/Action/CFWAction.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php

namespace Objectiv\Plugins\Checkout\Action;

/**
 * Class CFWAction
 *
 * @link checkoutwc.com
 * @since 3.6.0
 * @package Objectiv\Plugins\Checkout\Action
 * @author Clifton Griffin <[email protected]>
 */
abstract class CFWAction {
    
/**
     * @since 1.0.0
     * @access protected
     * @var string $id
     */
    
protected $id '';

    
/**
     * @since 1.0.6
     * @access private
     * @var bool
     */
    
private $no_privilege;

    
/**
     * @since 1.0.6
     * @access private
     * @var string
     */
    
private $action_prefix;

    
/**
     * Action constructor.
     *
     * @param $id
     * @param bool $no_privilege
     * @param string $action_prefix
     * @since 1.0.0
     * @access public
     */
    
public function __construct$idbool $no_privilege truestring $action_prefix 'wc_ajax_' ) {
        
$this->no_privilege  $no_privilege;
        
$this->action_prefix $action_prefix;

        
$this->set_id$id );
    }

    
/**
     * @since 1.0.0
     * @access public
     * @return string
     */
    
public function get_id(): string {
        return 
$this->id;
    }

    
/**
     * @since 1.0.0
     * @access public
     * @param $id
     */
    
public function set_id$id ) {
        
$this->id $id;
    }

    
/**
     * @since 1.0.0
     * @access public
     * @param boolean $np
     */
    
public function load() {
        
remove_all_actions"{$this->action_prefix}{$this->get_id()});
        
add_action"{$this->action_prefix}{$this->get_id()}", array( $this'execute' ) );

        if ( 
true === $this->no_privilege ) {
            
remove_all_actions"{$this->action_prefix}nopriv_{$this->get_id()});
            
add_action"{$this->action_prefix}nopriv_{$this->get_id()}", array( $this'execute' ) );
        }
    }

    public function 
execute() {
        
/**
         * PHP Warning / Notice Suppression
         */
        
if ( ! defined'CFW_DEV_MODE' ) || ! CFW_DEV_MODE ) {
            
ini_set'display_errors''Off' );
        }

        if ( ! 
defined'CFW_ACTION_NO_ERROR_SUPPRESSION_BUFFER' ) ) {
            
// Try to prevent errors and errata from leaking into AJAX responses
            // This output buffer is discarded on out();
            
@ob_end_clean(); // phpcs:ignore
            
ob_start();
        }

        
$this->action();
    }

    
/**
     * @since 1.0.0
     * @access protected
     * @param $out
     */
    
protected function out$out ) {
        
ini_set'display_errors''Off' );

        
// TODO: Execute and out (in Action) should be final and not overrideable. Action needs to NOT force JSON as an object. Could use a parameter to flip JSON to object
        
if ( ! defined'CFW_ACTION_NO_ERROR_SUPPRESSION_BUFFER' ) ) {
            @
ob_end_clean(); // @phpcs:ignore
        
}

        
wp_send_json$out );
    }
}