Passed
Push — master ( 763170...0f9edb )
by Kiran
07:19 queued 16s
created
vendor/ayecode/wp-ayecode-ui/includes/inc/bs-conversion.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -14,76 +14,76 @@
 block discarded – undo
14 14
  * @return array|mixed|string|string[]
15 15
  */
16 16
 function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) {
17
-	global $aui_bs5;
17
+    global $aui_bs5;
18 18
 
19
-	if ( $aui_bs5 ) {
20
-		$convert = array(
21
-			'"ml-' => '"ms-',
22
-			'"mr-' => '"me-',
23
-			'"pl-' => '"ps-',
24
-			'"pr-' => '"pe-',
25
-			"'ml-" => "'ms-",
26
-			"'mr-" => "'me-",
27
-			"'pl-" => "'ps-",
28
-			"'pr-" => "'pe-",
29
-			' ml-' => ' ms-',
30
-			' mr-' => ' me-',
31
-			' pl-' => ' ps-',
32
-			' pr-' => ' pe-',
33
-			'.ml-' => '.ms-',
34
-			'.mr-' => '.me-',
35
-			'.pl-' => '.ps-',
36
-			'.pr-' => '.pe-',
37
-			' form-row' => ' row',
38
-			' embed-responsive-item' => '',
39
-			' embed-responsive' => ' ratio',
40
-			'-1by1'    => '-1x1',
41
-			'-4by3'    => '-4x3',
42
-			'-16by9'    => '-16x9',
43
-			'-21by9'    => '-21x9',
44
-			'geodir-lightbox-image' => 'aui-lightbox-image',
45
-			'geodir-lightbox-iframe' => 'aui-lightbox-iframe',
46
-			' badge-'   => ' text-bg-',
47
-			'form-group'   => 'mb-3',
48
-			'custom-select'   => 'form-select',
49
-			'float-left'   => 'float-start',
50
-			'float-right'   => 'float-end',
51
-			'text-left'    => 'text-start',
52
-			'text-sm-left'    => 'text-sm-start',
53
-			'text-md-left'    => 'text-md-start',
54
-			'text-lg-left'    => 'text-lg-start',
55
-			'text-right'    => 'text-end',
56
-			'text-sm-right'    => 'text-sm-end',
57
-			'text-md-right'    => 'text-md-end',
58
-			'text-lg-right'    => 'text-lg-end',
59
-			'border-right'    => 'border-end',
60
-			'border-left'    => 'border-start',
61
-			'font-weight-'  => 'fw-',
62
-			'btn-block'     => 'w-100',
63
-			'rounded-left'  => 'rounded-start',
64
-			'rounded-right'  => 'rounded-end',
65
-			'font-italic' => 'fst-italic',
19
+    if ( $aui_bs5 ) {
20
+        $convert = array(
21
+            '"ml-' => '"ms-',
22
+            '"mr-' => '"me-',
23
+            '"pl-' => '"ps-',
24
+            '"pr-' => '"pe-',
25
+            "'ml-" => "'ms-",
26
+            "'mr-" => "'me-",
27
+            "'pl-" => "'ps-",
28
+            "'pr-" => "'pe-",
29
+            ' ml-' => ' ms-',
30
+            ' mr-' => ' me-',
31
+            ' pl-' => ' ps-',
32
+            ' pr-' => ' pe-',
33
+            '.ml-' => '.ms-',
34
+            '.mr-' => '.me-',
35
+            '.pl-' => '.ps-',
36
+            '.pr-' => '.pe-',
37
+            ' form-row' => ' row',
38
+            ' embed-responsive-item' => '',
39
+            ' embed-responsive' => ' ratio',
40
+            '-1by1'    => '-1x1',
41
+            '-4by3'    => '-4x3',
42
+            '-16by9'    => '-16x9',
43
+            '-21by9'    => '-21x9',
44
+            'geodir-lightbox-image' => 'aui-lightbox-image',
45
+            'geodir-lightbox-iframe' => 'aui-lightbox-iframe',
46
+            ' badge-'   => ' text-bg-',
47
+            'form-group'   => 'mb-3',
48
+            'custom-select'   => 'form-select',
49
+            'float-left'   => 'float-start',
50
+            'float-right'   => 'float-end',
51
+            'text-left'    => 'text-start',
52
+            'text-sm-left'    => 'text-sm-start',
53
+            'text-md-left'    => 'text-md-start',
54
+            'text-lg-left'    => 'text-lg-start',
55
+            'text-right'    => 'text-end',
56
+            'text-sm-right'    => 'text-sm-end',
57
+            'text-md-right'    => 'text-md-end',
58
+            'text-lg-right'    => 'text-lg-end',
59
+            'border-right'    => 'border-end',
60
+            'border-left'    => 'border-start',
61
+            'font-weight-'  => 'fw-',
62
+            'btn-block'     => 'w-100',
63
+            'rounded-left'  => 'rounded-start',
64
+            'rounded-right'  => 'rounded-end',
65
+            'font-italic' => 'fst-italic',
66 66
 
67 67
 //			'custom-control custom-checkbox'    => 'form-check',
68
-			// data
69
-			' data-toggle=' => ' data-bs-toggle=',
70
-			'data-ride=' => 'data-bs-ride=',
71
-			'data-controlnav=' => 'data-bs-controlnav=',
72
-			'data-slide='   => 'data-bs-slide=',
73
-			'data-slide-to=' => 'data-bs-slide-to=',
74
-			'data-target='  => 'data-bs-target=',
75
-			'data-dismiss="modal"'  => 'data-bs-dismiss="modal"',
76
-			'class="close"' => 'class="btn-close"',
77
-			'<span aria-hidden="true">&times;</span>' => '',
78
-		);
79
-		$output  = str_replace(
80
-			array_keys( $convert ),
81
-			array_values( $convert ),
82
-			$output
83
-		);
84
-	}
68
+            // data
69
+            ' data-toggle=' => ' data-bs-toggle=',
70
+            'data-ride=' => 'data-bs-ride=',
71
+            'data-controlnav=' => 'data-bs-controlnav=',
72
+            'data-slide='   => 'data-bs-slide=',
73
+            'data-slide-to=' => 'data-bs-slide-to=',
74
+            'data-target='  => 'data-bs-target=',
75
+            'data-dismiss="modal"'  => 'data-bs-dismiss="modal"',
76
+            'class="close"' => 'class="btn-close"',
77
+            '<span aria-hidden="true">&times;</span>' => '',
78
+        );
79
+        $output  = str_replace(
80
+            array_keys( $convert ),
81
+            array_values( $convert ),
82
+            $output
83
+        );
84
+    }
85 85
 
86
-	return $output;
86
+    return $output;
87 87
 }
88 88
 
89 89
 add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this
Please login to merge, or discard this patch.
vendor/ayecode/wp-super-duper/sd-plugin.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@  discard block
 block discarded – undo
15 15
  */
16 16
 
17 17
 if ( ! defined( 'ABSPATH' ) ) {
18
-	exit;
18
+    exit;
19 19
 }
20 20
 
21 21
 if ( ! class_exists( 'WP_Super_Duper' ) ) {
22
-	// include the class if needed
23
-	include_once( dirname( __FILE__ ) . "/wp-super-duper.php" );
22
+    // include the class if needed
23
+    include_once( dirname( __FILE__ ) . "/wp-super-duper.php" );
24 24
 }
25 25
 
26 26
 /*
@@ -35,5 +35,5 @@  discard block
 block discarded – undo
35 35
 
36 36
 
37 37
 if ( ! function_exists( 'sd_get_class_build_keys' ) ) {
38
-	include_once( dirname( __FILE__ ) . "/sd-functions.php" );
38
+    include_once( dirname( __FILE__ ) . "/sd-functions.php" );
39 39
 }
40 40
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-super-duper/hello-world.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -3,114 +3,114 @@  discard block
 block discarded – undo
3 3
 class SD_Hello_World extends WP_Super_Duper {
4 4
 
5 5
 
6
-	public $arguments;
7
-
8
-	/**
9
-	 * Sets up the widgets name etc
10
-	 */
11
-	public function __construct() {
12
-
13
-		$options = array(
14
-			'textdomain'     => 'super-duper',
15
-			// textdomain of the plugin/theme (used to prefix the Gutenberg block)
16
-			'block-icon'     => 'fas fa-globe-americas',
17
-			// Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right
18
-			// OR font-awesome 5 class name: fas fa-globe-americas
19
-			'block-category' => 'widgets',
20
-			// the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'.
21
-			'block-keywords' => "['hello','world']",
22
-			// used in the block search, MAX 3
23
-			'block-output'   => array( // the block visual output elements as an array
6
+    public $arguments;
7
+
8
+    /**
9
+     * Sets up the widgets name etc
10
+     */
11
+    public function __construct() {
12
+
13
+        $options = array(
14
+            'textdomain'     => 'super-duper',
15
+            // textdomain of the plugin/theme (used to prefix the Gutenberg block)
16
+            'block-icon'     => 'fas fa-globe-americas',
17
+            // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right
18
+            // OR font-awesome 5 class name: fas fa-globe-americas
19
+            'block-category' => 'widgets',
20
+            // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'.
21
+            'block-keywords' => "['hello','world']",
22
+            // used in the block search, MAX 3
23
+            'block-output'   => array( // the block visual output elements as an array
24 24
 //				array(
25 25
 //					'element' => 'p',
26 26
 //					'title'   => __( 'Placeholder', 'ayecode-connect' ),
27 27
 //					'class'   => '[%className%]',
28 28
 //					'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%]
29 29
 //				)
30
-				array(
31
-					'element'       => 'BlocksProps',
32
-					'inner_element' => 'p',
33
-					'blockProps'    => array(
34
-						'className'               => '[%WrapClass%]',
30
+                array(
31
+                    'element'       => 'BlocksProps',
32
+                    'inner_element' => 'p',
33
+                    'blockProps'    => array(
34
+                        'className'               => '[%WrapClass%]',
35 35
 //						'content' => 'Hello: [%after_text%]'
36 36
 //						'if_dangerouslySetInnerHTML' => '{__html: blockstrap_build_shape(props.attributes) }',
37
-					),
38
-					'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%]
39
-
40
-
41
-				),
42
-			),
43
-			'block-wrap'    => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all.
44
-			'class_name'     => __CLASS__,
45
-			// The calling class name
46
-			'base_id'        => 'hello_world',
47
-			// this is used as the widget id and the shortcode id.
48
-			'name'           => __( 'Hello World', 'ayecode-connect' ),
49
-			// the name of the widget/block
50
-			'widget_ops'     => array(
51
-				'classname'   => 'hello-world-class',
52
-				// widget class
53
-				'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ),
54
-				// widget description
55
-			),
56
-			'no_wrap'       => true, // This will prevent the widget being wrapped in the containing widget class div.
57
-			'arguments'      => array( // these are the arguments that will be used in the widget, shortcode and block settings.
58
-				'after_text' => array( // this is the input name=''
59
-					'title'       => __( 'Text after hello:', 'ayecode-connect' ),
60
-					// input title
61
-					'desc'        => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ),
62
-					// input description
63
-					'type'        => 'text',
64
-					// the type of input, test, select, checkbox etc.
65
-					'placeholder' => 'World',
66
-					// the input placeholder text.
67
-					'desc_tip'    => true,
68
-					// if the input should show the widget description text as a tooltip.
69
-					'default'     => 'World',
70
-					// the input default value.
71
-					'advanced'    => false
72
-					// not yet implemented
73
-				),
74
-			)
75
-		);
76
-
77
-		parent::__construct( $options );
78
-	}
79
-
80
-
81
-	/**
82
-	 * This is the output function for the widget, shortcode and block (front end).
83
-	 *
84
-	 * @param array $args The arguments values.
85
-	 * @param array $widget_args The widget arguments when used.
86
-	 * @param string $content The shortcode content argument
87
-	 *
88
-	 * @return string
89
-	 */
90
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
91
-
92
-		/**
93
-		 * @var string $after_text
94
-		 * @var string $another_input This is added by filter below.
95
-		 */
96
-		extract( $args, EXTR_SKIP );
97
-
98
-		/*
37
+                    ),
38
+                    'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%]
39
+
40
+
41
+                ),
42
+            ),
43
+            'block-wrap'    => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all.
44
+            'class_name'     => __CLASS__,
45
+            // The calling class name
46
+            'base_id'        => 'hello_world',
47
+            // this is used as the widget id and the shortcode id.
48
+            'name'           => __( 'Hello World', 'ayecode-connect' ),
49
+            // the name of the widget/block
50
+            'widget_ops'     => array(
51
+                'classname'   => 'hello-world-class',
52
+                // widget class
53
+                'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ),
54
+                // widget description
55
+            ),
56
+            'no_wrap'       => true, // This will prevent the widget being wrapped in the containing widget class div.
57
+            'arguments'      => array( // these are the arguments that will be used in the widget, shortcode and block settings.
58
+                'after_text' => array( // this is the input name=''
59
+                    'title'       => __( 'Text after hello:', 'ayecode-connect' ),
60
+                    // input title
61
+                    'desc'        => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ),
62
+                    // input description
63
+                    'type'        => 'text',
64
+                    // the type of input, test, select, checkbox etc.
65
+                    'placeholder' => 'World',
66
+                    // the input placeholder text.
67
+                    'desc_tip'    => true,
68
+                    // if the input should show the widget description text as a tooltip.
69
+                    'default'     => 'World',
70
+                    // the input default value.
71
+                    'advanced'    => false
72
+                    // not yet implemented
73
+                ),
74
+            )
75
+        );
76
+
77
+        parent::__construct( $options );
78
+    }
79
+
80
+
81
+    /**
82
+     * This is the output function for the widget, shortcode and block (front end).
83
+     *
84
+     * @param array $args The arguments values.
85
+     * @param array $widget_args The widget arguments when used.
86
+     * @param string $content The shortcode content argument
87
+     *
88
+     * @return string
89
+     */
90
+    public function output( $args = array(), $widget_args = array(), $content = '' ) {
91
+
92
+        /**
93
+         * @var string $after_text
94
+         * @var string $another_input This is added by filter below.
95
+         */
96
+        extract( $args, EXTR_SKIP );
97
+
98
+        /*
99 99
 		 * This value is added by filter so might not exist if filter is removed so we check.
100 100
 		 */
101
-		if ( ! isset( $another_input ) ) {
102
-			$another_input = '';
103
-		}
101
+        if ( ! isset( $another_input ) ) {
102
+            $another_input = '';
103
+        }
104 104
 
105
-		return "Helllo: " . $after_text . "" . $another_input;
105
+        return "Helllo: " . $after_text . "" . $another_input;
106 106
 
107
-	}
107
+    }
108 108
 
109 109
 }
110 110
 
111 111
 // register it.
112 112
 add_action( 'widgets_init', function () {
113
-	register_widget( 'SD_Hello_World' );
113
+    register_widget( 'SD_Hello_World' );
114 114
 } );
115 115
 
116 116
 
@@ -123,26 +123,26 @@  discard block
 block discarded – undo
123 123
  */
124 124
 function _my_extra_arguments( $options ) {
125 125
 
126
-	/*
126
+    /*
127 127
 	 * Add a new input option.
128 128
 	 */
129
-	$options['arguments']['another_input'] = array(
130
-		'name'        => 'another_input', // this is the input name=''
131
-		'title'       => __( 'Another input:', 'ayecode-connect' ), // input title
132
-		'desc'        => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description
133
-		'type'        => 'text', // the type of input, test, select, checkbox etc.
134
-		'placeholder' => 'Placeholder text', // the input placeholder text.
135
-		'desc_tip'    => true, // if the input should show the widget description text as a tooltip.
136
-		'default'     => '', // the input default value.
137
-		'advanced'    => false // not yet implemented
138
-	);
139
-
140
-	/*
129
+    $options['arguments']['another_input'] = array(
130
+        'name'        => 'another_input', // this is the input name=''
131
+        'title'       => __( 'Another input:', 'ayecode-connect' ), // input title
132
+        'desc'        => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description
133
+        'type'        => 'text', // the type of input, test, select, checkbox etc.
134
+        'placeholder' => 'Placeholder text', // the input placeholder text.
135
+        'desc_tip'    => true, // if the input should show the widget description text as a tooltip.
136
+        'default'     => '', // the input default value.
137
+        'advanced'    => false // not yet implemented
138
+    );
139
+
140
+    /*
141 141
 	 * Output the new option in the block output also.
142 142
 	 */
143
-	$options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";;
143
+    $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";;
144 144
 
145
-	return $options;
145
+    return $options;
146 146
 }
147 147
 
148 148
 //add_filter( 'wp_super_duper_options_hello_world', '_my_extra_arguments' );
149 149
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -14,620 +14,620 @@
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * @var array An array of payment gateways.
40
-	 */
41
-	public $gateways;
42
-
43
-	/**
44
-	 * Class constructor.
45
-	 */
46
-	public function __construct() {
47
-		$this->define_constants();
48
-		$this->includes();
49
-		$this->init_hooks();
50
-		$this->set_properties();
51
-	}
52
-
53
-	/**
54
-	 * Sets a custom data property.
55
-	 *
56
-	 * @param string $prop The prop to set.
57
-	 * @param mixed $value The value to retrieve.
58
-	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
61
-	}
62
-
63
-	/**
64
-	 * Gets a custom data property.
65
-	 *
66
-	 * @param string $prop The prop to set.
67
-	 * @return mixed The value.
68
-	 */
69
-	public function get( $prop ) {
70
-		if ( isset( $this->data[ $prop ] ) ) {
71
-			return $this->data[ $prop ];
72
-		}
73
-
74
-		return null;
75
-	}
76
-
77
-	/**
78
-	 * Define class properties.
79
-	 */
80
-	public function set_properties() {
81
-		// Sessions.
82
-		$this->set( 'session', new WPInv_Session_Handler() );
83
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
85
-
86
-		// Init other objects.
87
-		$this->set( 'notes', new WPInv_Notes() );
88
-		$this->set( 'api', new WPInv_API() );
89
-		$this->set( 'post_types', new GetPaid_Post_Types() );
90
-		$this->set( 'template', new GetPaid_Template() );
91
-		$this->set( 'admin', new GetPaid_Admin() );
92
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
93
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
94
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
95
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
96
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
97
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
98
-	}
99
-
100
-	 /**
101
-	 * Define plugin constants.
102
-	 */
103
-	public function define_constants() {
104
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
105
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
106
-		$this->version = WPINV_VERSION;
107
-	}
108
-
109
-	/**
110
-	 * Hook into actions and filters.
111
-	 *
112
-	 * @since 1.0.19
113
-	 */
114
-	protected function init_hooks() {
115
-		/* Internationalize the text strings used. */
116
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
117
-
118
-		// Init the plugin after WordPress inits.
119
-		add_action( 'init', array( $this, 'init' ), 1 );
120
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
121
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
122
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
123
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
124
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
125
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
126
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
127
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
128
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
129
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
130
-
131
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
132
-		add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
133
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
134
-
135
-		// Fires after registering actions.
136
-		do_action( 'wpinv_actions', $this );
137
-		do_action( 'getpaid_actions', $this );
138
-	}
139
-
140
-	public function plugins_loaded() {
141
-		/* Internationalize the text strings used. */
142
-		$this->load_textdomain();
143
-
144
-		do_action( 'wpinv_loaded' );
145
-
146
-		// Fix oxygen page builder conflict
147
-		if ( function_exists( 'ct_css_output' ) ) {
148
-			wpinv_oxygen_fix_conflict();
149
-		}
150
-	}
151
-
152
-	/**
153
-	 * Load Localisation files.
154
-	 *
155
-	 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
156
-	 *
157
-	 * Locales found in:
158
-	 *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
159
-	 *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
160
-	 *
161
-	 * @since 1.0.0
162
-	 */
163
-	public function load_textdomain() {
164
-		// Determines the current locale.
165
-		if ( function_exists( 'determine_locale' ) ) {
166
-			$locale = determine_locale();
167
-		} else if ( function_exists( 'get_user_locale' ) ) {
168
-			$locale = get_user_locale();
169
-		} else {
170
-			$locale = get_locale();
171
-		}
172
-
173
-		/**
174
-		 * Filter the locale to use for translations.
175
-		 */
176
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
177
-
178
-		unload_textdomain( 'invoicing' );
179
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
180
-		load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' );
181
-	}
182
-
183
-	/**
184
-	 * Include required core files used in admin and on the frontend.
185
-	 */
186
-	public function includes() {
187
-		// Start with the settings.
188
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
189
-
190
-		// Packages/libraries.
191
-		require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
192
-		require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
193
-
194
-		// Load functions.
195
-		require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
196
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
197
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
198
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
199
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
200
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
201
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
202
-		require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
203
-		require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
204
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
205
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
206
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
207
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
208
-		require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
209
-		require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
210
-
211
-		// Register autoloader.
212
-		try {
213
-			spl_autoload_register( array( $this, 'autoload' ), true );
214
-		} catch ( Exception $e ) {
215
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
216
-		}
217
-
218
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
219
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
220
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
221
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
222
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
223
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
224
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
225
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
226
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
227
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
228
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
229
-		require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
230
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
231
-		require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
232
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
233
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
234
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
235
-		require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
236
-		require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
237
-		require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
238
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
239
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
240
-
241
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
242
-			GetPaid_Post_Types_Admin::init();
243
-
244
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
245
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
246
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
247
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
248
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
249
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
250
-			// load the user class only on the users.php page
251
-			global $pagenow;
252
-			if ( $pagenow == 'users.php' ) {
253
-				new WPInv_Admin_Users();
254
-			}
255
-		}
256
-
257
-		// Register cli commands
258
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
259
-			require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
260
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
261
-		}
262
-	}
263
-
264
-	/**
265
-	 * Class autoloader
266
-	 *
267
-	 * @param       string $class_name The name of the class to load.
268
-	 * @access      public
269
-	 * @since       1.0.19
270
-	 * @return      void
271
-	 */
272
-	public function autoload( $class_name ) {
273
-		// Normalize the class name...
274
-		$class_name  = strtolower( $class_name );
275
-
276
-		// ... and make sure it is our class.
277
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
278
-			return;
279
-		}
280
-
281
-		// Next, prepare the file name from the class.
282
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
283
-
284
-		// Base path of the classes.
285
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
286
-
287
-		// And an array of possible locations in order of importance.
288
-		$locations = array(
289
-			"$plugin_path/includes",
290
-			"$plugin_path/includes/data-stores",
291
-			"$plugin_path/includes/gateways",
292
-			"$plugin_path/includes/payments",
293
-			"$plugin_path/includes/geolocation",
294
-			"$plugin_path/includes/reports",
295
-			"$plugin_path/includes/api",
296
-			"$plugin_path/includes/admin",
297
-			"$plugin_path/includes/admin/meta-boxes",
298
-		);
299
-
300
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
301
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
302
-				include trailingslashit( $location ) . $file_name;
303
-				break;
304
-			}
305
-		}
306
-	}
307
-
308
-	/**
309
-	 * Inits hooks etc.
310
-	 */
311
-	public function init() {
312
-		// Fires before getpaid inits.
313
-		do_action( 'before_getpaid_init', $this );
314
-
315
-		// Maybe upgrade.
316
-		$this->maybe_upgrade_database();
317
-
318
-		// Load default gateways.
319
-		$gateways = apply_filters(
320
-			'getpaid_default_gateways',
321
-			array(
322
-				'manual'        => 'GetPaid_Manual_Gateway',
323
-				'paypal'        => 'GetPaid_Paypal_Gateway',
324
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
-			)
328
-		);
329
-
330
-		foreach ( $gateways as $id => $class ) {
331
-			$this->gateways[ $id ] = new $class();
332
-		}
333
-
334
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
-			GetPaid_Installer::rename_gateways_label();
336
-			update_option( 'wpinv_renamed_gateways', 'yes' );
337
-		}
338
-
339
-		// Fires after getpaid inits.
340
-		do_action( 'getpaid_init', $this );
341
-	}
342
-
343
-	/**
344
-	 * Checks if this is an IPN request and processes it.
345
-	 */
346
-	public function maybe_process_ipn() {
347
-		// Ensure that this is an IPN request.
348
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
349
-			return;
350
-		}
351
-
352
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
353
-
354
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
355
-		do_action( "wpinv_verify_{$gateway}_ipn" );
356
-		exit;
357
-	}
358
-
359
-	public function enqueue_scripts() {
360
-		// Fires before adding scripts.
361
-		do_action( 'getpaid_enqueue_scripts' );
362
-
363
-		$localize                         = array();
364
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
365
-		$localize['thousands']            = wpinv_thousands_separator();
366
-		$localize['decimals']             = wpinv_decimal_separator();
367
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
368
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
369
-		$localize['UseTaxes']             = wpinv_use_taxes();
370
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
371
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
372
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
373
-		$localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
374
-
375
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
376
-
377
-		// reCaptcha.
378
-		if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) {
379
-			wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
380
-		}
381
-
382
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
383
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
384
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
385
-	}
386
-
387
-	public function wpinv_actions() {
388
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
389
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
390
-		}
391
-
392
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
393
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
394
-		}
395
-	}
396
-
397
-	/**
398
-	 * Fires an action after verifying that a user can fire them.
399
-	 *
400
-	 * Note: If the action is on an invoice, subscription etc, esure that the
401
-	 * current user owns the invoice/subscription.
402
-	 */
403
-	public function maybe_do_authenticated_action() {
404
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
405
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
-			$data = wp_unslash( $_REQUEST );
407
-
408
-			if ( is_user_logged_in() ) {
409
-				do_action( "getpaid_authenticated_action_$key", $data );
410
-			}
411
-
412
-			do_action( "getpaid_unauthenticated_action_$key", $data );
413
-		}
414
-	}
415
-
416
-	public function pre_get_posts( $wp_query ) {
417
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
418
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
419
-		}
420
-
421
-		return $wp_query;
422
-	}
423
-
424
-	/**
425
-	 * Register widgets
426
-	 *
427
-	 */
428
-	public function register_widgets() {
429
-		global $pagenow;
430
-
431
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
432
-		// So we disable our widgets when editing a page with UX Builder.
433
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
434
-			return;
435
-		}
436
-
437
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
438
-
439
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
440
-			// don't initiate in these conditions.
441
-		} else {
442
-			// Only load allowed widgets.
443
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
444
-			$widgets = apply_filters(
445
-				'getpaid_widget_classes',
446
-				array(
447
-					'WPInv_Checkout_Widget',
448
-					'WPInv_History_Widget',
449
-					'WPInv_Receipt_Widget',
450
-					'WPInv_Subscriptions_Widget',
451
-					'WPInv_Buy_Item_Widget',
452
-					'WPInv_Messages_Widget',
453
-					'WPInv_GetPaid_Widget',
454
-					'WPInv_Invoice_Widget',
455
-				)
456
-			);
457
-
458
-			// For each widget...
459
-			foreach ( $widgets as $widget ) {
460
-				// Abort early if it is excluded for this page.
461
-				if ( in_array( $widget, $exclude ) ) {
462
-					continue;
463
-				}
464
-
465
-				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
466
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
467
-					register_widget( $widget );
468
-				} else {
469
-					new $widget();
470
-				}
471
-			}
472
-		}
473
-	}
474
-
475
-	/**
476
-	 * Upgrades the database.
477
-	 *
478
-	 * @since 2.0.2
479
-	 */
480
-	public function maybe_upgrade_database() {
481
-		// Ensure the database tables are up to date.
482
-		GetPaid_Installer::maybe_create_db_tables();
483
-
484
-		$wpi_version = get_option( 'wpinv_version', 0 );
485
-
486
-		if ( $wpi_version == WPINV_VERSION ) {
487
-			return;
488
-		}
489
-
490
-		$installer = new GetPaid_Installer();
491
-
492
-		if ( empty( $wpi_version ) ) {
493
-			return $installer->upgrade_db( 0 );
494
-		}
495
-
496
-		$upgrades  = array(
497
-			'0.0.5' => '004',
498
-			'1.0.3' => '102',
499
-			'2.0.0' => '118',
500
-			'2.8.0' => '279',
501
-		);
502
-
503
-		foreach ( $upgrades as $key => $method ) {
504
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
505
-				return $installer->upgrade_db( $method );
506
-			}
507
-		}
508
-	}
509
-
510
-	/**
511
-	 * Flushes the permalinks if needed.
512
-	 *
513
-	 * @since 2.0.8
514
-	 */
515
-	public function maybe_flush_permalinks() {
516
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
517
-
518
-		if ( ! empty( $flush ) ) {
519
-			flush_rewrite_rules();
520
-			delete_option( 'wpinv_flush_permalinks' );
521
-		}
522
-	}
523
-
524
-	/**
525
-	 * Remove our pages from yoast sitemaps.
526
-	 *
527
-	 * @since 1.0.19
528
-	 * @param int[] $excluded_posts_ids
529
-	 */
530
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
531
-		// Ensure that we have an array.
532
-		if ( ! is_array( $excluded_posts_ids ) ) {
533
-			$excluded_posts_ids = array();
534
-		}
535
-
536
-		// Prepare our pages.
537
-		$our_pages = array();
538
-
539
-		// Checkout page.
540
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
541
-
542
-		// Success page.
543
-		$our_pages[] = wpinv_get_option( 'success_page', false );
544
-
545
-		// Failure page.
546
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
547
-
548
-		// History page.
549
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
550
-
551
-		// Subscriptions page.
552
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
553
-
554
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
555
-
556
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
557
-
558
-		return array_unique( $excluded_posts_ids );
559
-	}
560
-
561
-	/**
562
-	 * Remove our pages from yoast sitemaps.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param string[] $post_types
566
-	 */
567
-	public function exclude_invoicing_post_types( $post_types ) {
568
-		// Ensure that we have an array.
569
-		if ( ! is_array( $post_types ) ) {
570
-			$post_types = array();
571
-		}
572
-
573
-		// Remove our post types.
574
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
575
-	}
576
-
577
-	/**
578
-	 * Displays additional footer code.
579
-	 *
580
-	 * @since 2.0.0
581
-	 */
582
-	public function wp_footer() {
583
-		wpinv_get_template( 'frontend-footer.php' );
584
-	}
585
-
586
-	/**
587
-	 * Displays additional header code.
588
-	 *
589
-	 * @since 2.0.0
590
-	 */
591
-	public function wp_head() {
592
-		wpinv_get_template( 'frontend-head.php' );
593
-	}
594
-
595
-	/**
596
-	 * Custom query vars.
597
-	 *
598
-	 */
599
-	public function custom_query_vars( $vars ) {
600
-		$vars[] = 'getpaid-ipn';
601
-		return $vars;
602
-	}
603
-
604
-	/**
605
-	 * Add rewrite tags and rules.
606
-	 *
607
-	 */
608
-	public function add_rewrite_rule() {
609
-		$tag = 'getpaid-ipn';
610
-		add_rewrite_tag( "%$tag%", '([^&]+)' );
611
-		add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
612
-	}
613
-
614
-	/**
615
-	 * Processes non-query string ipns.
616
-	 *
617
-	 */
618
-	public function maybe_process_new_ipn( $query ) {
619
-		if ( is_admin() || ! $query->is_main_query() ) {
620
-			return;
621
-		}
622
-
623
-		$gateway = get_query_var( 'getpaid-ipn' );
624
-
625
-		if ( ! empty( $gateway ) ) {
626
-			$gateway = sanitize_text_field( $gateway );
627
-			nocache_headers();
628
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
629
-			do_action( "wpinv_verify_{$gateway}_ipn" );
630
-			exit;
631
-		}
632
-	}
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @var array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     *
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+        if ( isset( $this->data[ $prop ] ) ) {
71
+            return $this->data[ $prop ];
72
+        }
73
+
74
+        return null;
75
+    }
76
+
77
+    /**
78
+     * Define class properties.
79
+     */
80
+    public function set_properties() {
81
+        // Sessions.
82
+        $this->set( 'session', new WPInv_Session_Handler() );
83
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
85
+
86
+        // Init other objects.
87
+        $this->set( 'notes', new WPInv_Notes() );
88
+        $this->set( 'api', new WPInv_API() );
89
+        $this->set( 'post_types', new GetPaid_Post_Types() );
90
+        $this->set( 'template', new GetPaid_Template() );
91
+        $this->set( 'admin', new GetPaid_Admin() );
92
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
93
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
94
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
95
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
96
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
97
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
98
+    }
99
+
100
+        /**
101
+         * Define plugin constants.
102
+         */
103
+    public function define_constants() {
104
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
105
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
106
+        $this->version = WPINV_VERSION;
107
+    }
108
+
109
+    /**
110
+     * Hook into actions and filters.
111
+     *
112
+     * @since 1.0.19
113
+     */
114
+    protected function init_hooks() {
115
+        /* Internationalize the text strings used. */
116
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
117
+
118
+        // Init the plugin after WordPress inits.
119
+        add_action( 'init', array( $this, 'init' ), 1 );
120
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
121
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
122
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
123
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
124
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
125
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
126
+        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
127
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
128
+        add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
129
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
130
+
131
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
132
+        add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
133
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
134
+
135
+        // Fires after registering actions.
136
+        do_action( 'wpinv_actions', $this );
137
+        do_action( 'getpaid_actions', $this );
138
+    }
139
+
140
+    public function plugins_loaded() {
141
+        /* Internationalize the text strings used. */
142
+        $this->load_textdomain();
143
+
144
+        do_action( 'wpinv_loaded' );
145
+
146
+        // Fix oxygen page builder conflict
147
+        if ( function_exists( 'ct_css_output' ) ) {
148
+            wpinv_oxygen_fix_conflict();
149
+        }
150
+    }
151
+
152
+    /**
153
+     * Load Localisation files.
154
+     *
155
+     * Note: the first-loaded translation file overrides any following ones if the same translation is present.
156
+     *
157
+     * Locales found in:
158
+     *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
159
+     *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
160
+     *
161
+     * @since 1.0.0
162
+     */
163
+    public function load_textdomain() {
164
+        // Determines the current locale.
165
+        if ( function_exists( 'determine_locale' ) ) {
166
+            $locale = determine_locale();
167
+        } else if ( function_exists( 'get_user_locale' ) ) {
168
+            $locale = get_user_locale();
169
+        } else {
170
+            $locale = get_locale();
171
+        }
172
+
173
+        /**
174
+         * Filter the locale to use for translations.
175
+         */
176
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
177
+
178
+        unload_textdomain( 'invoicing' );
179
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
180
+        load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' );
181
+    }
182
+
183
+    /**
184
+     * Include required core files used in admin and on the frontend.
185
+     */
186
+    public function includes() {
187
+        // Start with the settings.
188
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
189
+
190
+        // Packages/libraries.
191
+        require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
192
+        require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
193
+
194
+        // Load functions.
195
+        require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
196
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
197
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
198
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
199
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
200
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
201
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
202
+        require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
203
+        require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
204
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
205
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
206
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
207
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
208
+        require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
209
+        require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
210
+
211
+        // Register autoloader.
212
+        try {
213
+            spl_autoload_register( array( $this, 'autoload' ), true );
214
+        } catch ( Exception $e ) {
215
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
216
+        }
217
+
218
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
219
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
220
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
221
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
222
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
223
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
224
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
225
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
226
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
227
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
228
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
229
+        require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
230
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
231
+        require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
232
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
233
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
234
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
235
+        require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
236
+        require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
237
+        require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
238
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
239
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
240
+
241
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
242
+            GetPaid_Post_Types_Admin::init();
243
+
244
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
245
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
246
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
247
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
248
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
249
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
250
+            // load the user class only on the users.php page
251
+            global $pagenow;
252
+            if ( $pagenow == 'users.php' ) {
253
+                new WPInv_Admin_Users();
254
+            }
255
+        }
256
+
257
+        // Register cli commands
258
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
259
+            require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
260
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
261
+        }
262
+    }
263
+
264
+    /**
265
+     * Class autoloader
266
+     *
267
+     * @param       string $class_name The name of the class to load.
268
+     * @access      public
269
+     * @since       1.0.19
270
+     * @return      void
271
+     */
272
+    public function autoload( $class_name ) {
273
+        // Normalize the class name...
274
+        $class_name  = strtolower( $class_name );
275
+
276
+        // ... and make sure it is our class.
277
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
278
+            return;
279
+        }
280
+
281
+        // Next, prepare the file name from the class.
282
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
283
+
284
+        // Base path of the classes.
285
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
286
+
287
+        // And an array of possible locations in order of importance.
288
+        $locations = array(
289
+            "$plugin_path/includes",
290
+            "$plugin_path/includes/data-stores",
291
+            "$plugin_path/includes/gateways",
292
+            "$plugin_path/includes/payments",
293
+            "$plugin_path/includes/geolocation",
294
+            "$plugin_path/includes/reports",
295
+            "$plugin_path/includes/api",
296
+            "$plugin_path/includes/admin",
297
+            "$plugin_path/includes/admin/meta-boxes",
298
+        );
299
+
300
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
301
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
302
+                include trailingslashit( $location ) . $file_name;
303
+                break;
304
+            }
305
+        }
306
+    }
307
+
308
+    /**
309
+     * Inits hooks etc.
310
+     */
311
+    public function init() {
312
+        // Fires before getpaid inits.
313
+        do_action( 'before_getpaid_init', $this );
314
+
315
+        // Maybe upgrade.
316
+        $this->maybe_upgrade_database();
317
+
318
+        // Load default gateways.
319
+        $gateways = apply_filters(
320
+            'getpaid_default_gateways',
321
+            array(
322
+                'manual'        => 'GetPaid_Manual_Gateway',
323
+                'paypal'        => 'GetPaid_Paypal_Gateway',
324
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
+            )
328
+        );
329
+
330
+        foreach ( $gateways as $id => $class ) {
331
+            $this->gateways[ $id ] = new $class();
332
+        }
333
+
334
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
+            GetPaid_Installer::rename_gateways_label();
336
+            update_option( 'wpinv_renamed_gateways', 'yes' );
337
+        }
338
+
339
+        // Fires after getpaid inits.
340
+        do_action( 'getpaid_init', $this );
341
+    }
342
+
343
+    /**
344
+     * Checks if this is an IPN request and processes it.
345
+     */
346
+    public function maybe_process_ipn() {
347
+        // Ensure that this is an IPN request.
348
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
349
+            return;
350
+        }
351
+
352
+        $gateway = sanitize_text_field( $_GET['wpi-gateway'] );
353
+
354
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
355
+        do_action( "wpinv_verify_{$gateway}_ipn" );
356
+        exit;
357
+    }
358
+
359
+    public function enqueue_scripts() {
360
+        // Fires before adding scripts.
361
+        do_action( 'getpaid_enqueue_scripts' );
362
+
363
+        $localize                         = array();
364
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
365
+        $localize['thousands']            = wpinv_thousands_separator();
366
+        $localize['decimals']             = wpinv_decimal_separator();
367
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
368
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
369
+        $localize['UseTaxes']             = wpinv_use_taxes();
370
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
371
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
372
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
373
+        $localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
374
+
375
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
376
+
377
+        // reCaptcha.
378
+        if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) {
379
+            wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
380
+        }
381
+
382
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
383
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
384
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
385
+    }
386
+
387
+    public function wpinv_actions() {
388
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
389
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
390
+        }
391
+
392
+        if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
393
+            include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
394
+        }
395
+    }
396
+
397
+    /**
398
+     * Fires an action after verifying that a user can fire them.
399
+     *
400
+     * Note: If the action is on an invoice, subscription etc, esure that the
401
+     * current user owns the invoice/subscription.
402
+     */
403
+    public function maybe_do_authenticated_action() {
404
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
405
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
+            $data = wp_unslash( $_REQUEST );
407
+
408
+            if ( is_user_logged_in() ) {
409
+                do_action( "getpaid_authenticated_action_$key", $data );
410
+            }
411
+
412
+            do_action( "getpaid_unauthenticated_action_$key", $data );
413
+        }
414
+    }
415
+
416
+    public function pre_get_posts( $wp_query ) {
417
+        if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
418
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
419
+        }
420
+
421
+        return $wp_query;
422
+    }
423
+
424
+    /**
425
+     * Register widgets
426
+     *
427
+     */
428
+    public function register_widgets() {
429
+        global $pagenow;
430
+
431
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
432
+        // So we disable our widgets when editing a page with UX Builder.
433
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
434
+            return;
435
+        }
436
+
437
+        $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
438
+
439
+        if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
440
+            // don't initiate in these conditions.
441
+        } else {
442
+            // Only load allowed widgets.
443
+            $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
444
+            $widgets = apply_filters(
445
+                'getpaid_widget_classes',
446
+                array(
447
+                    'WPInv_Checkout_Widget',
448
+                    'WPInv_History_Widget',
449
+                    'WPInv_Receipt_Widget',
450
+                    'WPInv_Subscriptions_Widget',
451
+                    'WPInv_Buy_Item_Widget',
452
+                    'WPInv_Messages_Widget',
453
+                    'WPInv_GetPaid_Widget',
454
+                    'WPInv_Invoice_Widget',
455
+                )
456
+            );
457
+
458
+            // For each widget...
459
+            foreach ( $widgets as $widget ) {
460
+                // Abort early if it is excluded for this page.
461
+                if ( in_array( $widget, $exclude ) ) {
462
+                    continue;
463
+                }
464
+
465
+                // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
466
+                if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
467
+                    register_widget( $widget );
468
+                } else {
469
+                    new $widget();
470
+                }
471
+            }
472
+        }
473
+    }
474
+
475
+    /**
476
+     * Upgrades the database.
477
+     *
478
+     * @since 2.0.2
479
+     */
480
+    public function maybe_upgrade_database() {
481
+        // Ensure the database tables are up to date.
482
+        GetPaid_Installer::maybe_create_db_tables();
483
+
484
+        $wpi_version = get_option( 'wpinv_version', 0 );
485
+
486
+        if ( $wpi_version == WPINV_VERSION ) {
487
+            return;
488
+        }
489
+
490
+        $installer = new GetPaid_Installer();
491
+
492
+        if ( empty( $wpi_version ) ) {
493
+            return $installer->upgrade_db( 0 );
494
+        }
495
+
496
+        $upgrades  = array(
497
+            '0.0.5' => '004',
498
+            '1.0.3' => '102',
499
+            '2.0.0' => '118',
500
+            '2.8.0' => '279',
501
+        );
502
+
503
+        foreach ( $upgrades as $key => $method ) {
504
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
505
+                return $installer->upgrade_db( $method );
506
+            }
507
+        }
508
+    }
509
+
510
+    /**
511
+     * Flushes the permalinks if needed.
512
+     *
513
+     * @since 2.0.8
514
+     */
515
+    public function maybe_flush_permalinks() {
516
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
517
+
518
+        if ( ! empty( $flush ) ) {
519
+            flush_rewrite_rules();
520
+            delete_option( 'wpinv_flush_permalinks' );
521
+        }
522
+    }
523
+
524
+    /**
525
+     * Remove our pages from yoast sitemaps.
526
+     *
527
+     * @since 1.0.19
528
+     * @param int[] $excluded_posts_ids
529
+     */
530
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
531
+        // Ensure that we have an array.
532
+        if ( ! is_array( $excluded_posts_ids ) ) {
533
+            $excluded_posts_ids = array();
534
+        }
535
+
536
+        // Prepare our pages.
537
+        $our_pages = array();
538
+
539
+        // Checkout page.
540
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
541
+
542
+        // Success page.
543
+        $our_pages[] = wpinv_get_option( 'success_page', false );
544
+
545
+        // Failure page.
546
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
547
+
548
+        // History page.
549
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
550
+
551
+        // Subscriptions page.
552
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
553
+
554
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
555
+
556
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
557
+
558
+        return array_unique( $excluded_posts_ids );
559
+    }
560
+
561
+    /**
562
+     * Remove our pages from yoast sitemaps.
563
+     *
564
+     * @since 1.0.19
565
+     * @param string[] $post_types
566
+     */
567
+    public function exclude_invoicing_post_types( $post_types ) {
568
+        // Ensure that we have an array.
569
+        if ( ! is_array( $post_types ) ) {
570
+            $post_types = array();
571
+        }
572
+
573
+        // Remove our post types.
574
+        return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
575
+    }
576
+
577
+    /**
578
+     * Displays additional footer code.
579
+     *
580
+     * @since 2.0.0
581
+     */
582
+    public function wp_footer() {
583
+        wpinv_get_template( 'frontend-footer.php' );
584
+    }
585
+
586
+    /**
587
+     * Displays additional header code.
588
+     *
589
+     * @since 2.0.0
590
+     */
591
+    public function wp_head() {
592
+        wpinv_get_template( 'frontend-head.php' );
593
+    }
594
+
595
+    /**
596
+     * Custom query vars.
597
+     *
598
+     */
599
+    public function custom_query_vars( $vars ) {
600
+        $vars[] = 'getpaid-ipn';
601
+        return $vars;
602
+    }
603
+
604
+    /**
605
+     * Add rewrite tags and rules.
606
+     *
607
+     */
608
+    public function add_rewrite_rule() {
609
+        $tag = 'getpaid-ipn';
610
+        add_rewrite_tag( "%$tag%", '([^&]+)' );
611
+        add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
612
+    }
613
+
614
+    /**
615
+     * Processes non-query string ipns.
616
+     *
617
+     */
618
+    public function maybe_process_new_ipn( $query ) {
619
+        if ( is_admin() || ! $query->is_main_query() ) {
620
+            return;
621
+        }
622
+
623
+        $gateway = get_query_var( 'getpaid-ipn' );
624
+
625
+        if ( ! empty( $gateway ) ) {
626
+            $gateway = sanitize_text_field( $gateway );
627
+            nocache_headers();
628
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
629
+            do_action( "wpinv_verify_{$gateway}_ipn" );
630
+            exit;
631
+        }
632
+    }
633 633
 }
Please login to merge, or discard this patch.
widgets/subscriptions.php 1 patch
Indentation   +347 added lines, -347 removed lines patch added patch discarded remove patch
@@ -14,143 +14,143 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_Widget extends WP_Super_Duper {
16 16
 
17
-	/**
18
-	 * Register the widget with WordPress.
19
-	 *
20
-	 */
21
-	public function __construct() {
22
-
23
-		$options = array(
24
-			'textdomain'     => 'invoicing',
25
-			'block-icon'     => 'controls-repeat',
26
-			'block-category' => 'widgets',
27
-			'block-keywords' => "['invoicing','subscriptions', 'getpaid']",
28
-			'class_name'     => __CLASS__,
29
-			'base_id'        => 'wpinv_subscriptions',
30
-			'name'           => __( 'GetPaid > Subscriptions', 'invoicing' ),
31
-			'widget_ops'     => array(
32
-				'classname'   => 'getpaid-subscriptions bsui',
33
-				'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
34
-			),
35
-			'arguments'      => array(
36
-				'title' => array(
37
-					'title'    => __( 'Widget title', 'invoicing' ),
38
-					'desc'     => __( 'Enter widget title.', 'invoicing' ),
39
-					'type'     => 'text',
40
-					'desc_tip' => true,
41
-					'default'  => '',
42
-					'advanced' => false,
43
-				),
44
-			),
45
-
46
-		);
47
-
48
-		parent::__construct( $options );
49
-	}
50
-
51
-	/**
52
-	 * Retrieves current user's subscriptions.
53
-	 *
54
-	 * @return GetPaid_Subscriptions_Query
55
-	 */
56
-	public function get_subscriptions() {
57
-
58
-		// Prepare license args.
59
-		$args  = array(
60
-			'customer_in' => get_current_user_id(),
61
-			'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
62
-		);
63
-
64
-		return new GetPaid_Subscriptions_Query( $args );
65
-
66
-	}
67
-
68
-	/**
69
-	 * The Super block output function.
70
-	 *
71
-	 * @param array $args
72
-	 * @param array $widget_args
73
-	 * @param string $content
74
-	 *
75
-	 * @return mixed|string|bool
76
-	 */
77
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
78
-
79
-		// Ensure that the user is logged in.
80
-		if ( ! is_user_logged_in() ) {
81
-
82
-			return aui()->alert(
83
-				array(
84
-					'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
85
-					'type'    => 'error',
86
-				)
87
-			);
88
-
89
-		}
90
-
91
-		// Are we displaying a single subscription?
92
-		if ( isset( $_GET['subscription'] ) ) {
93
-			return $this->display_single_subscription( intval( $_GET['subscription'] ) );
94
-		}
95
-
96
-		// Retrieve the user's subscriptions.
97
-		$subscriptions = $this->get_subscriptions();
98
-
99
-		// Start the output buffer.
100
-		ob_start();
101
-
102
-		// Backwards compatibility.
103
-		do_action( 'wpinv_before_user_subscriptions' );
104
-
105
-		// Display errors and notices.
106
-		wpinv_print_errors();
107
-
108
-		do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
109
-
110
-		// Print the table header.
111
-		$this->print_table_header();
112
-
113
-		// Print table body.
114
-		$this->print_table_body( $subscriptions->get_results() );
115
-
116
-		// Print table footer.
117
-		$this->print_table_footer();
118
-
119
-		// Print the navigation.
120
-		$this->print_navigation( $subscriptions->get_total() );
121
-
122
-		// Backwards compatibility.
123
-		do_action( 'wpinv_after_user_subscriptions' );
124
-
125
-		// Return the output.
126
-		return ob_get_clean();
127
-
128
-	}
129
-
130
-	/**
131
-	 * Retrieves the subscription columns.
132
-	 *
133
-	 * @return array
134
-	 */
135
-	public function get_subscriptions_table_columns() {
17
+    /**
18
+     * Register the widget with WordPress.
19
+     *
20
+     */
21
+    public function __construct() {
22
+
23
+        $options = array(
24
+            'textdomain'     => 'invoicing',
25
+            'block-icon'     => 'controls-repeat',
26
+            'block-category' => 'widgets',
27
+            'block-keywords' => "['invoicing','subscriptions', 'getpaid']",
28
+            'class_name'     => __CLASS__,
29
+            'base_id'        => 'wpinv_subscriptions',
30
+            'name'           => __( 'GetPaid > Subscriptions', 'invoicing' ),
31
+            'widget_ops'     => array(
32
+                'classname'   => 'getpaid-subscriptions bsui',
33
+                'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
34
+            ),
35
+            'arguments'      => array(
36
+                'title' => array(
37
+                    'title'    => __( 'Widget title', 'invoicing' ),
38
+                    'desc'     => __( 'Enter widget title.', 'invoicing' ),
39
+                    'type'     => 'text',
40
+                    'desc_tip' => true,
41
+                    'default'  => '',
42
+                    'advanced' => false,
43
+                ),
44
+            ),
45
+
46
+        );
47
+
48
+        parent::__construct( $options );
49
+    }
50
+
51
+    /**
52
+     * Retrieves current user's subscriptions.
53
+     *
54
+     * @return GetPaid_Subscriptions_Query
55
+     */
56
+    public function get_subscriptions() {
57
+
58
+        // Prepare license args.
59
+        $args  = array(
60
+            'customer_in' => get_current_user_id(),
61
+            'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
62
+        );
63
+
64
+        return new GetPaid_Subscriptions_Query( $args );
65
+
66
+    }
67
+
68
+    /**
69
+     * The Super block output function.
70
+     *
71
+     * @param array $args
72
+     * @param array $widget_args
73
+     * @param string $content
74
+     *
75
+     * @return mixed|string|bool
76
+     */
77
+    public function output( $args = array(), $widget_args = array(), $content = '' ) {
78
+
79
+        // Ensure that the user is logged in.
80
+        if ( ! is_user_logged_in() ) {
81
+
82
+            return aui()->alert(
83
+                array(
84
+                    'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
85
+                    'type'    => 'error',
86
+                )
87
+            );
88
+
89
+        }
90
+
91
+        // Are we displaying a single subscription?
92
+        if ( isset( $_GET['subscription'] ) ) {
93
+            return $this->display_single_subscription( intval( $_GET['subscription'] ) );
94
+        }
95
+
96
+        // Retrieve the user's subscriptions.
97
+        $subscriptions = $this->get_subscriptions();
98
+
99
+        // Start the output buffer.
100
+        ob_start();
101
+
102
+        // Backwards compatibility.
103
+        do_action( 'wpinv_before_user_subscriptions' );
104
+
105
+        // Display errors and notices.
106
+        wpinv_print_errors();
107
+
108
+        do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
109
+
110
+        // Print the table header.
111
+        $this->print_table_header();
112
+
113
+        // Print table body.
114
+        $this->print_table_body( $subscriptions->get_results() );
115
+
116
+        // Print table footer.
117
+        $this->print_table_footer();
118
+
119
+        // Print the navigation.
120
+        $this->print_navigation( $subscriptions->get_total() );
121
+
122
+        // Backwards compatibility.
123
+        do_action( 'wpinv_after_user_subscriptions' );
124
+
125
+        // Return the output.
126
+        return ob_get_clean();
127
+
128
+    }
129
+
130
+    /**
131
+     * Retrieves the subscription columns.
132
+     *
133
+     * @return array
134
+     */
135
+    public function get_subscriptions_table_columns() {
136 136
 
137
-		$columns = array(
138
-			'subscription' => __( 'Subscription', 'invoicing' ),
139
-			'amount'       => __( 'Amount', 'invoicing' ),
140
-			'renewal-date' => __( 'Next payment', 'invoicing' ),
141
-			'status'       => __( 'Status', 'invoicing' ),
142
-		);
137
+        $columns = array(
138
+            'subscription' => __( 'Subscription', 'invoicing' ),
139
+            'amount'       => __( 'Amount', 'invoicing' ),
140
+            'renewal-date' => __( 'Next payment', 'invoicing' ),
141
+            'status'       => __( 'Status', 'invoicing' ),
142
+        );
143 143
 
144
-		return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
145
-	}
144
+        return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
145
+    }
146 146
 
147
-	/**
148
-	 * Displays the table header.
149
-	 *
150
-	 */
151
-	public function print_table_header() {
147
+    /**
148
+     * Displays the table header.
149
+     *
150
+     */
151
+    public function print_table_header() {
152 152
 
153
-		?>
153
+        ?>
154 154
 
155 155
 			<table class="table table-bordered table-striped">
156 156
 
@@ -166,122 +166,122 @@  discard block
 block discarded – undo
166 166
 
167 167
 		<?php
168 168
 
169
-	}
169
+    }
170 170
 
171
-	/**
172
-	 * Displays the table body.
173
-	 *
174
-	 * @param WPInv_Subscription[] $subscriptions
175
-	 */
176
-	public function print_table_body( $subscriptions ) {
171
+    /**
172
+     * Displays the table body.
173
+     *
174
+     * @param WPInv_Subscription[] $subscriptions
175
+     */
176
+    public function print_table_body( $subscriptions ) {
177 177
 
178
-		if ( empty( $subscriptions ) ) {
179
-			$this->print_table_body_no_subscriptions();
180
-		} else {
181
-			$this->print_table_body_subscriptions( $subscriptions );
182
-		}
178
+        if ( empty( $subscriptions ) ) {
179
+            $this->print_table_body_no_subscriptions();
180
+        } else {
181
+            $this->print_table_body_subscriptions( $subscriptions );
182
+        }
183 183
 
184
-	}
184
+    }
185 185
 
186
-	/**
187
-	 * Displays the table body if no subscriptions were found.
188
-	 *
189
-	 */
190
-	public function print_table_body_no_subscriptions() {
186
+    /**
187
+     * Displays the table body if no subscriptions were found.
188
+     *
189
+     */
190
+    public function print_table_body_no_subscriptions() {
191 191
 
192
-		?>
192
+        ?>
193 193
 		<tbody>
194 194
 
195 195
 			<tr>
196 196
 				<td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>">
197 197
 
198 198
 					<?php
199
-						aui()->alert(
200
-							array(
201
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
202
-								'type'    => 'warning',
203
-							),
199
+                        aui()->alert(
200
+                            array(
201
+                                'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
202
+                                'type'    => 'warning',
203
+                            ),
204 204
                             true
205
-						);
206
-					?>
205
+                        );
206
+                    ?>
207 207
 
208 208
 				</td>
209 209
 			</tr>
210 210
 
211 211
 		</tbody>
212 212
 		<?php
213
-	}
213
+    }
214 214
 
215
-	/**
216
-	 * Displays the table body if subscriptions were found.
217
-	 *
218
-	 * @param WPInv_Subscription[] $subscriptions
219
-	 */
220
-	public function print_table_body_subscriptions( $subscriptions ) {
215
+    /**
216
+     * Displays the table body if subscriptions were found.
217
+     *
218
+     * @param WPInv_Subscription[] $subscriptions
219
+     */
220
+    public function print_table_body_subscriptions( $subscriptions ) {
221 221
 
222
-		?>
222
+        ?>
223 223
 		<tbody>
224 224
 
225 225
 			<?php foreach ( $subscriptions as $subscription ) : ?>
226 226
 				<tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>">
227 227
 					<?php
228
-						wpinv_get_template(
229
-							'subscriptions/subscriptions-table-row.php',
230
-							array(
231
-								'subscription' => $subscription,
232
-								'widget'       => $this,
233
-							)
234
-						);
235
-					?>
228
+                        wpinv_get_template(
229
+                            'subscriptions/subscriptions-table-row.php',
230
+                            array(
231
+                                'subscription' => $subscription,
232
+                                'widget'       => $this,
233
+                            )
234
+                        );
235
+                    ?>
236 236
 				</tr>
237 237
 			<?php endforeach; ?>
238 238
 
239 239
 		</tbody>
240 240
 		<?php
241
-	}
242
-
243
-	/**
244
-	 * Adds row actions to a column
245
-	 *
246
-	 * @param string $content column content
247
-	 * @param WPInv_Subscription $subscription
248
-	 * @since       1.0.0
249
-	 * @return      string
250
-	 */
251
-	public function add_row_actions( $content, $subscription ) {
252
-
253
-		// Prepare row actions.
254
-		$actions = array();
255
-
256
-		// View subscription action.
257
-		$view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
-		$view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
-		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
-
261
-		// Filter the actions.
262
-		$actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
-
264
-		$sanitized  = array();
265
-		foreach ( $actions as $key => $action ) {
266
-			$key         = sanitize_html_class( $key );
267
-			$action      = wp_kses_post( $action );
268
-			$sanitized[] = "<span class='$key'>$action</span>";
269
-		}
270
-
271
-		$row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
-		$row_actions .= implode( ' | ', $sanitized );
273
-		$row_actions .= '</small>';
274
-
275
-		return $content . $row_actions;
276
-	}
277
-
278
-	/**
279
-	 * Displays the table footer.
280
-	 *
281
-	 */
282
-	public function print_table_footer() {
283
-
284
-		?>
241
+    }
242
+
243
+    /**
244
+     * Adds row actions to a column
245
+     *
246
+     * @param string $content column content
247
+     * @param WPInv_Subscription $subscription
248
+     * @since       1.0.0
249
+     * @return      string
250
+     */
251
+    public function add_row_actions( $content, $subscription ) {
252
+
253
+        // Prepare row actions.
254
+        $actions = array();
255
+
256
+        // View subscription action.
257
+        $view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
+        $view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
+        $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
+
261
+        // Filter the actions.
262
+        $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
+
264
+        $sanitized  = array();
265
+        foreach ( $actions as $key => $action ) {
266
+            $key         = sanitize_html_class( $key );
267
+            $action      = wp_kses_post( $action );
268
+            $sanitized[] = "<span class='$key'>$action</span>";
269
+        }
270
+
271
+        $row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
+        $row_actions .= implode( ' | ', $sanitized );
273
+        $row_actions .= '</small>';
274
+
275
+        return $content . $row_actions;
276
+    }
277
+
278
+    /**
279
+     * Displays the table footer.
280
+     *
281
+     */
282
+    public function print_table_footer() {
283
+
284
+        ?>
285 285
 
286 286
 				<tfoot>
287 287
 					<tr>
@@ -296,145 +296,145 @@  discard block
 block discarded – undo
296 296
 			</table>
297 297
 		<?php
298 298
 
299
-	}
299
+    }
300 300
 
301
-	/**
302
-	 * Displays the navigation.
303
-	 *
304
-	 * @param int $total
305
-	 */
306
-	public function print_navigation( $total ) {
301
+    /**
302
+     * Displays the navigation.
303
+     *
304
+     * @param int $total
305
+     */
306
+    public function print_navigation( $total ) {
307 307
 
308
-		if ( $total < 1 ) {
308
+        if ( $total < 1 ) {
309 309
 
310
-			// Out-of-bounds, run the query again without LIMIT for total count.
311
-			$args  = array(
312
-				'customer_in' => get_current_user_id(),
313
-				'fields'      => 'id',
314
-			);
310
+            // Out-of-bounds, run the query again without LIMIT for total count.
311
+            $args  = array(
312
+                'customer_in' => get_current_user_id(),
313
+                'fields'      => 'id',
314
+            );
315 315
 
316
-			$count_query = new GetPaid_Subscriptions_Query( $args );
317
-			$total       = $count_query->get_total();
318
-		}
316
+            $count_query = new GetPaid_Subscriptions_Query( $args );
317
+            $total       = $count_query->get_total();
318
+        }
319 319
 
320
-		// Abort if we do not have pages.
321
-		if ( 2 > $total ) {
322
-			return;
323
-		}
320
+        // Abort if we do not have pages.
321
+        if ( 2 > $total ) {
322
+            return;
323
+        }
324 324
 
325
-		?>
325
+        ?>
326 326
 
327 327
 		<div class="getpaid-subscriptions-pagination">
328 328
 			<?php
329
-				$big = 999999;
330
-
331
-				echo wp_kses_post(
332
-					getpaid_paginate_links(
333
-						array(
334
-							'base'   => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
335
-							'format' => '?paged=%#%',
336
-							'total'  => (int) ceil( $total / 10 ),
337
-						)
338
-					)
339
-				);
340
-			?>
329
+                $big = 999999;
330
+
331
+                echo wp_kses_post(
332
+                    getpaid_paginate_links(
333
+                        array(
334
+                            'base'   => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
335
+                            'format' => '?paged=%#%',
336
+                            'total'  => (int) ceil( $total / 10 ),
337
+                        )
338
+                    )
339
+                );
340
+            ?>
341 341
 		</div>
342 342
 
343 343
 		<?php
344
-	}
345
-
346
-	/**
347
-	 * Returns a single subscription's columns.
348
-	 *
349
-	 * @param WPInv_Subscription $subscription
350
-	 *
351
-	 * @return array
352
-	 */
353
-	public function get_single_subscription_columns( $subscription ) {
354
-
355
-		// Prepare subscription detail columns.
356
-		$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
357
-		$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
358
-		$fields             = apply_filters(
359
-			'getpaid_single_subscription_details_fields',
360
-			array(
361
-				'status'           => __( 'Status', 'invoicing' ),
362
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
363
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
364
-				'start_date'       => __( 'Start date', 'invoicing' ),
365
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
366
-				'payments'         => __( 'Payments', 'invoicing' ),
367
-				'item'             => $items_count > 1 ? __( 'Items', $items_count, 'invoicing' ) : __( 'Item', 'invoicing' )
368
-			),
369
-			$subscription,
370
-			$items_count
371
-		);
372
-
373
-		if ( isset( $fields['expiry_date'] ) ) {
374
-
375
-			if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
376
-				$fields['expiry_date'] = __( 'End date', 'invoicing' );
377
-			}
378
-
379
-			if ( 'pending' === $subscription->get_status() ) {
380
-				unset( $fields['expiry_date'] );
381
-			}
382
-		}
383
-
384
-		if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) {
385
-			unset( $fields['start_date'] );
386
-		}
387
-
388
-		if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) {
389
-			unset( $fields['initial_amount'] );
390
-		}
391
-
392
-		return $fields;
393
-	}
394
-
395
-	/**
396
-	 * Displays a single subscription.
397
-	 *
398
-	 * @param string $subscription
399
-	 *
400
-	 * @return string
401
-	 */
402
-	public function display_single_subscription( $subscription ) {
403
-
404
-		// Fetch the subscription.
405
-		$subscription = new WPInv_Subscription( (int) $subscription );
406
-
407
-		if ( ! $subscription->exists() ) {
408
-
409
-			return aui()->alert(
410
-				array(
411
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
412
-					'type'    => 'error',
413
-				)
414
-			);
415
-
416
-		}
417
-
418
-		// Ensure that the user owns this subscription key.
419
-		if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
420
-
421
-			return aui()->alert(
422
-				array(
423
-					'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
424
-					'type'    => 'error',
425
-				)
426
-			);
427
-
428
-		}
429
-
430
-		return wpinv_get_template_html(
431
-			'subscriptions/subscription-details.php',
432
-			array(
433
-				'subscription' => $subscription,
434
-				'widget'       => $this,
435
-			)
436
-		);
437
-
438
-	}
344
+    }
345
+
346
+    /**
347
+     * Returns a single subscription's columns.
348
+     *
349
+     * @param WPInv_Subscription $subscription
350
+     *
351
+     * @return array
352
+     */
353
+    public function get_single_subscription_columns( $subscription ) {
354
+
355
+        // Prepare subscription detail columns.
356
+        $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
357
+        $items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
358
+        $fields             = apply_filters(
359
+            'getpaid_single_subscription_details_fields',
360
+            array(
361
+                'status'           => __( 'Status', 'invoicing' ),
362
+                'initial_amount'   => __( 'Initial amount', 'invoicing' ),
363
+                'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
364
+                'start_date'       => __( 'Start date', 'invoicing' ),
365
+                'expiry_date'      => __( 'Next payment', 'invoicing' ),
366
+                'payments'         => __( 'Payments', 'invoicing' ),
367
+                'item'             => $items_count > 1 ? __( 'Items', $items_count, 'invoicing' ) : __( 'Item', 'invoicing' )
368
+            ),
369
+            $subscription,
370
+            $items_count
371
+        );
372
+
373
+        if ( isset( $fields['expiry_date'] ) ) {
374
+
375
+            if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
376
+                $fields['expiry_date'] = __( 'End date', 'invoicing' );
377
+            }
378
+
379
+            if ( 'pending' === $subscription->get_status() ) {
380
+                unset( $fields['expiry_date'] );
381
+            }
382
+        }
383
+
384
+        if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) {
385
+            unset( $fields['start_date'] );
386
+        }
387
+
388
+        if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) {
389
+            unset( $fields['initial_amount'] );
390
+        }
391
+
392
+        return $fields;
393
+    }
394
+
395
+    /**
396
+     * Displays a single subscription.
397
+     *
398
+     * @param string $subscription
399
+     *
400
+     * @return string
401
+     */
402
+    public function display_single_subscription( $subscription ) {
403
+
404
+        // Fetch the subscription.
405
+        $subscription = new WPInv_Subscription( (int) $subscription );
406
+
407
+        if ( ! $subscription->exists() ) {
408
+
409
+            return aui()->alert(
410
+                array(
411
+                    'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
412
+                    'type'    => 'error',
413
+                )
414
+            );
415
+
416
+        }
417
+
418
+        // Ensure that the user owns this subscription key.
419
+        if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
420
+
421
+            return aui()->alert(
422
+                array(
423
+                    'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
424
+                    'type'    => 'error',
425
+                )
426
+            );
427
+
428
+        }
429
+
430
+        return wpinv_get_template_html(
431
+            'subscriptions/subscription-details.php',
432
+            array(
433
+                'subscription' => $subscription,
434
+                'widget'       => $this,
435
+            )
436
+        );
437
+
438
+    }
439 439
 
440 440
 }
Please login to merge, or discard this patch.
templates/payment-forms/elements/file_upload.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -21,20 +21,20 @@
 block discarded – undo
21 21
 
22 22
 foreach ( $file_types as $file_type ) {
23 23
 
24
-	if ( isset( $all_types[ $file_type ] ) ) {
25
-		$types[]   = $all_types[ $file_type ];
26
-		$file_type = explode( '|', $file_type );
24
+    if ( isset( $all_types[ $file_type ] ) ) {
25
+        $types[]   = $all_types[ $file_type ];
26
+        $file_type = explode( '|', $file_type );
27 27
 
28
-		foreach ( $file_type as $type ) {
29
-			$type     = trim( $type );
30
-			$types[]  = ".$type";
31
-			$_types[] = $type;
32
-		}
28
+        foreach ( $file_type as $type ) {
29
+            $type     = trim( $type );
30
+            $types[]  = ".$type";
31
+            $_types[] = $type;
32
+        }
33 33
 }
34 34
 }
35 35
 
36 36
 if ( ! empty( $required ) ) {
37
-	$label .= "<span class='text-danger'> *</span>";
37
+    $label .= "<span class='text-danger'> *</span>";
38 38
 }
39 39
 ?>
40 40
 <label><span v-html="form_element.label"></span></label>
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-bank-transfer-gateway.php 1 patch
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -13,47 +13,47 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'bank_transfer';
21 21
 
22
-	/**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
27
-	protected $supports = array(
28
-		'subscription',
29
-		'addons',
30
-		'single_subscription_group',
31
-		'multiple_subscription_groups',
32
-		'subscription_date_change',
33
-		'subscription_bill_times_change',
34
-	);
22
+    /**
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27
+    protected $supports = array(
28
+        'subscription',
29
+        'addons',
30
+        'single_subscription_group',
31
+        'multiple_subscription_groups',
32
+        'subscription_date_change',
33
+        'subscription_bill_times_change',
34
+    );
35
+
36
+    /**
37
+     * Payment method order.
38
+     *
39
+     * @var int
40
+     */
41
+    public $order = 8;
35 42
 
36 43
     /**
37
-	 * Payment method order.
38
-	 *
39
-	 * @var int
40
-	 */
41
-	public $order = 8;
42
-
43
-	/**
44
-	 * Bank transfer instructions.
45
-	 */
46
-	public $instructions;
47
-
48
-	/**
49
-	 * Locale array.
50
-	 */
51
-	public $locale;
44
+     * Bank transfer instructions.
45
+     */
46
+    public $instructions;
52 47
 
53 48
     /**
54
-	 * Class constructor.
55
-	 */
56
-	public function __construct() {
49
+     * Locale array.
50
+     */
51
+    public $locale;
52
+
53
+    /**
54
+     * Class constructor.
55
+     */
56
+    public function __construct() {
57 57
         parent::__construct();
58 58
 
59 59
         $this->title                = __( 'Direct bank transfer', 'invoicing' );
@@ -61,24 +61,24 @@  discard block
 block discarded – undo
61 61
         $this->checkout_button_text = __( 'Proceed', 'invoicing' );
62 62
         $this->instructions         = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) );
63 63
 
64
-		add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
65
-		add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
66
-		add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
67
-		add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
68
-		add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
69
-		add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
64
+        add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
65
+        add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
66
+        add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
67
+        add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
68
+        add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
69
+        add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
70 70
 
71 71
     }
72 72
 
73 73
     /**
74
-	 * Process Payment.
75
-	 *
76
-	 * @param WPInv_Invoice $invoice Invoice.
77
-	 * @param array $submission_data Posted checkout fields.
78
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
79
-	 * @return array
80
-	 */
81
-	public function process_payment( $invoice, $submission_data, $submission ) {
74
+     * Process Payment.
75
+     *
76
+     * @param WPInv_Invoice $invoice Invoice.
77
+     * @param array $submission_data Posted checkout fields.
78
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
79
+     * @return array
80
+     */
81
+    public function process_payment( $invoice, $submission_data, $submission ) {
82 82
 
83 83
         // Add a transaction id.
84 84
         $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) );
@@ -99,66 +99,66 @@  discard block
 block discarded – undo
99 99
     }
100 100
 
101 101
     /**
102
-	 * Output for the order received page.
103
-	 *
104
-	 * @param WPInv_Invoice $invoice Invoice.
105
-	 */
106
-	public function thankyou_page( $invoice ) {
102
+     * Output for the order received page.
103
+     *
104
+     * @param WPInv_Invoice $invoice Invoice.
105
+     */
106
+    public function thankyou_page( $invoice ) {
107 107
 
108 108
         if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
109 109
 
110
-			echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
110
+            echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
111 111
 
112 112
             if ( ! empty( $this->instructions ) ) {
113 113
                 echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
114
-			}
114
+            }
115 115
 
116
-			$this->bank_details( $invoice );
116
+            $this->bank_details( $invoice );
117 117
 
118
-			echo '</div>';
118
+            echo '</div>';
119 119
 
120 120
         }
121 121
 
122
-	}
122
+    }
123 123
 
124 124
     /**
125
-	 * Add content to the WPI emails.
126
-	 *
127
-	 * @param WPInv_Invoice $invoice Invoice.
128
-	 * @param string     $email_type Email format: plain text or HTML.
129
-	 * @param bool     $sent_to_admin Sent to admin.
130
-	 */
131
-	public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
125
+     * Add content to the WPI emails.
126
+     *
127
+     * @param WPInv_Invoice $invoice Invoice.
128
+     * @param string     $email_type Email format: plain text or HTML.
129
+     * @param bool     $sent_to_admin Sent to admin.
130
+     */
131
+    public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
132 132
 
133
-		if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
133
+        if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
134 134
 
135
-			echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
135
+            echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
136 136
 
137
-			if ( $this->instructions ) {
138
-				echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
137
+            if ( $this->instructions ) {
138
+                echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
139 139
             }
140 140
 
141
-			$this->bank_details( $invoice );
141
+            $this->bank_details( $invoice );
142 142
 
143
-			echo '</div>';
143
+            echo '</div>';
144 144
 
145
-		}
145
+        }
146 146
 
147 147
     }
148 148
 
149 149
     /**
150
-	 * Get bank details and place into a list format.
151
-	 *
152
-	 * @param WPInv_Invoice $invoice Invoice.
153
-	 */
154
-	protected function bank_details( $invoice ) {
150
+     * Get bank details and place into a list format.
151
+     *
152
+     * @param WPInv_Invoice $invoice Invoice.
153
+     */
154
+    protected function bank_details( $invoice ) {
155 155
 
156
-		// Get the invoice country and country $locale.
157
-		$country = $invoice->get_country();
158
-		$locale  = $this->get_country_locale();
156
+        // Get the invoice country and country $locale.
157
+        $country = $invoice->get_country();
158
+        $locale  = $this->get_country_locale();
159 159
 
160
-		// Get shortcode label in the $locale array and use appropriate one.
161
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
160
+        // Get shortcode label in the $locale array and use appropriate one.
161
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
162 162
 
163 163
         $bank_fields = array(
164 164
             'ac_name'   => __( 'Account Name', 'invoicing' ),
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 
178 178
             if ( ! empty( $value ) ) {
179 179
                 $bank_info[ $field ] = array(
180
-					'label' => $label,
181
-					'value' => $value,
182
-				);
180
+                    'label' => $label,
181
+                    'value' => $value,
182
+                );
183 183
             }
184
-		}
184
+        }
185 185
 
186 186
         $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice );
187 187
 
@@ -189,139 +189,139 @@  discard block
 block discarded – undo
189 189
             return;
190 190
         }
191 191
 
192
-		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
192
+        echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
193 193
 
194
-		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
194
+        echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
195 195
 
196
-		foreach ( $bank_info as $key => $data ) {
197
-			echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
198
-		}
196
+        foreach ( $bank_info as $key => $data ) {
197
+            echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
198
+        }
199 199
 
200
-		echo '</table>';
200
+        echo '</table>';
201 201
 
202 202
     }
203 203
 
204 204
     /**
205
-	 * Get country locale if localized.
206
-	 *
207
-	 * @return array
208
-	 */
209
-	public function get_country_locale() {
210
-
211
-		if ( empty( $this->locale ) ) {
212
-
213
-			// Locale information to be used - only those that are not 'Sort Code'.
214
-			$this->locale = apply_filters(
215
-				'getpaid_get_bank_transfer_locale',
216
-				array(
217
-					'AU' => array(
218
-						'sortcode' => array(
219
-							'label' => __( 'BSB', 'invoicing' ),
220
-						),
221
-					),
222
-					'CA' => array(
223
-						'sortcode' => array(
224
-							'label' => __( 'Bank transit number', 'invoicing' ),
225
-						),
226
-					),
227
-					'IN' => array(
228
-						'sortcode' => array(
229
-							'label' => __( 'IFSC', 'invoicing' ),
230
-						),
231
-					),
232
-					'IT' => array(
233
-						'sortcode' => array(
234
-							'label' => __( 'Branch sort', 'invoicing' ),
235
-						),
236
-					),
237
-					'NZ' => array(
238
-						'sortcode' => array(
239
-							'label' => __( 'Bank code', 'invoicing' ),
240
-						),
241
-					),
242
-					'SE' => array(
243
-						'sortcode' => array(
244
-							'label' => __( 'Bank code', 'invoicing' ),
245
-						),
246
-					),
247
-					'US' => array(
248
-						'sortcode' => array(
249
-							'label' => __( 'Routing number', 'invoicing' ),
250
-						),
251
-					),
252
-					'ZA' => array(
253
-						'sortcode' => array(
254
-							'label' => __( 'Branch code', 'invoicing' ),
255
-						),
256
-					),
257
-				)
258
-			);
259
-
260
-		}
261
-
262
-		return $this->locale;
263
-
264
-	}
265
-
266
-	/**
267
-	 * Filters the gateway settings.
268
-	 *
269
-	 * @param array $admin_settings
270
-	 */
271
-	public function admin_settings( $admin_settings ) {
205
+     * Get country locale if localized.
206
+     *
207
+     * @return array
208
+     */
209
+    public function get_country_locale() {
210
+
211
+        if ( empty( $this->locale ) ) {
212
+
213
+            // Locale information to be used - only those that are not 'Sort Code'.
214
+            $this->locale = apply_filters(
215
+                'getpaid_get_bank_transfer_locale',
216
+                array(
217
+                    'AU' => array(
218
+                        'sortcode' => array(
219
+                            'label' => __( 'BSB', 'invoicing' ),
220
+                        ),
221
+                    ),
222
+                    'CA' => array(
223
+                        'sortcode' => array(
224
+                            'label' => __( 'Bank transit number', 'invoicing' ),
225
+                        ),
226
+                    ),
227
+                    'IN' => array(
228
+                        'sortcode' => array(
229
+                            'label' => __( 'IFSC', 'invoicing' ),
230
+                        ),
231
+                    ),
232
+                    'IT' => array(
233
+                        'sortcode' => array(
234
+                            'label' => __( 'Branch sort', 'invoicing' ),
235
+                        ),
236
+                    ),
237
+                    'NZ' => array(
238
+                        'sortcode' => array(
239
+                            'label' => __( 'Bank code', 'invoicing' ),
240
+                        ),
241
+                    ),
242
+                    'SE' => array(
243
+                        'sortcode' => array(
244
+                            'label' => __( 'Bank code', 'invoicing' ),
245
+                        ),
246
+                    ),
247
+                    'US' => array(
248
+                        'sortcode' => array(
249
+                            'label' => __( 'Routing number', 'invoicing' ),
250
+                        ),
251
+                    ),
252
+                    'ZA' => array(
253
+                        'sortcode' => array(
254
+                            'label' => __( 'Branch code', 'invoicing' ),
255
+                        ),
256
+                    ),
257
+                )
258
+            );
259
+
260
+        }
261
+
262
+        return $this->locale;
263
+
264
+    }
265
+
266
+    /**
267
+     * Filters the gateway settings.
268
+     *
269
+     * @param array $admin_settings
270
+     */
271
+    public function admin_settings( $admin_settings ) {
272 272
 
273 273
         $admin_settings['bank_transfer_desc']['std']    = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' );
274
-		$admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
274
+        $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
275 275
 
276
-		$locale  = $this->get_country_locale();
276
+        $locale  = $this->get_country_locale();
277 277
 
278
-		// Get sortcode label in the $locale array and use appropriate one.
279
-		$country  = wpinv_default_billing_country();
280
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
278
+        // Get sortcode label in the $locale array and use appropriate one.
279
+        $country  = wpinv_default_billing_country();
280
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
281 281
 
282
-		$admin_settings['bank_transfer_ac_name'] = array(
282
+        $admin_settings['bank_transfer_ac_name'] = array(
283 283
             'type' => 'text',
284 284
             'id'   => 'bank_transfer_ac_name',
285 285
             'name' => __( 'Account Name', 'invoicing' ),
286
-		);
286
+        );
287 287
 
288
-		$admin_settings['bank_transfer_ac_no'] = array(
288
+        $admin_settings['bank_transfer_ac_no'] = array(
289 289
             'type' => 'text',
290 290
             'id'   => 'bank_transfer_ac_no',
291 291
             'name' => __( 'Account Number', 'invoicing' ),
292
-		);
292
+        );
293 293
 
294
-		$admin_settings['bank_transfer_bank_name'] = array(
294
+        $admin_settings['bank_transfer_bank_name'] = array(
295 295
             'type' => 'text',
296 296
             'id'   => 'bank_transfer_bank_name',
297 297
             'name' => __( 'Bank Name', 'invoicing' ),
298
-		);
298
+        );
299 299
 
300
-		$admin_settings['bank_transfer_ifsc'] = array(
300
+        $admin_settings['bank_transfer_ifsc'] = array(
301 301
             'type' => 'text',
302 302
             'id'   => 'bank_transfer_ifsc',
303 303
             'name' => __( 'IFSC Code', 'invoicing' ),
304
-		);
304
+        );
305 305
 
306
-		$admin_settings['bank_transfer_iban'] = array(
306
+        $admin_settings['bank_transfer_iban'] = array(
307 307
             'type' => 'text',
308 308
             'id'   => 'bank_transfer_iban',
309 309
             'name' => __( 'IBAN', 'invoicing' ),
310
-		);
310
+        );
311 311
 
312
-		$admin_settings['bank_transfer_bic'] = array(
312
+        $admin_settings['bank_transfer_bic'] = array(
313 313
             'type' => 'text',
314 314
             'id'   => 'bank_transfer_bic',
315 315
             'name' => __( 'BIC/Swift Code', 'invoicing' ),
316
-		);
316
+        );
317 317
 
318
-		$admin_settings['bank_transfer_sort_code'] = array(
319
-			'type' => 'text',
320
-			'id'   => 'bank_transfer_sort_code',
321
-			'name' => $sortcode,
322
-		);
318
+        $admin_settings['bank_transfer_sort_code'] = array(
319
+            'type' => 'text',
320
+            'id'   => 'bank_transfer_sort_code',
321
+            'name' => $sortcode,
322
+        );
323 323
 
324
-		$admin_settings['bank_transfer_info'] = array(
324
+        $admin_settings['bank_transfer_info'] = array(
325 325
             'id'   => 'bank_transfer_info',
326 326
             'name' => __( 'Instructions', 'invoicing' ),
327 327
             'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
@@ -331,17 +331,17 @@  discard block
 block discarded – undo
331 331
             'rows' => 5,
332 332
         );
333 333
 
334
-		return $admin_settings;
335
-	}
334
+        return $admin_settings;
335
+    }
336 336
 
337
-	/**
338
-	 * Processes invoice addons.
339
-	 *
340
-	 * @param WPInv_Invoice $invoice
341
-	 * @param GetPaid_Form_Item[] $items
342
-	 * @return WPInv_Invoice
343
-	 */
344
-	public function process_addons( $invoice, $items ) {
337
+    /**
338
+     * Processes invoice addons.
339
+     *
340
+     * @param WPInv_Invoice $invoice
341
+     * @param GetPaid_Form_Item[] $items
342
+     * @return WPInv_Invoice
343
+     */
344
+    public function process_addons( $invoice, $items ) {
345 345
 
346 346
         foreach ( $items as $item ) {
347 347
             $invoice->add_item( $item );
@@ -349,98 +349,98 @@  discard block
 block discarded – undo
349 349
 
350 350
         $invoice->recalculate_total();
351 351
         $invoice->save();
352
-	}
353
-
354
-	/**
355
-	 * (Maybe) renews a bank transfer subscription profile.
356
-	 *
357
-	 *
358
-	 * @param WPInv_Subscription $subscription
359
-	 */
360
-	public function maybe_renew_subscription( $subscription ) {
361
-		// Ensure its our subscription && it's active.
362
-		if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
363
-			add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
364
-
365
-			$invoice = $subscription->create_payment();
366
-
367
-			if ( ! empty( $invoice ) ) {
368
-				$is_logged_in = is_user_logged_in();
369
-
370
-				// Cron run.
371
-				if ( ! $is_logged_in ) {
372
-					$note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) );
373
-
374
-					$invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in );
375
-				}
376
-			}
377
-
378
-			remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
379
-		}
380
-	}
381
-
382
-	/**
383
-	 * Process a bank transfer payment.
384
-	 *
385
-	 *
352
+    }
353
+
354
+    /**
355
+     * (Maybe) renews a bank transfer subscription profile.
356
+     *
357
+     *
358
+     * @param WPInv_Subscription $subscription
359
+     */
360
+    public function maybe_renew_subscription( $subscription ) {
361
+        // Ensure its our subscription && it's active.
362
+        if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
363
+            add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
364
+
365
+            $invoice = $subscription->create_payment();
366
+
367
+            if ( ! empty( $invoice ) ) {
368
+                $is_logged_in = is_user_logged_in();
369
+
370
+                // Cron run.
371
+                if ( ! $is_logged_in ) {
372
+                    $note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) );
373
+
374
+                    $invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in );
375
+                }
376
+            }
377
+
378
+            remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
379
+        }
380
+    }
381
+
382
+    /**
383
+     * Process a bank transfer payment.
384
+     *
385
+     *
386 386
      * @param WPInv_Invoice $invoice
387
-	 */
388
-	public function invoice_paid( $invoice ) {
389
-
390
-		// Abort if not paid by bank transfer.
391
-		if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
392
-			return;
393
-		}
394
-
395
-		// Is it a parent payment?
396
-		if ( 0 == $invoice->get_parent_id() ) {
397
-
398
-			// (Maybe) activate subscriptions.
399
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
400
-
401
-			if ( ! empty( $subscriptions ) ) {
402
-				$subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
403
-
404
-				foreach ( $subscriptions as $subscription ) {
405
-					if ( $subscription->exists() ) {
406
-						$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
407
-						$expiry   = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
408
-
409
-						$subscription->set_next_renewal_date( $expiry );
410
-						$subscription->set_date_created( current_time( 'mysql' ) );
411
-						$subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
412
-						$subscription->activate();
413
-					}
414
-				}
415
-			}
416
-		} else {
417
-
418
-			$subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
419
-
420
-			// Renew the subscription.
421
-			if ( $subscription && $subscription->exists() ) {
422
-				$subscription->add_payment( array(), $invoice );
423
-				$subscription->renew( strtotime( $invoice->get_date_created() ) );
424
-			}
425
-		}
387
+     */
388
+    public function invoice_paid( $invoice ) {
389
+
390
+        // Abort if not paid by bank transfer.
391
+        if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
392
+            return;
393
+        }
394
+
395
+        // Is it a parent payment?
396
+        if ( 0 == $invoice->get_parent_id() ) {
397
+
398
+            // (Maybe) activate subscriptions.
399
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
400
+
401
+            if ( ! empty( $subscriptions ) ) {
402
+                $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
403
+
404
+                foreach ( $subscriptions as $subscription ) {
405
+                    if ( $subscription->exists() ) {
406
+                        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
407
+                        $expiry   = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
408
+
409
+                        $subscription->set_next_renewal_date( $expiry );
410
+                        $subscription->set_date_created( current_time( 'mysql' ) );
411
+                        $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
412
+                        $subscription->activate();
413
+                    }
414
+                }
415
+            }
416
+        } else {
417
+
418
+            $subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
419
+
420
+            // Renew the subscription.
421
+            if ( $subscription && $subscription->exists() ) {
422
+                $subscription->add_payment( array(), $invoice );
423
+                $subscription->renew( strtotime( $invoice->get_date_created() ) );
424
+            }
425
+        }
426 426
 
427 427
     }
428 428
 
429
-	/**
430
-	 * Force created from payment false to allow email for auto renewal generation invoice.
431
-	 *
432
-	 * @since 2.8.11
433
-	 *
434
-	 * @param bool $is_payment_form_invoice True when invoice created via payment form else false.
435
-	 * @param int  $invoice Invoice ID.
436
-	 * @return bool True when invoice created via payment form else false.
437
-	 */
438
-	public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) {
439
-		if ( $is_payment_form_invoice ) {
440
-			$is_payment_form_invoice = false;
441
-		}
442
-
443
-		return $is_payment_form_invoice;
444
-	}
429
+    /**
430
+     * Force created from payment false to allow email for auto renewal generation invoice.
431
+     *
432
+     * @since 2.8.11
433
+     *
434
+     * @param bool $is_payment_form_invoice True when invoice created via payment form else false.
435
+     * @param int  $invoice Invoice ID.
436
+     * @return bool True when invoice created via payment form else false.
437
+     */
438
+    public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) {
439
+        if ( $is_payment_form_invoice ) {
440
+            $is_payment_form_invoice = false;
441
+        }
442
+
443
+        return $is_payment_form_invoice;
444
+    }
445 445
 
446 446
 }
Please login to merge, or discard this patch.
includes/class-getpaid-post-types.php 1 patch
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -15,321 +15,321 @@
 block discarded – undo
15 15
 class GetPaid_Post_Types {
16 16
 
17 17
     /**
18
-	 * Hook in methods.
19
-	 */
20
-	public function __construct() {
21
-		add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 );
22
-		add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 );
23
-		add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) );
24
-		add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) );
25
-	}
18
+     * Hook in methods.
19
+     */
20
+    public function __construct() {
21
+        add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 );
22
+        add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 );
23
+        add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) );
24
+        add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) );
25
+    }
26 26
 
27
-	/**
28
-	 * Register core post types.
29
-	 */
30
-	public static function register_post_types() {
27
+    /**
28
+     * Register core post types.
29
+     */
30
+    public static function register_post_types() {
31 31
 
32
-		if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) {
33
-			return;
34
-		}
32
+        if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) {
33
+            return;
34
+        }
35 35
 
36
-		$capabilities = wpinv_current_user_can_manage_invoicing();
36
+        $capabilities = wpinv_current_user_can_manage_invoicing();
37 37
 
38
-		// Fires before registering post types.
39
-		do_action( 'getpaid_register_post_types' );
38
+        // Fires before registering post types.
39
+        do_action( 'getpaid_register_post_types' );
40 40
 
41
-		// Register item post type.
42
-		register_post_type(
43
-			'wpi_item',
44
-			apply_filters(
45
-				'wpinv_register_post_type_invoice_item',
46
-				array(
47
-					'labels'            => array(
48
-						'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
49
-						'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
50
-						'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
51
-						'name_admin_bar'     => _x( 'Item', 'add new on admin bar', 'invoicing' ),
52
-						'add_new'            => _x( 'Add New', 'Item', 'invoicing' ),
53
-						'add_new_item'       => __( 'Add New Item', 'invoicing' ),
54
-						'new_item'           => __( 'New Item', 'invoicing' ),
55
-						'edit_item'          => __( 'Edit Item', 'invoicing' ),
56
-						'view_item'          => __( 'View Item', 'invoicing' ),
57
-						'all_items'          => __( 'Items', 'invoicing' ),
58
-						'search_items'       => __( 'Search items', 'invoicing' ),
59
-						'parent_item_colon'  => __( 'Parent item:', 'invoicing' ),
60
-						'not_found'          => __( 'No items found.', 'invoicing' ),
61
-						'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ),
62
-					),
63
-					'description'       => __( 'This is where you can add new invoice items.', 'invoicing' ),
64
-					'public'            => false,
65
-					'has_archive'       => false,
66
-					'_builtin'          => false,
67
-					'show_ui'           => $capabilities ? true : false,
68
-					'show_in_menu'      => $capabilities ? 'wpinv' : false,
69
-					'show_in_nav_menus' => false,
70
-					'supports'          => array( 'title', 'excerpt', 'thumbnail' ),
71
-					'rewrite'           => false,
72
-					'query_var'         => false,
73
-					'map_meta_cap'      => true,
74
-					'show_in_admin_bar' => $capabilities ? true : false,
75
-					'can_export'        => $capabilities ? true : false
76
-				)
77
-			)
78
-		);
41
+        // Register item post type.
42
+        register_post_type(
43
+            'wpi_item',
44
+            apply_filters(
45
+                'wpinv_register_post_type_invoice_item',
46
+                array(
47
+                    'labels'            => array(
48
+                        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
49
+                        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
50
+                        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
51
+                        'name_admin_bar'     => _x( 'Item', 'add new on admin bar', 'invoicing' ),
52
+                        'add_new'            => _x( 'Add New', 'Item', 'invoicing' ),
53
+                        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
54
+                        'new_item'           => __( 'New Item', 'invoicing' ),
55
+                        'edit_item'          => __( 'Edit Item', 'invoicing' ),
56
+                        'view_item'          => __( 'View Item', 'invoicing' ),
57
+                        'all_items'          => __( 'Items', 'invoicing' ),
58
+                        'search_items'       => __( 'Search items', 'invoicing' ),
59
+                        'parent_item_colon'  => __( 'Parent item:', 'invoicing' ),
60
+                        'not_found'          => __( 'No items found.', 'invoicing' ),
61
+                        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ),
62
+                    ),
63
+                    'description'       => __( 'This is where you can add new invoice items.', 'invoicing' ),
64
+                    'public'            => false,
65
+                    'has_archive'       => false,
66
+                    '_builtin'          => false,
67
+                    'show_ui'           => $capabilities ? true : false,
68
+                    'show_in_menu'      => $capabilities ? 'wpinv' : false,
69
+                    'show_in_nav_menus' => false,
70
+                    'supports'          => array( 'title', 'excerpt', 'thumbnail' ),
71
+                    'rewrite'           => false,
72
+                    'query_var'         => false,
73
+                    'map_meta_cap'      => true,
74
+                    'show_in_admin_bar' => $capabilities ? true : false,
75
+                    'can_export'        => $capabilities ? true : false
76
+                )
77
+            )
78
+        );
79 79
 
80
-		// Register payment form post type.
81
-		register_post_type(
82
-			'wpi_payment_form',
83
-			apply_filters(
84
-				'wpinv_register_post_type_payment_form',
85
-				array(
86
-					'labels'            => array(
87
-						'name'               => _x( 'Payment Forms', 'post type general name', 'invoicing' ),
88
-						'singular_name'      => _x( 'Payment Form', 'post type singular name', 'invoicing' ),
89
-						'menu_name'          => _x( 'Payment Forms', 'admin menu', 'invoicing' ),
90
-						'name_admin_bar'     => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ),
91
-						'add_new'            => _x( 'Add New', 'Payment Form', 'invoicing' ),
92
-						'add_new_item'       => __( 'Add New Payment Form', 'invoicing' ),
93
-						'new_item'           => __( 'New Payment Form', 'invoicing' ),
94
-						'edit_item'          => __( 'Edit Payment Form', 'invoicing' ),
95
-						'view_item'          => __( 'View Payment Form', 'invoicing' ),
96
-						'all_items'          => __( 'Payment Forms', 'invoicing' ),
97
-						'search_items'       => __( 'Search Payment Forms', 'invoicing' ),
98
-						'parent_item_colon'  => __( 'Parent Payment Forms:', 'invoicing' ),
99
-						'not_found'          => __( 'No payment forms found.', 'invoicing' ),
100
-						'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ),
101
-					),
102
-					'description'       => __( 'Add new payment forms.', 'invoicing' ),
103
-					'public'            => false,
104
-					'show_ui'           => $capabilities ? true : false,
105
-					'show_in_menu'      => $capabilities ? 'wpinv' : false,
106
-					'show_in_nav_menus' => false,
107
-					'query_var'         => false,
108
-					'rewrite'           => true,
109
-					'map_meta_cap'      => true,
110
-					'has_archive'       => false,
111
-					'hierarchical'      => false,
112
-					'menu_position'     => null,
113
-					'supports'          => array( 'title' ),
114
-					'menu_icon'         => 'dashicons-media-form',
115
-				)
116
-			)
117
-		);
80
+        // Register payment form post type.
81
+        register_post_type(
82
+            'wpi_payment_form',
83
+            apply_filters(
84
+                'wpinv_register_post_type_payment_form',
85
+                array(
86
+                    'labels'            => array(
87
+                        'name'               => _x( 'Payment Forms', 'post type general name', 'invoicing' ),
88
+                        'singular_name'      => _x( 'Payment Form', 'post type singular name', 'invoicing' ),
89
+                        'menu_name'          => _x( 'Payment Forms', 'admin menu', 'invoicing' ),
90
+                        'name_admin_bar'     => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ),
91
+                        'add_new'            => _x( 'Add New', 'Payment Form', 'invoicing' ),
92
+                        'add_new_item'       => __( 'Add New Payment Form', 'invoicing' ),
93
+                        'new_item'           => __( 'New Payment Form', 'invoicing' ),
94
+                        'edit_item'          => __( 'Edit Payment Form', 'invoicing' ),
95
+                        'view_item'          => __( 'View Payment Form', 'invoicing' ),
96
+                        'all_items'          => __( 'Payment Forms', 'invoicing' ),
97
+                        'search_items'       => __( 'Search Payment Forms', 'invoicing' ),
98
+                        'parent_item_colon'  => __( 'Parent Payment Forms:', 'invoicing' ),
99
+                        'not_found'          => __( 'No payment forms found.', 'invoicing' ),
100
+                        'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ),
101
+                    ),
102
+                    'description'       => __( 'Add new payment forms.', 'invoicing' ),
103
+                    'public'            => false,
104
+                    'show_ui'           => $capabilities ? true : false,
105
+                    'show_in_menu'      => $capabilities ? 'wpinv' : false,
106
+                    'show_in_nav_menus' => false,
107
+                    'query_var'         => false,
108
+                    'rewrite'           => true,
109
+                    'map_meta_cap'      => true,
110
+                    'has_archive'       => false,
111
+                    'hierarchical'      => false,
112
+                    'menu_position'     => null,
113
+                    'supports'          => array( 'title' ),
114
+                    'menu_icon'         => 'dashicons-media-form',
115
+                )
116
+            )
117
+        );
118 118
 
119
-		// Register invoice post type.
120
-		register_post_type(
121
-			'wpi_invoice',
122
-			apply_filters(
123
-				'wpinv_register_post_type_invoice',
124
-				array(
125
-					'labels'              => array(
126
-						'name'                  => __( 'Invoices', 'invoicing' ),
127
-						'singular_name'         => __( 'Invoice', 'invoicing' ),
128
-						'all_items'             => __( 'Invoices', 'invoicing' ),
129
-						'menu_name'             => _x( 'Invoices', 'Admin menu name', 'invoicing' ),
130
-						'add_new'               => __( 'Add New', 'invoicing' ),
131
-						'add_new_item'          => __( 'Add new invoice', 'invoicing' ),
132
-						'edit'                  => __( 'Edit', 'invoicing' ),
133
-						'edit_item'             => __( 'Edit invoice', 'invoicing' ),
134
-						'new_item'              => __( 'New invoice', 'invoicing' ),
135
-						'view_item'             => __( 'View invoice', 'invoicing' ),
136
-						'view_items'            => __( 'View Invoices', 'invoicing' ),
137
-						'search_items'          => __( 'Search invoices', 'invoicing' ),
138
-						'not_found'             => __( 'No invoices found', 'invoicing' ),
139
-						'not_found_in_trash'    => __( 'No invoices found in trash', 'invoicing' ),
140
-						'parent'                => __( 'Parent invoice', 'invoicing' ),
141
-						'featured_image'        => __( 'Invoice image', 'invoicing' ),
142
-						'set_featured_image'    => __( 'Set invoice image', 'invoicing' ),
143
-						'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ),
144
-						'use_featured_image'    => __( 'Use as invoice image', 'invoicing' ),
145
-						'insert_into_item'      => __( 'Insert into invoice', 'invoicing' ),
146
-						'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ),
147
-						'filter_items_list'     => __( 'Filter invoices', 'invoicing' ),
148
-						'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ),
149
-						'items_list'            => __( 'Invoices list', 'invoicing' ),
150
-					),
151
-					'description'         => __( 'This is where invoices are stored.', 'invoicing' ),
152
-					'public'              => true,
153
-					'has_archive'         => false,
154
-					'publicly_queryable'  => true,
155
-        			'exclude_from_search' => true,
156
-        			'show_ui'             => $capabilities ? true : false,
157
-					'show_in_menu'        => $capabilities ? 'wpinv' : false,
158
-					'show_in_nav_menus'   => false,
159
-					'supports'            => array( 'title', 'author', 'excerpt' ),
160
-					'rewrite'             => array(
161
-						'slug'       => 'invoice',
162
-						'with_front' => false,
163
-					),
164
-					'query_var'           => false,
165
-					'map_meta_cap'        => true,
166
-					'show_in_admin_bar'   => $capabilities ? true : false,
167
-					'can_export'          => $capabilities ? true : false,
168
-					'hierarchical'        => false,
169
-					'menu_position'       => null,
170
-					'menu_icon'           => 'dashicons-media-spreadsheet',
171
-				)
172
-			)
173
-		);
119
+        // Register invoice post type.
120
+        register_post_type(
121
+            'wpi_invoice',
122
+            apply_filters(
123
+                'wpinv_register_post_type_invoice',
124
+                array(
125
+                    'labels'              => array(
126
+                        'name'                  => __( 'Invoices', 'invoicing' ),
127
+                        'singular_name'         => __( 'Invoice', 'invoicing' ),
128
+                        'all_items'             => __( 'Invoices', 'invoicing' ),
129
+                        'menu_name'             => _x( 'Invoices', 'Admin menu name', 'invoicing' ),
130
+                        'add_new'               => __( 'Add New', 'invoicing' ),
131
+                        'add_new_item'          => __( 'Add new invoice', 'invoicing' ),
132
+                        'edit'                  => __( 'Edit', 'invoicing' ),
133
+                        'edit_item'             => __( 'Edit invoice', 'invoicing' ),
134
+                        'new_item'              => __( 'New invoice', 'invoicing' ),
135
+                        'view_item'             => __( 'View invoice', 'invoicing' ),
136
+                        'view_items'            => __( 'View Invoices', 'invoicing' ),
137
+                        'search_items'          => __( 'Search invoices', 'invoicing' ),
138
+                        'not_found'             => __( 'No invoices found', 'invoicing' ),
139
+                        'not_found_in_trash'    => __( 'No invoices found in trash', 'invoicing' ),
140
+                        'parent'                => __( 'Parent invoice', 'invoicing' ),
141
+                        'featured_image'        => __( 'Invoice image', 'invoicing' ),
142
+                        'set_featured_image'    => __( 'Set invoice image', 'invoicing' ),
143
+                        'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ),
144
+                        'use_featured_image'    => __( 'Use as invoice image', 'invoicing' ),
145
+                        'insert_into_item'      => __( 'Insert into invoice', 'invoicing' ),
146
+                        'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ),
147
+                        'filter_items_list'     => __( 'Filter invoices', 'invoicing' ),
148
+                        'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ),
149
+                        'items_list'            => __( 'Invoices list', 'invoicing' ),
150
+                    ),
151
+                    'description'         => __( 'This is where invoices are stored.', 'invoicing' ),
152
+                    'public'              => true,
153
+                    'has_archive'         => false,
154
+                    'publicly_queryable'  => true,
155
+                    'exclude_from_search' => true,
156
+                    'show_ui'             => $capabilities ? true : false,
157
+                    'show_in_menu'        => $capabilities ? 'wpinv' : false,
158
+                    'show_in_nav_menus'   => false,
159
+                    'supports'            => array( 'title', 'author', 'excerpt' ),
160
+                    'rewrite'             => array(
161
+                        'slug'       => 'invoice',
162
+                        'with_front' => false,
163
+                    ),
164
+                    'query_var'           => false,
165
+                    'map_meta_cap'        => true,
166
+                    'show_in_admin_bar'   => $capabilities ? true : false,
167
+                    'can_export'          => $capabilities ? true : false,
168
+                    'hierarchical'        => false,
169
+                    'menu_position'       => null,
170
+                    'menu_icon'           => 'dashicons-media-spreadsheet',
171
+                )
172
+            )
173
+        );
174 174
 
175
-		// Register discount post type.
176
-		register_post_type(
177
-			'wpi_discount',
178
-			apply_filters(
179
-				'wpinv_register_post_type_discount',
180
-				array(
181
-					'labels'              => array(
182
-						'name'                  => __( 'Discounts', 'invoicing' ),
183
-						'singular_name'         => __( 'Discount', 'invoicing' ),
184
-						'all_items'             => __( 'Discounts', 'invoicing' ),
185
-						'menu_name'             => _x( 'Discounts', 'Admin menu name', 'invoicing' ),
186
-						'add_new'               => __( 'Add New', 'invoicing' ),
187
-						'add_new_item'          => __( 'Add new discount', 'invoicing' ),
188
-						'edit'                  => __( 'Edit', 'invoicing' ),
189
-						'edit_item'             => __( 'Edit discount', 'invoicing' ),
190
-						'new_item'              => __( 'New discount', 'invoicing' ),
191
-						'view_item'             => __( 'View discount', 'invoicing' ),
192
-						'view_items'            => __( 'View Discounts', 'invoicing' ),
193
-						'search_items'          => __( 'Search discounts', 'invoicing' ),
194
-						'not_found'             => __( 'No discounts found', 'invoicing' ),
195
-						'not_found_in_trash'    => __( 'No discounts found in trash', 'invoicing' ),
196
-						'parent'                => __( 'Parent discount', 'invoicing' ),
197
-						'featured_image'        => __( 'Discount image', 'invoicing' ),
198
-						'set_featured_image'    => __( 'Set discount image', 'invoicing' ),
199
-						'remove_featured_image' => __( 'Remove discount image', 'invoicing' ),
200
-						'use_featured_image'    => __( 'Use as discount image', 'invoicing' ),
201
-						'insert_into_item'      => __( 'Insert into discount', 'invoicing' ),
202
-						'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ),
203
-						'filter_items_list'     => __( 'Filter discounts', 'invoicing' ),
204
-						'items_list_navigation' => __( 'Discount navigation', 'invoicing' ),
205
-						'items_list'            => __( 'Discounts list', 'invoicing' ),
206
-					),
207
-					'description'         => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
208
-					'public'              => false,
209
-					'can_export'          => $capabilities ? true : false,
210
-					'_builtin'            => false,
211
-					'publicly_queryable'  => false,
212
-					'exclude_from_search' => true,
213
-					'show_ui'             => $capabilities ? true : false,
214
-					'show_in_menu'        => $capabilities ? 'wpinv' : false,
215
-					'query_var'           => false,
216
-					'rewrite'             => false,
217
-					'map_meta_cap'        => true,
218
-					'has_archive'         => false,
219
-					'hierarchical'        => false,
220
-					'supports'            => array( 'title', 'excerpt' ),
221
-					'show_in_nav_menus'   => false,
222
-					'show_in_admin_bar'   => $capabilities ? true : false,
223
-					'menu_position'       => null,
224
-				)
225
-			)
226
-		);
175
+        // Register discount post type.
176
+        register_post_type(
177
+            'wpi_discount',
178
+            apply_filters(
179
+                'wpinv_register_post_type_discount',
180
+                array(
181
+                    'labels'              => array(
182
+                        'name'                  => __( 'Discounts', 'invoicing' ),
183
+                        'singular_name'         => __( 'Discount', 'invoicing' ),
184
+                        'all_items'             => __( 'Discounts', 'invoicing' ),
185
+                        'menu_name'             => _x( 'Discounts', 'Admin menu name', 'invoicing' ),
186
+                        'add_new'               => __( 'Add New', 'invoicing' ),
187
+                        'add_new_item'          => __( 'Add new discount', 'invoicing' ),
188
+                        'edit'                  => __( 'Edit', 'invoicing' ),
189
+                        'edit_item'             => __( 'Edit discount', 'invoicing' ),
190
+                        'new_item'              => __( 'New discount', 'invoicing' ),
191
+                        'view_item'             => __( 'View discount', 'invoicing' ),
192
+                        'view_items'            => __( 'View Discounts', 'invoicing' ),
193
+                        'search_items'          => __( 'Search discounts', 'invoicing' ),
194
+                        'not_found'             => __( 'No discounts found', 'invoicing' ),
195
+                        'not_found_in_trash'    => __( 'No discounts found in trash', 'invoicing' ),
196
+                        'parent'                => __( 'Parent discount', 'invoicing' ),
197
+                        'featured_image'        => __( 'Discount image', 'invoicing' ),
198
+                        'set_featured_image'    => __( 'Set discount image', 'invoicing' ),
199
+                        'remove_featured_image' => __( 'Remove discount image', 'invoicing' ),
200
+                        'use_featured_image'    => __( 'Use as discount image', 'invoicing' ),
201
+                        'insert_into_item'      => __( 'Insert into discount', 'invoicing' ),
202
+                        'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ),
203
+                        'filter_items_list'     => __( 'Filter discounts', 'invoicing' ),
204
+                        'items_list_navigation' => __( 'Discount navigation', 'invoicing' ),
205
+                        'items_list'            => __( 'Discounts list', 'invoicing' ),
206
+                    ),
207
+                    'description'         => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
208
+                    'public'              => false,
209
+                    'can_export'          => $capabilities ? true : false,
210
+                    '_builtin'            => false,
211
+                    'publicly_queryable'  => false,
212
+                    'exclude_from_search' => true,
213
+                    'show_ui'             => $capabilities ? true : false,
214
+                    'show_in_menu'        => $capabilities ? 'wpinv' : false,
215
+                    'query_var'           => false,
216
+                    'rewrite'             => false,
217
+                    'map_meta_cap'        => true,
218
+                    'has_archive'         => false,
219
+                    'hierarchical'        => false,
220
+                    'supports'            => array( 'title', 'excerpt' ),
221
+                    'show_in_nav_menus'   => false,
222
+                    'show_in_admin_bar'   => $capabilities ? true : false,
223
+                    'menu_position'       => null,
224
+                )
225
+            )
226
+        );
227 227
 
228
-		do_action( 'getpaid_after_register_post_types' );
229
-	}
228
+        do_action( 'getpaid_after_register_post_types' );
229
+    }
230 230
 
231
-	/**
232
-	 * Register our custom post statuses.
233
-	 */
234
-	public static function register_post_status() {
231
+    /**
232
+     * Register our custom post statuses.
233
+     */
234
+    public static function register_post_status() {
235 235
 
236
-		$invoice_statuses = apply_filters(
237
-			'getpaid_register_invoice_post_statuses',
238
-			array(
236
+        $invoice_statuses = apply_filters(
237
+            'getpaid_register_invoice_post_statuses',
238
+            array(
239 239
 
240
-				'wpi-pending'    => array(
241
-					'label'                     => _x( 'Pending Payment', 'Invoice status', 'invoicing' ),
242
-        			'public'                    => true,
243
-        			'exclude_from_search'       => true,
244
-        			'show_in_admin_all_list'    => true,
245
-					'show_in_admin_status_list' => true,
246
-					/* translators: %s: number of invoices */
247
-        			'label_count'               => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ),
248
-				),
240
+                'wpi-pending'    => array(
241
+                    'label'                     => _x( 'Pending Payment', 'Invoice status', 'invoicing' ),
242
+                    'public'                    => true,
243
+                    'exclude_from_search'       => true,
244
+                    'show_in_admin_all_list'    => true,
245
+                    'show_in_admin_status_list' => true,
246
+                    /* translators: %s: number of invoices */
247
+                    'label_count'               => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ),
248
+                ),
249 249
 
250
-				'wpi-processing' => array(
251
-					'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
252
-        			'public'                    => true,
253
-        			'exclude_from_search'       => true,
254
-        			'show_in_admin_all_list'    => true,
255
-					'show_in_admin_status_list' => true,
256
-					/* translators: %s: number of invoices */
257
-        			'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ),
258
-				),
250
+                'wpi-processing' => array(
251
+                    'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
252
+                    'public'                    => true,
253
+                    'exclude_from_search'       => true,
254
+                    'show_in_admin_all_list'    => true,
255
+                    'show_in_admin_status_list' => true,
256
+                    /* translators: %s: number of invoices */
257
+                    'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ),
258
+                ),
259 259
 
260
-				'wpi-onhold'     => array(
261
-					'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
262
-        			'public'                    => true,
263
-        			'exclude_from_search'       => true,
264
-        			'show_in_admin_all_list'    => true,
265
-					'show_in_admin_status_list' => true,
266
-					/* translators: %s: number of invoices */
267
-        			'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ),
268
-				),
260
+                'wpi-onhold'     => array(
261
+                    'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
262
+                    'public'                    => true,
263
+                    'exclude_from_search'       => true,
264
+                    'show_in_admin_all_list'    => true,
265
+                    'show_in_admin_status_list' => true,
266
+                    /* translators: %s: number of invoices */
267
+                    'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ),
268
+                ),
269 269
 
270
-				'wpi-cancelled'  => array(
271
-					'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
272
-        			'public'                    => true,
273
-        			'exclude_from_search'       => true,
274
-        			'show_in_admin_all_list'    => true,
275
-					'show_in_admin_status_list' => true,
276
-					/* translators: %s: number of invoices */
277
-        			'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ),
278
-				),
270
+                'wpi-cancelled'  => array(
271
+                    'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
272
+                    'public'                    => true,
273
+                    'exclude_from_search'       => true,
274
+                    'show_in_admin_all_list'    => true,
275
+                    'show_in_admin_status_list' => true,
276
+                    /* translators: %s: number of invoices */
277
+                    'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ),
278
+                ),
279 279
 
280
-				'wpi-refunded'   => array(
281
-					'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
282
-        			'public'                    => true,
283
-        			'exclude_from_search'       => true,
284
-        			'show_in_admin_all_list'    => true,
285
-					'show_in_admin_status_list' => true,
286
-					/* translators: %s: number of invoices */
287
-        			'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ),
288
-				),
280
+                'wpi-refunded'   => array(
281
+                    'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
282
+                    'public'                    => true,
283
+                    'exclude_from_search'       => true,
284
+                    'show_in_admin_all_list'    => true,
285
+                    'show_in_admin_status_list' => true,
286
+                    /* translators: %s: number of invoices */
287
+                    'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ),
288
+                ),
289 289
 
290
-				'wpi-failed'     => array(
291
-					'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
292
-        			'public'                    => true,
293
-        			'exclude_from_search'       => true,
294
-        			'show_in_admin_all_list'    => true,
295
-					'show_in_admin_status_list' => true,
296
-					/* translators: %s: number of invoices */
297
-        			'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ),
298
-				),
290
+                'wpi-failed'     => array(
291
+                    'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
292
+                    'public'                    => true,
293
+                    'exclude_from_search'       => true,
294
+                    'show_in_admin_all_list'    => true,
295
+                    'show_in_admin_status_list' => true,
296
+                    /* translators: %s: number of invoices */
297
+                    'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ),
298
+                ),
299 299
 
300
-				'wpi-renewal'    => array(
301
-					'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
302
-        			'public'                    => true,
303
-        			'exclude_from_search'       => true,
304
-        			'show_in_admin_all_list'    => true,
305
-					'show_in_admin_status_list' => true,
306
-					/* translators: %s: number of invoices */
307
-        			'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ),
308
-				),
309
-			)
310
-		);
300
+                'wpi-renewal'    => array(
301
+                    'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
302
+                    'public'                    => true,
303
+                    'exclude_from_search'       => true,
304
+                    'show_in_admin_all_list'    => true,
305
+                    'show_in_admin_status_list' => true,
306
+                    /* translators: %s: number of invoices */
307
+                    'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ),
308
+                ),
309
+            )
310
+        );
311 311
 
312
-		foreach ( $invoice_statuses as $invoice_statuse => $args ) {
313
-			register_post_status( $invoice_statuse, $args );
314
-		}
315
-	}
312
+        foreach ( $invoice_statuses as $invoice_statuse => $args ) {
313
+            register_post_status( $invoice_statuse, $args );
314
+        }
315
+    }
316 316
 
317
-	/**
318
-	 * Flush rewrite rules.
319
-	 */
320
-	public static function flush_rewrite_rules() {
321
-		flush_rewrite_rules();
322
-	}
317
+    /**
318
+     * Flush rewrite rules.
319
+     */
320
+    public static function flush_rewrite_rules() {
321
+        flush_rewrite_rules();
322
+    }
323 323
 
324
-	/**
325
-	 * Flush rules to prevent 404.
326
-	 *
327
-	 */
328
-	public static function maybe_flush_rewrite_rules() {
329
-		if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) {
330
-			update_option( 'getpaid_flushed_rewrite_rules', '1' );
331
-			self::flush_rewrite_rules();
332
-		}
333
-	}
324
+    /**
325
+     * Flush rules to prevent 404.
326
+     *
327
+     */
328
+    public static function maybe_flush_rewrite_rules() {
329
+        if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) {
330
+            update_option( 'getpaid_flushed_rewrite_rules', '1' );
331
+            self::flush_rewrite_rules();
332
+        }
333
+    }
334 334
 
335 335
 }
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 1 patch
Indentation   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 }
9 9
 
10 10
 if ( ! class_exists( 'WP_List_Table' ) ) {
11
-	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
11
+    include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
12 12
 }
13 13
 
14 14
 /**
@@ -16,472 +16,472 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class WPInv_Subscriptions_List_Table extends WP_List_Table {
18 18
 
19
-	/**
20
-	 * URL of this page
21
-	 *
22
-	 * @var   string
23
-	 * @since 1.0.19
24
-	 */
25
-	public $base_url;
26
-
27
-	/**
28
-	 * Query
29
-	 *
30
-	 * @var   GetPaid_Subscriptions_Query
31
-	 * @since 1.0.19
32
-	 */
33
-	public $query;
34
-
35
-	/**
36
-	 * Total subscriptions
37
-	 *
38
-	 * @var   string
39
-	 * @since 1.0.0
40
-	 */
41
-	public $total_count;
42
-
43
-	/**
44
-	 * Current status subscriptions
45
-	 *
46
-	 * @var   string
47
-	 * @since 1.0.0
48
-	 */
49
-	public $current_total_count;
50
-
51
-	/**
52
-	 * Status counts
53
-	 *
54
-	 * @var   array
55
-	 * @since 1.0.19
56
-	 */
57
-	public $status_counts;
58
-
59
-	/**
60
-	 * Number of results to show per page
61
-	 *
62
-	 * @var   int
63
-	 * @since 1.0.0
64
-	 */
65
-	public $per_page = 10;
66
-
67
-	/**
68
-	 *  Constructor function.
69
-	 */
70
-	public function __construct() {
71
-
72
-		parent::__construct(
73
-			array(
74
-				'singular' => 'subscription',
75
-				'plural'   => 'subscriptions',
76
-			)
77
-		);
78
-
79
-		$this->process_bulk_action();
80
-
81
-		$this->prepare_query();
82
-
83
-		$this->base_url = remove_query_arg( 'status' );
84
-
85
-	}
86
-
87
-	/**
88
-	 *  Prepares the display query
89
-	 */
90
-	public function prepare_query() {
91
-
92
-		// Prepare query args.
93
-		$query = array(
94
-			'number'      => $this->per_page,
95
-			'paged'       => $this->get_paged(),
96
-			'status'      => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all',
97
-			'orderby'     => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id',
98
-			'order'       => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC',
99
-			'customer_in' => $this->get_user_in(),
100
-		);
101
-
102
-		if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) {
103
-			$this->total_count         = 0;
104
-			$this->current_total_count = 0;
105
-			$this->items               = array();
106
-			$this->status_counts       = array();
107
-			return;
108
-		}
109
-
110
-		// Prepare class properties.
111
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
112
-		$this->total_count         = $this->query->get_total();
113
-		$this->current_total_count = $this->query->get_total();
114
-		$this->items               = $this->query->get_results();
115
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
116
-
117
-		if ( 'all' != $query['status'] ) {
118
-			unset( $query['status'] );
119
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
120
-		}
121
-
122
-	}
123
-
124
-	/**
125
-	 * Get user in.
126
-	 *
127
-	 */
128
-	public function get_user_in() {
129
-
130
-		// Abort if no user.
131
-		if ( empty( $_GET['s'] ) ) {
132
-			return null;
133
-		}
134
-
135
-		// Or invalid user.
136
-		$user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) );
137
-
138
-		if ( empty( $user ) ) {
139
-			return null;
140
-		}
141
-
142
-		// Search matching users.
143
-		$user  = '*' . $user . '*';
144
-		$users = new WP_User_Query(
145
-			array(
146
-				'fields'      => 'ID',
147
-				'search'      => $user,
148
-				'count_total' => false,
149
-			)
150
-		);
151
-
152
-		return $users->get_results();
153
-	}
154
-
155
-	/**
156
-	 * Gets the list of views available on this table.
157
-	 *
158
-	 * The format is an associative array:
159
-	 * - `'id' => 'link'`
160
-	 *
161
-	 * @since 1.0.0
162
-	 *
163
-	 * @return array
164
-	 */
165
-	public function get_views() {
166
-
167
-		$current  = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all';
168
-		$views    = array(
169
-
170
-			'all' => sprintf(
171
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
172
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
173
-				$current === 'all' ? ' class="current"' : '',
174
-				__( 'All', 'invoicing' ),
175
-				$this->total_count
176
-			),
177
-
178
-		);
179
-
180
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
181
-
182
-			$views[ $status ] = sprintf(
183
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
184
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
185
-				$current === $status ? ' class="current"' : '',
186
-				esc_html( getpaid_get_subscription_status_label( $status ) ),
187
-				$count
188
-			);
189
-
190
-		}
191
-
192
-		return $views;
193
-
194
-	}
195
-
196
-	/**
197
-	 * Render most columns
198
-	 *
199
-	 * @access      private
200
-	 * @since       1.0.0
201
-	 * @return      string
202
-	 */
203
-	public function column_default( $item, $column_name ) {
204
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
205
-	}
206
-
207
-	/**
208
-	 * This is how checkbox column renders.
209
-	 *
210
-	 * @param WPInv_Subscription $item
211
-	 * @return string
212
-	 */
213
-	public function column_cb( $item ) {
214
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
215
-	}
216
-
217
-	/**
218
-	 * Status column
219
-	 *
220
-	 * @param WPInv_Subscription $item
221
-	 * @since       1.0.0
222
-	 * @return      string
223
-	 */
224
-	public function column_status( $item ) {
225
-		return $item->get_status_label_html();
226
-	}
227
-
228
-	/**
229
-	 * Subscription column
230
-	 *
231
-	 * @param WPInv_Subscription $item
232
-	 * @since       1.0.0
233
-	 * @return      string
234
-	 */
235
-	public function column_subscription( $item ) {
236
-
237
-		$username = __( '(Missing User)', 'invoicing' );
238
-
239
-		$user = get_userdata( $item->get_customer_id() );
240
-		$capabilities = wpinv_current_user_can_manage_invoicing();
241
-
242
-		if ( $user ) {
243
-			$username = sprintf(
244
-				'<a href="user-edit.php?user_id=%s">%s</a>',
245
-				absint( $user->ID ),
246
-				! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
247
-			);
248
-		}
249
-
250
-		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
251
-		$column_content = sprintf(
252
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
253
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
254
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>',
255
-			'</a>',
256
-			$username
257
-		);
258
-
259
-		$row_actions = array();
260
-
261
-		// View subscription.
262
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) );
263
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
264
-
265
-		// View invoice.
266
-		$invoice = get_post( $item->get_parent_invoice_id() );
267
-
268
-		if ( ! empty( $invoice ) ) {
269
-			$invoice_url            = get_edit_post_link( $invoice );
270
-			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
271
-		}
272
-
273
-		$delete_url            = esc_url(
274
-			wp_nonce_url(
275
-				add_query_arg(
276
-					array(
277
-						'getpaid-admin-action' => 'subscription_manual_delete',
278
-						'id'                   => $item->get_id(),
279
-					)
280
-				),
281
-				'getpaid-nonce',
282
-				'getpaid-nonce'
283
-			)
284
-		);
285
-		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
286
-
287
-		if ( ! $capabilities ) {
288
-			$row_actions = array();
289
-		}
290
-
291
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
292
-
293
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
294
-	}
295
-
296
-	/**
297
-	 * Renewal date column
298
-	 *
299
-	 * @param WPInv_Subscription $item
300
-	 * @since       1.0.0
301
-	 * @return      string
302
-	 */
303
-	public function column_renewal_date( $item ) {
304
-		return getpaid_format_date_value( $item->get_expiration() );
305
-	}
306
-
307
-	/**
308
-	 * Start date column
309
-	 *
310
-	 * @param WPInv_Subscription $item
311
-	 * @since       1.0.0
312
-	 * @return      string
313
-	 */
314
-	public function column_start_date( $item ) {
315
-
316
-		$gateway = $item->get_parent_invoice()->get_gateway_title();
317
-
318
-		if ( empty( $gateway ) ) {
319
-			return getpaid_format_date_value( $item->get_date_created() );
320
-		}
321
-
322
-		$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item );
323
-		if ( ! empty( $url ) ) {
324
-
325
-			return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
326
-				__( 'Via %s', 'invoicing' ),
327
-				'<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>'
328
-			);
329
-
330
-		}
331
-
332
-		return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
333
-			__( 'Via %s', 'invoicing' ),
334
-			'<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>'
335
-		);
336
-
337
-	}
338
-
339
-	/**
340
-	 * Amount column
341
-	 *
342
-	 * @param WPInv_Subscription $item
343
-	 * @since       1.0.19
344
-	 * @return      string
345
-	 */
346
-	public static function column_amount( $item ) {
347
-		$amount = getpaid_get_formatted_subscription_amount( $item );
348
-		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
349
-	}
350
-
351
-	/**
352
-	 * Billing Times column
353
-	 *
354
-	 * @param WPInv_Subscription $item
355
-	 * @since       1.0.0
356
-	 * @return      string
357
-	 */
358
-	public function column_renewals( $item ) {
359
-		$max_bills = $item->get_bill_times();
360
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '&infin;' : $max_bills );
361
-	}
362
-
363
-	/**
364
-	 * Product ID column
365
-	 *
366
-	 * @param WPInv_Subscription $item
367
-	 * @since       1.0.0
368
-	 * @return      string
369
-	 */
370
-	public function column_item( $item ) {
371
-		$subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
372
-
373
-		if ( empty( $subscription_group ) ) {
374
-			return $this->generate_item_markup( $item->get_product_id() );
375
-		}
376
-
377
-		$markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
378
-		return implode( ' | ', $markup );
379
-
380
-	}
381
-
382
-	/**
383
-	 * Generates the items markup.
384
-	 *
385
-	 * @param int $item_id
386
-	 * @since       1.0.0
387
-	 * @return      string
388
-	 */
389
-	public static function generate_item_markup( $item_id ) {
390
-		$item = get_post( $item_id );
391
-
392
-		if ( ! empty( $item ) ) {
393
-			$link = get_edit_post_link( $item );
394
-			$link = esc_url( $link );
395
-			$name = esc_html( get_the_title( $item ) );
396
-			return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name;
397
-		} else {
398
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
399
-		}
400
-
401
-	}
402
-
403
-	/**
404
-	 * Retrieve the current page number
405
-	 *
406
-	 * @return      int
407
-	 */
408
-	public function get_paged() {
409
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
410
-	}
411
-
412
-	/**
413
-	 * Setup the final data for the table
414
-	 *
415
-	 */
416
-	public function prepare_items() {
417
-
418
-		$columns  = $this->get_columns();
419
-		$hidden   = array();
420
-		$sortable = $this->get_sortable_columns();
421
-
422
-		$this->_column_headers = array( $columns, $hidden, $sortable );
423
-
424
-		$this->set_pagination_args(
425
-			array(
426
-				'total_items' => $this->current_total_count,
427
-				'per_page'    => $this->per_page,
428
-				'total_pages' => ceil( $this->current_total_count / $this->per_page ),
429
-			)
430
-		);
431
-	}
432
-
433
-	/**
434
-	 * Table columns
435
-	 *
436
-	 * @return array
437
-	 */
438
-	public function get_columns() {
439
-		$columns = array(
440
-			'cb'           => '<input type="checkbox" />',
441
-			'subscription' => __( 'Subscription', 'invoicing' ),
442
-			'start_date'   => __( 'Start Date', 'invoicing' ),
443
-			'renewal_date' => __( 'Next Payment', 'invoicing' ),
444
-			'renewals'     => __( 'Payments', 'invoicing' ),
445
-			'item'         => __( 'Items', 'invoicing' ),
446
-			'status'       => __( 'Status', 'invoicing' ),
447
-		);
448
-
449
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
450
-	}
451
-
452
-	/**
453
-	 * Sortable table columns.
454
-	 *
455
-	 * @return array
456
-	 */
457
-	public function get_sortable_columns() {
458
-		$sortable = array(
459
-			'subscription' => array( 'id', true ),
460
-			'start_date'   => array( 'created', true ),
461
-			'renewal_date' => array( 'expiration', true ),
462
-			'renewals'     => array( 'bill_times', true ),
463
-			'item'         => array( 'product_id', true ),
464
-			'status'       => array( 'status', true ),
465
-		);
466
-
467
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
468
-	}
469
-
470
-	/**
471
-	 * Whether the table has items to display or not
472
-	 *
473
-	 * @return bool
474
-	 */
475
-	public function has_items() {
476
-		return ! empty( $this->current_total_count );
477
-	}
478
-
479
-	/**
480
-	 * Processes bulk actions.
481
-	 *
482
-	 */
483
-	public function process_bulk_action() {
484
-
485
-	}
19
+    /**
20
+     * URL of this page
21
+     *
22
+     * @var   string
23
+     * @since 1.0.19
24
+     */
25
+    public $base_url;
26
+
27
+    /**
28
+     * Query
29
+     *
30
+     * @var   GetPaid_Subscriptions_Query
31
+     * @since 1.0.19
32
+     */
33
+    public $query;
34
+
35
+    /**
36
+     * Total subscriptions
37
+     *
38
+     * @var   string
39
+     * @since 1.0.0
40
+     */
41
+    public $total_count;
42
+
43
+    /**
44
+     * Current status subscriptions
45
+     *
46
+     * @var   string
47
+     * @since 1.0.0
48
+     */
49
+    public $current_total_count;
50
+
51
+    /**
52
+     * Status counts
53
+     *
54
+     * @var   array
55
+     * @since 1.0.19
56
+     */
57
+    public $status_counts;
58
+
59
+    /**
60
+     * Number of results to show per page
61
+     *
62
+     * @var   int
63
+     * @since 1.0.0
64
+     */
65
+    public $per_page = 10;
66
+
67
+    /**
68
+     *  Constructor function.
69
+     */
70
+    public function __construct() {
71
+
72
+        parent::__construct(
73
+            array(
74
+                'singular' => 'subscription',
75
+                'plural'   => 'subscriptions',
76
+            )
77
+        );
78
+
79
+        $this->process_bulk_action();
80
+
81
+        $this->prepare_query();
82
+
83
+        $this->base_url = remove_query_arg( 'status' );
84
+
85
+    }
86
+
87
+    /**
88
+     *  Prepares the display query
89
+     */
90
+    public function prepare_query() {
91
+
92
+        // Prepare query args.
93
+        $query = array(
94
+            'number'      => $this->per_page,
95
+            'paged'       => $this->get_paged(),
96
+            'status'      => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all',
97
+            'orderby'     => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id',
98
+            'order'       => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC',
99
+            'customer_in' => $this->get_user_in(),
100
+        );
101
+
102
+        if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) {
103
+            $this->total_count         = 0;
104
+            $this->current_total_count = 0;
105
+            $this->items               = array();
106
+            $this->status_counts       = array();
107
+            return;
108
+        }
109
+
110
+        // Prepare class properties.
111
+        $this->query               = new GetPaid_Subscriptions_Query( $query );
112
+        $this->total_count         = $this->query->get_total();
113
+        $this->current_total_count = $this->query->get_total();
114
+        $this->items               = $this->query->get_results();
115
+        $this->status_counts       = getpaid_get_subscription_status_counts( $query );
116
+
117
+        if ( 'all' != $query['status'] ) {
118
+            unset( $query['status'] );
119
+            $this->total_count   = getpaid_get_subscriptions( $query, 'count' );
120
+        }
121
+
122
+    }
123
+
124
+    /**
125
+     * Get user in.
126
+     *
127
+     */
128
+    public function get_user_in() {
129
+
130
+        // Abort if no user.
131
+        if ( empty( $_GET['s'] ) ) {
132
+            return null;
133
+        }
134
+
135
+        // Or invalid user.
136
+        $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) );
137
+
138
+        if ( empty( $user ) ) {
139
+            return null;
140
+        }
141
+
142
+        // Search matching users.
143
+        $user  = '*' . $user . '*';
144
+        $users = new WP_User_Query(
145
+            array(
146
+                'fields'      => 'ID',
147
+                'search'      => $user,
148
+                'count_total' => false,
149
+            )
150
+        );
151
+
152
+        return $users->get_results();
153
+    }
154
+
155
+    /**
156
+     * Gets the list of views available on this table.
157
+     *
158
+     * The format is an associative array:
159
+     * - `'id' => 'link'`
160
+     *
161
+     * @since 1.0.0
162
+     *
163
+     * @return array
164
+     */
165
+    public function get_views() {
166
+
167
+        $current  = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all';
168
+        $views    = array(
169
+
170
+            'all' => sprintf(
171
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
172
+                esc_url( add_query_arg( 'status', false, $this->base_url ) ),
173
+                $current === 'all' ? ' class="current"' : '',
174
+                __( 'All', 'invoicing' ),
175
+                $this->total_count
176
+            ),
177
+
178
+        );
179
+
180
+        foreach ( array_filter( $this->status_counts ) as $status => $count ) {
181
+
182
+            $views[ $status ] = sprintf(
183
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
184
+                esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
185
+                $current === $status ? ' class="current"' : '',
186
+                esc_html( getpaid_get_subscription_status_label( $status ) ),
187
+                $count
188
+            );
189
+
190
+        }
191
+
192
+        return $views;
193
+
194
+    }
195
+
196
+    /**
197
+     * Render most columns
198
+     *
199
+     * @access      private
200
+     * @since       1.0.0
201
+     * @return      string
202
+     */
203
+    public function column_default( $item, $column_name ) {
204
+        return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
205
+    }
206
+
207
+    /**
208
+     * This is how checkbox column renders.
209
+     *
210
+     * @param WPInv_Subscription $item
211
+     * @return string
212
+     */
213
+    public function column_cb( $item ) {
214
+        return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
215
+    }
216
+
217
+    /**
218
+     * Status column
219
+     *
220
+     * @param WPInv_Subscription $item
221
+     * @since       1.0.0
222
+     * @return      string
223
+     */
224
+    public function column_status( $item ) {
225
+        return $item->get_status_label_html();
226
+    }
227
+
228
+    /**
229
+     * Subscription column
230
+     *
231
+     * @param WPInv_Subscription $item
232
+     * @since       1.0.0
233
+     * @return      string
234
+     */
235
+    public function column_subscription( $item ) {
236
+
237
+        $username = __( '(Missing User)', 'invoicing' );
238
+
239
+        $user = get_userdata( $item->get_customer_id() );
240
+        $capabilities = wpinv_current_user_can_manage_invoicing();
241
+
242
+        if ( $user ) {
243
+            $username = sprintf(
244
+                '<a href="user-edit.php?user_id=%s">%s</a>',
245
+                absint( $user->ID ),
246
+                ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
247
+            );
248
+        }
249
+
250
+        // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
251
+        $column_content = sprintf(
252
+            _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
253
+            '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
254
+            '<strong>' . esc_attr( $item->get_id() ) . '</strong>',
255
+            '</a>',
256
+            $username
257
+        );
258
+
259
+        $row_actions = array();
260
+
261
+        // View subscription.
262
+        $view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) );
263
+        $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
264
+
265
+        // View invoice.
266
+        $invoice = get_post( $item->get_parent_invoice_id() );
267
+
268
+        if ( ! empty( $invoice ) ) {
269
+            $invoice_url            = get_edit_post_link( $invoice );
270
+            $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
271
+        }
272
+
273
+        $delete_url            = esc_url(
274
+            wp_nonce_url(
275
+                add_query_arg(
276
+                    array(
277
+                        'getpaid-admin-action' => 'subscription_manual_delete',
278
+                        'id'                   => $item->get_id(),
279
+                    )
280
+                ),
281
+                'getpaid-nonce',
282
+                'getpaid-nonce'
283
+            )
284
+        );
285
+        $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
286
+
287
+        if ( ! $capabilities ) {
288
+            $row_actions = array();
289
+        }
290
+
291
+        $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
292
+
293
+        return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
294
+    }
295
+
296
+    /**
297
+     * Renewal date column
298
+     *
299
+     * @param WPInv_Subscription $item
300
+     * @since       1.0.0
301
+     * @return      string
302
+     */
303
+    public function column_renewal_date( $item ) {
304
+        return getpaid_format_date_value( $item->get_expiration() );
305
+    }
306
+
307
+    /**
308
+     * Start date column
309
+     *
310
+     * @param WPInv_Subscription $item
311
+     * @since       1.0.0
312
+     * @return      string
313
+     */
314
+    public function column_start_date( $item ) {
315
+
316
+        $gateway = $item->get_parent_invoice()->get_gateway_title();
317
+
318
+        if ( empty( $gateway ) ) {
319
+            return getpaid_format_date_value( $item->get_date_created() );
320
+        }
321
+
322
+        $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item );
323
+        if ( ! empty( $url ) ) {
324
+
325
+            return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
326
+                __( 'Via %s', 'invoicing' ),
327
+                '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>'
328
+            );
329
+
330
+        }
331
+
332
+        return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
333
+            __( 'Via %s', 'invoicing' ),
334
+            '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>'
335
+        );
336
+
337
+    }
338
+
339
+    /**
340
+     * Amount column
341
+     *
342
+     * @param WPInv_Subscription $item
343
+     * @since       1.0.19
344
+     * @return      string
345
+     */
346
+    public static function column_amount( $item ) {
347
+        $amount = getpaid_get_formatted_subscription_amount( $item );
348
+        return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
349
+    }
350
+
351
+    /**
352
+     * Billing Times column
353
+     *
354
+     * @param WPInv_Subscription $item
355
+     * @since       1.0.0
356
+     * @return      string
357
+     */
358
+    public function column_renewals( $item ) {
359
+        $max_bills = $item->get_bill_times();
360
+        return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '&infin;' : $max_bills );
361
+    }
362
+
363
+    /**
364
+     * Product ID column
365
+     *
366
+     * @param WPInv_Subscription $item
367
+     * @since       1.0.0
368
+     * @return      string
369
+     */
370
+    public function column_item( $item ) {
371
+        $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
372
+
373
+        if ( empty( $subscription_group ) ) {
374
+            return $this->generate_item_markup( $item->get_product_id() );
375
+        }
376
+
377
+        $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
378
+        return implode( ' | ', $markup );
379
+
380
+    }
381
+
382
+    /**
383
+     * Generates the items markup.
384
+     *
385
+     * @param int $item_id
386
+     * @since       1.0.0
387
+     * @return      string
388
+     */
389
+    public static function generate_item_markup( $item_id ) {
390
+        $item = get_post( $item_id );
391
+
392
+        if ( ! empty( $item ) ) {
393
+            $link = get_edit_post_link( $item );
394
+            $link = esc_url( $link );
395
+            $name = esc_html( get_the_title( $item ) );
396
+            return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name;
397
+        } else {
398
+            return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
399
+        }
400
+
401
+    }
402
+
403
+    /**
404
+     * Retrieve the current page number
405
+     *
406
+     * @return      int
407
+     */
408
+    public function get_paged() {
409
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
410
+    }
411
+
412
+    /**
413
+     * Setup the final data for the table
414
+     *
415
+     */
416
+    public function prepare_items() {
417
+
418
+        $columns  = $this->get_columns();
419
+        $hidden   = array();
420
+        $sortable = $this->get_sortable_columns();
421
+
422
+        $this->_column_headers = array( $columns, $hidden, $sortable );
423
+
424
+        $this->set_pagination_args(
425
+            array(
426
+                'total_items' => $this->current_total_count,
427
+                'per_page'    => $this->per_page,
428
+                'total_pages' => ceil( $this->current_total_count / $this->per_page ),
429
+            )
430
+        );
431
+    }
432
+
433
+    /**
434
+     * Table columns
435
+     *
436
+     * @return array
437
+     */
438
+    public function get_columns() {
439
+        $columns = array(
440
+            'cb'           => '<input type="checkbox" />',
441
+            'subscription' => __( 'Subscription', 'invoicing' ),
442
+            'start_date'   => __( 'Start Date', 'invoicing' ),
443
+            'renewal_date' => __( 'Next Payment', 'invoicing' ),
444
+            'renewals'     => __( 'Payments', 'invoicing' ),
445
+            'item'         => __( 'Items', 'invoicing' ),
446
+            'status'       => __( 'Status', 'invoicing' ),
447
+        );
448
+
449
+        return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
450
+    }
451
+
452
+    /**
453
+     * Sortable table columns.
454
+     *
455
+     * @return array
456
+     */
457
+    public function get_sortable_columns() {
458
+        $sortable = array(
459
+            'subscription' => array( 'id', true ),
460
+            'start_date'   => array( 'created', true ),
461
+            'renewal_date' => array( 'expiration', true ),
462
+            'renewals'     => array( 'bill_times', true ),
463
+            'item'         => array( 'product_id', true ),
464
+            'status'       => array( 'status', true ),
465
+        );
466
+
467
+        return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
468
+    }
469
+
470
+    /**
471
+     * Whether the table has items to display or not
472
+     *
473
+     * @return bool
474
+     */
475
+    public function has_items() {
476
+        return ! empty( $this->current_total_count );
477
+    }
478
+
479
+    /**
480
+     * Processes bulk actions.
481
+     *
482
+     */
483
+    public function process_bulk_action() {
484
+
485
+    }
486 486
 
487 487
 }
Please login to merge, or discard this patch.