Passed
Push — master ( 330418...c4952f )
by Brian
05:45 queued 27s
created
includes/class-wpinv-addons.php 1 patch
Indentation   +212 added lines, -212 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 = WPINV_PLUGIN_URL . 'assets/images/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 = WPINV_PLUGIN_URL . 'assets/images/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,9 +229,9 @@  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 235
 		<a
236 236
 			data-licence="<?php echo esc_attr($button_args['license']);?>"
237 237
 			data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>"
@@ -253,33 +253,33 @@  discard block
 block discarded – undo
253 253
 		<?php
254 254
 
255 255
 
256
-	}
257
-
258
-
259
-	/**
260
-	 * Handles output of the addons page in admin.
261
-	 */
262
-	public function output() {
263
-		$tabs            = self::get_tabs();
264
-		$sections        = self::get_sections();
265
-		$theme           = wp_get_theme();
266
-		$section_keys    = array_keys( $sections );
267
-		$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
268
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
269
-		include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' );
270
-	}
271
-
272
-	/**
273
-	 * A list of recommended wp.org plugins.
274
-	 * @return array
275
-	 */
276
-	public function get_recommend_wp_plugins(){
277
-		$plugins = array(
256
+    }
257
+
258
+
259
+    /**
260
+     * Handles output of the addons page in admin.
261
+     */
262
+    public function output() {
263
+        $tabs            = self::get_tabs();
264
+        $sections        = self::get_sections();
265
+        $theme           = wp_get_theme();
266
+        $section_keys    = array_keys( $sections );
267
+        $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
268
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
269
+        include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' );
270
+    }
271
+
272
+    /**
273
+     * A list of recommended wp.org plugins.
274
+     * @return array
275
+     */
276
+    public function get_recommend_wp_plugins(){
277
+        $plugins = array(
278 278
             'invoicing-quotes' => array(
279 279
                 'url'   => 'https://wordpress.org/plugins/invoicing-quotes/',
280 280
                 'slug'   => 'invoicing-quotes',
281
-				'name'   => 'Quotes',
282
-				'thumbnail'  => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
281
+                'name'   => 'Quotes',
282
+                'thumbnail'  => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
283 283
                 'desc'   => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'),
284 284
             ),
285 285
             'geodirectory' => array(
@@ -294,8 +294,8 @@  discard block
 block discarded – undo
294 294
                 'name'   => 'UsersWP',
295 295
                 'desc'   => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'),
296 296
             ),
297
-		);
297
+        );
298 298
 
299
-		return $plugins;
300
-	}
299
+        return $plugins;
300
+    }
301 301
 }
Please login to merge, or discard this patch.