PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.1.1
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.1.1
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / includes / class-addons.php

class-addons.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.1.1, at includes/class-addons.php

289 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UsersWP extensions screen related functions
4 *
5 * All UsersWP extensions screen related functions can be found here.
6 *
7 * @since 1.0.24
8 */
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * UsersWP_Admin_Addons Class.
15 */
16 class UsersWP_Admin_Addons extends Ayecode_Addons {
17
18
19 /**
20 * Get the extensions page tabs.
21 *
22 * @return array of tabs.
23 */
24 public function get_tabs(){
25 $tabs = array(
26 'addons' => __("Addons", "userswp"),
27 'recommended_plugins' => __("Recommended plugins", "userswp"),
28 'membership' => __("Membership", "userswp"),
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 = $this->get_tab( $section_id );
43 $api_url = "https://userswp.io/edd-api/v2/products/";
44 $section_data = new stdClass();
45
46 //echo '###'.$section_id;
47
48 if($section_id=='recommended_plugins'){
49 $section_data->products = $this->get_recommend_wp_plugins_edd_formatted();
50 }
51 elseif ( ! empty( $section ) ) {
52 if ( false === ( $section_data = get_transient( 'uwp_addons_section_' . $section_id ) ) ) { //@todo restore after testing
53 //if ( 1==1) {
54
55 $query_args = array( 'category' => $section_id, 'number' => 100);
56 $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id);
57
58 $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'UsersWP Addons Page','timeout' => 15, ) );
59
60 if ( ! is_wp_error( $raw_section ) ) {
61 $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
62
63 if ( ! empty( $section_data->products ) ) {
64 set_transient( 'uwp_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
65 }
66 }
67 }
68 }
69
70 $products = isset($section_data->products) ? $section_data->products : '';
71
72 return apply_filters( 'uwp_addons_section_data', $products, $section_id );
73 }
74
75 /**
76 * Outputs a button.
77 *
78 * @param string $url
79 * @param string $text
80 * @param string $theme
81 * @param string $plugin
82 */
83 public function output_button( $addon ) {
84 $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
85 // $button_text = __('Free','userswp');
86 // $licensing = false;
87 // $installed = false;
88 // $price = '';
89 // $license = '';
90 // $slug = '';
91 // $url = isset($addon->info->link) ? $addon->info->link : '';
92 // $class = 'button-primary';
93 // $install_status = 'get';
94 // $onclick = '';
95
96 $wp_org_themes = array('supreme-directory','directory-starter');
97
98 $button_args = array(
99 'type' => $current_tab,
100 'id' => isset($addon->info->id) ? absint($addon->info->id) : '',
101 'title' => isset($addon->info->title) ? $addon->info->title : '',
102 'button_text' => __('Free','userswp'),
103 'price_text' => __('Free','userswp'),
104 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product
105 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url
106 'class' => 'button-primary',
107 'install_status' => 'get',
108 'installed' => false,
109 'price' => '',
110 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false,
111 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '',
112 'onclick' => '',
113 'slug' => isset($addon->info->slug) ? $addon->info->slug : '',
114 'active' => false,
115 'file' => '',
116 'update_url' => '',
117 );
118
119 if($current_tab == 'addons' && isset($addon->info->id) && $addon->info->id){
120 include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
121 if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
122 $status = $this->install_plugin_install_status($addon);
123 $button_args['file'] = isset($status['file']) ? $status['file'] : '';
124 if(isset($status['status'])){$button_args['install_status'] = $status['status'];}
125 $button_args['update_url'] = "https://userswp.io";
126 }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
127 if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
128 $button_args['installed'] = $this->is_theme_installed($addon);
129 if(!in_array($button_args['slug'],$wp_org_themes)){
130 $button_args['update_url'] = "https://userswp.io";
131 }
132 }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){
133 include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
134 $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>""));
135 $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install';
136 $button_args['file'] = isset($status['file']) ? $status['file'] : '';
137 }
138
139 // set price
140 if(isset($addon->pricing) && !empty($addon->pricing)){
141 if(is_object($addon->pricing)){
142 $prices = (Array)$addon->pricing;
143 $button_args['price'] = reset($prices);
144 }elseif(isset($addon->pricing)){
145 $button_args['price'] = $addon->pricing;
146 }
147 }
148
149 // set price text
150 if( $button_args['price'] && $button_args['price'] != '0.00' ){
151 $button_args['price_text'] = sprintf( __('From: $%d', 'userswp'), $button_args['price']);
152 }
153
154
155 // set if installed
156 if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){
157 $button_args['installed'] = true;
158 }
159
160 // print_r($button_args);
161 // set if active
162 if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){
163 if($button_args['type'] != 'themes'){
164 $button_args['active'] = is_plugin_active($button_args['file']);
165 }else{
166 $button_args['active'] = $this->is_theme_active($addon);
167 }
168 }
169
170 // set button text and class
171 if($button_args['active']){
172 $button_args['button_text'] = __('Active','userswp');
173 $button_args['class'] = ' button-secondary disabled ';
174 }elseif($button_args['installed']){
175 $button_args['button_text'] = __('Activate','userswp');
176
177 if($button_args['type'] != 'themes'){
178 if ( current_user_can( 'manage_options' ) ) {
179 $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']);
180 }else{
181 $button_args['url'] = '#';
182 }
183 }else{
184 if ( current_user_can( 'switch_themes' ) ) {
185 $button_args['url'] = $this->get_theme_activation_url($addon);
186 }else{
187 $button_args['url'] = '#';
188 }
189 }
190
191 }else{
192 if($button_args['type'] == 'recommended_plugins'){
193 $button_args['button_text'] = __('Install','userswp');
194 }else{
195 $button_args['button_text'] = __('Get it','userswp');
196
197 /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
198 $button_args['button_text'] = __('Install','userswp');
199 $button_args['url'] = $this->get_theme_install_url($button_args['slug']);
200 $button_args['onclick'] = 'gd_set_button_installing(this);';
201 }*/
202
203 }
204 }
205
206 // filter the button arguments
207 $button_args = apply_filters('edd_api_button_args',$button_args);
208
209 // set price text
210 if(isset($button_args['price_text'])){
211 ?>
212 <a
213 target="_blank"
214 class="addons-price-text"
215 href="<?php echo esc_url( $button_args['link'] ); ?>">
216 <?php echo esc_html( $button_args['price_text'] ); ?>
217 </a>
218 <?php
219 }
220
221 $target = '';
222 if ( ! empty( $button_args['url'] ) ) {
223 $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" ';
224 }
225
226 ?>
227 <a
228 data-licence="<?php echo esc_attr($button_args['license']);?>"
229 data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>"
230 data-title="<?php echo esc_attr($button_args['title']);?>"
231 data-type="<?php echo esc_attr($button_args['type']);?>"
232 data-text-error-message="<?php _e('Something went wrong!','userswp');?>"
233 data-text-activate="<?php _e('Activate','userswp');?>"
234 data-text-activating="<?php _e('Activating','userswp');?>"
235 data-text-deactivate="<?php _e('Deactivate','userswp');?>"
236 data-text-installed="<?php _e('Installed','userswp');?>"
237 data-text-install="<?php _e('Install','userswp');?>"
238 data-text-installing="<?php _e('Installing','userswp');?>"
239 data-text-error="<?php _e('Error','userswp');?>"
240 <?php if(!empty($button_args['onclick'])){echo " onclick='".$button_args['onclick']."' ";}?>
241 <?php echo $target;?>
242 class="addons-button <?php echo esc_attr( $button_args['class'] ); ?>"
243 href="<?php echo esc_url( $button_args['url'] ); ?>">
244 <?php echo esc_html( $button_args['button_text'] ); ?>
245 </a>
246 <?php
247 }
248
249
250 /**
251 * Handles output of the addons page in admin.
252 */
253 public function output() {
254 $tabs = $this->get_tabs();
255 $sections = $this->get_sections();
256 $theme = wp_get_theme();
257 $section_keys = array_keys( $sections );
258 $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
259 $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
260 include_once( USERSWP_PATH . '/admin/views/html-admin-page-addons.php' );
261 }
262
263 /**
264 * A list of recommended wp.org plugins.
265 * @return array
266 */
267 public function get_recommend_wp_plugins(){
268 $plugins = array(
269 'geodirectory' => array(
270 'url' => 'https://wordpress.org/plugins/geodirectory/',
271 'slug' => 'geodirectory',
272 'name' => 'GeoDirectory',
273 'desc' => __('Turn any WordPress theme into a global business directory portal.','userswp'),
274 'thumbnail' => "https://ps.w.org/geodirectory/assets/banner-772x250.jpg"
275 ),
276 'invoicing' => array(
277 'url' => 'https://wordpress.org/plugins/invoicing/',
278 'slug' => 'invoicing',
279 'name' => 'Invoicing',
280 'desc' => __('Create & Send Invoices, Manage Taxes & VAT. Collect One Time & Recurring Payments.','userswp'),
281 ),
282 );
283
284 return $plugins;
285 }
286
287
288 }
289