Passed
Push — master ( f20c5b...584b12 )
by Brian
12:51
created
includes/class-getpaid-post-types.php 1 patch
Indentation   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -15,331 +15,331 @@
 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'               => true,
68
-					'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? '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'     => true,
75
-					'can_export'            => true,
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'               => true,
68
+                    'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? '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'     => true,
75
+                    'can_export'            => true,
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'            => true,
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
-					'capabilities' => array(
116
-						'edit_post'          => $capabilities,
117
-						'read_post'          => $capabilities,
118
-						'delete_post'        => $capabilities,
119
-						'edit_posts'         => 'update_core',
120
-						'edit_others_posts'  => 'update_core',
121
-						'delete_posts'       => 'update_core',
122
-						'publish_posts'      => 'update_core',
123
-						'read_private_posts' => 'update_core'
124
-					),
125
-				)
126
-			)
127
-		);
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'            => true,
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
+                    'capabilities' => array(
116
+                        'edit_post'          => $capabilities,
117
+                        'read_post'          => $capabilities,
118
+                        'delete_post'        => $capabilities,
119
+                        'edit_posts'         => 'update_core',
120
+                        'edit_others_posts'  => 'update_core',
121
+                        'delete_posts'       => 'update_core',
122
+                        'publish_posts'      => 'update_core',
123
+                        'read_private_posts' => 'update_core'
124
+                    ),
125
+                )
126
+            )
127
+        );
128 128
 
129
-		// Register invoice post type.
130
-		register_post_type(
131
-			'wpi_invoice',
132
-			apply_filters(
133
-				'wpinv_register_post_type_invoice',
134
-				array(
135
-					'labels'                 => array(
136
-						'name'                  => __( 'Invoices', 'invoicing' ),
137
-						'singular_name'         => __( 'Invoice', 'invoicing' ),
138
-						'all_items'             => __( 'Invoices', 'invoicing' ),
139
-						'menu_name'             => _x( 'Invoices', 'Admin menu name', 'invoicing' ),
140
-						'add_new'               => __( 'Add New', 'invoicing' ),
141
-						'add_new_item'          => __( 'Add new invoice', 'invoicing' ),
142
-						'edit'                  => __( 'Edit', 'invoicing' ),
143
-						'edit_item'             => __( 'Edit invoice', 'invoicing' ),
144
-						'new_item'              => __( 'New invoice', 'invoicing' ),
145
-						'view_item'             => __( 'View invoice', 'invoicing' ),
146
-						'view_items'            => __( 'View Invoices', 'invoicing' ),
147
-						'search_items'          => __( 'Search invoices', 'invoicing' ),
148
-						'not_found'             => __( 'No invoices found', 'invoicing' ),
149
-						'not_found_in_trash'    => __( 'No invoices found in trash', 'invoicing' ),
150
-						'parent'                => __( 'Parent invoice', 'invoicing' ),
151
-						'featured_image'        => __( 'Invoice image', 'invoicing' ),
152
-						'set_featured_image'    => __( 'Set invoice image', 'invoicing' ),
153
-						'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ),
154
-						'use_featured_image'    => __( 'Use as invoice image', 'invoicing' ),
155
-						'insert_into_item'      => __( 'Insert into invoice', 'invoicing' ),
156
-						'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ),
157
-						'filter_items_list'     => __( 'Filter invoices', 'invoicing' ),
158
-						'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ),
159
-						'items_list'            => __( 'Invoices list', 'invoicing' ),
160
-					),
161
-					'description'           => __( 'This is where invoices are stored.', 'invoicing' ),
162
-					'public'                => true,
163
-					'has_archive'           => false,
164
-					'publicly_queryable'    => true,
165
-        			'exclude_from_search'   => true,
166
-        			'show_ui'               => true,
167
-					'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
168
-					'show_in_nav_menus'     => false,
169
-					'supports'              => array( 'title', 'author', 'excerpt'  ),
170
-					'rewrite'               => array(
171
-						'slug'              => 'invoice',
172
-						'with_front'        => false,
173
-					),
174
-					'query_var'             => false,
175
-					'map_meta_cap'          => true,
176
-					'show_in_admin_bar'     => true,
177
-					'can_export'            => true,
178
-					'hierarchical'          => false,
179
-					'menu_position'         => null,
180
-					'menu_icon'             => 'dashicons-media-spreadsheet',
181
-				)
182
-			)
183
-		);
129
+        // Register invoice post type.
130
+        register_post_type(
131
+            'wpi_invoice',
132
+            apply_filters(
133
+                'wpinv_register_post_type_invoice',
134
+                array(
135
+                    'labels'                 => array(
136
+                        'name'                  => __( 'Invoices', 'invoicing' ),
137
+                        'singular_name'         => __( 'Invoice', 'invoicing' ),
138
+                        'all_items'             => __( 'Invoices', 'invoicing' ),
139
+                        'menu_name'             => _x( 'Invoices', 'Admin menu name', 'invoicing' ),
140
+                        'add_new'               => __( 'Add New', 'invoicing' ),
141
+                        'add_new_item'          => __( 'Add new invoice', 'invoicing' ),
142
+                        'edit'                  => __( 'Edit', 'invoicing' ),
143
+                        'edit_item'             => __( 'Edit invoice', 'invoicing' ),
144
+                        'new_item'              => __( 'New invoice', 'invoicing' ),
145
+                        'view_item'             => __( 'View invoice', 'invoicing' ),
146
+                        'view_items'            => __( 'View Invoices', 'invoicing' ),
147
+                        'search_items'          => __( 'Search invoices', 'invoicing' ),
148
+                        'not_found'             => __( 'No invoices found', 'invoicing' ),
149
+                        'not_found_in_trash'    => __( 'No invoices found in trash', 'invoicing' ),
150
+                        'parent'                => __( 'Parent invoice', 'invoicing' ),
151
+                        'featured_image'        => __( 'Invoice image', 'invoicing' ),
152
+                        'set_featured_image'    => __( 'Set invoice image', 'invoicing' ),
153
+                        'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ),
154
+                        'use_featured_image'    => __( 'Use as invoice image', 'invoicing' ),
155
+                        'insert_into_item'      => __( 'Insert into invoice', 'invoicing' ),
156
+                        'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ),
157
+                        'filter_items_list'     => __( 'Filter invoices', 'invoicing' ),
158
+                        'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ),
159
+                        'items_list'            => __( 'Invoices list', 'invoicing' ),
160
+                    ),
161
+                    'description'           => __( 'This is where invoices are stored.', 'invoicing' ),
162
+                    'public'                => true,
163
+                    'has_archive'           => false,
164
+                    'publicly_queryable'    => true,
165
+                    'exclude_from_search'   => true,
166
+                    'show_ui'               => true,
167
+                    'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
168
+                    'show_in_nav_menus'     => false,
169
+                    'supports'              => array( 'title', 'author', 'excerpt'  ),
170
+                    'rewrite'               => array(
171
+                        'slug'              => 'invoice',
172
+                        'with_front'        => false,
173
+                    ),
174
+                    'query_var'             => false,
175
+                    'map_meta_cap'          => true,
176
+                    'show_in_admin_bar'     => true,
177
+                    'can_export'            => true,
178
+                    'hierarchical'          => false,
179
+                    'menu_position'         => null,
180
+                    'menu_icon'             => 'dashicons-media-spreadsheet',
181
+                )
182
+            )
183
+        );
184 184
 
185
-		// Register discount post type.
186
-		register_post_type(
187
-			'wpi_discount',
188
-			apply_filters(
189
-				'wpinv_register_post_type_discount',
190
-				array(
191
-					'labels'                 => array(
192
-						'name'                  => __( 'Discounts', 'invoicing' ),
193
-						'singular_name'         => __( 'Discount', 'invoicing' ),
194
-						'all_items'             => __( 'Discounts', 'invoicing' ),
195
-						'menu_name'             => _x( 'Discounts', 'Admin menu name', 'invoicing' ),
196
-						'add_new'               => __( 'Add New', 'invoicing' ),
197
-						'add_new_item'          => __( 'Add new discount', 'invoicing' ),
198
-						'edit'                  => __( 'Edit', 'invoicing' ),
199
-						'edit_item'             => __( 'Edit discount', 'invoicing' ),
200
-						'new_item'              => __( 'New discount', 'invoicing' ),
201
-						'view_item'             => __( 'View discount', 'invoicing' ),
202
-						'view_items'            => __( 'View Discounts', 'invoicing' ),
203
-						'search_items'          => __( 'Search discounts', 'invoicing' ),
204
-						'not_found'             => __( 'No discounts found', 'invoicing' ),
205
-						'not_found_in_trash'    => __( 'No discounts found in trash', 'invoicing' ),
206
-						'parent'                => __( 'Parent discount', 'invoicing' ),
207
-						'featured_image'        => __( 'Discount image', 'invoicing' ),
208
-						'set_featured_image'    => __( 'Set discount image', 'invoicing' ),
209
-						'remove_featured_image' => __( 'Remove discount image', 'invoicing' ),
210
-						'use_featured_image'    => __( 'Use as discount image', 'invoicing' ),
211
-						'insert_into_item'      => __( 'Insert into discount', 'invoicing' ),
212
-						'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ),
213
-						'filter_items_list'     => __( 'Filter discounts', 'invoicing' ),
214
-						'items_list_navigation' => __( 'Discount navigation', 'invoicing' ),
215
-						'items_list'            => __( 'Discounts list', 'invoicing' ),
216
-					),
217
-					'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
218
-					'public'             => false,
219
-					'can_export'         => true,
220
-					'_builtin'           => false,
221
-					'publicly_queryable' => false,
222
-					'exclude_from_search'=> true,
223
-					'show_ui'            => true,
224
-					'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
225
-					'query_var'          => false,
226
-					'rewrite'            => false,
227
-					'map_meta_cap'       => true,
228
-					'has_archive'        => false,
229
-					'hierarchical'       => false,
230
-					'supports'           => array( 'title', 'excerpt' ),
231
-					'show_in_nav_menus'  => false,
232
-					'show_in_admin_bar'  => true,
233
-					'menu_position'      => null,
234
-				)
235
-			)
236
-		);
185
+        // Register discount post type.
186
+        register_post_type(
187
+            'wpi_discount',
188
+            apply_filters(
189
+                'wpinv_register_post_type_discount',
190
+                array(
191
+                    'labels'                 => array(
192
+                        'name'                  => __( 'Discounts', 'invoicing' ),
193
+                        'singular_name'         => __( 'Discount', 'invoicing' ),
194
+                        'all_items'             => __( 'Discounts', 'invoicing' ),
195
+                        'menu_name'             => _x( 'Discounts', 'Admin menu name', 'invoicing' ),
196
+                        'add_new'               => __( 'Add New', 'invoicing' ),
197
+                        'add_new_item'          => __( 'Add new discount', 'invoicing' ),
198
+                        'edit'                  => __( 'Edit', 'invoicing' ),
199
+                        'edit_item'             => __( 'Edit discount', 'invoicing' ),
200
+                        'new_item'              => __( 'New discount', 'invoicing' ),
201
+                        'view_item'             => __( 'View discount', 'invoicing' ),
202
+                        'view_items'            => __( 'View Discounts', 'invoicing' ),
203
+                        'search_items'          => __( 'Search discounts', 'invoicing' ),
204
+                        'not_found'             => __( 'No discounts found', 'invoicing' ),
205
+                        'not_found_in_trash'    => __( 'No discounts found in trash', 'invoicing' ),
206
+                        'parent'                => __( 'Parent discount', 'invoicing' ),
207
+                        'featured_image'        => __( 'Discount image', 'invoicing' ),
208
+                        'set_featured_image'    => __( 'Set discount image', 'invoicing' ),
209
+                        'remove_featured_image' => __( 'Remove discount image', 'invoicing' ),
210
+                        'use_featured_image'    => __( 'Use as discount image', 'invoicing' ),
211
+                        'insert_into_item'      => __( 'Insert into discount', 'invoicing' ),
212
+                        'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ),
213
+                        'filter_items_list'     => __( 'Filter discounts', 'invoicing' ),
214
+                        'items_list_navigation' => __( 'Discount navigation', 'invoicing' ),
215
+                        'items_list'            => __( 'Discounts list', 'invoicing' ),
216
+                    ),
217
+                    'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
218
+                    'public'             => false,
219
+                    'can_export'         => true,
220
+                    '_builtin'           => false,
221
+                    'publicly_queryable' => false,
222
+                    'exclude_from_search'=> true,
223
+                    'show_ui'            => true,
224
+                    'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
225
+                    'query_var'          => false,
226
+                    'rewrite'            => false,
227
+                    'map_meta_cap'       => true,
228
+                    'has_archive'        => false,
229
+                    'hierarchical'       => false,
230
+                    'supports'           => array( 'title', 'excerpt' ),
231
+                    'show_in_nav_menus'  => false,
232
+                    'show_in_admin_bar'  => true,
233
+                    'menu_position'      => null,
234
+                )
235
+            )
236
+        );
237 237
 
238
-		do_action( 'getpaid_after_register_post_types' );
239
-	}
238
+        do_action( 'getpaid_after_register_post_types' );
239
+    }
240 240
 
241
-	/**
242
-	 * Register our custom post statuses.
243
-	 */
244
-	public static function register_post_status() {
241
+    /**
242
+     * Register our custom post statuses.
243
+     */
244
+    public static function register_post_status() {
245 245
 
246
-		$invoice_statuses = apply_filters(
247
-			'getpaid_register_invoice_post_statuses',
248
-			array(
246
+        $invoice_statuses = apply_filters(
247
+            'getpaid_register_invoice_post_statuses',
248
+            array(
249 249
 
250
-				'wpi-pending' => array(
251
-					'label'                     => _x( 'Pending Payment', '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( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' )
258
-				),
250
+                'wpi-pending' => array(
251
+                    'label'                     => _x( 'Pending Payment', '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( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' )
258
+                ),
259 259
 
260
-				'wpi-processing' => array(
261
-					'label'                     => _x( 'Processing', '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( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
268
-				),
260
+                'wpi-processing' => array(
261
+                    'label'                     => _x( 'Processing', '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( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
268
+                ),
269 269
 
270
-				'wpi-onhold' => array(
271
-					'label'                     => _x( 'On Hold', '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( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
278
-				),
270
+                'wpi-onhold' => array(
271
+                    'label'                     => _x( 'On Hold', '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( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
278
+                ),
279 279
 
280
-				'wpi-cancelled' => array(
281
-					'label'                     => _x( 'Cancelled', '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( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
288
-				),
280
+                'wpi-cancelled' => array(
281
+                    'label'                     => _x( 'Cancelled', '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( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
288
+                ),
289 289
 
290
-				'wpi-refunded' => array(
291
-					'label'                     => _x( 'Refunded', '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( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
298
-				),
290
+                'wpi-refunded' => array(
291
+                    'label'                     => _x( 'Refunded', '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( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
298
+                ),
299 299
 
300
-				'wpi-failed' => array(
301
-					'label'                     => _x( 'Failed', '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( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
308
-				),
300
+                'wpi-failed' => array(
301
+                    'label'                     => _x( 'Failed', '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( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
308
+                ),
309 309
 
310
-				'wpi-renewal' => array(
311
-					'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
312
-        			'public'                    => true,
313
-        			'exclude_from_search'       => true,
314
-        			'show_in_admin_all_list'    => true,
315
-					'show_in_admin_status_list' => true,
316
-					/* translators: %s: number of invoices */
317
-        			'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
318
-				)
319
-			)
320
-		);
310
+                'wpi-renewal' => array(
311
+                    'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
312
+                    'public'                    => true,
313
+                    'exclude_from_search'       => true,
314
+                    'show_in_admin_all_list'    => true,
315
+                    'show_in_admin_status_list' => true,
316
+                    /* translators: %s: number of invoices */
317
+                    'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
318
+                )
319
+            )
320
+        );
321 321
 
322
-		foreach ( $invoice_statuses as $invoice_statuse => $args ) {
323
-			register_post_status( $invoice_statuse, $args );
324
-		}
325
-	}
322
+        foreach ( $invoice_statuses as $invoice_statuse => $args ) {
323
+            register_post_status( $invoice_statuse, $args );
324
+        }
325
+    }
326 326
 
327
-	/**
328
-	 * Flush rewrite rules.
329
-	 */
330
-	public static function flush_rewrite_rules() {
331
-		flush_rewrite_rules();
332
-	}
327
+    /**
328
+     * Flush rewrite rules.
329
+     */
330
+    public static function flush_rewrite_rules() {
331
+        flush_rewrite_rules();
332
+    }
333 333
 
334
-	/**
335
-	 * Flush rules to prevent 404.
336
-	 *
337
-	 */
338
-	public static function maybe_flush_rewrite_rules() {
339
-		if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) {
340
-			update_option( 'getpaid_flushed_rewrite_rules', '1' );
341
-			self::flush_rewrite_rules();
342
-		}
343
-	}
334
+    /**
335
+     * Flush rules to prevent 404.
336
+     *
337
+     */
338
+    public static function maybe_flush_rewrite_rules() {
339
+        if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) {
340
+            update_option( 'getpaid_flushed_rewrite_rules', '1' );
341
+            self::flush_rewrite_rules();
342
+        }
343
+    }
344 344
 
345 345
 }
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +528 added lines, -528 removed lines patch added patch discarded remove patch
@@ -14,591 +14,591 @@
 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
-
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
73
-		}
74
-
75
-		return null;
76
-	}
77
-
78
-	/**
79
-	 * Define class properties.
80
-	 */
81
-	public function set_properties() {
82
-
83
-		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
-
88
-		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
-
102
-	}
103
-
104
-	 /**
105
-	 * Define plugin constants.
106
-	 */
107
-	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
-		$this->version = WPINV_VERSION;
111
-	}
112
-
113
-	/**
114
-	 * Hook into actions and filters.
115
-	 *
116
-	 * @since 1.0.19
117
-	 */
118
-	protected function init_hooks() {
119
-		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
-
122
-		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
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
+
71
+        if ( isset( $this->data[ $prop ] ) ) {
72
+            return $this->data[ $prop ];
73
+        }
74
+
75
+        return null;
76
+    }
77
+
78
+    /**
79
+     * Define class properties.
80
+     */
81
+    public function set_properties() {
82
+
83
+        // Sessions.
84
+        $this->set( 'session', new WPInv_Session_Handler() );
85
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
+
88
+        // Init other objects.
89
+        $this->set( 'session', new WPInv_Session_Handler() );
90
+        $this->set( 'notes', new WPInv_Notes() );
91
+        $this->set( 'api', new WPInv_API() );
92
+        $this->set( 'post_types', new GetPaid_Post_Types() );
93
+        $this->set( 'template', new GetPaid_Template() );
94
+        $this->set( 'admin', new GetPaid_Admin() );
95
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
96
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
+
102
+    }
103
+
104
+        /**
105
+         * Define plugin constants.
106
+         */
107
+    public function define_constants() {
108
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
+        $this->version = WPINV_VERSION;
111
+    }
112
+
113
+    /**
114
+     * Hook into actions and filters.
115
+     *
116
+     * @since 1.0.19
117
+     */
118
+    protected function init_hooks() {
119
+        /* Internationalize the text strings used. */
120
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
+
122
+        // Init the plugin after WordPress inits.
123
+        add_action( 'init', array( $this, 'init' ), 1 );
124
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
126
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
130
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
+
134
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135 135
         add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
-
138
-		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
141
-
142
-	}
143
-
144
-	public function plugins_loaded() {
145
-		/* Internationalize the text strings used. */
146
-		$this->load_textdomain();
147
-
148
-		do_action( 'wpinv_loaded' );
149
-
150
-		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
152
-			wpinv_oxygen_fix_conflict();
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Load Localisation files.
158
-	 *
159
-	 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
-	 *
161
-	 * Locales found in:
162
-	 *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
-	 *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
-	 * 
165
-	 * @since 1.0.0
166
-	 */
167
-	public function load_textdomain() {
168
-
169
-		load_plugin_textdomain(
170
-			'invoicing',
171
-			false,
172
-			plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
-		);
174
-
175
-	}
176
-
177
-	/**
178
-	 * Include required core files used in admin and on the frontend.
179
-	 */
180
-	public function includes() {
181
-
182
-		// Start with the settings.
183
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
184
-
185
-		// Packages/libraries.
186
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
187
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
188
-
189
-		// Load functions.
190
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
205
-
206
-		// Register autoloader.
207
-		try {
208
-			spl_autoload_register( array( $this, 'autoload' ), true );
209
-		} catch ( Exception $e ) {
210
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
-		}
212
-
213
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
234
-
235
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
236
-			GetPaid_Post_Types_Admin::init();
237
-
238
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
241
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
242
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
243
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
244
-			// load the user class only on the users.php page
245
-			global $pagenow;
246
-			if($pagenow=='users.php'){
247
-				new WPInv_Admin_Users();
248
-			}
249
-		}
250
-
251
-		// Register cli commands
252
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
253
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
254
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
255
-		}
256
-
257
-	}
258
-
259
-	/**
260
-	 * Class autoloader
261
-	 *
262
-	 * @param       string $class_name The name of the class to load.
263
-	 * @access      public
264
-	 * @since       1.0.19
265
-	 * @return      void
266
-	 */
267
-	public function autoload( $class_name ) {
268
-
269
-		// Normalize the class name...
270
-		$class_name  = strtolower( $class_name );
271
-
272
-		// ... and make sure it is our class.
273
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
274
-			return;
275
-		}
276
-
277
-		// Next, prepare the file name from the class.
278
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
279
-
280
-		// Base path of the classes.
281
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
282
-
283
-		// And an array of possible locations in order of importance.
284
-		$locations = array(
285
-			"$plugin_path/includes",
286
-			"$plugin_path/includes/data-stores",
287
-			"$plugin_path/includes/gateways",
288
-			"$plugin_path/includes/payments",
289
-			"$plugin_path/includes/geolocation",
290
-			"$plugin_path/includes/reports",
291
-			"$plugin_path/includes/api",
292
-			"$plugin_path/includes/admin",
293
-			"$plugin_path/includes/admin/meta-boxes",
294
-		);
295
-
296
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
297
-
298
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
299
-				include trailingslashit( $location ) . $file_name;
300
-				break;
301
-			}
302
-
303
-		}
304
-
305
-	}
306
-
307
-	/**
308
-	 * Inits hooks etc.
309
-	 */
310
-	public function init() {
311
-
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
-	/**
345
-	 * Checks if this is an IPN request and processes it.
346
-	 */
347
-	public function maybe_process_ipn() {
348
-
349
-		// Ensure that this is an IPN request.
350
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
-			return;
352
-		}
353
-
354
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
355
-
356
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
357
-		do_action( "wpinv_verify_{$gateway}_ipn" );
358
-		exit;
359
-
360
-	}
361
-
362
-	public function enqueue_scripts() {
363
-
364
-		// Fires before adding scripts.
365
-		do_action( 'getpaid_enqueue_scripts' );
366
-
367
-		$localize                         = array();
368
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
-		$localize['thousands']            = wpinv_thousands_separator();
370
-		$localize['decimals']             = wpinv_decimal_separator();
371
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
-		$localize['UseTaxes']             = wpinv_use_taxes();
374
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
376
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
-
378
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
379
-
380
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
381
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
382
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
383
-	}
384
-
385
-	public function wpinv_actions() {
386
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
387
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
388
-		}
389
-	}
390
-
391
-	/**
136
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
+
138
+        // Fires after registering actions.
139
+        do_action( 'wpinv_actions', $this );
140
+        do_action( 'getpaid_actions', $this );
141
+
142
+    }
143
+
144
+    public function plugins_loaded() {
145
+        /* Internationalize the text strings used. */
146
+        $this->load_textdomain();
147
+
148
+        do_action( 'wpinv_loaded' );
149
+
150
+        // Fix oxygen page builder conflict
151
+        if ( function_exists( 'ct_css_output' ) ) {
152
+            wpinv_oxygen_fix_conflict();
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Load Localisation files.
158
+     *
159
+     * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
+     *
161
+     * Locales found in:
162
+     *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
+     *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
+     * 
165
+     * @since 1.0.0
166
+     */
167
+    public function load_textdomain() {
168
+
169
+        load_plugin_textdomain(
170
+            'invoicing',
171
+            false,
172
+            plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
+        );
174
+
175
+    }
176
+
177
+    /**
178
+     * Include required core files used in admin and on the frontend.
179
+     */
180
+    public function includes() {
181
+
182
+        // Start with the settings.
183
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
184
+
185
+        // Packages/libraries.
186
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
187
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
188
+
189
+        // Load functions.
190
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
191
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
192
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
193
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
194
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
195
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
196
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
198
+        require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
199
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
205
+
206
+        // Register autoloader.
207
+        try {
208
+            spl_autoload_register( array( $this, 'autoload' ), true );
209
+        } catch ( Exception $e ) {
210
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
+        }
212
+
213
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
214
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
215
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
216
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
217
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
218
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
219
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
220
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
221
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
222
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
234
+
235
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
236
+            GetPaid_Post_Types_Admin::init();
237
+
238
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
239
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
240
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
241
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
242
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
243
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
244
+            // load the user class only on the users.php page
245
+            global $pagenow;
246
+            if($pagenow=='users.php'){
247
+                new WPInv_Admin_Users();
248
+            }
249
+        }
250
+
251
+        // Register cli commands
252
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
253
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
254
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
255
+        }
256
+
257
+    }
258
+
259
+    /**
260
+     * Class autoloader
261
+     *
262
+     * @param       string $class_name The name of the class to load.
263
+     * @access      public
264
+     * @since       1.0.19
265
+     * @return      void
266
+     */
267
+    public function autoload( $class_name ) {
268
+
269
+        // Normalize the class name...
270
+        $class_name  = strtolower( $class_name );
271
+
272
+        // ... and make sure it is our class.
273
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
274
+            return;
275
+        }
276
+
277
+        // Next, prepare the file name from the class.
278
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
279
+
280
+        // Base path of the classes.
281
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
282
+
283
+        // And an array of possible locations in order of importance.
284
+        $locations = array(
285
+            "$plugin_path/includes",
286
+            "$plugin_path/includes/data-stores",
287
+            "$plugin_path/includes/gateways",
288
+            "$plugin_path/includes/payments",
289
+            "$plugin_path/includes/geolocation",
290
+            "$plugin_path/includes/reports",
291
+            "$plugin_path/includes/api",
292
+            "$plugin_path/includes/admin",
293
+            "$plugin_path/includes/admin/meta-boxes",
294
+        );
295
+
296
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
297
+
298
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
299
+                include trailingslashit( $location ) . $file_name;
300
+                break;
301
+            }
302
+
303
+        }
304
+
305
+    }
306
+
307
+    /**
308
+     * Inits hooks etc.
309
+     */
310
+    public function init() {
311
+
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
+    /**
345
+     * Checks if this is an IPN request and processes it.
346
+     */
347
+    public function maybe_process_ipn() {
348
+
349
+        // Ensure that this is an IPN request.
350
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
+            return;
352
+        }
353
+
354
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
355
+
356
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
357
+        do_action( "wpinv_verify_{$gateway}_ipn" );
358
+        exit;
359
+
360
+    }
361
+
362
+    public function enqueue_scripts() {
363
+
364
+        // Fires before adding scripts.
365
+        do_action( 'getpaid_enqueue_scripts' );
366
+
367
+        $localize                         = array();
368
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
+        $localize['thousands']            = wpinv_thousands_separator();
370
+        $localize['decimals']             = wpinv_decimal_separator();
371
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
+        $localize['UseTaxes']             = wpinv_use_taxes();
374
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
376
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
+
378
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
379
+
380
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
381
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
382
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
383
+    }
384
+
385
+    public function wpinv_actions() {
386
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
387
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
388
+        }
389
+    }
390
+
391
+    /**
392 392
      * Fires an action after verifying that a user can fire them.
393
-	 *
394
-	 * Note: If the action is on an invoice, subscription etc, esure that the
395
-	 * current user owns the invoice/subscription.
393
+     *
394
+     * Note: If the action is on an invoice, subscription etc, esure that the
395
+     * current user owns the invoice/subscription.
396 396
      */
397 397
     public function maybe_do_authenticated_action() {
398 398
 
399
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
399
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
400 400
 
401
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
402
-			$data = wp_unslash( $_REQUEST );
403
-			if ( is_user_logged_in() ) {
404
-				do_action( "getpaid_authenticated_action_$key", $data );
405
-			}
401
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
402
+            $data = wp_unslash( $_REQUEST );
403
+            if ( is_user_logged_in() ) {
404
+                do_action( "getpaid_authenticated_action_$key", $data );
405
+            }
406 406
 
407
-			do_action( "getpaid_unauthenticated_action_$key", $data );
407
+            do_action( "getpaid_unauthenticated_action_$key", $data );
408 408
 
409
-		}
409
+        }
410 410
 
411 411
     }
412 412
 
413
-	public function pre_get_posts( $wp_query ) {
414
-
415
-		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() ) {
416
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
417
-		}
418
-
419
-		return $wp_query;
420
-	}
421
-
422
-	/**
423
-	 * Register widgets
424
-	 *
425
-	 */
426
-	public function register_widgets() {
427
-
428
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
429
-		// So we disable our widgets when editing a page with UX Builder.
430
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
431
-			return;
432
-		}
433
-
434
-		$widgets = apply_filters(
435
-			'getpaid_widget_classes',
436
-			array(
437
-				'WPInv_Checkout_Widget',
438
-				'WPInv_History_Widget',
439
-				'WPInv_Receipt_Widget',
440
-				'WPInv_Subscriptions_Widget',
441
-				'WPInv_Buy_Item_Widget',
442
-				'WPInv_Messages_Widget',
443
-				'WPInv_GetPaid_Widget'
444
-			)
445
-		);
446
-
447
-		foreach ( $widgets as $widget ) {
448
-			register_widget( $widget );
449
-		}
413
+    public function pre_get_posts( $wp_query ) {
414
+
415
+        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() ) {
416
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
417
+        }
418
+
419
+        return $wp_query;
420
+    }
421
+
422
+    /**
423
+     * Register widgets
424
+     *
425
+     */
426
+    public function register_widgets() {
427
+
428
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
429
+        // So we disable our widgets when editing a page with UX Builder.
430
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
431
+            return;
432
+        }
433
+
434
+        $widgets = apply_filters(
435
+            'getpaid_widget_classes',
436
+            array(
437
+                'WPInv_Checkout_Widget',
438
+                'WPInv_History_Widget',
439
+                'WPInv_Receipt_Widget',
440
+                'WPInv_Subscriptions_Widget',
441
+                'WPInv_Buy_Item_Widget',
442
+                'WPInv_Messages_Widget',
443
+                'WPInv_GetPaid_Widget'
444
+            )
445
+        );
446
+
447
+        foreach ( $widgets as $widget ) {
448
+            register_widget( $widget );
449
+        }
450 450
 		
451
-	}
451
+    }
452 452
 
453
-	/**
454
-	 * Upgrades the database.
455
-	 *
456
-	 * @since 2.0.2
457
-	 */
458
-	public function maybe_upgrade_database() {
453
+    /**
454
+     * Upgrades the database.
455
+     *
456
+     * @since 2.0.2
457
+     */
458
+    public function maybe_upgrade_database() {
459 459
 
460
-		$wpi_version = get_option( 'wpinv_version', 0 );
460
+        $wpi_version = get_option( 'wpinv_version', 0 );
461 461
 
462
-		if ( $wpi_version == WPINV_VERSION ) {
463
-			return;
464
-		}
462
+        if ( $wpi_version == WPINV_VERSION ) {
463
+            return;
464
+        }
465 465
 
466
-		$installer = new GetPaid_Installer();
466
+        $installer = new GetPaid_Installer();
467 467
 
468
-		if ( empty( $wpi_version ) ) {
469
-			return $installer->upgrade_db( 0 );
470
-		}
468
+        if ( empty( $wpi_version ) ) {
469
+            return $installer->upgrade_db( 0 );
470
+        }
471 471
 
472
-		$upgrades  = array(
473
-			'0.0.5' => '004',
474
-			'1.0.3' => '102',
475
-			'2.0.0' => '118',
476
-			'2.0.8' => '207',
477
-		);
472
+        $upgrades  = array(
473
+            '0.0.5' => '004',
474
+            '1.0.3' => '102',
475
+            '2.0.0' => '118',
476
+            '2.0.8' => '207',
477
+        );
478 478
 
479
-		foreach ( $upgrades as $key => $method ) {
479
+        foreach ( $upgrades as $key => $method ) {
480 480
 
481
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
482
-				return $installer->upgrade_db( $method );
483
-			}
481
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
482
+                return $installer->upgrade_db( $method );
483
+            }
484 484
 
485
-		}
485
+        }
486 486
 
487
-	}
487
+    }
488 488
 
489
-	/**
490
-	 * Flushes the permalinks if needed.
491
-	 *
492
-	 * @since 2.0.8
493
-	 */
494
-	public function maybe_flush_permalinks() {
489
+    /**
490
+     * Flushes the permalinks if needed.
491
+     *
492
+     * @since 2.0.8
493
+     */
494
+    public function maybe_flush_permalinks() {
495 495
 
496
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
496
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
497 497
 
498
-		if ( ! empty( $flush ) ) {
499
-			flush_rewrite_rules();
500
-			delete_option( 'wpinv_flush_permalinks' );
501
-		}
498
+        if ( ! empty( $flush ) ) {
499
+            flush_rewrite_rules();
500
+            delete_option( 'wpinv_flush_permalinks' );
501
+        }
502 502
 
503
-	}
503
+    }
504 504
 
505
-	/**
506
-	 * Remove our pages from yoast sitemaps.
507
-	 *
508
-	 * @since 1.0.19
509
-	 * @param int[] $excluded_posts_ids
510
-	 */
511
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
505
+    /**
506
+     * Remove our pages from yoast sitemaps.
507
+     *
508
+     * @since 1.0.19
509
+     * @param int[] $excluded_posts_ids
510
+     */
511
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
512 512
 
513
-		// Ensure that we have an array.
514
-		if ( ! is_array( $excluded_posts_ids ) ) {
515
-			$excluded_posts_ids = array();
516
-		}
513
+        // Ensure that we have an array.
514
+        if ( ! is_array( $excluded_posts_ids ) ) {
515
+            $excluded_posts_ids = array();
516
+        }
517 517
 
518
-		// Prepare our pages.
519
-		$our_pages = array();
518
+        // Prepare our pages.
519
+        $our_pages = array();
520 520
 
521
-		// Checkout page.
522
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
521
+        // Checkout page.
522
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
523 523
 
524
-		// Success page.
525
-		$our_pages[] = wpinv_get_option( 'success_page', false );
524
+        // Success page.
525
+        $our_pages[] = wpinv_get_option( 'success_page', false );
526 526
 
527
-		// Failure page.
528
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
527
+        // Failure page.
528
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
529 529
 
530
-		// History page.
531
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
530
+        // History page.
531
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
532 532
 
533
-		// Subscriptions page.
534
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
533
+        // Subscriptions page.
534
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
535 535
 
536
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
536
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
537 537
 
538
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
539
-		return array_unique( $excluded_posts_ids );
538
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
539
+        return array_unique( $excluded_posts_ids );
540 540
 
541
-	}
541
+    }
542 542
 
543
-	/**
544
-	 * Displays additional footer code.
545
-	 * 
546
-	 * @since 2.0.0
547
-	 */
548
-	public function wp_footer() {
549
-		wpinv_get_template( 'frontend-footer.php' );
550
-	}
543
+    /**
544
+     * Displays additional footer code.
545
+     * 
546
+     * @since 2.0.0
547
+     */
548
+    public function wp_footer() {
549
+        wpinv_get_template( 'frontend-footer.php' );
550
+    }
551 551
 
552
-	/**
553
-	 * Displays additional header code.
554
-	 * 
555
-	 * @since 2.0.0
556
-	 */
557
-	public function wp_head() {
558
-		wpinv_get_template( 'frontend-head.php' );
559
-	}
552
+    /**
553
+     * Displays additional header code.
554
+     * 
555
+     * @since 2.0.0
556
+     */
557
+    public function wp_head() {
558
+        wpinv_get_template( 'frontend-head.php' );
559
+    }
560 560
 
561
-	/**
562
-	 * Custom query vars.
563
-	 *
564
-	 */
565
-	public function custom_query_vars( $vars ) {
561
+    /**
562
+     * Custom query vars.
563
+     *
564
+     */
565
+    public function custom_query_vars( $vars ) {
566 566
         $vars[] = 'getpaid-ipn';
567 567
         return $vars;
568
-	}
568
+    }
569 569
 
570
-	/**
571
-	 * Add rewrite tags and rules.
572
-	 *
573
-	 */
574
-	public function add_rewrite_rule() {
570
+    /**
571
+     * Add rewrite tags and rules.
572
+     *
573
+     */
574
+    public function add_rewrite_rule() {
575 575
         $tag = 'getpaid-ipn';
576 576
         add_rewrite_tag( "%$tag%", '([^&]+)' );
577 577
         add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' );
578
-	}
578
+    }
579 579
 
580
-	/**
581
-	 * Processes non-query string ipns.
582
-	 *
583
-	 */
584
-	public function maybe_process_new_ipn( $query ) {
580
+    /**
581
+     * Processes non-query string ipns.
582
+     *
583
+     */
584
+    public function maybe_process_new_ipn( $query ) {
585 585
 
586 586
         if ( is_admin() || ! $query->is_main_query() ) {
587 587
             return;
588 588
         }
589 589
 
590
-		$gateway = get_query_var( 'getpaid-ipn' );
590
+        $gateway = get_query_var( 'getpaid-ipn' );
591 591
 
592 592
         if ( ! empty( $gateway ) ){
593 593
 
594
-			$gateway = sanitize_text_field( $gateway );
595
-			nocache_headers();
596
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
597
-			do_action( "wpinv_verify_{$gateway}_ipn" );
598
-			exit;
594
+            $gateway = sanitize_text_field( $gateway );
595
+            nocache_headers();
596
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
597
+            do_action( "wpinv_verify_{$gateway}_ipn" );
598
+            exit;
599 599
 
600 600
         }
601 601
 
602
-	}
602
+    }
603 603
 
604 604
 }
Please login to merge, or discard this patch.
includes/class-getpaid-daily-maintenance.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -12,145 +12,145 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct(){
19
-
20
-		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
-
23
-		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
-
26
-		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) );
31
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
32
-
33
-	}
34
-
35
-	/**
36
-	 * Schedules a cron to run every day at 7 a.m
37
-	 *
38
-	 */
39
-	public function maybe_create_scheduled_event() {
40
-
41
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
42
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
43
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
44
-		}
45
-
46
-	}
47
-
48
-	/**
49
-	 * Clears deprecated events.
50
-	 *
51
-	 */
52
-	public function maybe_clear_deprecated_events() {
53
-
54
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
56
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
57
-			update_option( 'wpinv_cleared_old_events', 1 );
58
-		}
59
-
60
-	}
61
-
62
-	/**
63
-	 * Fires the old hook for backwards compatibility.
64
-	 *
65
-	 */
66
-	public function backwards_compat() {
67
-		do_action( 'wpinv_register_schedule_event_daily' );
68
-	}
69
-
70
-	/**
71
-	 * Checks for subscriptions that are scheduled to renew.
72
-	 *
73
-	 */
74
-	public function check_renewing_subscriptions() {
75
-
76
-		// Fetch subscriptions that expire today.
77
-		$args  = array(
78
-			'number'             => -1,
79
-			'count_total'        => false,
80
-			'status'             => 'trialling active',
81
-			'date_expires_query' => array(
82
-				array(
83
-					'year'          => date( 'Y', current_time( 'timestamp' ) ),
84
-					'month'         => date( 'n', current_time( 'timestamp' ) ),
85
-					'day'           => date( 'j', current_time( 'timestamp' ) ),
86
-					'compare'       => '=',
87
-				),
88
-			),
89
-		);
90
-
91
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
92
-
93
-		foreach ( $subscriptions->get_results() as $subscription ) {
94
-
95
-			/** @var WPInv_Subscription $subscription */
96
-			if ( $subscription->is_last_renewal() ) {
97
-				$subscription->complete();
98
-			} else {
99
-				do_action( 'getpaid_should_renew_subscription', $subscription );
100
-			}
101
-
102
-		}
103
-
104
-	}
105
-
106
-	/**
107
-	 * Expires expired subscriptions.
108
-	 *
109
-	 */
110
-	public function maybe_expire_subscriptions() {
111
-
112
-		// Fetch expired subscriptions (skips those that expire today).
113
-		$args  = array(
114
-			'number'             => -1,
115
-			'count_total'        => false,
116
-			'status'             => 'trialling active failing cancelled',
117
-			'date_expires_query' => array(
118
-				'before'    => 'yesterday',
119
-				'inclusive' => false,
120
-			),
121
-		);
122
-
123
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
124
-
125
-		foreach ( $subscriptions->get_results() as $subscription ) {
126
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) {
127
-				$subscription->set_status( 'expired' );
128
-				$subscription->save();
129
-			}
130
-		}
131
-
132
-	}
133
-
134
-	/**
135
-	 * Logs cron runs.
136
-	 *
137
-	 */
138
-	public function log_cron_run() {
139
-		wpinv_error_log( 'GetPaid Daily Cron', false );
140
-	}
141
-
142
-	/**
143
-	 * Updates GeoIP databases.
144
-	 *
145
-	 */
146
-	public function maybe_update_geoip_databases() {
147
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
148
-
149
-		if ( false === $updated ) {
150
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
151
-			do_action( 'getpaid_update_geoip_databases' );
152
-		}
153
-
154
-	}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct(){
19
+
20
+        // Clear deprecated events.
21
+        add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
+
23
+        // (Maybe) schedule a cron that runs daily.
24
+        add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
+
26
+        // Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
+        add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
+        add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
+        add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) );
31
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
32
+
33
+    }
34
+
35
+    /**
36
+     * Schedules a cron to run every day at 7 a.m
37
+     *
38
+     */
39
+    public function maybe_create_scheduled_event() {
40
+
41
+        if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
42
+            $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
43
+            wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
44
+        }
45
+
46
+    }
47
+
48
+    /**
49
+     * Clears deprecated events.
50
+     *
51
+     */
52
+    public function maybe_clear_deprecated_events() {
53
+
54
+        if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
55
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
56
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
57
+            update_option( 'wpinv_cleared_old_events', 1 );
58
+        }
59
+
60
+    }
61
+
62
+    /**
63
+     * Fires the old hook for backwards compatibility.
64
+     *
65
+     */
66
+    public function backwards_compat() {
67
+        do_action( 'wpinv_register_schedule_event_daily' );
68
+    }
69
+
70
+    /**
71
+     * Checks for subscriptions that are scheduled to renew.
72
+     *
73
+     */
74
+    public function check_renewing_subscriptions() {
75
+
76
+        // Fetch subscriptions that expire today.
77
+        $args  = array(
78
+            'number'             => -1,
79
+            'count_total'        => false,
80
+            'status'             => 'trialling active',
81
+            'date_expires_query' => array(
82
+                array(
83
+                    'year'          => date( 'Y', current_time( 'timestamp' ) ),
84
+                    'month'         => date( 'n', current_time( 'timestamp' ) ),
85
+                    'day'           => date( 'j', current_time( 'timestamp' ) ),
86
+                    'compare'       => '=',
87
+                ),
88
+            ),
89
+        );
90
+
91
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
92
+
93
+        foreach ( $subscriptions->get_results() as $subscription ) {
94
+
95
+            /** @var WPInv_Subscription $subscription */
96
+            if ( $subscription->is_last_renewal() ) {
97
+                $subscription->complete();
98
+            } else {
99
+                do_action( 'getpaid_should_renew_subscription', $subscription );
100
+            }
101
+
102
+        }
103
+
104
+    }
105
+
106
+    /**
107
+     * Expires expired subscriptions.
108
+     *
109
+     */
110
+    public function maybe_expire_subscriptions() {
111
+
112
+        // Fetch expired subscriptions (skips those that expire today).
113
+        $args  = array(
114
+            'number'             => -1,
115
+            'count_total'        => false,
116
+            'status'             => 'trialling active failing cancelled',
117
+            'date_expires_query' => array(
118
+                'before'    => 'yesterday',
119
+                'inclusive' => false,
120
+            ),
121
+        );
122
+
123
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
124
+
125
+        foreach ( $subscriptions->get_results() as $subscription ) {
126
+            if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) {
127
+                $subscription->set_status( 'expired' );
128
+                $subscription->save();
129
+            }
130
+        }
131
+
132
+    }
133
+
134
+    /**
135
+     * Logs cron runs.
136
+     *
137
+     */
138
+    public function log_cron_run() {
139
+        wpinv_error_log( 'GetPaid Daily Cron', false );
140
+    }
141
+
142
+    /**
143
+     * Updates GeoIP databases.
144
+     *
145
+     */
146
+    public function maybe_update_geoip_databases() {
147
+        $updated = get_transient( 'getpaid_updated_geoip_databases' );
148
+
149
+        if ( false === $updated ) {
150
+            set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
151
+            do_action( 'getpaid_update_geoip_databases' );
152
+        }
153
+
154
+    }
155 155
 
156 156
 }
Please login to merge, or discard this patch.
includes/class-wpinv-addons.php 1 patch
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 if ( ! defined( 'ABSPATH' ) ) {
9
-	exit;
9
+    exit;
10 10
 }
11 11
 
12 12
 /**
@@ -15,85 +15,85 @@  discard block
 block discarded – undo
15 15
 class WPInv_Admin_Addons extends Ayecode_Addons {
16 16
 
17 17
 
18
-	/**
19
-	 * Get the extensions page tabs.
20
-	 *
21
-	 * @return array of tabs.
22
-	 */
23
-	public function get_tabs(){
24
-		$tabs = array(
25
-			'addons' => __("Addons", "invoicing"),
18
+    /**
19
+     * Get the extensions page tabs.
20
+     *
21
+     * @return array of tabs.
22
+     */
23
+    public function get_tabs(){
24
+        $tabs = array(
25
+            'addons' => __("Addons", "invoicing"),
26 26
             'gateways' => __("Payment Gateways", "invoicing"),
27 27
             'recommended_plugins' => __("Recommended plugins", "invoicing"),
28 28
             'membership' => __("Membership", "invoicing"),
29
-		);
30
-
31
-		return $tabs;
32
-	}
33
-
34
-	/**
35
-	 * Get section content for the addons screen.
36
-	 *
37
-	 * @param  string $section_id
38
-	 *
39
-	 * @return array
40
-	 */
41
-	public function get_section_data( $section_id ) {
42
-		$section      = self::get_tab( $section_id );
43
-		$api_url = "https://wpinvoicing.com/edd-api/v2/products/";
44
-		$section_data = new stdClass();
45
-
46
-		if($section_id=='recommended_plugins'){
47
-			$section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
-		}
49
-		elseif ( ! empty( $section ) ) {
50
-			if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
51
-			//if ( 1==1) {
52
-
53
-				$query_args = array( 'category' => $section_id, 'number' => 100);
54
-				$query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id);
55
-
56
-				$raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout'     => 15, ) );
57
-
58
-				if ( ! is_wp_error( $raw_section ) ) {
59
-					$section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
60
-
61
-					if ( ! empty( $section_data->products ) ) {
62
-						set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
63
-					}
64
-				}
65
-			}
66
-
67
-		}
68
-
69
-		$products = isset($section_data->products) ? $section_data->products : array();
70
-		if ( 'addons' == $section_id ) {
71
-
72
-			$quotes = new stdClass();
73
-			$quotes->info = new stdClass();
74
-			$quotes->info->id = '';
75
-			$quotes->info->slug = 'invoicing-quotes';
76
-			$quotes->info->title = __( 'Quotes', 'invoicing' );
77
-			$quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
78
-			$quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
79
-			$quotes->info->thumbnail = 'https://wpgetpaid.com/wp-content/uploads/sites/13/edd/2019/11/Quotes-1-768x384.png';
80
-
81
-			$products[] = $quotes;
82
-		}
29
+        );
30
+
31
+        return $tabs;
32
+    }
33
+
34
+    /**
35
+     * Get section content for the addons screen.
36
+     *
37
+     * @param  string $section_id
38
+     *
39
+     * @return array
40
+     */
41
+    public function get_section_data( $section_id ) {
42
+        $section      = self::get_tab( $section_id );
43
+        $api_url = "https://wpinvoicing.com/edd-api/v2/products/";
44
+        $section_data = new stdClass();
45
+
46
+        if($section_id=='recommended_plugins'){
47
+            $section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
+        }
49
+        elseif ( ! empty( $section ) ) {
50
+            if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
51
+            //if ( 1==1) {
52
+
53
+                $query_args = array( 'category' => $section_id, 'number' => 100);
54
+                $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id);
55
+
56
+                $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout'     => 15, ) );
57
+
58
+                if ( ! is_wp_error( $raw_section ) ) {
59
+                    $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
60
+
61
+                    if ( ! empty( $section_data->products ) ) {
62
+                        set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
63
+                    }
64
+                }
65
+            }
66
+
67
+        }
68
+
69
+        $products = isset($section_data->products) ? $section_data->products : array();
70
+        if ( 'addons' == $section_id ) {
71
+
72
+            $quotes = new stdClass();
73
+            $quotes->info = new stdClass();
74
+            $quotes->info->id = '';
75
+            $quotes->info->slug = 'invoicing-quotes';
76
+            $quotes->info->title = __( 'Quotes', 'invoicing' );
77
+            $quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
78
+            $quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
79
+            $quotes->info->thumbnail = 'https://wpgetpaid.com/wp-content/uploads/sites/13/edd/2019/11/Quotes-1-768x384.png';
80
+
81
+            $products[] = $quotes;
82
+        }
83 83
 		
84
-		return apply_filters( 'wpi_addons_section_data', $products, $section_id );
85
-	}
86
-
87
-	/**
88
-	 * Outputs a button.
89
-	 *ccc
90
-	 * @param string $url
91
-	 * @param string $text
92
-	 * @param string $theme
93
-	 * @param string $plugin
94
-	 */
95
-	public function output_button( $addon ) {
96
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
84
+        return apply_filters( 'wpi_addons_section_data', $products, $section_id );
85
+    }
86
+
87
+    /**
88
+     * Outputs a button.
89
+     *ccc
90
+     * @param string $url
91
+     * @param string $text
92
+     * @param string $theme
93
+     * @param string $plugin
94
+     */
95
+    public function output_button( $addon ) {
96
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
97 97
 //		$button_text = __('Free','invoicing');
98 98
 //		$licensing = false;
99 99
 //		$installed = false;
@@ -105,123 +105,123 @@  discard block
 block discarded – undo
105 105
 //		$install_status = 'get';
106 106
 //		$onclick = '';
107 107
 
108
-		$wp_org_themes = array('supreme-directory','directory-starter');
109
-
110
-		$button_args = array(
111
-			'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab,
112
-			'id' => isset($addon->info->id) ? absint($addon->info->id) : '',
113
-			'title' => isset($addon->info->title) ? $addon->info->title : '',
114
-			'button_text' => __('Free','invoicing'),
115
-			'price_text' => __('Free','invoicing'),
116
-			'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product
117
-			'url' => isset($addon->info->link) ? $addon->info->link : '', // button url
118
-			'class' => 'button-primary',
119
-			'install_status' => 'get',
120
-			'installed' => false,
121
-			'price' => '',
122
-			'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false,
123
-			'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '',
124
-			'onclick' => '',
125
-			'slug' => isset($addon->info->slug) ? $addon->info->slug : '',
126
-			'active' => false,
127
-			'file' => '',
128
-			'update_url' => '',
129
-		);
130
-
131
-		if( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){
132
-			include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
133
-			$status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>""));
134
-			$button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install';
135
-			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
136
-		}elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){
137
-			include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
138
-			if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
139
-			$status = self::install_plugin_install_status($addon);
140
-			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
141
-			if(isset($status['status'])){$button_args['install_status'] = $status['status'];}
142
-			$button_args['update_url'] = "https://wpinvoicing.com";
143
-		}elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
144
-			if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
145
-			$button_args['installed'] = self::is_theme_installed($addon);
146
-			if(!in_array($button_args['slug'],$wp_org_themes)){
147
-				$button_args['update_url'] = "https://wpinvoicing.com";
148
-			}
149
-		}
150
-
151
-		// set price
152
-		if(isset($addon->pricing) && !empty($addon->pricing)){
153
-			if(is_object($addon->pricing)){
154
-				$prices = (Array)$addon->pricing;
155
-				$button_args['price'] = reset($prices);
156
-			}elseif(isset($addon->pricing)){
157
-				$button_args['price'] = $addon->pricing;
158
-			}
159
-		}
160
-
161
-		// set price text
162
-		if( $button_args['price'] && $button_args['price'] != '0.00' ){
163
-			$button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']);
164
-		}
165
-
166
-
167
-		// set if installed
168
-		if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){
169
-			$button_args['installed'] = true;
170
-		}
108
+        $wp_org_themes = array('supreme-directory','directory-starter');
109
+
110
+        $button_args = array(
111
+            'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab,
112
+            'id' => isset($addon->info->id) ? absint($addon->info->id) : '',
113
+            'title' => isset($addon->info->title) ? $addon->info->title : '',
114
+            'button_text' => __('Free','invoicing'),
115
+            'price_text' => __('Free','invoicing'),
116
+            'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product
117
+            'url' => isset($addon->info->link) ? $addon->info->link : '', // button url
118
+            'class' => 'button-primary',
119
+            'install_status' => 'get',
120
+            'installed' => false,
121
+            'price' => '',
122
+            'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false,
123
+            'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '',
124
+            'onclick' => '',
125
+            'slug' => isset($addon->info->slug) ? $addon->info->slug : '',
126
+            'active' => false,
127
+            'file' => '',
128
+            'update_url' => '',
129
+        );
130
+
131
+        if( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){
132
+            include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
133
+            $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>""));
134
+            $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install';
135
+            $button_args['file'] = isset($status['file']) ? $status['file'] : '';
136
+        }elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){
137
+            include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
138
+            if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
139
+            $status = self::install_plugin_install_status($addon);
140
+            $button_args['file'] = isset($status['file']) ? $status['file'] : '';
141
+            if(isset($status['status'])){$button_args['install_status'] = $status['status'];}
142
+            $button_args['update_url'] = "https://wpinvoicing.com";
143
+        }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
144
+            if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
145
+            $button_args['installed'] = self::is_theme_installed($addon);
146
+            if(!in_array($button_args['slug'],$wp_org_themes)){
147
+                $button_args['update_url'] = "https://wpinvoicing.com";
148
+            }
149
+        }
150
+
151
+        // set price
152
+        if(isset($addon->pricing) && !empty($addon->pricing)){
153
+            if(is_object($addon->pricing)){
154
+                $prices = (Array)$addon->pricing;
155
+                $button_args['price'] = reset($prices);
156
+            }elseif(isset($addon->pricing)){
157
+                $button_args['price'] = $addon->pricing;
158
+            }
159
+        }
160
+
161
+        // set price text
162
+        if( $button_args['price'] && $button_args['price'] != '0.00' ){
163
+            $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']);
164
+        }
165
+
166
+
167
+        // set if installed
168
+        if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){
169
+            $button_args['installed'] = true;
170
+        }
171 171
 
172 172
 //		print_r($button_args);
173
-		// set if active
174
-		if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){
175
-			if($button_args['type'] != 'themes'){
176
-				$button_args['active'] = is_plugin_active($button_args['file']);
177
-			}else{
178
-				$button_args['active'] = self::is_theme_active($addon);
179
-			}
180
-		}
181
-
182
-		// set button text and class
183
-		if($button_args['active']){
184
-			$button_args['button_text'] = __('Active','invoicing');
185
-			$button_args['class'] = ' button-secondary disabled ';
186
-		}elseif($button_args['installed']){
187
-			$button_args['button_text'] = __('Activate','invoicing');
188
-
189
-			if($button_args['type'] != 'themes'){
190
-				if ( current_user_can( 'manage_options' ) ) {
191
-					$button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']);
192
-				}else{
193
-					$button_args['url'] = '#';
194
-				}
195
-			}else{
196
-				if ( current_user_can( 'switch_themes' ) ) {
197
-					$button_args['url'] = self::get_theme_activation_url($addon);
198
-				}else{
199
-					$button_args['url'] = '#';
200
-				}
201
-			}
202
-
203
-		}else{
204
-			if($button_args['type'] == 'recommended_plugins'){
205
-				$button_args['button_text'] = __('Install','invoicing');
206
-			}else{
207
-				$button_args['button_text'] = __('Get it','invoicing');
208
-
209
-				/*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
173
+        // set if active
174
+        if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){
175
+            if($button_args['type'] != 'themes'){
176
+                $button_args['active'] = is_plugin_active($button_args['file']);
177
+            }else{
178
+                $button_args['active'] = self::is_theme_active($addon);
179
+            }
180
+        }
181
+
182
+        // set button text and class
183
+        if($button_args['active']){
184
+            $button_args['button_text'] = __('Active','invoicing');
185
+            $button_args['class'] = ' button-secondary disabled ';
186
+        }elseif($button_args['installed']){
187
+            $button_args['button_text'] = __('Activate','invoicing');
188
+
189
+            if($button_args['type'] != 'themes'){
190
+                if ( current_user_can( 'manage_options' ) ) {
191
+                    $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']);
192
+                }else{
193
+                    $button_args['url'] = '#';
194
+                }
195
+            }else{
196
+                if ( current_user_can( 'switch_themes' ) ) {
197
+                    $button_args['url'] = self::get_theme_activation_url($addon);
198
+                }else{
199
+                    $button_args['url'] = '#';
200
+                }
201
+            }
202
+
203
+        }else{
204
+            if($button_args['type'] == 'recommended_plugins'){
205
+                $button_args['button_text'] = __('Install','invoicing');
206
+            }else{
207
+                $button_args['button_text'] = __('Get it','invoicing');
208
+
209
+                /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
210 210
 					$button_args['button_text'] = __('Install','invoicing');
211 211
 					$button_args['url'] = self::get_theme_install_url($button_args['slug']);
212 212
 					$button_args['onclick'] = 'gd_set_button_installing(this);';
213 213
 				}*/
214 214
 
215
-			}
216
-		}
215
+            }
216
+        }
217 217
 
218 218
 		
219
-		// filter the button arguments
220
-		$button_args = apply_filters('edd_api_button_args',$button_args);
219
+        // filter the button arguments
220
+        $button_args = apply_filters('edd_api_button_args',$button_args);
221 221
 //		print_r($button_args);
222
-		// set price text
223
-		if(isset($button_args['price_text'])){
224
-			?>
222
+        // set price text
223
+        if(isset($button_args['price_text'])){
224
+            ?>
225 225
 			<a
226 226
 				target="_blank"
227 227
 				class="addons-price-text"
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
 				<?php echo esc_html( $button_args['price_text'] ); ?>
230 230
 			</a>
231 231
 			<?php
232
-		}
232
+        }
233 233
 
234 234
 
235
-		$target = '';
236
-		if ( ! empty( $button_args['url'] ) ) {
237
-			$target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" ';
238
-		}
235
+        $target = '';
236
+        if ( ! empty( $button_args['url'] ) ) {
237
+            $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" ';
238
+        }
239 239
 
240
-		?>
240
+        ?>
241 241
 		<a
242 242
 			data-licence="<?php echo esc_attr($button_args['license']);?>"
243 243
 			data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>"
@@ -260,33 +260,33 @@  discard block
 block discarded – undo
260 260
 		<?php
261 261
 
262 262
 
263
-	}
264
-
265
-
266
-	/**
267
-	 * Handles output of the addons page in admin.
268
-	 */
269
-	public function output() {
270
-		$tabs            = self::get_tabs();
271
-		$sections        = self::get_sections();
272
-		$theme           = wp_get_theme();
273
-		$section_keys    = array_keys( $sections );
274
-		$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
275
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
276
-		include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' );
277
-	}
278
-
279
-	/**
280
-	 * A list of recommended wp.org plugins.
281
-	 * @return array
282
-	 */
283
-	public function get_recommend_wp_plugins(){
284
-		$plugins = array(
263
+    }
264
+
265
+
266
+    /**
267
+     * Handles output of the addons page in admin.
268
+     */
269
+    public function output() {
270
+        $tabs            = self::get_tabs();
271
+        $sections        = self::get_sections();
272
+        $theme           = wp_get_theme();
273
+        $section_keys    = array_keys( $sections );
274
+        $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
275
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
276
+        include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' );
277
+    }
278
+
279
+    /**
280
+     * A list of recommended wp.org plugins.
281
+     * @return array
282
+     */
283
+    public function get_recommend_wp_plugins(){
284
+        $plugins = array(
285 285
             'invoicing-quotes' => array(
286 286
                 'url'   => 'https://wordpress.org/plugins/invoicing-quotes/',
287 287
                 'slug'   => 'invoicing-quotes',
288
-				'name'   => 'Quotes',
289
-				'thumbnail'  => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
288
+                'name'   => 'Quotes',
289
+                'thumbnail'  => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
290 290
                 'desc'   => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'),
291 291
             ),
292 292
             'geodirectory' => array(
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
                 'name'   => 'UsersWP',
302 302
                 'desc'   => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'),
303 303
             ),
304
-		);
304
+        );
305 305
 
306
-		return $plugins;
307
-	}
306
+        return $plugins;
307
+    }
308 308
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 1 patch
Indentation   +403 added lines, -403 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,300 +21,300 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class WP_Font_Awesome_Settings
28
-	 * @since 1.0.10 Now able to pass wp.org theme check.
29
-	 * @since 1.0.11 Font Awesome Pro now supported.
30
-	 * @since 1.0.11 Font Awesome Kits now supported.
31
-	 * @since 1.0.13 RTL language support added.
32
-	 * @ver 1.0.13
33
-	 * @todo decide how to implement textdomain
34
-	 */
35
-	class WP_Font_Awesome_Settings {
36
-
37
-		/**
38
-		 * Class version version.
39
-		 *
40
-		 * @var string
41
-		 */
42
-		public $version = '1.0.13';
43
-
44
-		/**
45
-		 * Class textdomain.
46
-		 *
47
-		 * @var string
48
-		 */
49
-		public $textdomain = 'font-awesome-settings';
50
-
51
-		/**
52
-		 * Latest version of Font Awesome at time of publish published.
53
-		 *
54
-		 * @var string
55
-		 */
56
-		public $latest = "5.8.2";
57
-
58
-		/**
59
-		 * The title.
60
-		 *
61
-		 * @var string
62
-		 */
63
-		public $name = 'Font Awesome';
64
-
65
-		/**
66
-		 * Holds the settings values.
67
-		 *
68
-		 * @var array
69
-		 */
70
-		private $settings;
71
-
72
-		/**
73
-		 * WP_Font_Awesome_Settings instance.
74
-		 *
75
-		 * @access private
76
-		 * @since  1.0.0
77
-		 * @var    WP_Font_Awesome_Settings There can be only one!
78
-		 */
79
-		private static $instance = null;
80
-
81
-		/**
82
-		 * Main WP_Font_Awesome_Settings Instance.
83
-		 *
84
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
85
-		 *
86
-		 * @since 1.0.0
87
-		 * @static
88
-		 * @return WP_Font_Awesome_Settings - Main instance.
89
-		 */
90
-		public static function instance() {
91
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
92
-				self::$instance = new WP_Font_Awesome_Settings;
93
-
94
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
95
-
96
-				if ( is_admin() ) {
97
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
98
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
99
-				}
100
-
101
-				do_action( 'wp_font_awesome_settings_loaded' );
102
-			}
103
-
104
-			return self::$instance;
105
-		}
106
-
107
-		/**
108
-		 * Initiate the settings and add the required action hooks.
109
-		 *
110
-		 * @since 1.0.8 Settings name wrong - FIXED
111
-		 */
112
-		public function init() {
113
-			$this->settings = $this->get_settings();
114
-
115
-			if ( $this->settings['type'] == 'CSS' ) {
116
-
117
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
118
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
119
-				}
120
-
121
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
122
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
123
-				}
124
-
125
-			} else {
126
-
127
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
128
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
129
-				}
130
-
131
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
132
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
133
-				}
134
-			}
135
-
136
-			// remove font awesome if set to do so
137
-			if ( $this->settings['dequeue'] == '1' ) {
138
-				add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
139
-			}
140
-
141
-		}
142
-
143
-		/**
144
-		 * Adds the Font Awesome styles.
145
-		 */
146
-		public function enqueue_style() {
147
-			// build url
148
-			$url = $this->get_url();
149
-
150
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
151
-			wp_register_style( 'font-awesome', $url, array(), null );
152
-			wp_enqueue_style( 'font-awesome' );
153
-
154
-			// RTL language support CSS.
155
-			if ( is_rtl() ) {
156
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
157
-			}
158
-
159
-			if ( $this->settings['shims'] ) {
160
-				$url = $this->get_url( true );
161
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
162
-				wp_register_style( 'font-awesome-shims', $url, array(), null );
163
-				wp_enqueue_style( 'font-awesome-shims' );
164
-			}
165
-		}
166
-
167
-		/**
168
-		 * Adds the Font Awesome JS.
169
-		 */
170
-		public function enqueue_scripts() {
171
-			// build url
172
-			$url = $this->get_url();
173
-
174
-			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
175
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
176
-			wp_register_script( 'font-awesome', $url, array(), null );
177
-			wp_enqueue_script( 'font-awesome' );
178
-
179
-			if ( $this->settings['shims'] ) {
180
-				$url = $this->get_url( true );
181
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
182
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
183
-				wp_enqueue_script( 'font-awesome-shims' );
184
-			}
185
-		}
186
-
187
-		/**
188
-		 * Get the url of the Font Awesome files.
189
-		 *
190
-		 * @param bool $shims If this is a shim file or not.
191
-		 *
192
-		 * @return string The url to the file.
193
-		 */
194
-		public function get_url( $shims = false ) {
195
-			$script  = $shims ? 'v4-shims' : 'all';
196
-			$sub     = $this->settings['pro'] ? 'pro' : 'use';
197
-			$type    = $this->settings['type'];
198
-			$version = $this->settings['version'];
199
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
200
-			$url     = '';
201
-
202
-			if ( $type == 'KIT' && $kit_url ) {
203
-				if ( $shims ) {
204
-					// if its a kit then we don't add shims here
205
-					return '';
206
-				}
207
-				$url .= $kit_url; // CDN
208
-				$url .= "?wpfas=true"; // set our var so our version is not removed
209
-			} else {
210
-				$url .= "https://$sub.fontawesome.com/releases/"; // CDN
211
-				$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
212
-				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
213
-				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
214
-				$url .= "?wpfas=true"; // set our var so our version is not removed
215
-			}
216
-
217
-			return $url;
218
-		}
219
-
220
-		/**
221
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
222
-		 *
223
-		 * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
224
-		 *
225
-		 * @param $url
226
-		 * @param $original_url
227
-		 * @param $_context
228
-		 *
229
-		 * @return string The filtered url.
230
-		 */
231
-		public function remove_font_awesome( $url, $original_url, $_context ) {
232
-
233
-			if ( $_context == 'display'
234
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
235
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
236
-			) {// it's a font-awesome-url (probably)
237
-
238
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
239
-					if ( $this->settings['type'] == 'JS' ) {
240
-						if ( $this->settings['js-pseudo'] ) {
241
-							$url .= "' data-search-pseudo-elements defer='defer";
242
-						} else {
243
-							$url .= "' defer='defer";
244
-						}
245
-					}
246
-				} else {
247
-					$url = ''; // removing the url removes the file
248
-				}
249
-
250
-			}
251
-
252
-			return $url;
253
-		}
254
-
255
-		/**
256
-		 * Register the database settings with WordPress.
257
-		 */
258
-		public function register_settings() {
259
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
260
-		}
261
-
262
-		/**
263
-		 * Add the WordPress settings menu item.
264
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
265
-		 */
266
-		public function menu_item() {
267
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
268
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
269
-				$this,
270
-				'settings_page'
271
-			) );
272
-		}
273
-
274
-		/**
275
-		 * Get the current Font Awesome output settings.
276
-		 *
277
-		 * @return array The array of settings.
278
-		 */
279
-		public function get_settings() {
280
-
281
-			$db_settings = get_option( 'wp-font-awesome-settings' );
282
-
283
-			$defaults = array(
284
-				'type'      => 'CSS', // type to use, CSS or JS or KIT
285
-				'version'   => '', // latest
286
-				'enqueue'   => '', // front and backend
287
-				'shims'     => '0', // default OFF now in 2020
288
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
289
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
290
-				'pro'       => '0', // if pro CDN url should be used
291
-				'kit-url'   => '', // the kit url
292
-			);
293
-
294
-			$settings = wp_parse_args( $db_settings, $defaults );
295
-
296
-			/**
297
-			 * Filter the Font Awesome settings.
298
-			 *
299
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
300
-			 */
301
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
302
-		}
303
-
304
-
305
-		/**
306
-		 * The settings page html output.
307
-		 */
308
-		public function settings_page() {
309
-			if ( ! current_user_can( 'manage_options' ) ) {
310
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
311
-			}
312
-
313
-			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
314
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
315
-				$this->get_latest_version( $force_api = true );
316
-			}
317
-			?>
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     * @since 1.0.10 Now able to pass wp.org theme check.
29
+     * @since 1.0.11 Font Awesome Pro now supported.
30
+     * @since 1.0.11 Font Awesome Kits now supported.
31
+     * @since 1.0.13 RTL language support added.
32
+     * @ver 1.0.13
33
+     * @todo decide how to implement textdomain
34
+     */
35
+    class WP_Font_Awesome_Settings {
36
+
37
+        /**
38
+         * Class version version.
39
+         *
40
+         * @var string
41
+         */
42
+        public $version = '1.0.13';
43
+
44
+        /**
45
+         * Class textdomain.
46
+         *
47
+         * @var string
48
+         */
49
+        public $textdomain = 'font-awesome-settings';
50
+
51
+        /**
52
+         * Latest version of Font Awesome at time of publish published.
53
+         *
54
+         * @var string
55
+         */
56
+        public $latest = "5.8.2";
57
+
58
+        /**
59
+         * The title.
60
+         *
61
+         * @var string
62
+         */
63
+        public $name = 'Font Awesome';
64
+
65
+        /**
66
+         * Holds the settings values.
67
+         *
68
+         * @var array
69
+         */
70
+        private $settings;
71
+
72
+        /**
73
+         * WP_Font_Awesome_Settings instance.
74
+         *
75
+         * @access private
76
+         * @since  1.0.0
77
+         * @var    WP_Font_Awesome_Settings There can be only one!
78
+         */
79
+        private static $instance = null;
80
+
81
+        /**
82
+         * Main WP_Font_Awesome_Settings Instance.
83
+         *
84
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
85
+         *
86
+         * @since 1.0.0
87
+         * @static
88
+         * @return WP_Font_Awesome_Settings - Main instance.
89
+         */
90
+        public static function instance() {
91
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
92
+                self::$instance = new WP_Font_Awesome_Settings;
93
+
94
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
95
+
96
+                if ( is_admin() ) {
97
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
98
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
99
+                }
100
+
101
+                do_action( 'wp_font_awesome_settings_loaded' );
102
+            }
103
+
104
+            return self::$instance;
105
+        }
106
+
107
+        /**
108
+         * Initiate the settings and add the required action hooks.
109
+         *
110
+         * @since 1.0.8 Settings name wrong - FIXED
111
+         */
112
+        public function init() {
113
+            $this->settings = $this->get_settings();
114
+
115
+            if ( $this->settings['type'] == 'CSS' ) {
116
+
117
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
118
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
119
+                }
120
+
121
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
122
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
123
+                }
124
+
125
+            } else {
126
+
127
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
128
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
129
+                }
130
+
131
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
132
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
133
+                }
134
+            }
135
+
136
+            // remove font awesome if set to do so
137
+            if ( $this->settings['dequeue'] == '1' ) {
138
+                add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
139
+            }
140
+
141
+        }
142
+
143
+        /**
144
+         * Adds the Font Awesome styles.
145
+         */
146
+        public function enqueue_style() {
147
+            // build url
148
+            $url = $this->get_url();
149
+
150
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
151
+            wp_register_style( 'font-awesome', $url, array(), null );
152
+            wp_enqueue_style( 'font-awesome' );
153
+
154
+            // RTL language support CSS.
155
+            if ( is_rtl() ) {
156
+                wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
157
+            }
158
+
159
+            if ( $this->settings['shims'] ) {
160
+                $url = $this->get_url( true );
161
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
162
+                wp_register_style( 'font-awesome-shims', $url, array(), null );
163
+                wp_enqueue_style( 'font-awesome-shims' );
164
+            }
165
+        }
166
+
167
+        /**
168
+         * Adds the Font Awesome JS.
169
+         */
170
+        public function enqueue_scripts() {
171
+            // build url
172
+            $url = $this->get_url();
173
+
174
+            $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
175
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
176
+            wp_register_script( 'font-awesome', $url, array(), null );
177
+            wp_enqueue_script( 'font-awesome' );
178
+
179
+            if ( $this->settings['shims'] ) {
180
+                $url = $this->get_url( true );
181
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
182
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
183
+                wp_enqueue_script( 'font-awesome-shims' );
184
+            }
185
+        }
186
+
187
+        /**
188
+         * Get the url of the Font Awesome files.
189
+         *
190
+         * @param bool $shims If this is a shim file or not.
191
+         *
192
+         * @return string The url to the file.
193
+         */
194
+        public function get_url( $shims = false ) {
195
+            $script  = $shims ? 'v4-shims' : 'all';
196
+            $sub     = $this->settings['pro'] ? 'pro' : 'use';
197
+            $type    = $this->settings['type'];
198
+            $version = $this->settings['version'];
199
+            $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
200
+            $url     = '';
201
+
202
+            if ( $type == 'KIT' && $kit_url ) {
203
+                if ( $shims ) {
204
+                    // if its a kit then we don't add shims here
205
+                    return '';
206
+                }
207
+                $url .= $kit_url; // CDN
208
+                $url .= "?wpfas=true"; // set our var so our version is not removed
209
+            } else {
210
+                $url .= "https://$sub.fontawesome.com/releases/"; // CDN
211
+                $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
212
+                $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
213
+                $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
214
+                $url .= "?wpfas=true"; // set our var so our version is not removed
215
+            }
216
+
217
+            return $url;
218
+        }
219
+
220
+        /**
221
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
222
+         *
223
+         * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
224
+         *
225
+         * @param $url
226
+         * @param $original_url
227
+         * @param $_context
228
+         *
229
+         * @return string The filtered url.
230
+         */
231
+        public function remove_font_awesome( $url, $original_url, $_context ) {
232
+
233
+            if ( $_context == 'display'
234
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
235
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
236
+            ) {// it's a font-awesome-url (probably)
237
+
238
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
239
+                    if ( $this->settings['type'] == 'JS' ) {
240
+                        if ( $this->settings['js-pseudo'] ) {
241
+                            $url .= "' data-search-pseudo-elements defer='defer";
242
+                        } else {
243
+                            $url .= "' defer='defer";
244
+                        }
245
+                    }
246
+                } else {
247
+                    $url = ''; // removing the url removes the file
248
+                }
249
+
250
+            }
251
+
252
+            return $url;
253
+        }
254
+
255
+        /**
256
+         * Register the database settings with WordPress.
257
+         */
258
+        public function register_settings() {
259
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
260
+        }
261
+
262
+        /**
263
+         * Add the WordPress settings menu item.
264
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
265
+         */
266
+        public function menu_item() {
267
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
268
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
269
+                $this,
270
+                'settings_page'
271
+            ) );
272
+        }
273
+
274
+        /**
275
+         * Get the current Font Awesome output settings.
276
+         *
277
+         * @return array The array of settings.
278
+         */
279
+        public function get_settings() {
280
+
281
+            $db_settings = get_option( 'wp-font-awesome-settings' );
282
+
283
+            $defaults = array(
284
+                'type'      => 'CSS', // type to use, CSS or JS or KIT
285
+                'version'   => '', // latest
286
+                'enqueue'   => '', // front and backend
287
+                'shims'     => '0', // default OFF now in 2020
288
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
289
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
290
+                'pro'       => '0', // if pro CDN url should be used
291
+                'kit-url'   => '', // the kit url
292
+            );
293
+
294
+            $settings = wp_parse_args( $db_settings, $defaults );
295
+
296
+            /**
297
+             * Filter the Font Awesome settings.
298
+             *
299
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
300
+             */
301
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
302
+        }
303
+
304
+
305
+        /**
306
+         * The settings page html output.
307
+         */
308
+        public function settings_page() {
309
+            if ( ! current_user_can( 'manage_options' ) ) {
310
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
311
+            }
312
+
313
+            // a hidden way to force the update of the version number via api instead of waiting the 48 hours
314
+            if ( isset( $_REQUEST['force-version-check'] ) ) {
315
+                $this->get_latest_version( $force_api = true );
316
+            }
317
+            ?>
318 318
 			<style>
319 319
 				.wpfas-kit-show {
320 320
 					display: none;
@@ -332,10 +332,10 @@  discard block
 block discarded – undo
332 332
 				<h1><?php echo $this->name; ?></h1>
333 333
 				<form method="post" action="options.php">
334 334
 					<?php
335
-					settings_fields( 'wp-font-awesome-settings' );
336
-					do_settings_sections( 'wp-font-awesome-settings' );
337
-					$kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : '';
338
-					?>
335
+                    settings_fields( 'wp-font-awesome-settings' );
336
+                    do_settings_sections( 'wp-font-awesome-settings' );
337
+                    $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : '';
338
+                    ?>
339 339
 					<table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>">
340 340
 						<tr valign="top">
341 341
 							<th scope="row"><label
@@ -361,12 +361,12 @@  discard block
 block discarded – undo
361 361
 								       value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>"
362 362
 								       placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
363 363
 								<span><?php
364
-									echo sprintf(
365
-										__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
366
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
367
-										'</a>'
368
-									);
369
-									?></span>
364
+                                    echo sprintf(
365
+                                        __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
366
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
367
+                                        '</a>'
368
+                                    );
369
+                                    ?></span>
370 370
 							</td>
371 371
 						</tr>
372 372
 
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
 								<input type="checkbox" name="wp-font-awesome-settings[pro]"
427 427
 								       value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/>
428 428
 								<span><?php
429
-									echo sprintf(
430
-										__( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ),
431
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>',
432
-										'</a>',
433
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>',
434
-										'</a>'
435
-									);
436
-									?></span>
429
+                                    echo sprintf(
430
+                                        __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ),
431
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>',
432
+                                        '</a>',
433
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>',
434
+                                        '</a>'
435
+                                    );
436
+                                    ?></span>
437 437
 							</td>
438 438
 						</tr>
439 439
 
@@ -476,100 +476,100 @@  discard block
 block discarded – undo
476 476
 
477 477
 					</table>
478 478
 					<?php
479
-					submit_button();
480
-					?>
479
+                    submit_button();
480
+                    ?>
481 481
 				</form>
482 482
 
483 483
 				<div id="wpfas-version"><?php echo $this->version; ?></div>
484 484
 			</div>
485 485
 
486 486
 			<?php
487
-		}
488
-
489
-		/**
490
-		 * Check a version number is valid and if so return it or else return an empty string.
491
-		 *
492
-		 * @param $version string The version number to check.
493
-		 *
494
-		 * @since 1.0.6
495
-		 *
496
-		 * @return string Either a valid version number or an empty string.
497
-		 */
498
-		public function validate_version_number( $version ) {
499
-
500
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
501
-				// valid
502
-			} else {
503
-				$version = '';// not validated
504
-			}
505
-
506
-			return $version;
507
-		}
508
-
509
-
510
-		/**
511
-		 * Get the latest version of Font Awesome.
512
-		 *
513
-		 * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
514
-		 *
515
-		 * @since 1.0.7
516
-		 * @return mixed|string The latest version number found.
517
-		 */
518
-		public function get_latest_version( $force_api = false ) {
519
-			$latest_version = $this->latest;
520
-
521
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
522
-
523
-			if ( $cache === false || $force_api ) { // its not set
524
-				$api_ver = $this->get_latest_version_from_api();
525
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
526
-					$latest_version = $api_ver;
527
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
528
-				}
529
-			} elseif ( $this->validate_version_number( $cache ) ) {
530
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
531
-					$latest_version = $cache;
532
-				}
533
-			}
534
-
535
-			return $latest_version;
536
-		}
537
-
538
-		/**
539
-		 * Get the latest Font Awesome version from the github API.
540
-		 *
541
-		 * @since 1.0.7
542
-		 * @return string The latest version number or `0` on API fail.
543
-		 */
544
-		public function get_latest_version_from_api() {
545
-			$version  = "0";
546
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
547
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
548
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
549
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
550
-					$version = $api_response['tag_name'];
551
-				}
552
-			}
553
-
554
-			return $version;
555
-		}
556
-
557
-		/**
558
-		 * Inline CSS for RTL language support.
559
-		 *
560
-		 * @since 1.0.13
561
-		 * @return string Inline CSS.
562
-		 */
563
-		public function rtl_inline_css() {
564
-			$inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
565
-
566
-			return $inline_css;
567
-		}
568
-
569
-	}
570
-
571
-	/**
572
-	 * Run the class if found.
573
-	 */
574
-	WP_Font_Awesome_Settings::instance();
487
+        }
488
+
489
+        /**
490
+         * Check a version number is valid and if so return it or else return an empty string.
491
+         *
492
+         * @param $version string The version number to check.
493
+         *
494
+         * @since 1.0.6
495
+         *
496
+         * @return string Either a valid version number or an empty string.
497
+         */
498
+        public function validate_version_number( $version ) {
499
+
500
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
501
+                // valid
502
+            } else {
503
+                $version = '';// not validated
504
+            }
505
+
506
+            return $version;
507
+        }
508
+
509
+
510
+        /**
511
+         * Get the latest version of Font Awesome.
512
+         *
513
+         * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
514
+         *
515
+         * @since 1.0.7
516
+         * @return mixed|string The latest version number found.
517
+         */
518
+        public function get_latest_version( $force_api = false ) {
519
+            $latest_version = $this->latest;
520
+
521
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
522
+
523
+            if ( $cache === false || $force_api ) { // its not set
524
+                $api_ver = $this->get_latest_version_from_api();
525
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
526
+                    $latest_version = $api_ver;
527
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
528
+                }
529
+            } elseif ( $this->validate_version_number( $cache ) ) {
530
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
531
+                    $latest_version = $cache;
532
+                }
533
+            }
534
+
535
+            return $latest_version;
536
+        }
537
+
538
+        /**
539
+         * Get the latest Font Awesome version from the github API.
540
+         *
541
+         * @since 1.0.7
542
+         * @return string The latest version number or `0` on API fail.
543
+         */
544
+        public function get_latest_version_from_api() {
545
+            $version  = "0";
546
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
547
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
548
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
549
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
550
+                    $version = $api_response['tag_name'];
551
+                }
552
+            }
553
+
554
+            return $version;
555
+        }
556
+
557
+        /**
558
+         * Inline CSS for RTL language support.
559
+         *
560
+         * @since 1.0.13
561
+         * @return string Inline CSS.
562
+         */
563
+        public function rtl_inline_css() {
564
+            $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
565
+
566
+            return $inline_css;
567
+        }
568
+
569
+    }
570
+
571
+    /**
572
+     * Run the class if found.
573
+     */
574
+    WP_Font_Awesome_Settings::instance();
575 575
 }
576 576
\ No newline at end of file
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-input.php 1 patch
Indentation   +1036 added lines, -1036 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,1046 +11,1046 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Input {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function input($args = array()){
22
-		$defaults = array(
23
-			'type'       => 'text',
24
-			'name'       => '',
25
-			'class'      => '',
26
-			'wrap_class' => '',
27
-			'id'         => '',
28
-			'placeholder'=> '',
29
-			'title'      => '',
30
-			'value'      => '',
31
-			'required'   => false,
32
-			'label'      => '',
33
-			'label_after'=> false,
34
-			'label_class'=> '',
35
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
36
-			'help_text'  => '',
37
-			'validation_text'   => '',
38
-			'validation_pattern' => '',
39
-			'no_wrap'    => false,
40
-			'input_group_right' => '',
41
-			'input_group_left' => '',
42
-			'input_group_right_inside' => false, // forces the input group inside the input
43
-			'input_group_left_inside' => false, // forces the input group inside the input
44
-			'step'       => '',
45
-			'switch'     => false, // to show checkbox as a switch
46
-			'checked'   => false, // set a checkbox or radio as selected
47
-			'password_toggle' => true, // toggle view/hide password
48
-			'element_require'   => '', // [%element_id%] == "1"
49
-			'extra_attributes'  => array() // an array of extra attributes
50
-		);
51
-
52
-		/**
53
-		 * Parse incoming $args into an array and merge it with $defaults
54
-		 */
55
-		$args   = wp_parse_args( $args, $defaults );
56
-		$output = '';
57
-		if ( ! empty( $args['type'] ) ) {
58
-			// hidden label option needs to be empty
59
-			$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
60
-
61
-			$type = sanitize_html_class( $args['type'] );
62
-
63
-			$help_text = '';
64
-			$label = '';
65
-			$label_after = $args['label_after'];
66
-			$label_args = array(
67
-				'title'=> $args['label'],
68
-				'for'=> $args['id'],
69
-				'class' => $args['label_class']." ",
70
-				'label_type' => $args['label_type']
71
-			);
72
-
73
-			// floating labels need label after
74
-			if( $args['label_type'] == 'floating' && $type != 'checkbox' ){
75
-				$label_after = true;
76
-				$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
77
-			}
78
-
79
-			// Some special sauce for files
80
-			if($type=='file' ){
81
-				$label_after = true; // if type file we need the label after
82
-				$args['class'] .= ' custom-file-input ';
83
-			}elseif($type=='checkbox'){
84
-				$label_after = true; // if type file we need the label after
85
-				$args['class'] .= ' custom-control-input ';
86
-			}elseif($type=='datepicker' || $type=='timepicker'){
87
-				$type = 'text';
88
-				//$args['class'] .= ' aui-flatpickr bg-initial ';
89
-				$args['class'] .= ' bg-initial ';
90
-
91
-				$args['extra_attributes']['data-aui-init'] = 'flatpickr';
92
-				// enqueue the script
93
-				$aui_settings = AyeCode_UI_Settings::instance();
94
-				$aui_settings->enqueue_flatpickr();
95
-			}
96
-
97
-
98
-			// open/type
99
-			$output .= '<input type="' . $type . '" ';
100
-
101
-			// name
102
-			if(!empty($args['name'])){
103
-				$output .= ' name="'.esc_attr($args['name']).'" ';
104
-			}
105
-
106
-			// id
107
-			if(!empty($args['id'])){
108
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
109
-			}
110
-
111
-			// placeholder
112
-			if(isset($args['placeholder']) && '' != $args['placeholder'] ){
113
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
114
-			}
115
-
116
-			// title
117
-			if(!empty($args['title'])){
118
-				$output .= ' title="'.esc_attr($args['title']).'" ';
119
-			}
120
-
121
-			// value
122
-			if(!empty($args['value'])){
123
-				$output .= AUI_Component_Helper::value($args['value']);
124
-			}
125
-
126
-			// checked, for radio and checkboxes
127
-			if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){
128
-				$output .= ' checked ';
129
-			}
130
-
131
-			// validation text
132
-			if(!empty($args['validation_text'])){
133
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
134
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
135
-			}
136
-
137
-			// validation_pattern
138
-			if(!empty($args['validation_pattern'])){
139
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
140
-			}
141
-
142
-			// step (for numbers)
143
-			if(!empty($args['step'])){
144
-				$output .= ' step="'.$args['step'].'" ';
145
-			}
146
-
147
-			// required
148
-			if(!empty($args['required'])){
149
-				$output .= ' required ';
150
-			}
151
-
152
-			// class
153
-			$class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
154
-			$output .= ' class="form-control '.$class.'" ';
155
-
156
-			// data-attributes
157
-			$output .= AUI_Component_Helper::data_attributes($args);
158
-
159
-			// extra attributes
160
-			if(!empty($args['extra_attributes'])){
161
-				$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
162
-			}
163
-
164
-			// close
165
-			$output .= ' >';
166
-
167
-
168
-			// label
169
-			if(!empty($args['label'])){
170
-				if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
171
-				elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
172
-				$label = self::label( $label_args, $type );
173
-			}
174
-
175
-			// help text
176
-			if(!empty($args['help_text'])){
177
-				$help_text = AUI_Component_Helper::help_text($args['help_text']);
178
-			}
179
-
180
-
181
-			// set help text in the correct possition
182
-			if($label_after){
183
-				$output .= $label . $help_text;
184
-			}
185
-
186
-			// some input types need a separate wrap
187
-			if($type == 'file') {
188
-				$output = self::wrap( array(
189
-					'content' => $output,
190
-					'class'   => 'form-group custom-file'
191
-				) );
192
-			}elseif($type == 'checkbox'){
193
-				$wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
194
-				$output = self::wrap( array(
195
-					'content' => $output,
196
-					'class'   => 'custom-control '.$wrap_class
197
-				) );
198
-
199
-				if($args['label_type']=='horizontal'){
200
-					$output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
201
-				}
202
-			}elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
203
-
204
-
205
-				// allow password field to toggle view
206
-				$args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function input($args = array()){
22
+        $defaults = array(
23
+            'type'       => 'text',
24
+            'name'       => '',
25
+            'class'      => '',
26
+            'wrap_class' => '',
27
+            'id'         => '',
28
+            'placeholder'=> '',
29
+            'title'      => '',
30
+            'value'      => '',
31
+            'required'   => false,
32
+            'label'      => '',
33
+            'label_after'=> false,
34
+            'label_class'=> '',
35
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
36
+            'help_text'  => '',
37
+            'validation_text'   => '',
38
+            'validation_pattern' => '',
39
+            'no_wrap'    => false,
40
+            'input_group_right' => '',
41
+            'input_group_left' => '',
42
+            'input_group_right_inside' => false, // forces the input group inside the input
43
+            'input_group_left_inside' => false, // forces the input group inside the input
44
+            'step'       => '',
45
+            'switch'     => false, // to show checkbox as a switch
46
+            'checked'   => false, // set a checkbox or radio as selected
47
+            'password_toggle' => true, // toggle view/hide password
48
+            'element_require'   => '', // [%element_id%] == "1"
49
+            'extra_attributes'  => array() // an array of extra attributes
50
+        );
51
+
52
+        /**
53
+         * Parse incoming $args into an array and merge it with $defaults
54
+         */
55
+        $args   = wp_parse_args( $args, $defaults );
56
+        $output = '';
57
+        if ( ! empty( $args['type'] ) ) {
58
+            // hidden label option needs to be empty
59
+            $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
60
+
61
+            $type = sanitize_html_class( $args['type'] );
62
+
63
+            $help_text = '';
64
+            $label = '';
65
+            $label_after = $args['label_after'];
66
+            $label_args = array(
67
+                'title'=> $args['label'],
68
+                'for'=> $args['id'],
69
+                'class' => $args['label_class']." ",
70
+                'label_type' => $args['label_type']
71
+            );
72
+
73
+            // floating labels need label after
74
+            if( $args['label_type'] == 'floating' && $type != 'checkbox' ){
75
+                $label_after = true;
76
+                $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
77
+            }
78
+
79
+            // Some special sauce for files
80
+            if($type=='file' ){
81
+                $label_after = true; // if type file we need the label after
82
+                $args['class'] .= ' custom-file-input ';
83
+            }elseif($type=='checkbox'){
84
+                $label_after = true; // if type file we need the label after
85
+                $args['class'] .= ' custom-control-input ';
86
+            }elseif($type=='datepicker' || $type=='timepicker'){
87
+                $type = 'text';
88
+                //$args['class'] .= ' aui-flatpickr bg-initial ';
89
+                $args['class'] .= ' bg-initial ';
90
+
91
+                $args['extra_attributes']['data-aui-init'] = 'flatpickr';
92
+                // enqueue the script
93
+                $aui_settings = AyeCode_UI_Settings::instance();
94
+                $aui_settings->enqueue_flatpickr();
95
+            }
96
+
97
+
98
+            // open/type
99
+            $output .= '<input type="' . $type . '" ';
100
+
101
+            // name
102
+            if(!empty($args['name'])){
103
+                $output .= ' name="'.esc_attr($args['name']).'" ';
104
+            }
105
+
106
+            // id
107
+            if(!empty($args['id'])){
108
+                $output .= ' id="'.sanitize_html_class($args['id']).'" ';
109
+            }
110
+
111
+            // placeholder
112
+            if(isset($args['placeholder']) && '' != $args['placeholder'] ){
113
+                $output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
114
+            }
115
+
116
+            // title
117
+            if(!empty($args['title'])){
118
+                $output .= ' title="'.esc_attr($args['title']).'" ';
119
+            }
120
+
121
+            // value
122
+            if(!empty($args['value'])){
123
+                $output .= AUI_Component_Helper::value($args['value']);
124
+            }
125
+
126
+            // checked, for radio and checkboxes
127
+            if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){
128
+                $output .= ' checked ';
129
+            }
130
+
131
+            // validation text
132
+            if(!empty($args['validation_text'])){
133
+                $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
134
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
135
+            }
136
+
137
+            // validation_pattern
138
+            if(!empty($args['validation_pattern'])){
139
+                $output .= ' pattern="'.$args['validation_pattern'].'" ';
140
+            }
141
+
142
+            // step (for numbers)
143
+            if(!empty($args['step'])){
144
+                $output .= ' step="'.$args['step'].'" ';
145
+            }
146
+
147
+            // required
148
+            if(!empty($args['required'])){
149
+                $output .= ' required ';
150
+            }
151
+
152
+            // class
153
+            $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
154
+            $output .= ' class="form-control '.$class.'" ';
155
+
156
+            // data-attributes
157
+            $output .= AUI_Component_Helper::data_attributes($args);
158
+
159
+            // extra attributes
160
+            if(!empty($args['extra_attributes'])){
161
+                $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
162
+            }
163
+
164
+            // close
165
+            $output .= ' >';
166
+
167
+
168
+            // label
169
+            if(!empty($args['label'])){
170
+                if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
171
+                elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
172
+                $label = self::label( $label_args, $type );
173
+            }
174
+
175
+            // help text
176
+            if(!empty($args['help_text'])){
177
+                $help_text = AUI_Component_Helper::help_text($args['help_text']);
178
+            }
179
+
180
+
181
+            // set help text in the correct possition
182
+            if($label_after){
183
+                $output .= $label . $help_text;
184
+            }
185
+
186
+            // some input types need a separate wrap
187
+            if($type == 'file') {
188
+                $output = self::wrap( array(
189
+                    'content' => $output,
190
+                    'class'   => 'form-group custom-file'
191
+                ) );
192
+            }elseif($type == 'checkbox'){
193
+                $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
194
+                $output = self::wrap( array(
195
+                    'content' => $output,
196
+                    'class'   => 'custom-control '.$wrap_class
197
+                ) );
198
+
199
+                if($args['label_type']=='horizontal'){
200
+                    $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
201
+                }
202
+            }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
203
+
204
+
205
+                // allow password field to toggle view
206
+                $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
207 207
 onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\');
208 208
 var $eli = jQuery(this).parent().parent().find(\'input\');
209 209
 if($el.hasClass(\'fa-eye\'))
210 210
 {$eli.attr(\'type\',\'text\');}
211 211
 else{$eli.attr(\'type\',\'password\');}"
212 212
 ><i class="far fa-fw fa-eye-slash"></i></span>';
213
-			}
214
-
215
-			// input group wraps
216
-			if($args['input_group_left'] || $args['input_group_right']){
217
-				$w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
218
-				if($args['input_group_left']){
219
-					$output = self::wrap( array(
220
-						'content' => $output,
221
-						'class'   => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100  : 'input-group',
222
-						'input_group_left' => $args['input_group_left'],
223
-						'input_group_left_inside'    => $args['input_group_left_inside']
224
-					) );
225
-				}
226
-				if($args['input_group_right']){
227
-					$output = self::wrap( array(
228
-						'content' => $output,
229
-						'class'   => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group',
230
-						'input_group_right' => $args['input_group_right'],
231
-						'input_group_right_inside'    => $args['input_group_right_inside']
232
-					) );
233
-				}
234
-
235
-			}
236
-
237
-			if(!$label_after){
238
-				$output .= $help_text;
239
-			}
240
-
241
-
242
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
243
-				$output = self::wrap( array(
244
-					'content' => $output,
245
-					'class'   => 'col-sm-10',
246
-				) );
247
-			}
248
-
249
-			if(!$label_after){
250
-				$output = $label . $output;
251
-			}
252
-
253
-			// wrap
254
-			if(!$args['no_wrap']){
255
-
256
-				$form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
257
-				$wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
258
-				$wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
259
-				$output = self::wrap(array(
260
-					'content' => $output,
261
-					'class'   => $wrap_class,
262
-					'element_require'   => $args['element_require'],
263
-					'argument_id'  => $args['id']
264
-				));
265
-			}
266
-
267
-
268
-
269
-		}
270
-
271
-		return $output;
272
-	}
273
-
274
-	/**
275
-	 * Build the component.
276
-	 *
277
-	 * @param array $args
278
-	 *
279
-	 * @return string The rendered component.
280
-	 */
281
-	public static function textarea($args = array()){
282
-		$defaults = array(
283
-			'name'       => '',
284
-			'class'      => '',
285
-			'wrap_class' => '',
286
-			'id'         => '',
287
-			'placeholder'=> '',
288
-			'title'      => '',
289
-			'value'      => '',
290
-			'required'   => false,
291
-			'label'      => '',
292
-			'label_after'=> false,
293
-			'label_class'      => '',
294
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
295
-			'help_text'  => '',
296
-			'validation_text'   => '',
297
-			'validation_pattern' => '',
298
-			'no_wrap'    => false,
299
-			'rows'      => '',
300
-			'wysiwyg'   => false,
301
-			'allow_tags' => false, // Allow HTML tags
302
-			'element_require'   => '', // [%element_id%] == "1"
303
-			'extra_attributes'  => array(), // an array of extra attributes
304
-		);
305
-
306
-		/**
307
-		 * Parse incoming $args into an array and merge it with $defaults
308
-		 */
309
-		$args   = wp_parse_args( $args, $defaults );
310
-		$output = '';
311
-
312
-		// hidden label option needs to be empty
313
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
314
-
315
-		// floating labels don't work with wysiwyg so set it as top
316
-		if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){
317
-			$args['label_type'] = 'top';
318
-		}
319
-
320
-		$label_after = $args['label_after'];
321
-
322
-		// floating labels need label after
323
-		if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){
324
-			$label_after = true;
325
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
326
-		}
327
-
328
-		// label
329
-		if(!empty($args['label']) && is_array($args['label'])){
330
-		}elseif(!empty($args['label']) && !$label_after){
331
-			$label_args = array(
332
-				'title'=> $args['label'],
333
-				'for'=> $args['id'],
334
-				'class' => $args['label_class']." ",
335
-				'label_type' => $args['label_type']
336
-			);
337
-			$output .= self::label( $label_args );
338
-		}
339
-
340
-		// maybe horizontal label
341
-		if($args['label_type']=='horizontal'){
342
-			$output .= '<div class="col-sm-10">';
343
-		}
344
-
345
-		if(!empty($args['wysiwyg'])){
346
-			ob_start();
347
-			$content = $args['value'];
348
-			$editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
349
-			$settings = array(
350
-				'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4,
351
-				'quicktags'     => false,
352
-				'media_buttons' => false,
353
-				'editor_class'  => 'form-control',
354
-				'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']),
355
-				'teeny'         => true,
356
-			);
357
-
358
-			// maybe set settings if array
359
-			if(is_array($args['wysiwyg'])){
360
-				$settings  = wp_parse_args( $args['wysiwyg'], $settings );
361
-			}
362
-
363
-			wp_editor( $content, $editor_id, $settings );
364
-			$output .= ob_get_clean();
365
-		}else{
366
-
367
-			// open
368
-			$output .= '<textarea ';
369
-
370
-			// name
371
-			if(!empty($args['name'])){
372
-				$output .= ' name="'.esc_attr($args['name']).'" ';
373
-			}
374
-
375
-			// id
376
-			if(!empty($args['id'])){
377
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
378
-			}
379
-
380
-			// placeholder
381
-			if(isset($args['placeholder']) && '' != $args['placeholder']){
382
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
383
-			}
384
-
385
-			// title
386
-			if(!empty($args['title'])){
387
-				$output .= ' title="'.esc_attr($args['title']).'" ';
388
-			}
389
-
390
-			// validation text
391
-			if(!empty($args['validation_text'])){
392
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
393
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
394
-			}
395
-
396
-			// validation_pattern
397
-			if(!empty($args['validation_pattern'])){
398
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
399
-			}
400
-
401
-			// required
402
-			if(!empty($args['required'])){
403
-				$output .= ' required ';
404
-			}
405
-
406
-			// rows
407
-			if(!empty($args['rows'])){
408
-				$output .= ' rows="'.absint($args['rows']).'" ';
409
-			}
410
-
411
-
412
-			// class
413
-			$class = !empty($args['class']) ? $args['class'] : '';
414
-			$output .= ' class="form-control '.$class.'" ';
415
-
416
-			// extra attributes
417
-			if(!empty($args['extra_attributes'])){
418
-				$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
419
-			}
420
-
421
-			// close tag
422
-			$output .= ' >';
423
-
424
-			// value
425
-			if ( ! empty( $args['value'] ) ) {
426
-				if ( ! empty( $args['allow_tags'] ) ) {
427
-					$output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
428
-				} else {
429
-					$output .= sanitize_textarea_field( $args['value'] );
430
-				}
431
-			}
432
-
433
-			// closing tag
434
-			$output .= '</textarea>';
435
-
436
-		}
437
-
438
-		if(!empty($args['label']) && $label_after){
439
-			$label_args = array(
440
-				'title'=> $args['label'],
441
-				'for'=> $args['id'],
442
-				'class' => $args['label_class']." ",
443
-				'label_type' => $args['label_type']
444
-			);
445
-			$output .= self::label( $label_args );
446
-		}
447
-
448
-		// help text
449
-		if(!empty($args['help_text'])){
450
-			$output .= AUI_Component_Helper::help_text($args['help_text']);
451
-		}
452
-
453
-		// maybe horizontal label
454
-		if($args['label_type']=='horizontal'){
455
-			$output .= '</div>';
456
-		}
457
-
458
-
459
-		// wrap
460
-		if(!$args['no_wrap']){
461
-			$form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group';
462
-			$wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
463
-			$wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
464
-			$output = self::wrap(array(
465
-				'content' => $output,
466
-				'class'   => $wrap_class,
467
-				'element_require'   => $args['element_require'],
468
-				'argument_id'  => $args['id']
469
-			));
470
-		}
471
-
472
-
473
-		return $output;
474
-	}
475
-
476
-	public static function label($args = array(), $type = ''){
477
-		//<label for="exampleInputEmail1">Email address</label>
478
-		$defaults = array(
479
-			'title'       => 'div',
480
-			'for'      => '',
481
-			'class'      => '',
482
-			'label_type'    => '', // empty = hidden, top, horizontal
483
-		);
484
-
485
-		/**
486
-		 * Parse incoming $args into an array and merge it with $defaults
487
-		 */
488
-		$args   = wp_parse_args( $args, $defaults );
489
-		$output = '';
490
-
491
-		if($args['title']){
492
-
493
-			// maybe hide labels //@todo set a global option for visibility class
494
-			if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
495
-				$class = $args['class'];
496
-			}else{
497
-				$class = 'sr-only '.$args['class'];
498
-			}
499
-
500
-			// maybe horizontal
501
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
502
-				$class .= ' col-sm-2 col-form-label';
503
-			}
504
-
505
-			// open
506
-			$output .= '<label ';
507
-
508
-			// for
509
-			if(!empty($args['for'])){
510
-				$output .= ' for="'.esc_attr($args['for']).'" ';
511
-			}
512
-
513
-			// class
514
-			$class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
515
-			$output .= ' class="'.$class.'" ';
516
-
517
-			// close
518
-			$output .= '>';
519
-
520
-
521
-			// title, don't escape fully as can contain html
522
-			if(!empty($args['title'])){
523
-				$output .= wp_kses_post($args['title']);
524
-			}
525
-
526
-			// close wrap
527
-			$output .= '</label>';
528
-
529
-
530
-		}
531
-
532
-
533
-		return $output;
534
-	}
535
-
536
-	/**
537
-	 * Wrap some content in a HTML wrapper.
538
-	 *
539
-	 * @param array $args
540
-	 *
541
-	 * @return string
542
-	 */
543
-	public static function wrap($args = array()){
544
-		$defaults = array(
545
-			'type'       => 'div',
546
-			'class'      => 'form-group',
547
-			'content'   => '',
548
-			'input_group_left' => '',
549
-			'input_group_right' => '',
550
-			'input_group_left_inside' => false,
551
-			'input_group_right_inside' => false,
552
-			'element_require'   => '',
553
-			'argument_id'   => '',
554
-		);
555
-
556
-		/**
557
-		 * Parse incoming $args into an array and merge it with $defaults
558
-		 */
559
-		$args   = wp_parse_args( $args, $defaults );
560
-		$output = '';
561
-		if($args['type']){
562
-
563
-			// open
564
-			$output .= '<'.sanitize_html_class($args['type']);
565
-
566
-			// element require
567
-			if(!empty($args['element_require'])){
568
-				$output .= AUI_Component_Helper::element_require($args['element_require']);
569
-				$args['class'] .= " aui-conditional-field";
570
-			}
571
-
572
-			// argument_id
573
-			if( !empty($args['argument_id']) ){
574
-				$output .= ' data-argument="'.esc_attr($args['argument_id']).'"';
575
-			}
576
-
577
-			// class
578
-			$class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
579
-			$output .= ' class="'.$class.'" ';
580
-
581
-			// close wrap
582
-			$output .= ' >';
583
-
584
-
585
-			// Input group left
586
-			if(!empty($args['input_group_left'])){
587
-				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
588
-				$input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>';
589
-				$output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>';
590
-			}
591
-
592
-			// content
593
-			$output .= $args['content'];
594
-
595
-			// Input group right
596
-			if(!empty($args['input_group_right'])){
597
-				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
598
-				$input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>';
599
-				$output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>';
600
-			}
601
-
602
-
603
-			// close wrap
604
-			$output .= '</'.sanitize_html_class($args['type']).'>';
605
-
606
-
607
-		}else{
608
-			$output = $args['content'];
609
-		}
610
-
611
-		return $output;
612
-	}
613
-
614
-	/**
615
-	 * Build the component.
616
-	 *
617
-	 * @param array $args
618
-	 *
619
-	 * @return string The rendered component.
620
-	 */
621
-	public static function select($args = array()){
622
-		$defaults = array(
623
-			'class'      => '',
624
-			'wrap_class' => '',
625
-			'id'         => '',
626
-			'title'      => '',
627
-			'value'      => '', // can be an array or a string
628
-			'required'   => false,
629
-			'label'      => '',
630
-			'label_after'=> false,
631
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
632
-			'label_class'      => '',
633
-			'help_text'  => '',
634
-			'placeholder'=> '',
635
-			'options'    => array(), // array or string
636
-			'icon'       => '',
637
-			'multiple'   => false,
638
-			'select2'    => false,
639
-			'no_wrap'    => false,
640
-			'element_require'   => '', // [%element_id%] == "1"
641
-			'extra_attributes'  => array(), // an array of extra attributes
642
-		);
643
-
644
-		/**
645
-		 * Parse incoming $args into an array and merge it with $defaults
646
-		 */
647
-		$args   = wp_parse_args( $args, $defaults );
648
-		$output = '';
649
-
650
-		// for now lets hide floating labels
651
-		if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';}
652
-
653
-		// hidden label option needs to be empty
654
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
655
-
656
-
657
-		$label_after = $args['label_after'];
658
-
659
-		// floating labels need label after
660
-		if( $args['label_type'] == 'floating' ){
661
-			$label_after = true;
662
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
663
-		}
664
-
665
-		// Maybe setup select2
666
-		$is_select2 = false;
667
-		if(!empty($args['select2'])){
668
-			$args['class'] .= ' aui-select2';
669
-			$is_select2 = true;
670
-		}elseif( strpos($args['class'], 'aui-select2') !== false){
671
-			$is_select2 = true;
672
-		}
673
-
674
-		// select2 tags
675
-		if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason
676
-			$args['data-tags'] = 'true';
677
-			$args['data-token-separators'] = "[',']";
678
-			$args['multiple'] = true;
679
-		}
680
-
681
-		// select2 placeholder
682
-		if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){
683
-			$args['data-placeholder'] = esc_attr($args['placeholder']);
684
-			$args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true;
685
-		}
686
-
687
-		// label
688
-		if(!empty($args['label']) && is_array($args['label'])){
689
-		}elseif(!empty($args['label']) && !$label_after){
690
-			$label_args = array(
691
-				'title'=> $args['label'],
692
-				'for'=> $args['id'],
693
-				'class' => $args['label_class']." ",
694
-				'label_type' => $args['label_type']
695
-			);
696
-			$output .= self::label($label_args);
697
-		}
698
-
699
-		// maybe horizontal label
700
-		if($args['label_type']=='horizontal'){
701
-			$output .= '<div class="col-sm-10">';
702
-		}
703
-
704
-		// Set hidden input to save empty value for multiselect.
705
-		if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
706
-			$output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>';
707
-		}
708
-
709
-		// open/type
710
-		$output .= '<select ';
711
-
712
-		// style
713
-		if($is_select2){
714
-			$output .= " style='width:100%;' ";
715
-		}
716
-
717
-		// element require
718
-		if(!empty($args['element_require'])){
719
-			$output .= AUI_Component_Helper::element_require($args['element_require']);
720
-			$args['class'] .= " aui-conditional-field";
721
-		}
722
-
723
-		// class
724
-		$class = !empty($args['class']) ? $args['class'] : '';
725
-		$output .= AUI_Component_Helper::class_attr('custom-select '.$class);
726
-
727
-		// name
728
-		if(!empty($args['name'])){
729
-			$output .= AUI_Component_Helper::name($args['name'],$args['multiple']);
730
-		}
731
-
732
-		// id
733
-		if(!empty($args['id'])){
734
-			$output .= AUI_Component_Helper::id($args['id']);
735
-		}
736
-
737
-		// title
738
-		if(!empty($args['title'])){
739
-			$output .= AUI_Component_Helper::title($args['title']);
740
-		}
741
-
742
-		// data-attributes
743
-		$output .= AUI_Component_Helper::data_attributes($args);
744
-
745
-		// aria-attributes
746
-		$output .= AUI_Component_Helper::aria_attributes($args);
747
-
748
-		// extra attributes
749
-		if(!empty($args['extra_attributes'])){
750
-			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
751
-		}
752
-
753
-		// required
754
-		if(!empty($args['required'])){
755
-			$output .= ' required ';
756
-		}
757
-
758
-		// multiple
759
-		if(!empty($args['multiple'])){
760
-			$output .= ' multiple ';
761
-		}
762
-
763
-		// close opening tag
764
-		$output .= ' >';
765
-
766
-		// placeholder
767
-		if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){
768
-			$output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>';
769
-		}elseif($is_select2 && !empty($args['placeholder'])){
770
-			$output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
771
-		}
772
-
773
-		// Options
774
-		if(!empty($args['options'])){
775
-
776
-			if(!is_array($args['options'])){
777
-				$output .= $args['options']; // not the preferred way but an option
778
-			}else{
779
-				foreach($args['options'] as $val => $name){
780
-					$selected = '';
781
-					if(is_array($name)){
782
-						if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
783
-							$option_label = isset($name['label']) ? $name['label'] : '';
784
-
785
-							$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
786
-						} else {
787
-							$option_label = isset($name['label']) ? $name['label'] : '';
788
-							$option_value = isset($name['value']) ? $name['value'] : '';
789
-							if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){
790
-								$selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
791
-							} elseif(!empty($args['value'])) {
792
-								$selected = selected($option_value,stripslashes_deep($args['value']), false);
793
-							}
794
-
795
-							$output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
796
-						}
797
-					}else{
798
-						if(!empty($args['value'])){
799
-							if(is_array($args['value'])){
800
-								$selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
801
-							} elseif(!empty($args['value'])) {
802
-								$selected = selected( $args['value'], $val, false);
803
-							}
804
-						}
805
-						$output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>';
806
-					}
807
-				}
808
-			}
809
-
810
-		}
811
-
812
-		// closing tag
813
-		$output .= '</select>';
814
-
815
-		if(!empty($args['label']) && $label_after){
816
-			$label_args = array(
817
-				'title'=> $args['label'],
818
-				'for'=> $args['id'],
819
-				'class' => $args['label_class']." ",
820
-				'label_type' => $args['label_type']
821
-			);
822
-			$output .= self::label($label_args);
823
-		}
824
-
825
-		// help text
826
-		if(!empty($args['help_text'])){
827
-			$output .= AUI_Component_Helper::help_text($args['help_text']);
828
-		}
829
-
830
-		// maybe horizontal label
831
-		if($args['label_type']=='horizontal'){
832
-			$output .= '</div>';
833
-		}
834
-
835
-
836
-		// wrap
837
-		if(!$args['no_wrap']){
838
-			$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
839
-			$wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
840
-			$output = self::wrap(array(
841
-				'content' => $output,
842
-				'class'   => $wrap_class,
843
-				'element_require'   => $args['element_require'],
844
-				'argument_id'  => $args['id']
845
-			));
846
-		}
847
-
848
-
849
-		return $output;
850
-	}
851
-
852
-	/**
853
-	 * Build the component.
854
-	 *
855
-	 * @param array $args
856
-	 *
857
-	 * @return string The rendered component.
858
-	 */
859
-	public static function radio($args = array()){
860
-		$defaults = array(
861
-			'class'      => '',
862
-			'wrap_class' => '',
863
-			'id'         => '',
864
-			'title'      => '',
865
-			'horizontal' => false, // sets the lable horizontal
866
-			'value'      => '',
867
-			'label'      => '',
868
-			'label_class'=> '',
869
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
870
-			'help_text'  => '',
871
-			'inline'     => true,
872
-			'required'   => false,
873
-			'options'    => array(),
874
-			'icon'       => '',
875
-			'no_wrap'    => false,
876
-			'element_require'   => '', // [%element_id%] == "1"
877
-			'extra_attributes'  => array() // an array of extra attributes
878
-		);
879
-
880
-		/**
881
-		 * Parse incoming $args into an array and merge it with $defaults
882
-		 */
883
-		$args   = wp_parse_args( $args, $defaults );
884
-
885
-		// for now lets use horizontal for floating
886
-		if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';}
887
-
888
-		$label_args = array(
889
-			'title'=> $args['label'],
890
-			'class' => $args['label_class']." pt-0 ",
891
-			'label_type' => $args['label_type']
892
-		);
893
-
894
-		$output = '';
895
-
896
-
897
-
898
-		// label before
899
-		if(!empty($args['label'])){
900
-			$output .= self::label( $label_args, 'radio' );
901
-		}
902
-
903
-		// maybe horizontal label
904
-		if($args['label_type']=='horizontal'){
905
-			$output .= '<div class="col-sm-10">';
906
-		}
907
-
908
-		if(!empty($args['options'])){
909
-			$count = 0;
910
-			foreach($args['options'] as $value => $label){
911
-				$option_args = $args;
912
-				$option_args['value'] = $value;
913
-				$option_args['label'] = $label;
914
-				$option_args['checked'] = $value == $args['value'] ? true : false;
915
-				$output .= self::radio_option($option_args,$count);
916
-				$count++;
917
-			}
918
-		}
919
-
920
-		// help text
921
-		$help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
922
-		$output .= $help_text;
923
-
924
-		// maybe horizontal label
925
-		if($args['label_type']=='horizontal'){
926
-			$output .= '</div>';
927
-		}
928
-
929
-		// wrap
930
-		$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
931
-		$wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
932
-		$output = self::wrap(array(
933
-			'content' => $output,
934
-			'class'   => $wrap_class,
935
-			'element_require'   => $args['element_require'],
936
-			'argument_id'  => $args['id']
937
-		));
938
-
939
-
940
-		return $output;
941
-	}
942
-
943
-	/**
944
-	 * Build the component.
945
-	 *
946
-	 * @param array $args
947
-	 *
948
-	 * @return string The rendered component.
949
-	 */
950
-	public static function radio_option($args = array(),$count = ''){
951
-		$defaults = array(
952
-			'class'      => '',
953
-			'id'         => '',
954
-			'title'      => '',
955
-			'value'      => '',
956
-			'required'   => false,
957
-			'inline'     => true,
958
-			'label'      => '',
959
-			'options'    => array(),
960
-			'icon'       => '',
961
-			'no_wrap'    => false,
962
-			'extra_attributes'  => array() // an array of extra attributes
963
-		);
964
-
965
-		/**
966
-		 * Parse incoming $args into an array and merge it with $defaults
967
-		 */
968
-		$args   = wp_parse_args( $args, $defaults );
969
-
970
-		$output = '';
971
-
972
-		// open/type
973
-		$output .= '<input type="radio"';
974
-
975
-		// class
976
-		$output .= ' class="form-check-input" ';
977
-
978
-		// name
979
-		if(!empty($args['name'])){
980
-			$output .= AUI_Component_Helper::name($args['name']);
981
-		}
982
-
983
-		// id
984
-		if(!empty($args['id'])){
985
-			$output .= AUI_Component_Helper::id($args['id'].$count);
986
-		}
987
-
988
-		// title
989
-		if(!empty($args['title'])){
990
-			$output .= AUI_Component_Helper::title($args['title']);
991
-		}
992
-
993
-		// value
994
-		if(isset($args['value'])){
995
-			$output .= AUI_Component_Helper::value($args['value']);
996
-		}
997
-
998
-		// checked, for radio and checkboxes
999
-		if( $args['checked'] ){
1000
-			$output .= ' checked ';
1001
-		}
1002
-
1003
-		// data-attributes
1004
-		$output .= AUI_Component_Helper::data_attributes($args);
1005
-
1006
-		// aria-attributes
1007
-		$output .= AUI_Component_Helper::aria_attributes($args);
1008
-
1009
-		// extra attributes
1010
-		if(!empty($args['extra_attributes'])){
1011
-			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
1012
-		}
1013
-
1014
-		// required
1015
-		if(!empty($args['required'])){
1016
-			$output .= ' required ';
1017
-		}
1018
-
1019
-		// close opening tag
1020
-		$output .= ' >';
1021
-
1022
-		// label
1023
-		if(!empty($args['label']) && is_array($args['label'])){
1024
-		}elseif(!empty($args['label'])){
1025
-			$output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
1026
-		}
1027
-
1028
-		// wrap
1029
-		if ( ! $args['no_wrap'] ) {
1030
-			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1031
-
1032
-			// Unique wrap class
1033
-			$uniq_class = 'fwrap';
1034
-			if ( ! empty( $args['name'] ) ) {
1035
-				$uniq_class .= '-' . $args['name'];
1036
-			} else if ( ! empty( $args['id'] ) ) {
1037
-				$uniq_class .= '-' . $args['id'];
1038
-			}
1039
-
1040
-			if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1041
-				$uniq_class .= '-' . $args['value'];
1042
-			} else {
1043
-				$uniq_class .= '-' . $count;
1044
-			}
1045
-			$wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1046
-
1047
-			$output = self::wrap(array(
1048
-				'content' => $output,
1049
-				'class' => $wrap_class
1050
-			));
1051
-		}
1052
-
1053
-		return $output;
1054
-	}
213
+            }
214
+
215
+            // input group wraps
216
+            if($args['input_group_left'] || $args['input_group_right']){
217
+                $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
218
+                if($args['input_group_left']){
219
+                    $output = self::wrap( array(
220
+                        'content' => $output,
221
+                        'class'   => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100  : 'input-group',
222
+                        'input_group_left' => $args['input_group_left'],
223
+                        'input_group_left_inside'    => $args['input_group_left_inside']
224
+                    ) );
225
+                }
226
+                if($args['input_group_right']){
227
+                    $output = self::wrap( array(
228
+                        'content' => $output,
229
+                        'class'   => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group',
230
+                        'input_group_right' => $args['input_group_right'],
231
+                        'input_group_right_inside'    => $args['input_group_right_inside']
232
+                    ) );
233
+                }
234
+
235
+            }
236
+
237
+            if(!$label_after){
238
+                $output .= $help_text;
239
+            }
240
+
241
+
242
+            if($args['label_type']=='horizontal' && $type != 'checkbox'){
243
+                $output = self::wrap( array(
244
+                    'content' => $output,
245
+                    'class'   => 'col-sm-10',
246
+                ) );
247
+            }
248
+
249
+            if(!$label_after){
250
+                $output = $label . $output;
251
+            }
252
+
253
+            // wrap
254
+            if(!$args['no_wrap']){
255
+
256
+                $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
257
+                $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
258
+                $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
259
+                $output = self::wrap(array(
260
+                    'content' => $output,
261
+                    'class'   => $wrap_class,
262
+                    'element_require'   => $args['element_require'],
263
+                    'argument_id'  => $args['id']
264
+                ));
265
+            }
266
+
267
+
268
+
269
+        }
270
+
271
+        return $output;
272
+    }
273
+
274
+    /**
275
+     * Build the component.
276
+     *
277
+     * @param array $args
278
+     *
279
+     * @return string The rendered component.
280
+     */
281
+    public static function textarea($args = array()){
282
+        $defaults = array(
283
+            'name'       => '',
284
+            'class'      => '',
285
+            'wrap_class' => '',
286
+            'id'         => '',
287
+            'placeholder'=> '',
288
+            'title'      => '',
289
+            'value'      => '',
290
+            'required'   => false,
291
+            'label'      => '',
292
+            'label_after'=> false,
293
+            'label_class'      => '',
294
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
295
+            'help_text'  => '',
296
+            'validation_text'   => '',
297
+            'validation_pattern' => '',
298
+            'no_wrap'    => false,
299
+            'rows'      => '',
300
+            'wysiwyg'   => false,
301
+            'allow_tags' => false, // Allow HTML tags
302
+            'element_require'   => '', // [%element_id%] == "1"
303
+            'extra_attributes'  => array(), // an array of extra attributes
304
+        );
305
+
306
+        /**
307
+         * Parse incoming $args into an array and merge it with $defaults
308
+         */
309
+        $args   = wp_parse_args( $args, $defaults );
310
+        $output = '';
311
+
312
+        // hidden label option needs to be empty
313
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
314
+
315
+        // floating labels don't work with wysiwyg so set it as top
316
+        if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){
317
+            $args['label_type'] = 'top';
318
+        }
319
+
320
+        $label_after = $args['label_after'];
321
+
322
+        // floating labels need label after
323
+        if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){
324
+            $label_after = true;
325
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
326
+        }
327
+
328
+        // label
329
+        if(!empty($args['label']) && is_array($args['label'])){
330
+        }elseif(!empty($args['label']) && !$label_after){
331
+            $label_args = array(
332
+                'title'=> $args['label'],
333
+                'for'=> $args['id'],
334
+                'class' => $args['label_class']." ",
335
+                'label_type' => $args['label_type']
336
+            );
337
+            $output .= self::label( $label_args );
338
+        }
339
+
340
+        // maybe horizontal label
341
+        if($args['label_type']=='horizontal'){
342
+            $output .= '<div class="col-sm-10">';
343
+        }
344
+
345
+        if(!empty($args['wysiwyg'])){
346
+            ob_start();
347
+            $content = $args['value'];
348
+            $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
349
+            $settings = array(
350
+                'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4,
351
+                'quicktags'     => false,
352
+                'media_buttons' => false,
353
+                'editor_class'  => 'form-control',
354
+                'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']),
355
+                'teeny'         => true,
356
+            );
357
+
358
+            // maybe set settings if array
359
+            if(is_array($args['wysiwyg'])){
360
+                $settings  = wp_parse_args( $args['wysiwyg'], $settings );
361
+            }
362
+
363
+            wp_editor( $content, $editor_id, $settings );
364
+            $output .= ob_get_clean();
365
+        }else{
366
+
367
+            // open
368
+            $output .= '<textarea ';
369
+
370
+            // name
371
+            if(!empty($args['name'])){
372
+                $output .= ' name="'.esc_attr($args['name']).'" ';
373
+            }
374
+
375
+            // id
376
+            if(!empty($args['id'])){
377
+                $output .= ' id="'.sanitize_html_class($args['id']).'" ';
378
+            }
379
+
380
+            // placeholder
381
+            if(isset($args['placeholder']) && '' != $args['placeholder']){
382
+                $output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
383
+            }
384
+
385
+            // title
386
+            if(!empty($args['title'])){
387
+                $output .= ' title="'.esc_attr($args['title']).'" ';
388
+            }
389
+
390
+            // validation text
391
+            if(!empty($args['validation_text'])){
392
+                $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
393
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
394
+            }
395
+
396
+            // validation_pattern
397
+            if(!empty($args['validation_pattern'])){
398
+                $output .= ' pattern="'.$args['validation_pattern'].'" ';
399
+            }
400
+
401
+            // required
402
+            if(!empty($args['required'])){
403
+                $output .= ' required ';
404
+            }
405
+
406
+            // rows
407
+            if(!empty($args['rows'])){
408
+                $output .= ' rows="'.absint($args['rows']).'" ';
409
+            }
410
+
411
+
412
+            // class
413
+            $class = !empty($args['class']) ? $args['class'] : '';
414
+            $output .= ' class="form-control '.$class.'" ';
415
+
416
+            // extra attributes
417
+            if(!empty($args['extra_attributes'])){
418
+                $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
419
+            }
420
+
421
+            // close tag
422
+            $output .= ' >';
423
+
424
+            // value
425
+            if ( ! empty( $args['value'] ) ) {
426
+                if ( ! empty( $args['allow_tags'] ) ) {
427
+                    $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
428
+                } else {
429
+                    $output .= sanitize_textarea_field( $args['value'] );
430
+                }
431
+            }
432
+
433
+            // closing tag
434
+            $output .= '</textarea>';
435
+
436
+        }
437
+
438
+        if(!empty($args['label']) && $label_after){
439
+            $label_args = array(
440
+                'title'=> $args['label'],
441
+                'for'=> $args['id'],
442
+                'class' => $args['label_class']." ",
443
+                'label_type' => $args['label_type']
444
+            );
445
+            $output .= self::label( $label_args );
446
+        }
447
+
448
+        // help text
449
+        if(!empty($args['help_text'])){
450
+            $output .= AUI_Component_Helper::help_text($args['help_text']);
451
+        }
452
+
453
+        // maybe horizontal label
454
+        if($args['label_type']=='horizontal'){
455
+            $output .= '</div>';
456
+        }
457
+
458
+
459
+        // wrap
460
+        if(!$args['no_wrap']){
461
+            $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group';
462
+            $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
463
+            $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
464
+            $output = self::wrap(array(
465
+                'content' => $output,
466
+                'class'   => $wrap_class,
467
+                'element_require'   => $args['element_require'],
468
+                'argument_id'  => $args['id']
469
+            ));
470
+        }
471
+
472
+
473
+        return $output;
474
+    }
475
+
476
+    public static function label($args = array(), $type = ''){
477
+        //<label for="exampleInputEmail1">Email address</label>
478
+        $defaults = array(
479
+            'title'       => 'div',
480
+            'for'      => '',
481
+            'class'      => '',
482
+            'label_type'    => '', // empty = hidden, top, horizontal
483
+        );
484
+
485
+        /**
486
+         * Parse incoming $args into an array and merge it with $defaults
487
+         */
488
+        $args   = wp_parse_args( $args, $defaults );
489
+        $output = '';
490
+
491
+        if($args['title']){
492
+
493
+            // maybe hide labels //@todo set a global option for visibility class
494
+            if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
495
+                $class = $args['class'];
496
+            }else{
497
+                $class = 'sr-only '.$args['class'];
498
+            }
499
+
500
+            // maybe horizontal
501
+            if($args['label_type']=='horizontal' && $type != 'checkbox'){
502
+                $class .= ' col-sm-2 col-form-label';
503
+            }
504
+
505
+            // open
506
+            $output .= '<label ';
507
+
508
+            // for
509
+            if(!empty($args['for'])){
510
+                $output .= ' for="'.esc_attr($args['for']).'" ';
511
+            }
512
+
513
+            // class
514
+            $class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
515
+            $output .= ' class="'.$class.'" ';
516
+
517
+            // close
518
+            $output .= '>';
519
+
520
+
521
+            // title, don't escape fully as can contain html
522
+            if(!empty($args['title'])){
523
+                $output .= wp_kses_post($args['title']);
524
+            }
525
+
526
+            // close wrap
527
+            $output .= '</label>';
528
+
529
+
530
+        }
531
+
532
+
533
+        return $output;
534
+    }
535
+
536
+    /**
537
+     * Wrap some content in a HTML wrapper.
538
+     *
539
+     * @param array $args
540
+     *
541
+     * @return string
542
+     */
543
+    public static function wrap($args = array()){
544
+        $defaults = array(
545
+            'type'       => 'div',
546
+            'class'      => 'form-group',
547
+            'content'   => '',
548
+            'input_group_left' => '',
549
+            'input_group_right' => '',
550
+            'input_group_left_inside' => false,
551
+            'input_group_right_inside' => false,
552
+            'element_require'   => '',
553
+            'argument_id'   => '',
554
+        );
555
+
556
+        /**
557
+         * Parse incoming $args into an array and merge it with $defaults
558
+         */
559
+        $args   = wp_parse_args( $args, $defaults );
560
+        $output = '';
561
+        if($args['type']){
562
+
563
+            // open
564
+            $output .= '<'.sanitize_html_class($args['type']);
565
+
566
+            // element require
567
+            if(!empty($args['element_require'])){
568
+                $output .= AUI_Component_Helper::element_require($args['element_require']);
569
+                $args['class'] .= " aui-conditional-field";
570
+            }
571
+
572
+            // argument_id
573
+            if( !empty($args['argument_id']) ){
574
+                $output .= ' data-argument="'.esc_attr($args['argument_id']).'"';
575
+            }
576
+
577
+            // class
578
+            $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
579
+            $output .= ' class="'.$class.'" ';
580
+
581
+            // close wrap
582
+            $output .= ' >';
583
+
584
+
585
+            // Input group left
586
+            if(!empty($args['input_group_left'])){
587
+                $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
588
+                $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>';
589
+                $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>';
590
+            }
591
+
592
+            // content
593
+            $output .= $args['content'];
594
+
595
+            // Input group right
596
+            if(!empty($args['input_group_right'])){
597
+                $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
598
+                $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>';
599
+                $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>';
600
+            }
601
+
602
+
603
+            // close wrap
604
+            $output .= '</'.sanitize_html_class($args['type']).'>';
605
+
606
+
607
+        }else{
608
+            $output = $args['content'];
609
+        }
610
+
611
+        return $output;
612
+    }
613
+
614
+    /**
615
+     * Build the component.
616
+     *
617
+     * @param array $args
618
+     *
619
+     * @return string The rendered component.
620
+     */
621
+    public static function select($args = array()){
622
+        $defaults = array(
623
+            'class'      => '',
624
+            'wrap_class' => '',
625
+            'id'         => '',
626
+            'title'      => '',
627
+            'value'      => '', // can be an array or a string
628
+            'required'   => false,
629
+            'label'      => '',
630
+            'label_after'=> false,
631
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
632
+            'label_class'      => '',
633
+            'help_text'  => '',
634
+            'placeholder'=> '',
635
+            'options'    => array(), // array or string
636
+            'icon'       => '',
637
+            'multiple'   => false,
638
+            'select2'    => false,
639
+            'no_wrap'    => false,
640
+            'element_require'   => '', // [%element_id%] == "1"
641
+            'extra_attributes'  => array(), // an array of extra attributes
642
+        );
643
+
644
+        /**
645
+         * Parse incoming $args into an array and merge it with $defaults
646
+         */
647
+        $args   = wp_parse_args( $args, $defaults );
648
+        $output = '';
649
+
650
+        // for now lets hide floating labels
651
+        if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';}
652
+
653
+        // hidden label option needs to be empty
654
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
655
+
656
+
657
+        $label_after = $args['label_after'];
658
+
659
+        // floating labels need label after
660
+        if( $args['label_type'] == 'floating' ){
661
+            $label_after = true;
662
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
663
+        }
664
+
665
+        // Maybe setup select2
666
+        $is_select2 = false;
667
+        if(!empty($args['select2'])){
668
+            $args['class'] .= ' aui-select2';
669
+            $is_select2 = true;
670
+        }elseif( strpos($args['class'], 'aui-select2') !== false){
671
+            $is_select2 = true;
672
+        }
673
+
674
+        // select2 tags
675
+        if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason
676
+            $args['data-tags'] = 'true';
677
+            $args['data-token-separators'] = "[',']";
678
+            $args['multiple'] = true;
679
+        }
680
+
681
+        // select2 placeholder
682
+        if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){
683
+            $args['data-placeholder'] = esc_attr($args['placeholder']);
684
+            $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true;
685
+        }
686
+
687
+        // label
688
+        if(!empty($args['label']) && is_array($args['label'])){
689
+        }elseif(!empty($args['label']) && !$label_after){
690
+            $label_args = array(
691
+                'title'=> $args['label'],
692
+                'for'=> $args['id'],
693
+                'class' => $args['label_class']." ",
694
+                'label_type' => $args['label_type']
695
+            );
696
+            $output .= self::label($label_args);
697
+        }
698
+
699
+        // maybe horizontal label
700
+        if($args['label_type']=='horizontal'){
701
+            $output .= '<div class="col-sm-10">';
702
+        }
703
+
704
+        // Set hidden input to save empty value for multiselect.
705
+        if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
706
+            $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>';
707
+        }
708
+
709
+        // open/type
710
+        $output .= '<select ';
711
+
712
+        // style
713
+        if($is_select2){
714
+            $output .= " style='width:100%;' ";
715
+        }
716
+
717
+        // element require
718
+        if(!empty($args['element_require'])){
719
+            $output .= AUI_Component_Helper::element_require($args['element_require']);
720
+            $args['class'] .= " aui-conditional-field";
721
+        }
722
+
723
+        // class
724
+        $class = !empty($args['class']) ? $args['class'] : '';
725
+        $output .= AUI_Component_Helper::class_attr('custom-select '.$class);
726
+
727
+        // name
728
+        if(!empty($args['name'])){
729
+            $output .= AUI_Component_Helper::name($args['name'],$args['multiple']);
730
+        }
731
+
732
+        // id
733
+        if(!empty($args['id'])){
734
+            $output .= AUI_Component_Helper::id($args['id']);
735
+        }
736
+
737
+        // title
738
+        if(!empty($args['title'])){
739
+            $output .= AUI_Component_Helper::title($args['title']);
740
+        }
741
+
742
+        // data-attributes
743
+        $output .= AUI_Component_Helper::data_attributes($args);
744
+
745
+        // aria-attributes
746
+        $output .= AUI_Component_Helper::aria_attributes($args);
747
+
748
+        // extra attributes
749
+        if(!empty($args['extra_attributes'])){
750
+            $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
751
+        }
752
+
753
+        // required
754
+        if(!empty($args['required'])){
755
+            $output .= ' required ';
756
+        }
757
+
758
+        // multiple
759
+        if(!empty($args['multiple'])){
760
+            $output .= ' multiple ';
761
+        }
762
+
763
+        // close opening tag
764
+        $output .= ' >';
765
+
766
+        // placeholder
767
+        if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){
768
+            $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>';
769
+        }elseif($is_select2 && !empty($args['placeholder'])){
770
+            $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
771
+        }
772
+
773
+        // Options
774
+        if(!empty($args['options'])){
775
+
776
+            if(!is_array($args['options'])){
777
+                $output .= $args['options']; // not the preferred way but an option
778
+            }else{
779
+                foreach($args['options'] as $val => $name){
780
+                    $selected = '';
781
+                    if(is_array($name)){
782
+                        if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
783
+                            $option_label = isset($name['label']) ? $name['label'] : '';
784
+
785
+                            $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
786
+                        } else {
787
+                            $option_label = isset($name['label']) ? $name['label'] : '';
788
+                            $option_value = isset($name['value']) ? $name['value'] : '';
789
+                            if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){
790
+                                $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
791
+                            } elseif(!empty($args['value'])) {
792
+                                $selected = selected($option_value,stripslashes_deep($args['value']), false);
793
+                            }
794
+
795
+                            $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
796
+                        }
797
+                    }else{
798
+                        if(!empty($args['value'])){
799
+                            if(is_array($args['value'])){
800
+                                $selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
801
+                            } elseif(!empty($args['value'])) {
802
+                                $selected = selected( $args['value'], $val, false);
803
+                            }
804
+                        }
805
+                        $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>';
806
+                    }
807
+                }
808
+            }
809
+
810
+        }
811
+
812
+        // closing tag
813
+        $output .= '</select>';
814
+
815
+        if(!empty($args['label']) && $label_after){
816
+            $label_args = array(
817
+                'title'=> $args['label'],
818
+                'for'=> $args['id'],
819
+                'class' => $args['label_class']." ",
820
+                'label_type' => $args['label_type']
821
+            );
822
+            $output .= self::label($label_args);
823
+        }
824
+
825
+        // help text
826
+        if(!empty($args['help_text'])){
827
+            $output .= AUI_Component_Helper::help_text($args['help_text']);
828
+        }
829
+
830
+        // maybe horizontal label
831
+        if($args['label_type']=='horizontal'){
832
+            $output .= '</div>';
833
+        }
834
+
835
+
836
+        // wrap
837
+        if(!$args['no_wrap']){
838
+            $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
839
+            $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
840
+            $output = self::wrap(array(
841
+                'content' => $output,
842
+                'class'   => $wrap_class,
843
+                'element_require'   => $args['element_require'],
844
+                'argument_id'  => $args['id']
845
+            ));
846
+        }
847
+
848
+
849
+        return $output;
850
+    }
851
+
852
+    /**
853
+     * Build the component.
854
+     *
855
+     * @param array $args
856
+     *
857
+     * @return string The rendered component.
858
+     */
859
+    public static function radio($args = array()){
860
+        $defaults = array(
861
+            'class'      => '',
862
+            'wrap_class' => '',
863
+            'id'         => '',
864
+            'title'      => '',
865
+            'horizontal' => false, // sets the lable horizontal
866
+            'value'      => '',
867
+            'label'      => '',
868
+            'label_class'=> '',
869
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
870
+            'help_text'  => '',
871
+            'inline'     => true,
872
+            'required'   => false,
873
+            'options'    => array(),
874
+            'icon'       => '',
875
+            'no_wrap'    => false,
876
+            'element_require'   => '', // [%element_id%] == "1"
877
+            'extra_attributes'  => array() // an array of extra attributes
878
+        );
879
+
880
+        /**
881
+         * Parse incoming $args into an array and merge it with $defaults
882
+         */
883
+        $args   = wp_parse_args( $args, $defaults );
884
+
885
+        // for now lets use horizontal for floating
886
+        if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';}
887
+
888
+        $label_args = array(
889
+            'title'=> $args['label'],
890
+            'class' => $args['label_class']." pt-0 ",
891
+            'label_type' => $args['label_type']
892
+        );
893
+
894
+        $output = '';
895
+
896
+
897
+
898
+        // label before
899
+        if(!empty($args['label'])){
900
+            $output .= self::label( $label_args, 'radio' );
901
+        }
902
+
903
+        // maybe horizontal label
904
+        if($args['label_type']=='horizontal'){
905
+            $output .= '<div class="col-sm-10">';
906
+        }
907
+
908
+        if(!empty($args['options'])){
909
+            $count = 0;
910
+            foreach($args['options'] as $value => $label){
911
+                $option_args = $args;
912
+                $option_args['value'] = $value;
913
+                $option_args['label'] = $label;
914
+                $option_args['checked'] = $value == $args['value'] ? true : false;
915
+                $output .= self::radio_option($option_args,$count);
916
+                $count++;
917
+            }
918
+        }
919
+
920
+        // help text
921
+        $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
922
+        $output .= $help_text;
923
+
924
+        // maybe horizontal label
925
+        if($args['label_type']=='horizontal'){
926
+            $output .= '</div>';
927
+        }
928
+
929
+        // wrap
930
+        $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
931
+        $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class;
932
+        $output = self::wrap(array(
933
+            'content' => $output,
934
+            'class'   => $wrap_class,
935
+            'element_require'   => $args['element_require'],
936
+            'argument_id'  => $args['id']
937
+        ));
938
+
939
+
940
+        return $output;
941
+    }
942
+
943
+    /**
944
+     * Build the component.
945
+     *
946
+     * @param array $args
947
+     *
948
+     * @return string The rendered component.
949
+     */
950
+    public static function radio_option($args = array(),$count = ''){
951
+        $defaults = array(
952
+            'class'      => '',
953
+            'id'         => '',
954
+            'title'      => '',
955
+            'value'      => '',
956
+            'required'   => false,
957
+            'inline'     => true,
958
+            'label'      => '',
959
+            'options'    => array(),
960
+            'icon'       => '',
961
+            'no_wrap'    => false,
962
+            'extra_attributes'  => array() // an array of extra attributes
963
+        );
964
+
965
+        /**
966
+         * Parse incoming $args into an array and merge it with $defaults
967
+         */
968
+        $args   = wp_parse_args( $args, $defaults );
969
+
970
+        $output = '';
971
+
972
+        // open/type
973
+        $output .= '<input type="radio"';
974
+
975
+        // class
976
+        $output .= ' class="form-check-input" ';
977
+
978
+        // name
979
+        if(!empty($args['name'])){
980
+            $output .= AUI_Component_Helper::name($args['name']);
981
+        }
982
+
983
+        // id
984
+        if(!empty($args['id'])){
985
+            $output .= AUI_Component_Helper::id($args['id'].$count);
986
+        }
987
+
988
+        // title
989
+        if(!empty($args['title'])){
990
+            $output .= AUI_Component_Helper::title($args['title']);
991
+        }
992
+
993
+        // value
994
+        if(isset($args['value'])){
995
+            $output .= AUI_Component_Helper::value($args['value']);
996
+        }
997
+
998
+        // checked, for radio and checkboxes
999
+        if( $args['checked'] ){
1000
+            $output .= ' checked ';
1001
+        }
1002
+
1003
+        // data-attributes
1004
+        $output .= AUI_Component_Helper::data_attributes($args);
1005
+
1006
+        // aria-attributes
1007
+        $output .= AUI_Component_Helper::aria_attributes($args);
1008
+
1009
+        // extra attributes
1010
+        if(!empty($args['extra_attributes'])){
1011
+            $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
1012
+        }
1013
+
1014
+        // required
1015
+        if(!empty($args['required'])){
1016
+            $output .= ' required ';
1017
+        }
1018
+
1019
+        // close opening tag
1020
+        $output .= ' >';
1021
+
1022
+        // label
1023
+        if(!empty($args['label']) && is_array($args['label'])){
1024
+        }elseif(!empty($args['label'])){
1025
+            $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
1026
+        }
1027
+
1028
+        // wrap
1029
+        if ( ! $args['no_wrap'] ) {
1030
+            $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1031
+
1032
+            // Unique wrap class
1033
+            $uniq_class = 'fwrap';
1034
+            if ( ! empty( $args['name'] ) ) {
1035
+                $uniq_class .= '-' . $args['name'];
1036
+            } else if ( ! empty( $args['id'] ) ) {
1037
+                $uniq_class .= '-' . $args['id'];
1038
+            }
1039
+
1040
+            if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1041
+                $uniq_class .= '-' . $args['value'];
1042
+            } else {
1043
+                $uniq_class .= '-' . $count;
1044
+            }
1045
+            $wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1046
+
1047
+            $output = self::wrap(array(
1048
+                'content' => $output,
1049
+                'class' => $wrap_class
1050
+            ));
1051
+        }
1052
+
1053
+        return $output;
1054
+    }
1055 1055
 
1056 1056
 }
1057 1057
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Indentation   +344 added lines, -344 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_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 = 'paypal';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
 
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89 89
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
90
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92 92
 
93 93
         parent::__construct();
94 94
     }
95 95
 
96 96
     /**
97
-	 * Process Payment.
98
-	 *
99
-	 *
100
-	 * @param WPInv_Invoice $invoice Invoice.
101
-	 * @param array $submission_data Posted checkout fields.
102
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
-	 * @return array
104
-	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
97
+     * Process Payment.
98
+     *
99
+     *
100
+     * @param WPInv_Invoice $invoice Invoice.
101
+     * @param array $submission_data Posted checkout fields.
102
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
+     * @return array
104
+     */
105
+    public function process_payment( $invoice, $submission_data, $submission ) {
106 106
 
107 107
         // Get redirect url.
108 108
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get the PayPal request URL for an invoice.
129
-	 *
130
-	 * @param  WPInv_Invoice $invoice Invoice object.
131
-	 * @return string
132
-	 */
133
-	public function get_request_url( $invoice ) {
128
+     * Get the PayPal request URL for an invoice.
129
+     *
130
+     * @param  WPInv_Invoice $invoice Invoice object.
131
+     * @return string
132
+     */
133
+    public function get_request_url( $invoice ) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139 139
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -146,45 +146,45 @@  discard block
 block discarded – undo
146 146
 
147 147
         return add_query_arg( $paypal_args, $this->endpoint );
148 148
 
149
-	}
149
+    }
150 150
 
151 151
     /**
152
-	 * Get PayPal Args for passing to PP.
153
-	 *
154
-	 * @param  WPInv_Invoice $invoice Invoice object.
155
-	 * @return array
156
-	 */
157
-	protected function get_paypal_args( $invoice ) {
152
+     * Get PayPal Args for passing to PP.
153
+     *
154
+     * @param  WPInv_Invoice $invoice Invoice object.
155
+     * @return array
156
+     */
157
+    protected function get_paypal_args( $invoice ) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
-
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
-			$force_one_line_item = true;
164
-		}
165
-
166
-		$paypal_args = apply_filters(
167
-			'getpaid_paypal_args',
168
-			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
171
-			),
172
-			$invoice
173
-		);
174
-
175
-		return $this->fix_request_length( $invoice, $paypal_args );
160
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
+
162
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
+            $force_one_line_item = true;
164
+        }
165
+
166
+        $paypal_args = apply_filters(
167
+            'getpaid_paypal_args',
168
+            array_merge(
169
+                $this->get_transaction_args( $invoice ),
170
+                $this->get_line_item_args( $invoice, $force_one_line_item )
171
+            ),
172
+            $invoice
173
+        );
174
+
175
+        return $this->fix_request_length( $invoice, $paypal_args );
176 176
     }
177 177
 
178 178
     /**
179
-	 * Get transaction args for paypal request.
180
-	 *
181
-	 * @param WPInv_Invoice $invoice Invoice object.
182
-	 * @return array
183
-	 */
184
-	protected function get_transaction_args( $invoice ) {
185
-
186
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
-		return array(
179
+     * Get transaction args for paypal request.
180
+     *
181
+     * @param WPInv_Invoice $invoice Invoice object.
182
+     * @return array
183
+     */
184
+    protected function get_transaction_args( $invoice ) {
185
+
186
+        $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
+        return array(
188 188
             'cmd'           => '_cart',
189 189
             'business'      => $email,
190 190
             'no_shipping'   => '1',
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get line item args for paypal request.
213
-	 *
214
-	 * @param  WPInv_Invoice $invoice Invoice object.
215
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
216
-	 * @return array
217
-	 */
218
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
212
+     * Get line item args for paypal request.
213
+     *
214
+     * @param  WPInv_Invoice $invoice Invoice object.
215
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
216
+     * @return array
217
+     */
218
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
219 219
 
220 220
         // Maybe send invoice as a single item.
221
-		if ( $force_one_line_item ) {
221
+        if ( $force_one_line_item ) {
222 222
             return $this->get_line_item_args_single_item( $invoice );
223 223
         }
224 224
 
@@ -238,129 +238,129 @@  discard block
 block discarded – undo
238 238
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
239 239
         }
240 240
 
241
-		return array_merge( $line_item_args, $this->get_line_items() );
241
+        return array_merge( $line_item_args, $this->get_line_items() );
242 242
 
243 243
     }
244 244
 
245 245
     /**
246
-	 * Get line item args for paypal request as a single line item.
247
-	 *
248
-	 * @param  WPInv_Invoice $invoice Invoice object.
249
-	 * @return array
250
-	 */
251
-	protected function get_line_item_args_single_item( $invoice ) {
252
-		$this->delete_line_items();
246
+     * Get line item args for paypal request as a single line item.
247
+     *
248
+     * @param  WPInv_Invoice $invoice Invoice object.
249
+     * @return array
250
+     */
251
+    protected function get_line_item_args_single_item( $invoice ) {
252
+        $this->delete_line_items();
253 253
 
254 254
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
255
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
255
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
256 256
 
257
-		return $this->get_line_items();
257
+        return $this->get_line_items();
258 258
     }
259 259
 
260 260
     /**
261
-	 * Return all line items.
262
-	 */
263
-	protected function get_line_items() {
264
-		return $this->line_items;
265
-	}
261
+     * Return all line items.
262
+     */
263
+    protected function get_line_items() {
264
+        return $this->line_items;
265
+    }
266 266
 
267 267
     /**
268
-	 * Remove all line items.
269
-	 */
270
-	protected function delete_line_items() {
271
-		$this->line_items = array();
268
+     * Remove all line items.
269
+     */
270
+    protected function delete_line_items() {
271
+        $this->line_items = array();
272 272
     }
273 273
 
274 274
     /**
275
-	 * Prepare line items to send to paypal.
276
-	 *
277
-	 * @param  WPInv_Invoice $invoice Invoice object.
278
-	 */
279
-	protected function prepare_line_items( $invoice ) {
280
-		$this->delete_line_items();
281
-
282
-		// Items.
283
-		foreach ( $invoice->get_items() as $item ) {
284
-			$amount   = $item->get_price();
285
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
275
+     * Prepare line items to send to paypal.
276
+     *
277
+     * @param  WPInv_Invoice $invoice Invoice object.
278
+     */
279
+    protected function prepare_line_items( $invoice ) {
280
+        $this->delete_line_items();
281
+
282
+        // Items.
283
+        foreach ( $invoice->get_items() as $item ) {
284
+            $amount   = $item->get_price();
285
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
287 287
         }
288 288
 
289 289
         // Fees.
290
-		foreach ( $invoice->get_fees() as $fee => $data ) {
290
+        foreach ( $invoice->get_fees() as $fee => $data ) {
291 291
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
292 292
         }
293 293
 
294 294
     }
295 295
 
296 296
     /**
297
-	 * Add PayPal Line Item.
298
-	 *
299
-	 * @param  string $item_name Item name.
300
-	 * @param  float    $quantity Item quantity.
301
-	 * @param  float  $amount Amount.
302
-	 * @param  string $item_number Item number.
303
-	 */
304
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
-		$index = ( count( $this->line_items ) / 4 ) + 1;
306
-
307
-		$item = apply_filters(
308
-			'getpaid_paypal_line_item',
309
-			array(
310
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
-				'quantity'    => (float) $quantity,
312
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
-				'item_number' => $item_number,
314
-			),
315
-			$item_name,
316
-			$quantity,
317
-			$amount,
318
-			$item_number
319
-		);
320
-
321
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
297
+     * Add PayPal Line Item.
298
+     *
299
+     * @param  string $item_name Item name.
300
+     * @param  float    $quantity Item quantity.
301
+     * @param  float  $amount Amount.
302
+     * @param  string $item_number Item number.
303
+     */
304
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
+        $index = ( count( $this->line_items ) / 4 ) + 1;
306
+
307
+        $item = apply_filters(
308
+            'getpaid_paypal_line_item',
309
+            array(
310
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
+                'quantity'    => (float) $quantity,
312
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
+                'item_number' => $item_number,
314
+            ),
315
+            $item_name,
316
+            $quantity,
317
+            $amount,
318
+            $item_number
319
+        );
320
+
321
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
322 322
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
323 323
 
324 324
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
325
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
325
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
327 327
     }
328 328
 
329 329
     /**
330
-	 * If the default request with line items is too long, generate a new one with only one line item.
331
-	 *
332
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
-	 *
334
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
336
-	 * @return array
337
-	 */
338
-	protected function fix_request_length( $invoice, $paypal_args ) {
339
-		$max_paypal_length = 2083;
340
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
341
-
342
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
-			return $paypal_args;
344
-		}
345
-
346
-		return apply_filters(
347
-			'getpaid_paypal_args',
348
-			array_merge(
349
-				$this->get_transaction_args( $invoice ),
350
-				$this->get_line_item_args( $invoice, true )
351
-			),
352
-			$invoice
353
-		);
330
+     * If the default request with line items is too long, generate a new one with only one line item.
331
+     *
332
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
+     *
334
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
336
+     * @return array
337
+     */
338
+    protected function fix_request_length( $invoice, $paypal_args ) {
339
+        $max_paypal_length = 2083;
340
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
341
+
342
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
+            return $paypal_args;
344
+        }
345
+
346
+        return apply_filters(
347
+            'getpaid_paypal_args',
348
+            array_merge(
349
+                $this->get_transaction_args( $invoice ),
350
+                $this->get_line_item_args( $invoice, true )
351
+            ),
352
+            $invoice
353
+        );
354 354
 
355 355
     }
356 356
 
357 357
     /**
358
-	 * Processes recurring invoices.
359
-	 *
360
-	 * @param  array $paypal_args PayPal args.
361
-	 * @param  WPInv_Invoice    $invoice Invoice object.
362
-	 */
363
-	public function process_subscription( $paypal_args, $invoice ) {
358
+     * Processes recurring invoices.
359
+     *
360
+     * @param  array $paypal_args PayPal args.
361
+     * @param  WPInv_Invoice    $invoice Invoice object.
362
+     */
363
+    public function process_subscription( $paypal_args, $invoice ) {
364 364
 
365 365
         // Make sure this is a subscription.
366 366
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
 
386 386
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
387 387
 
388
-			// Trial period length.
389
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
388
+            // Trial period length.
389
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
390 390
 
391
-			// Trial period.
392
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
391
+            // Trial period.
392
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
393 393
 
394 394
         } else if ( $initial_amount != $recurring_amount ) {
395 395
 
@@ -412,40 +412,40 @@  discard block
 block discarded – undo
412 412
         }
413 413
 
414 414
         // We have a recurring payment
415
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
415
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
416 416
 
417
-			// Subscription price
418
-			$paypal_args['a3'] = $recurring_amount;
417
+            // Subscription price
418
+            $paypal_args['a3'] = $recurring_amount;
419 419
 
420
-			// Subscription duration
421
-			$paypal_args['p3'] = $interval;
420
+            // Subscription duration
421
+            $paypal_args['p3'] = $interval;
422 422
 
423
-			// Subscription period
424
-			$paypal_args['t3'] = $period;
423
+            // Subscription period
424
+            $paypal_args['t3'] = $period;
425 425
 
426 426
         }
427 427
 
428 428
         // Recurring payments
429
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
429
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
430 430
 
431
-			// Non-recurring payments
432
-			$paypal_args['src'] = 0;
431
+            // Non-recurring payments
432
+            $paypal_args['src'] = 0;
433 433
 
434
-		} else {
434
+        } else {
435 435
 
436
-			$paypal_args['src'] = 1;
436
+            $paypal_args['src'] = 1;
437 437
 
438
-			if ( $bill_times > 0 ) {
438
+            if ( $bill_times > 0 ) {
439 439
 
440
-				// An initial period is being used to charge a sign-up fee
441
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
442
-					$bill_times--;
443
-				}
440
+                // An initial period is being used to charge a sign-up fee
441
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
442
+                    $bill_times--;
443
+                }
444 444
 
445 445
                 // Make sure it's not over the max of 52
446 446
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
447 447
 
448
-			}
448
+            }
449 449
         }
450 450
 
451 451
         // Force return URL so that order description & instructions display
@@ -461,19 +461,19 @@  discard block
 block discarded – undo
461 461
         }
462 462
 
463 463
         return apply_filters(
464
-			'getpaid_paypal_subscription_args',
465
-			$paypal_args,
466
-			$invoice
464
+            'getpaid_paypal_subscription_args',
465
+            $paypal_args,
466
+            $invoice
467 467
         );
468 468
 
469 469
     }
470 470
 
471 471
     /**
472
-	 * Processes ipns and marks payments as complete.
473
-	 *
474
-	 * @return void
475
-	 */
476
-	public function verify_ipn() {
472
+     * Processes ipns and marks payments as complete.
473
+     *
474
+     * @return void
475
+     */
476
+    public function verify_ipn() {
477 477
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
478 478
     }
479 479
 
@@ -483,19 +483,19 @@  discard block
 block discarded – undo
483 483
     public function sandbox_notice() {
484 484
 
485 485
         return sprintf(
486
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
487
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
488
-			'</a>'
489
-		);
486
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
487
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
488
+            '</a>'
489
+        );
490 490
 
491 491
     }
492 492
 
493
-	/**
494
-	 * Filters the gateway settings.
495
-	 *
496
-	 * @param array $admin_settings
497
-	 */
498
-	public function admin_settings( $admin_settings ) {
493
+    /**
494
+     * Filters the gateway settings.
495
+     *
496
+     * @param array $admin_settings
497
+     */
498
+    public function admin_settings( $admin_settings ) {
499 499
 
500 500
         $currencies = sprintf(
501 501
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -505,39 +505,39 @@  discard block
 block discarded – undo
505 505
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
506 506
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
507 507
 
508
-		// Access tokens.
509
-		$live_email      = wpinv_get_option( 'paypal_email' );
510
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
511
-
512
-		$admin_settings['paypal_connect'] = array(
513
-			'type'       => 'raw_html',
514
-			'id'         => 'paypal_connect',
515
-			'name'       => __( 'Connect to PayPal', 'invoicing' ),
516
-			'desc'       => sprintf(
517
-				'<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s',
518
-				esc_url( self::get_connect_url( false ) ),
519
-				__( 'Connect to PayPal', 'invoicing' ),
520
-				esc_url( self::get_connect_url( true ) ),
521
-				__( 'Connect to PayPal Sandox', 'invoicing' ),
522
-				$this->get_js()
523
-			),
524
-		);
508
+        // Access tokens.
509
+        $live_email      = wpinv_get_option( 'paypal_email' );
510
+        $sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
511
+
512
+        $admin_settings['paypal_connect'] = array(
513
+            'type'       => 'raw_html',
514
+            'id'         => 'paypal_connect',
515
+            'name'       => __( 'Connect to PayPal', 'invoicing' ),
516
+            'desc'       => sprintf(
517
+                '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s',
518
+                esc_url( self::get_connect_url( false ) ),
519
+                __( 'Connect to PayPal', 'invoicing' ),
520
+                esc_url( self::get_connect_url( true ) ),
521
+                __( 'Connect to PayPal Sandox', 'invoicing' ),
522
+                $this->get_js()
523
+            ),
524
+        );
525 525
 
526 526
         $admin_settings['paypal_email'] = array(
527 527
             'type'  => 'text',
528
-			'class' => 'live-auth-data',
528
+            'class' => 'live-auth-data',
529 529
             'id'    => 'paypal_email',
530 530
             'name'  => __( 'Live Email Address', 'invoicing' ),
531 531
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
532 532
         );
533 533
 
534
-		$admin_settings['paypal_sandbox_email'] = array(
534
+        $admin_settings['paypal_sandbox_email'] = array(
535 535
             'type'  => 'text',
536
-			'class' => 'sandbox-auth-data',
536
+            'class' => 'sandbox-auth-data',
537 537
             'id'    => 'paypal_sandbox_email',
538 538
             'name'  => __( 'Sandbox Email Address', 'invoicing' ),
539 539
             'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
540
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
540
+            'std'   => wpinv_get_option( 'paypal_email', '' ),
541 541
         );
542 542
 
543 543
         $admin_settings['paypal_ipn_url'] = array(
@@ -549,29 +549,29 @@  discard block
 block discarded – undo
549 549
             'readonly' => true,
550 550
         );
551 551
 
552
-		return $admin_settings;
553
-	}
552
+        return $admin_settings;
553
+    }
554 554
 
555
-	/**
556
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
557
-	 *
558
-	 *
555
+    /**
556
+     * Retrieves the PayPal connect URL when using the setup wizzard.
557
+     *
558
+     *
559 559
      * @param array $data
560 560
      * @return string
561
-	 */
562
-	public static function maybe_get_connect_url( $url = '', $data ) {
563
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
564
-	}
565
-
566
-	/**
567
-	 * Retrieves the PayPal connect URL.
568
-	 *
569
-	 *
561
+     */
562
+    public static function maybe_get_connect_url( $url = '', $data ) {
563
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
564
+    }
565
+
566
+    /**
567
+     * Retrieves the PayPal connect URL.
568
+     *
569
+     *
570 570
      * @param bool $is_sandbox
571
-	 * @param string $redirect
571
+     * @param string $redirect
572 572
      * @return string
573
-	 */
574
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
573
+     */
574
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
575 575
 
576 576
         $redirect_url = add_query_arg(
577 577
             array(
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
                 'tab'                  => 'gateways',
582 582
                 'section'              => 'paypal',
583 583
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
584
-				'redirect'             => urlencode( $redirect ),
584
+                'redirect'             => urlencode( $redirect ),
585 585
             ),
586 586
             admin_url( 'admin.php' )
587 587
         );
@@ -596,12 +596,12 @@  discard block
 block discarded – undo
596 596
 
597 597
     }
598 598
 
599
-	/**
600
-	 * Generates settings page js.
601
-	 *
599
+    /**
600
+     * Generates settings page js.
601
+     *
602 602
      * @return void
603
-	 */
604
-	public static function get_js() {
603
+     */
604
+    public static function get_js() {
605 605
         ob_start();
606 606
         ?>
607 607
             <script>
@@ -637,72 +637,72 @@  discard block
 block discarded – undo
637 637
         return ob_get_clean();
638 638
     }
639 639
 
640
-	/**
641
-	 * Connects to PayPal.
642
-	 *
643
-	 * @param array $data Connection data.
644
-	 * @return void
645
-	 */
646
-	public function connect_paypal( $data ) {
647
-
648
-		$sandbox      = $this->is_sandbox();
649
-		$data         = wp_unslash( $data );
650
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
651
-
652
-		if ( isset( $data['live_mode'] ) ) {
653
-			$sandbox = empty( $data['live_mode'] );
654
-		}
655
-
656
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
657
-		wpinv_update_option( 'paypal_active', 1 );
658
-
659
-		if ( ! empty( $data['error_description'] ) ) {
660
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
661
-		} else {
662
-
663
-			// Retrieve the user info.
664
-			$user_info = wp_remote_get(
665
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
666
-				array(
667
-
668
-					'headers' => array(
669
-						'Authorization' => 'Bearer ' . $access_token,
670
-						'Content-type'  => 'application/json',
671
-					)
672
-
673
-				)
674
-			);
675
-
676
-			if ( is_wp_error( $user_info ) ) {
677
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
678
-			} else {
679
-
680
-				// Create application.
681
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
682
-
683
-				if ( $sandbox ) {
684
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
685
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
686
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
687
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
688
-				} else {
689
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
690
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
691
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
692
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
693
-				}
694
-
695
-			}
696
-
697
-		}
698
-
699
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
700
-
701
-		if ( isset( $data['step'] ) ) {
702
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
703
-		}
704
-		wp_redirect( $redirect );
705
-		exit;
706
-	}
640
+    /**
641
+     * Connects to PayPal.
642
+     *
643
+     * @param array $data Connection data.
644
+     * @return void
645
+     */
646
+    public function connect_paypal( $data ) {
647
+
648
+        $sandbox      = $this->is_sandbox();
649
+        $data         = wp_unslash( $data );
650
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
651
+
652
+        if ( isset( $data['live_mode'] ) ) {
653
+            $sandbox = empty( $data['live_mode'] );
654
+        }
655
+
656
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
657
+        wpinv_update_option( 'paypal_active', 1 );
658
+
659
+        if ( ! empty( $data['error_description'] ) ) {
660
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
661
+        } else {
662
+
663
+            // Retrieve the user info.
664
+            $user_info = wp_remote_get(
665
+                ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
666
+                array(
667
+
668
+                    'headers' => array(
669
+                        'Authorization' => 'Bearer ' . $access_token,
670
+                        'Content-type'  => 'application/json',
671
+                    )
672
+
673
+                )
674
+            );
675
+
676
+            if ( is_wp_error( $user_info ) ) {
677
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
678
+            } else {
679
+
680
+                // Create application.
681
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
682
+
683
+                if ( $sandbox ) {
684
+                    wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
685
+                    wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
686
+                    set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
687
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
688
+                } else {
689
+                    wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
690
+                    wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
691
+                    set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
692
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
693
+                }
694
+
695
+            }
696
+
697
+        }
698
+
699
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
700
+
701
+        if ( isset( $data['step'] ) ) {
702
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
703
+        }
704
+        wp_redirect( $redirect );
705
+        exit;
706
+    }
707 707
 
708 708
 }
Please login to merge, or discard this patch.
invoicing.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@  discard block
 block discarded – undo
19 19
 
20 20
 // Define constants.
21 21
 if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+    define( 'WPINV_PLUGIN_FILE', __FILE__ );
23 23
 }
24 24
 
25 25
 if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.4.4' );
26
+    define( 'WPINV_VERSION', '2.4.4' );
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30 30
 if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
31
+    require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
46
-	return $GLOBALS['invoicing'];
46
+    return $GLOBALS['invoicing'];
47 47
 }
48 48
 
49 49
 /**
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Indentation   +477 added lines, -477 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,542 +15,542 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'_wpinv_phone',
34
-		'_wpinv_company_id',
35
-		'wpinv_email_cc',
36
-		'wpinv_template',
37
-		'wpinv_created_via'
38
-	);
39
-
40
-	/**
41
-	 * A map of meta keys to data props.
42
-	 *
43
-	 * @since 1.0.19
44
-	 *
45
-	 * @var array
46
-	 */
47
-	protected $meta_key_to_props = array(
48
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
49
-		'_wpinv_subscription_id'   => 'subscription_id',
50
-		'_wpinv_taxes'             => 'taxes',
51
-		'_wpinv_fees'              => 'fees',
52
-		'_wpinv_discounts'         => 'discounts',
53
-		'_wpinv_submission_id'     => 'submission_id',
54
-		'_wpinv_payment_form'      => 'payment_form',
55
-		'_wpinv_is_viewed'         => 'is_viewed',
56
-		'wpinv_email_cc'           => 'email_cc',
57
-		'wpinv_template'           => 'template',
58
-		'wpinv_created_via'        => 'created_via',
59
-		'_wpinv_phone'             => 'phone',
60
-		'_wpinv_company_id'        => 'company_id',
61
-	);
62
-
63
-	/**
64
-	 * A map of database fields to data props.
65
-	 *
66
-	 * @since 1.0.19
67
-	 *
68
-	 * @var array
69
-	 */
70
-	protected $database_fields_to_props = array(
71
-		'post_id'            => 'id',
72
-		'number'             => 'number',
73
-		'currency'           => 'currency',
74
-		'key'                => 'key',
75
-		'type'               => 'type',
76
-		'mode'               => 'mode',
77
-		'user_ip'            => 'user_ip',
78
-		'first_name'         => 'first_name',
79
-		'last_name'          => 'last_name',
80
-		'address'            => 'address',
81
-		'city'               => 'city',
82
-		'state'              => 'state',
83
-		'country'            => 'country',
84
-		'zip'                => 'zip',
85
-		'zip'                => 'zip',
86
-		'adddress_confirmed' => 'address_confirmed',
87
-		'gateway'            => 'gateway',
88
-		'transaction_id'     => 'transaction_id',
89
-		'currency'           => 'currency',
90
-		'subtotal'           => 'subtotal',
91
-		'tax'                => 'total_tax',
92
-		'fees_total'         => 'total_fees',
93
-		'discount'           => 'total_discount',
94
-		'total'              => 'total',
95
-		'discount_code'      => 'discount_code',
96
-		'disable_taxes'      => 'disable_taxes',
97
-		'due_date'           => 'due_date',
98
-		'completed_date'     => 'completed_date',
99
-		'company'            => 'company',
100
-		'vat_number'         => 'vat_number',
101
-		'vat_rate'           => 'vat_rate',
102
-	);
103
-
104
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        '_wpinv_phone',
34
+        '_wpinv_company_id',
35
+        'wpinv_email_cc',
36
+        'wpinv_template',
37
+        'wpinv_created_via'
38
+    );
39
+
40
+    /**
41
+     * A map of meta keys to data props.
42
+     *
43
+     * @since 1.0.19
44
+     *
45
+     * @var array
46
+     */
47
+    protected $meta_key_to_props = array(
48
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
49
+        '_wpinv_subscription_id'   => 'subscription_id',
50
+        '_wpinv_taxes'             => 'taxes',
51
+        '_wpinv_fees'              => 'fees',
52
+        '_wpinv_discounts'         => 'discounts',
53
+        '_wpinv_submission_id'     => 'submission_id',
54
+        '_wpinv_payment_form'      => 'payment_form',
55
+        '_wpinv_is_viewed'         => 'is_viewed',
56
+        'wpinv_email_cc'           => 'email_cc',
57
+        'wpinv_template'           => 'template',
58
+        'wpinv_created_via'        => 'created_via',
59
+        '_wpinv_phone'             => 'phone',
60
+        '_wpinv_company_id'        => 'company_id',
61
+    );
62
+
63
+    /**
64
+     * A map of database fields to data props.
65
+     *
66
+     * @since 1.0.19
67
+     *
68
+     * @var array
69
+     */
70
+    protected $database_fields_to_props = array(
71
+        'post_id'            => 'id',
72
+        'number'             => 'number',
73
+        'currency'           => 'currency',
74
+        'key'                => 'key',
75
+        'type'               => 'type',
76
+        'mode'               => 'mode',
77
+        'user_ip'            => 'user_ip',
78
+        'first_name'         => 'first_name',
79
+        'last_name'          => 'last_name',
80
+        'address'            => 'address',
81
+        'city'               => 'city',
82
+        'state'              => 'state',
83
+        'country'            => 'country',
84
+        'zip'                => 'zip',
85
+        'zip'                => 'zip',
86
+        'adddress_confirmed' => 'address_confirmed',
87
+        'gateway'            => 'gateway',
88
+        'transaction_id'     => 'transaction_id',
89
+        'currency'           => 'currency',
90
+        'subtotal'           => 'subtotal',
91
+        'tax'                => 'total_tax',
92
+        'fees_total'         => 'total_fees',
93
+        'discount'           => 'total_discount',
94
+        'total'              => 'total',
95
+        'discount_code'      => 'discount_code',
96
+        'disable_taxes'      => 'disable_taxes',
97
+        'due_date'           => 'due_date',
98
+        'completed_date'     => 'completed_date',
99
+        'company'            => 'company',
100
+        'vat_number'         => 'vat_number',
101
+        'vat_rate'           => 'vat_rate',
102
+    );
103
+
104
+    /*
105 105
 	|--------------------------------------------------------------------------
106 106
 	| CRUD Methods
107 107
 	|--------------------------------------------------------------------------
108 108
 	*/
109 109
 
110
-	/**
111
-	 * Method to create a new invoice in the database.
112
-	 *
113
-	 * @param WPInv_Invoice $invoice Invoice object.
114
-	 */
115
-	public function create( &$invoice ) {
116
-		$invoice->set_version( WPINV_VERSION );
117
-		$invoice->set_date_created( current_time('mysql') );
118
-
119
-		// Create a new post.
120
-		$id = wp_insert_post(
121
-			apply_filters(
122
-				'getpaid_new_invoice_data',
123
-				array(
124
-					'post_date'     => $invoice->get_date_created( 'edit' ),
125
-					'post_type'     => $invoice->get_post_type( 'edit' ),
126
-					'post_status'   => $this->get_post_status( $invoice ),
127
-					'ping_status'   => 'closed',
128
-					'post_author'   => $invoice->get_user_id( 'edit' ),
129
-					'post_title'    => $invoice->get_title( 'edit' ),
130
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
131
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
132
-				)
133
-			),
134
-			true
135
-		);
136
-
137
-		if ( $id && ! is_wp_error( $id ) ) {
138
-
139
-			// Update the new id and regenerate a title.
140
-			$invoice->set_id( $id );
141
-
142
-			$invoice->maybe_set_number();
143
-
144
-			wp_update_post(
145
-				array(
146
-					'ID'         => $invoice->get_id(),
147
-					'post_title' => $invoice->get_number( 'edit' ),
148
-					'post_name'  => $invoice->get_path( 'edit' )
149
-				)
150
-			);
151
-
152
-			// Save special fields and items.
153
-			$this->save_special_fields( $invoice );
154
-			$this->save_items( $invoice );
155
-
156
-			// Update meta data.
157
-			$this->update_post_meta( $invoice );
158
-			$invoice->save_meta_data();
159
-
160
-			// Apply changes.
161
-			$invoice->apply_changes();
162
-			$this->clear_caches( $invoice );
163
-
164
-			// Fires after a new invoice is created.
165
-			do_action( 'getpaid_new_invoice', $invoice );
166
-			return true;
167
-		}
168
-
169
-		if ( is_wp_error( $id ) ) {
170
-			$invoice->last_error = $id->get_error_message();
171
-		}
172
-
173
-		return false;
174
-	}
175
-
176
-	/**
177
-	 * Method to read an invoice from the database.
178
-	 *
179
-	 * @param WPInv_Invoice $invoice Invoice object.
180
-	 *
181
-	 */
182
-	public function read( &$invoice ) {
183
-
184
-		$invoice->set_defaults();
185
-		$invoice_object = get_post( $invoice->get_id() );
186
-
187
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
188
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
189
-			$invoice->set_id( 0 );
190
-			return false;
191
-		}
192
-
193
-		$invoice->set_props(
194
-			array(
195
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
196
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
197
-				'status'        => $invoice_object->post_status,
198
-				'author'        => $invoice_object->post_author,
199
-				'description'   => $invoice_object->post_excerpt,
200
-				'parent_id'     => $invoice_object->post_parent,
201
-				'name'          => $invoice_object->post_title,
202
-				'path'          => $invoice_object->post_name,
203
-				'post_type'     => $invoice_object->post_type,
204
-			)
205
-		);
206
-
207
-		$invoice->set_type( $invoice_object->post_type );
208
-
209
-		$this->read_object_data( $invoice, $invoice_object );
210
-		$this->add_special_fields( $invoice );
211
-		$this->add_items( $invoice );
212
-		$invoice->read_meta_data();
213
-		$invoice->set_object_read( true );
214
-		do_action( 'getpaid_read_invoice', $invoice );
215
-
216
-	}
217
-
218
-	/**
219
-	 * Method to update an invoice in the database.
220
-	 *
221
-	 * @param WPInv_Invoice $invoice Invoice object.
222
-	 */
223
-	public function update( &$invoice ) {
224
-		$invoice->save_meta_data();
225
-		$invoice->set_version( WPINV_VERSION );
226
-
227
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
228
-			$invoice->set_date_created(  current_time('mysql') );
229
-		}
230
-
231
-		// Ensure both the key and number are set.
232
-		$invoice->get_path();
233
-
234
-		// Grab the current status so we can compare.
235
-		$previous_status = get_post_status( $invoice->get_id() );
236
-
237
-		$changes = $invoice->get_changes();
238
-
239
-		// Only update the post when the post data changes.
240
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
241
-			$post_data = array(
242
-				'post_date'         => $invoice->get_date_created( 'edit' ),
243
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
244
-				'post_status'       => $invoice->get_status( 'edit' ),
245
-				'post_title'        => $invoice->get_name( 'edit' ),
246
-				'post_author'       => $invoice->get_user_id( 'edit' ),
247
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
248
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
249
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
250
-				'post_name'         => $invoice->get_path( 'edit' ),
251
-				'post_type'         => $invoice->get_post_type( 'edit' ),
252
-			);
253
-
254
-			/**
255
-			 * When updating this object, to prevent infinite loops, use $wpdb
256
-			 * to update data, since wp_update_post spawns more calls to the
257
-			 * save_post action.
258
-			 *
259
-			 * This ensures hooks are fired by either WP itself (admin screen save),
260
-			 * or an update purely from CRUD.
261
-			 */
262
-			if ( doing_action( 'save_post' ) ) {
263
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
264
-				clean_post_cache( $invoice->get_id() );
265
-			} else {
266
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
267
-			}
268
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
269
-		}
270
-
271
-		// Update meta data.
272
-		$this->update_post_meta( $invoice );
273
-
274
-		// Save special fields and items.
275
-		$this->save_special_fields( $invoice );
276
-		$this->save_items( $invoice );
277
-
278
-		// Apply the changes.
279
-		$invoice->apply_changes();
280
-
281
-		// Clear caches.
282
-		$this->clear_caches( $invoice );
283
-
284
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
285
-		$new_status = $invoice->get_status( 'edit' );
286
-
287
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
288
-			do_action( 'getpaid_new_invoice', $invoice );
289
-		} else {
290
-			do_action( 'getpaid_update_invoice', $invoice );
291
-		}
292
-
293
-	}
294
-
295
-	/*
110
+    /**
111
+     * Method to create a new invoice in the database.
112
+     *
113
+     * @param WPInv_Invoice $invoice Invoice object.
114
+     */
115
+    public function create( &$invoice ) {
116
+        $invoice->set_version( WPINV_VERSION );
117
+        $invoice->set_date_created( current_time('mysql') );
118
+
119
+        // Create a new post.
120
+        $id = wp_insert_post(
121
+            apply_filters(
122
+                'getpaid_new_invoice_data',
123
+                array(
124
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
125
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
126
+                    'post_status'   => $this->get_post_status( $invoice ),
127
+                    'ping_status'   => 'closed',
128
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
129
+                    'post_title'    => $invoice->get_title( 'edit' ),
130
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
131
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
132
+                )
133
+            ),
134
+            true
135
+        );
136
+
137
+        if ( $id && ! is_wp_error( $id ) ) {
138
+
139
+            // Update the new id and regenerate a title.
140
+            $invoice->set_id( $id );
141
+
142
+            $invoice->maybe_set_number();
143
+
144
+            wp_update_post(
145
+                array(
146
+                    'ID'         => $invoice->get_id(),
147
+                    'post_title' => $invoice->get_number( 'edit' ),
148
+                    'post_name'  => $invoice->get_path( 'edit' )
149
+                )
150
+            );
151
+
152
+            // Save special fields and items.
153
+            $this->save_special_fields( $invoice );
154
+            $this->save_items( $invoice );
155
+
156
+            // Update meta data.
157
+            $this->update_post_meta( $invoice );
158
+            $invoice->save_meta_data();
159
+
160
+            // Apply changes.
161
+            $invoice->apply_changes();
162
+            $this->clear_caches( $invoice );
163
+
164
+            // Fires after a new invoice is created.
165
+            do_action( 'getpaid_new_invoice', $invoice );
166
+            return true;
167
+        }
168
+
169
+        if ( is_wp_error( $id ) ) {
170
+            $invoice->last_error = $id->get_error_message();
171
+        }
172
+
173
+        return false;
174
+    }
175
+
176
+    /**
177
+     * Method to read an invoice from the database.
178
+     *
179
+     * @param WPInv_Invoice $invoice Invoice object.
180
+     *
181
+     */
182
+    public function read( &$invoice ) {
183
+
184
+        $invoice->set_defaults();
185
+        $invoice_object = get_post( $invoice->get_id() );
186
+
187
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
188
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
189
+            $invoice->set_id( 0 );
190
+            return false;
191
+        }
192
+
193
+        $invoice->set_props(
194
+            array(
195
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
196
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
197
+                'status'        => $invoice_object->post_status,
198
+                'author'        => $invoice_object->post_author,
199
+                'description'   => $invoice_object->post_excerpt,
200
+                'parent_id'     => $invoice_object->post_parent,
201
+                'name'          => $invoice_object->post_title,
202
+                'path'          => $invoice_object->post_name,
203
+                'post_type'     => $invoice_object->post_type,
204
+            )
205
+        );
206
+
207
+        $invoice->set_type( $invoice_object->post_type );
208
+
209
+        $this->read_object_data( $invoice, $invoice_object );
210
+        $this->add_special_fields( $invoice );
211
+        $this->add_items( $invoice );
212
+        $invoice->read_meta_data();
213
+        $invoice->set_object_read( true );
214
+        do_action( 'getpaid_read_invoice', $invoice );
215
+
216
+    }
217
+
218
+    /**
219
+     * Method to update an invoice in the database.
220
+     *
221
+     * @param WPInv_Invoice $invoice Invoice object.
222
+     */
223
+    public function update( &$invoice ) {
224
+        $invoice->save_meta_data();
225
+        $invoice->set_version( WPINV_VERSION );
226
+
227
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
228
+            $invoice->set_date_created(  current_time('mysql') );
229
+        }
230
+
231
+        // Ensure both the key and number are set.
232
+        $invoice->get_path();
233
+
234
+        // Grab the current status so we can compare.
235
+        $previous_status = get_post_status( $invoice->get_id() );
236
+
237
+        $changes = $invoice->get_changes();
238
+
239
+        // Only update the post when the post data changes.
240
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
241
+            $post_data = array(
242
+                'post_date'         => $invoice->get_date_created( 'edit' ),
243
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
244
+                'post_status'       => $invoice->get_status( 'edit' ),
245
+                'post_title'        => $invoice->get_name( 'edit' ),
246
+                'post_author'       => $invoice->get_user_id( 'edit' ),
247
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
248
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
249
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
250
+                'post_name'         => $invoice->get_path( 'edit' ),
251
+                'post_type'         => $invoice->get_post_type( 'edit' ),
252
+            );
253
+
254
+            /**
255
+             * When updating this object, to prevent infinite loops, use $wpdb
256
+             * to update data, since wp_update_post spawns more calls to the
257
+             * save_post action.
258
+             *
259
+             * This ensures hooks are fired by either WP itself (admin screen save),
260
+             * or an update purely from CRUD.
261
+             */
262
+            if ( doing_action( 'save_post' ) ) {
263
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
264
+                clean_post_cache( $invoice->get_id() );
265
+            } else {
266
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
267
+            }
268
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
269
+        }
270
+
271
+        // Update meta data.
272
+        $this->update_post_meta( $invoice );
273
+
274
+        // Save special fields and items.
275
+        $this->save_special_fields( $invoice );
276
+        $this->save_items( $invoice );
277
+
278
+        // Apply the changes.
279
+        $invoice->apply_changes();
280
+
281
+        // Clear caches.
282
+        $this->clear_caches( $invoice );
283
+
284
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
285
+        $new_status = $invoice->get_status( 'edit' );
286
+
287
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
288
+            do_action( 'getpaid_new_invoice', $invoice );
289
+        } else {
290
+            do_action( 'getpaid_update_invoice', $invoice );
291
+        }
292
+
293
+    }
294
+
295
+    /*
296 296
 	|--------------------------------------------------------------------------
297 297
 	| Additional Methods
298 298
 	|--------------------------------------------------------------------------
299 299
 	*/
300 300
 
301
-	/**
301
+    /**
302 302
      * Retrieves special fields and adds to the invoice.
303
-	 *
304
-	 * @param WPInv_Invoice $invoice Invoice object.
303
+     *
304
+     * @param WPInv_Invoice $invoice Invoice object.
305 305
      */
306 306
     public function add_special_fields( &$invoice ) {
307
-		global $wpdb;
307
+        global $wpdb;
308 308
 
309
-		// Maybe retrieve from the cache.
310
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
309
+        // Maybe retrieve from the cache.
310
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
311 311
 
312
-		// If not found, retrieve from the db.
313
-		if ( false === $data ) {
314
-			$table =  $wpdb->prefix . 'getpaid_invoices';
312
+        // If not found, retrieve from the db.
313
+        if ( false === $data ) {
314
+            $table =  $wpdb->prefix . 'getpaid_invoices';
315 315
 
316
-			$data  = $wpdb->get_row(
317
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
318
-				ARRAY_A
319
-			);
316
+            $data  = $wpdb->get_row(
317
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
318
+                ARRAY_A
319
+            );
320 320
 
321
-			// Update the cache with our data
322
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
321
+            // Update the cache with our data
322
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
323 323
 
324
-		}
324
+        }
325 325
 
326
-		// Abort if the data does not exist.
327
-		if ( empty( $data ) ) {
328
-			$invoice->set_object_read( true );
329
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
330
-			return;
331
-		}
326
+        // Abort if the data does not exist.
327
+        if ( empty( $data ) ) {
328
+            $invoice->set_object_read( true );
329
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
330
+            return;
331
+        }
332 332
 
333
-		$props = array();
333
+        $props = array();
334 334
 
335
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
335
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
336 336
 			
337
-			if ( $db_field == 'post_id' ) {
338
-				continue;
339
-			}
340
-
341
-			$props[ $prop ] = $data[ $db_field ];
342
-		}
343
-
344
-		$invoice->set_props( $props );
345
-
346
-	}
347
-
348
-	/**
349
-	 * Gets a list of special fields that need updated based on change state
350
-	 * or if they are present in the database or not.
351
-	 *
352
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
353
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
354
-	 */
355
-	protected function get_special_fields_to_update( $invoice ) {
356
-		$fields_to_update = array();
357
-		$changed_props   = $invoice->get_changes();
358
-
359
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
360
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
361
-			if ( array_key_exists( $prop, $changed_props ) ) {
362
-				$fields_to_update[ $database_field ] = $prop;
363
-			}
364
-		}
365
-
366
-		return $fields_to_update;
367
-	}
368
-
369
-	/**
370
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
371
-	 *
372
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
373
-	 * @since 1.0.19
374
-	 */
375
-	protected function update_special_fields( &$invoice ) {
376
-		global $wpdb;
377
-
378
-		$updated_props    = array();
379
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
380
-
381
-		foreach ( $fields_to_update as $database_field => $prop ) {
382
-			$value = $invoice->{"get_$prop"}( 'edit' );
383
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
384
-			$value = is_bool( $value ) ? ( int ) $value : $value;
385
-			$updated_props[ $database_field ] = maybe_serialize( $value );
386
-		}
387
-
388
-		if ( ! empty( $updated_props ) ) {
389
-
390
-			$table = $wpdb->prefix . 'getpaid_invoices';
391
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
392
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
393
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
394
-
395
-		}
396
-
397
-	}
398
-
399
-	/**
400
-	 * Helper method that inserts special fields to the database.
401
-	 *
402
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
403
-	 * @since 1.0.19
404
-	 */
405
-	protected function insert_special_fields( &$invoice ) {
406
-		global $wpdb;
407
-
408
-		$updated_props   = array();
409
-
410
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
411
-			$value = $invoice->{"get_$prop"}( 'edit' );
412
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
413
-			$value = is_bool( $value ) ? ( int ) $value : $value;
414
-			$updated_props[ $database_field ] = maybe_serialize( $value );
415
-		}
416
-
417
-		$table = $wpdb->prefix . 'getpaid_invoices';
418
-		$wpdb->insert( $table, $updated_props );
419
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
420
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
421
-
422
-	}
423
-
424
-	/**
337
+            if ( $db_field == 'post_id' ) {
338
+                continue;
339
+            }
340
+
341
+            $props[ $prop ] = $data[ $db_field ];
342
+        }
343
+
344
+        $invoice->set_props( $props );
345
+
346
+    }
347
+
348
+    /**
349
+     * Gets a list of special fields that need updated based on change state
350
+     * or if they are present in the database or not.
351
+     *
352
+     * @param  WPInv_Invoice $invoice       The Invoice object.
353
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
354
+     */
355
+    protected function get_special_fields_to_update( $invoice ) {
356
+        $fields_to_update = array();
357
+        $changed_props   = $invoice->get_changes();
358
+
359
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
360
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
361
+            if ( array_key_exists( $prop, $changed_props ) ) {
362
+                $fields_to_update[ $database_field ] = $prop;
363
+            }
364
+        }
365
+
366
+        return $fields_to_update;
367
+    }
368
+
369
+    /**
370
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
371
+     *
372
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
373
+     * @since 1.0.19
374
+     */
375
+    protected function update_special_fields( &$invoice ) {
376
+        global $wpdb;
377
+
378
+        $updated_props    = array();
379
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
380
+
381
+        foreach ( $fields_to_update as $database_field => $prop ) {
382
+            $value = $invoice->{"get_$prop"}( 'edit' );
383
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
384
+            $value = is_bool( $value ) ? ( int ) $value : $value;
385
+            $updated_props[ $database_field ] = maybe_serialize( $value );
386
+        }
387
+
388
+        if ( ! empty( $updated_props ) ) {
389
+
390
+            $table = $wpdb->prefix . 'getpaid_invoices';
391
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
392
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
393
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
394
+
395
+        }
396
+
397
+    }
398
+
399
+    /**
400
+     * Helper method that inserts special fields to the database.
401
+     *
402
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
403
+     * @since 1.0.19
404
+     */
405
+    protected function insert_special_fields( &$invoice ) {
406
+        global $wpdb;
407
+
408
+        $updated_props   = array();
409
+
410
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
411
+            $value = $invoice->{"get_$prop"}( 'edit' );
412
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
413
+            $value = is_bool( $value ) ? ( int ) $value : $value;
414
+            $updated_props[ $database_field ] = maybe_serialize( $value );
415
+        }
416
+
417
+        $table = $wpdb->prefix . 'getpaid_invoices';
418
+        $wpdb->insert( $table, $updated_props );
419
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
420
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
421
+
422
+    }
423
+
424
+    /**
425 425
      * Saves all special fields.
426
-	 *
427
-	 * @param WPInv_Invoice $invoice Invoice object.
426
+     *
427
+     * @param WPInv_Invoice $invoice Invoice object.
428 428
      */
429 429
     public function save_special_fields( & $invoice ) {
430
-		global $wpdb;
430
+        global $wpdb;
431 431
 
432
-		// The invoices table.
433
-		$table = $wpdb->prefix . 'getpaid_invoices';
434
-		$id    = (int) $invoice->get_id();
435
-		$invoice->maybe_set_key();
432
+        // The invoices table.
433
+        $table = $wpdb->prefix . 'getpaid_invoices';
434
+        $id    = (int) $invoice->get_id();
435
+        $invoice->maybe_set_key();
436 436
 
437
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
437
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
438 438
 
439
-			$this->update_special_fields( $invoice );
439
+            $this->update_special_fields( $invoice );
440 440
 
441
-		} else {
441
+        } else {
442 442
 
443
-			$this->insert_special_fields( $invoice );
443
+            $this->insert_special_fields( $invoice );
444 444
 
445
-		}
445
+        }
446 446
 
447
-	}
447
+    }
448 448
 
449
-	/**
449
+    /**
450 450
      * Set's up cart details.
451
-	 *
452
-	 * @param WPInv_Invoice $invoice Invoice object.
451
+     *
452
+     * @param WPInv_Invoice $invoice Invoice object.
453 453
      */
454 454
     public function add_items( &$invoice ) {
455
-		global $wpdb;
455
+        global $wpdb;
456 456
 
457
-		// Maybe retrieve from the cache.
458
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
457
+        // Maybe retrieve from the cache.
458
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
459 459
 
460
-		// If not found, retrieve from the db.
461
-		if ( false === $items ) {
462
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
460
+        // If not found, retrieve from the db.
461
+        if ( false === $items ) {
462
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
463 463
 
464
-			$items = $wpdb->get_results(
465
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
466
-			);
464
+            $items = $wpdb->get_results(
465
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
466
+            );
467 467
 
468
-			// Update the cache with our data
469
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
468
+            // Update the cache with our data
469
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
470 470
 
471
-		}
471
+        }
472 472
 
473
-		// Abort if no items found.
473
+        // Abort if no items found.
474 474
         if ( empty( $items ) ) {
475 475
             return;
476
-		}
477
-
478
-		$_items = array();
479
-		foreach ( $items as $item_data ) {
480
-			$item = new GetPaid_Form_Item( $item_data->item_id );
481
-
482
-			// Set item data.
483
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
484
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
485
-			$item->set_name( $item_data->item_name );
486
-			$item->set_description( $item_data->item_description );
487
-			$item->set_price( $item_data->item_price );
488
-			$item->set_quantity( $item_data->quantity );
489
-			$item->set_item_meta( $item_data->meta );
490
-			$_items[] = $item;
491
-		}
492
-
493
-		$invoice->set_items( $_items );
494
-	}
495
-
496
-	/**
476
+        }
477
+
478
+        $_items = array();
479
+        foreach ( $items as $item_data ) {
480
+            $item = new GetPaid_Form_Item( $item_data->item_id );
481
+
482
+            // Set item data.
483
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
484
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
485
+            $item->set_name( $item_data->item_name );
486
+            $item->set_description( $item_data->item_description );
487
+            $item->set_price( $item_data->item_price );
488
+            $item->set_quantity( $item_data->quantity );
489
+            $item->set_item_meta( $item_data->meta );
490
+            $_items[] = $item;
491
+        }
492
+
493
+        $invoice->set_items( $_items );
494
+    }
495
+
496
+    /**
497 497
      * Saves cart details.
498
-	 *
499
-	 * @param WPInv_Invoice $invoice Invoice object.
498
+     *
499
+     * @param WPInv_Invoice $invoice Invoice object.
500 500
      */
501 501
     public function save_items( $invoice ) {
502 502
 
503
-		// Delete previously existing items.
504
-		$this->delete_items( $invoice );
503
+        // Delete previously existing items.
504
+        $this->delete_items( $invoice );
505 505
 
506
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
506
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
507 507
 
508
-		foreach ( $invoice->get_cart_details() as $item_data ) {
509
-			$item_data = array_map( 'maybe_serialize', $item_data );
510
-			$GLOBALS['wpdb']->insert( $table, $item_data );
511
-		}
508
+        foreach ( $invoice->get_cart_details() as $item_data ) {
509
+            $item_data = array_map( 'maybe_serialize', $item_data );
510
+            $GLOBALS['wpdb']->insert( $table, $item_data );
511
+        }
512 512
 
513
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
514
-		do_action( "getpaid_invoice_save_items", $invoice );
513
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
514
+        do_action( "getpaid_invoice_save_items", $invoice );
515 515
 
516
-	}
516
+    }
517 517
 
518
-	/**
518
+    /**
519 519
      * Deletes an invoice's cart details from the database.
520
-	 *
521
-	 * @param WPInv_Invoice $invoice Invoice object.
520
+     *
521
+     * @param WPInv_Invoice $invoice Invoice object.
522 522
      */
523 523
     public function delete_items( $invoice ) {
524
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
525
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
526
-	}
524
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
525
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
526
+    }
527 527
 
528
-	/**
528
+    /**
529 529
      * Deletes an invoice's special fields from the database.
530
-	 *
531
-	 * @param WPInv_Invoice $invoice Invoice object.
530
+     *
531
+     * @param WPInv_Invoice $invoice Invoice object.
532 532
      */
533 533
     public function delete_special_fields( $invoice ) {
534
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
535
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
536
-	}
534
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
535
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
536
+    }
537 537
 	
538
-	/**
539
-	 * Get the status to save to the post object.
540
-	 *
541
-	 *
542
-	 * @since 1.0.19
543
-	 * @param  WPInv_Invoice $object GetPaid_Data object.
544
-	 * @return string
545
-	 */
546
-	protected function get_post_status( $object ) {
547
-		$object_status = $object->get_status( 'edit' );
548
-
549
-		if ( ! $object_status ) {
550
-			$object_status = $object->get_default_status();
551
-		}
552
-
553
-		return $object_status;
554
-	}
538
+    /**
539
+     * Get the status to save to the post object.
540
+     *
541
+     *
542
+     * @since 1.0.19
543
+     * @param  WPInv_Invoice $object GetPaid_Data object.
544
+     * @return string
545
+     */
546
+    protected function get_post_status( $object ) {
547
+        $object_status = $object->get_status( 'edit' );
548
+
549
+        if ( ! $object_status ) {
550
+            $object_status = $object->get_default_status();
551
+        }
552
+
553
+        return $object_status;
554
+    }
555 555
 
556 556
 }
Please login to merge, or discard this patch.