PageRenderTime 29ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/adminpages/addons.php

https://github.com/strangerstudios/paid-memberships-pro
PHP | 303 lines | 251 code | 29 blank | 23 comment | 52 complexity | ffa0f3554172735189c76aa9a4e9b444 MD5 | raw file
  1. <?php
  2. //only admins can get this
  3. if(!function_exists("current_user_can") || (!current_user_can("manage_options") && !current_user_can("pmpro_addons")))
  4. {
  5. die(__("You do not have permissions to perform this action.", 'paid-memberships-pro' ));
  6. }
  7. global $wpdb, $msg, $msgt, $pmpro_addons;
  8. wp_enqueue_script( 'plugin-install' );
  9. add_thickbox();
  10. wp_enqueue_script( 'updates' );
  11. require_once(dirname(__FILE__) . "/admin_header.php");
  12. //force a check of plugin versions?
  13. if(!empty($_REQUEST['force-check']))
  14. {
  15. wp_version_check(array(), true);
  16. wp_update_plugins();
  17. $pmpro_license_key = get_option("pmpro_license_key", "");
  18. pmpro_license_isValid($pmpro_license_key, NULL, true);
  19. }
  20. //some vars
  21. $addons = pmpro_getAddons();
  22. $addons_timestamp = get_option("pmpro_addons_timestamp", false);
  23. $plugin_info = get_site_transient( 'update_plugins' );
  24. $pmpro_license_key = get_option("pmpro_license_key", "");
  25. //get plugin status for filters
  26. if(!empty($_REQUEST['plugin_status']))
  27. $status = pmpro_sanitize_with_safelist($_REQUEST['plugin_status'], array('', 'all', 'active', 'inactive', 'update', 'uninstalled'));
  28. //make sure we have an approved status
  29. $approved_statuses = array('all', 'active', 'inactive', 'update', 'uninstalled');
  30. if(empty($status) || !in_array($status, $approved_statuses))
  31. $status = "all";
  32. // Split Add Ons into groups for filtering
  33. $all_visible_addons = array();
  34. $all_hidden_addons = array();
  35. $active_addons = array();
  36. $inactive_addons = array();
  37. $update_available_addons = array();
  38. $not_installed_addons = array();
  39. // Build array of Visible, Hidden, Active, Inactive, Installed, and Not Installed Add Ons.
  40. foreach ( $addons as $addon ) {
  41. $plugin_file = $addon['Slug'] . '/' . $addon['Slug'] . '.php';
  42. $plugin_file_abs = ABSPATH . 'wp-content/plugins/' . $plugin_file;
  43. // Build Visible and Hidden arrays.
  44. if ( empty ( $addon['HideFromAddOnsList'] ) || file_exists( $plugin_file_abs ) ) {
  45. $all_visible_addons[] = $addon;
  46. } else {
  47. $all_hidden_addons[] = $addon;
  48. }
  49. // Build Active and Inactive arrays - exclude hidden Add Ons that are not installed.
  50. if ( is_plugin_active( $plugin_file ) ) {
  51. $active_addons[] = $addon;
  52. } elseif ( empty ( $addon['HideFromAddOnsList'] ) || file_exists( $plugin_file_abs ) ) {
  53. $inactive_addons[] = $addon;
  54. }
  55. // Build array of Add Ons that have an update available.
  56. if ( isset( $plugin_info->response[$plugin_file] ) ) {
  57. $update_available_addons[] = $addon;
  58. }
  59. // Build array of Add Ons that are visible and not installed.
  60. if ( empty ( $addon['HideFromAddOnsList'] ) && ! file_exists( $plugin_file_abs ) ) {
  61. $not_installed_addons[] = $addon;
  62. }
  63. }
  64. ?>
  65. <h1 class="wp-heading-inline"><?php esc_html_e( 'Add Ons', 'paid-memberships-pro' ); ?></h1>
  66. <hr class="wp-header-end">
  67. <?php
  68. pmpro_showMessage();
  69. ?>
  70. <p>
  71. <?php printf(__('Last checked on %s at %s.', 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $addons_timestamp), date_i18n(get_option('time_format'), $addons_timestamp));?> &nbsp;
  72. <a class="button" href="<?php echo esc_url( admin_url("admin.php?page=pmpro-addons&force-check=1&plugin_status=" . $status) );?>"><?php esc_html_e('Check Again', 'paid-memberships-pro' ); ?></a>
  73. </p>
  74. <ul class="subsubsub">
  75. <li class="all"><a href="admin.php?page=pmpro-addons&plugin_status=all" <?php if(empty($status) || $status == "all") { ?>class="current"<?php } ?>><?php esc_html_e('All', 'paid-memberships-pro' ); ?> <span class="count">(<?php echo count($all_visible_addons);?>)</span></a> |</li>
  76. <li class="active"><a href="admin.php?page=pmpro-addons&plugin_status=active" <?php if($status == "active") { ?>class="current"<?php } ?>><?php esc_html_e('Active', 'paid-memberships-pro' ); ?> <span class="count">(<?php echo count($active_addons);?>)</span></a> |</li>
  77. <li class="inactive"><a href="admin.php?page=pmpro-addons&plugin_status=inactive" <?php if($status == "inactive") { ?>class="current"<?php } ?>><?php esc_html_e('Inactive', 'paid-memberships-pro' ); ?> <span class="count">(<?php echo count($inactive_addons);?>)</span></a> |</li>
  78. <li class="update"><a href="admin.php?page=pmpro-addons&plugin_status=update" <?php if($status == "update") { ?>class="current"<?php } ?>><?php esc_html_e('Update Available', 'paid-memberships-pro' ); ?> <span class="count">(<?php echo count($update_available_addons);?>)</span></a> |</li>
  79. <li class="uninstalled"><a href="admin.php?page=pmpro-addons&plugin_status=uninstalled" <?php if($status == "uninstalled") { ?>class="current"<?php } ?>><?php esc_html_e('Not Installed', 'paid-memberships-pro' ); ?> <span class="count">(<?php echo count($not_installed_addons);?>)</span></a></li>
  80. </ul>
  81. <table class="wp-list-table widefat plugins">
  82. <thead>
  83. <tr>
  84. <th scope="col" id="cb" class="manage-column column-cb check-column" style="">
  85. <?php /*
  86. <label class="screen-reader-text" for="cb-select-all-1"><?php esc_html_e('Select All'); ?></label><input id="cb-select-all-1" type="checkbox">
  87. */ ?>
  88. </th>
  89. <th scope="col" id="name" class="manage-column column-name" style=""><?php esc_html_e('Add On Name', 'paid-memberships-pro' ); ?></th>
  90. <th scope="col" id="type" class="manage-column column-type" style=""><?php esc_html_e('Type', 'paid-memberships-pro' ); ?></th>
  91. <th scope="col" id="description" class="manage-column column-description" style=""><?php esc_html_e('Description', 'paid-memberships-pro' ); ?></th>
  92. </tr>
  93. </thead>
  94. <tbody id="the-list">
  95. <?php
  96. //which addons to show?
  97. if ( $status == "active" ) {
  98. $addons = $active_addons;
  99. } elseif ( $status == "inactive") {
  100. $addons = $inactive_addons;
  101. } elseif ( $status == "update" ) {
  102. $addons = $update_available_addons;
  103. } elseif ( $status == "uninstalled" ) {
  104. $addons = $not_installed_addons;
  105. } else {
  106. $addons = $all_visible_addons;
  107. }
  108. //no addons for this filter?
  109. if(count($addons) < 1)
  110. {
  111. ?>
  112. <tr>
  113. <td></td>
  114. <td colspan="3"><p><?php esc_html_e('No Add Ons found.', 'paid-memberships-pro' ); ?></p></td>
  115. </tr>
  116. <?php
  117. }
  118. foreach($addons as $addon)
  119. {
  120. $plugin_file = $addon['Slug'] . '/' . $addon['Slug'] . '.php';
  121. $plugin_file_abs = ABSPATH . 'wp-content/plugins/' . $plugin_file;
  122. if(file_exists($plugin_file_abs))
  123. $plugin_data = get_plugin_data( $plugin_file_abs, false, true);
  124. else
  125. $plugin_data = $addon;
  126. //make sure plugin value is set
  127. if(empty($plugin_data['plugin']))
  128. $plugin_data['plugin'] = $plugin_file;
  129. $plugin_name = $plugin_data['Name'];
  130. $id = sanitize_title( $plugin_name );
  131. $checkbox_id = "checkbox_" . md5($plugin_name);
  132. if(!empty($plugin_data['License']))
  133. {
  134. $context = 'uninstalled inactive';
  135. }
  136. elseif(isset($plugin_info->response[$plugin_file]))
  137. {
  138. $context = 'active update';
  139. }
  140. elseif(is_plugin_active($plugin_file))
  141. {
  142. $context = 'active';
  143. }
  144. elseif(file_exists($plugin_file_abs))
  145. {
  146. $context = 'inactive';
  147. }
  148. else
  149. {
  150. $context = false;
  151. }
  152. ?>
  153. <tr id="<?php echo $id; ?>" class="<?php echo $context;?>" data-slug="<?php echo $id; ?>">
  154. <th scope="row" class="check-column">
  155. <?php /*
  156. <label class="screen-reader-text" for="<?php echo $checkbox_id; ?>"><?php sprintf( __( 'Select %s' ), $plugin_name ); ?></label>
  157. <input type="checkbox" name="checked[]" value="<?php esc_attr( $plugin_file ); ?>" id="<?php echo $checkbox_id; ?>">
  158. */ ?>
  159. </th>
  160. <td class="plugin-title">
  161. <strong><?php echo $plugin_name; ?></strong>
  162. <div class="row-actions visible">
  163. <?php
  164. $actions = array();
  165. if($context === 'uninstalled inactive')
  166. {
  167. if($plugin_data['License'] == 'wordpress.org')
  168. {
  169. //wordpress.org
  170. $actions['install'] = '<span class="install"><a href="' . wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $plugin_data['Slug']), 'install-plugin_' . $plugin_data['Slug']) . '">' . __('Install Now', 'paid-memberships-pro' ) . '</a></span>';
  171. }
  172. elseif($plugin_data['License'] == 'free')
  173. {
  174. //free
  175. $actions['install'] = '<span class="install"><a href="' . wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $plugin_data['Slug']), 'install-plugin_' . $plugin_data['Slug']) . '">' . __('Install Now', 'paid-memberships-pro' ) . '</a></span>';
  176. $actions['download'] = '<span class="download"><a target="_blank" href="' . $plugin_data['Download'] . '?key=' . $pmpro_license_key . '">' . __('Download', 'paid-memberships-pro' ) . '</a></span>';
  177. }
  178. elseif(empty($pmpro_license_key))
  179. {
  180. //no key
  181. $actions['settings'] = '<span class="settings"><a href="' . admin_url('admin.php?page=pmpro-license') . '">' . __('Update License', 'paid-memberships-pro' ) . '</a></span>';
  182. $actions['download'] = '<span class="download"><a target="_blank" href="' . $plugin_data['PluginURI'] . '">' . __('Download', 'paid-memberships-pro' ) . '</a></span>';
  183. }
  184. elseif(pmpro_can_download_addon_with_license($plugin_data['License']))
  185. {
  186. //valid key
  187. $actions['install'] = '<span class="install"><a href="' . wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $plugin_data['Slug']), 'install-plugin_' . $plugin_data['Slug']) . '">' . __('Install Now', 'paid-memberships-pro' ) . '</a></span>';
  188. $actions['download'] = '<span class="download"><a target="_blank" href="' . $plugin_data['Download'] . '?key=' . $pmpro_license_key . '">' . __('Download', 'paid-memberships-pro' ) . '</a></span>';
  189. }
  190. else
  191. {
  192. //invalid key
  193. $actions['settings'] = '<span class="settings"><a href="' . admin_url('admin.php?page=pmpro-license') . '">' . __('Update License', 'paid-memberships-pro' ) . '</a></span>';
  194. $actions['download'] = '<span class="download"><a target="_blank" href="' . $plugin_data['PluginURI'] . '">' . __('Download', 'paid-memberships-pro' ) . '</a></span>';
  195. }
  196. }
  197. elseif($context === 'active' || $context === 'active update')
  198. {
  199. $actions['deactivate'] = '<span class="deactivate"><a href="' . wp_nonce_url(self_admin_url('plugins.php?action=deactivate&plugin=' . $plugin_file), 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( __( 'Deactivate %s' ), $plugin_data['Name'] ) ) . '">' . __('Deactivate') . '</a></span>';
  200. }
  201. elseif($context === 'inactive')
  202. {
  203. $actions['activate'] = '<span class="activate"><a href="' . wp_nonce_url(self_admin_url('plugins.php?action=activate&plugin=' . $plugin_file), 'activate-plugin_' . $plugin_file) . '" class="edit" aria-label="' . esc_attr( sprintf( __( 'Activate %s' ), $plugin_data['Name'] ) ) . '">' . __('Activate') . '</a></span>';
  204. $actions['delete'] = '<span class="delete"><a href="' . wp_nonce_url(self_admin_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file), 'bulk-plugins') . '" class="delete" aria-label="' . esc_attr( sprintf( __( 'Delete %s' ), $plugin_data['Name'] ) ) . '">' . __('Delete') . '</a></span>';
  205. }
  206. $actions = apply_filters( 'plugin_action_links_' . $plugin_file, $actions, $plugin_file, $plugin_data, $context );
  207. echo implode(' | ',$actions);
  208. ?>
  209. </div>
  210. </td>
  211. <td class="column-type">
  212. <?php
  213. if($addon['License'] == 'free')
  214. _e("PMPro Free", 'paid-memberships-pro' );
  215. elseif($addon['License'] == 'standard')
  216. _e("PMPro Standard", 'paid-memberships-pro' );
  217. elseif($addon['License'] == 'plus')
  218. _e("PMPro Plus", 'paid-memberships-pro' );
  219. elseif($addon['License'] == 'builder')
  220. _e("PMPro Builder", 'paid-memberships-pro' );
  221. elseif($addon['License'] == 'wordpress.org')
  222. _e("WordPress.org", 'paid-memberships-pro' );
  223. else
  224. _e("N/A", 'paid-memberships-pro' );
  225. ?>
  226. </td>
  227. <td class="column-description desc">
  228. <div class="plugin-description"><p><?php echo $plugin_data['Description']; ?></p></div>
  229. <div class="inactive second plugin-version-author-uri">
  230. <?php
  231. $plugin_meta = array();
  232. if ( !empty( $plugin_data['Version'] ) )
  233. $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
  234. if ( !empty( $plugin_data['Author'] ) ) {
  235. $author = $plugin_data['Author'];
  236. if ( !empty( $plugin_data['AuthorURI'] ) )
  237. $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
  238. $plugin_meta[] = sprintf( __( 'By %s' ), $author );
  239. }
  240. // Details link using API info, if available
  241. if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) {
  242. $plugin_meta[] = sprintf( '<a href="%s" class="thickbox" aria-label="%s" data-title="%s">%s</a>',
  243. esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] .
  244. '&TB_iframe=true&width=600&height=550' ) ),
  245. esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ),
  246. esc_attr( $plugin_name ),
  247. __( 'View details' )
  248. );
  249. } elseif ( ! empty( $plugin_data['PluginURI'] ) ) {
  250. $plugin_meta[] = sprintf( '<a target="_blank" href="%s">%s</a>',
  251. esc_url( $plugin_data['PluginURI'] ) . '?utm_source=plugin&utm_medium=pmpro-addons&utm_campaign=add-ons',
  252. __( 'Visit plugin site' )
  253. );
  254. }
  255. $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status);
  256. echo implode( ' | ', $plugin_meta );
  257. ?>
  258. </div>
  259. </td>
  260. </tr>
  261. <?php
  262. ob_start();
  263. wp_plugin_update_row( $plugin_file, $plugin_data );
  264. $row = ob_get_contents();
  265. ob_end_clean();
  266. echo str_replace('colspan="0"', 'colspan="4"', $row);
  267. }
  268. ?>
  269. </tbody>
  270. </table>
  271. <?php
  272. require_once(dirname(__FILE__) . "/admin_footer.php");
  273. wp_print_request_filesystem_credentials_modal();
  274. ?>