pmpro_admin_init_updating_plugins

Detect when trying to update a PMPro Plus plugin without a valid license key.

Description

pmpro_admin_init_updating_plugins(); 

Usage

  1. if ( !function_exists( 'pmpro_admin_init_updating_plugins' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/addons.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = pmpro_admin_init_updating_plugins(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/addons.php  
  1. function pmpro_admin_init_updating_plugins() {  
  2. //if user can't edit plugins, then WP will catch this later 
  3. if ( ! current_user_can('update_plugins') ) 
  4. return; 
  5.  
  6. //updating one or more plugins via Dashboard -> Upgrade 
  7. if(basename($_SERVER['SCRIPT_NAME']) == 'update.php' && !empty($_REQUEST['action']) && $_REQUEST['action'] == 'update-selected' && !empty($_REQUEST['plugins'])) { 
  8. //figure out which plugin we are updating 
  9. $plugins = explode( ', ', stripslashes($_GET['plugins']) );  
  10. $plugins = array_map('urldecode', $plugins);  
  11.  
  12. //look for addons 
  13. $plus_addons = array(); 
  14. $plus_plugins = array(); 
  15. foreach($plugins as $plugin) {  
  16. $slug = str_replace('.php', '', basename($plugin)); 
  17. $addon = pmpro_getAddonBySlug($slug);  
  18. if(!empty($addon) && $addon['License'] == 'plus') { 
  19. $plus_addons[] = $addon['Name']; 
  20. $plus_plugins[] = $plugin; 
  21. }  
  22. unset($plugin); 
  23.  
  24. //if Plus addons found, check license key 
  25. if(!empty($plus_plugins) && !pmpro_license_isValid()) { 
  26. //show error 
  27. $msg = __('You must have a <a href="https://www.paidmembershipspro.com/pricing/?utm_source=wp-admin&utm_pluginlink=bulkupdate">valid PMPro Plus License Key</a> to update PMPro Plus add ons. The following plugins will not be updated:', 'paid-memberships-pro'); 
  28. echo '<div class="error"><p>' . $msg . ' <strong>' . implode(', ', $plus_addons) . '</strong></p></div>';  
  29.  
  30. //can exit out of this function now 
  31. return; 
  32.  
  33. //upgrading just one or plugin via an update.php link 
  34. if(basename($_SERVER['SCRIPT_NAME']) == 'update.php' && !empty($_REQUEST['action']) && $_REQUEST['action'] == 'upgrade-plugin' && !empty($_REQUEST['plugin'])) { 
  35. //figure out which plugin we are updating 
  36. $plugin = urldecode(trim($_REQUEST['plugin'])); 
  37.  
  38. $slug = str_replace('.php', '', basename($plugin)); 
  39. $addon = pmpro_getAddonBySlug($slug); 
  40. if(!empty($addon) && !pmpro_license_isValid()) { 
  41. require_once(ABSPATH . 'wp-admin/admin-header.php'); 
  42.  
  43. echo '<div class="wrap"><h2>' . __('Update Plugin') . '</h2>'; 
  44.  
  45. $msg = __('You must have a <a href="https://www.paidmembershipspro.com/pricing/?utm_source=wp-admin&utm_pluginlink=addon_update">valid PMPro Plus License Key</a> to update PMPro Plus add ons.', 'paid-memberships-pro'); 
  46. echo '<div class="error"><p>' . $msg . '</p></div>'; 
  47.  
  48. echo '<p><a href="' . admin_url('admin.php?page=pmpro-addons') . '" target="_parent">' . __('Return to the PMPro Add Ons page', 'paid-memberships-pro') . '</a></p>'; 
  49.  
  50. echo '</div>'; 
  51.  
  52. include(ABSPATH . 'wp-admin/admin-footer.php'); 
  53.  
  54. //can exit WP now 
  55. exit;  
  56. }  
  57.  
  58. //updating via AJAX on the plugins page 
  59. if(basename($_SERVER['SCRIPT_NAME']) == 'admin-ajax.php' && !empty($_REQUEST['action']) && $_REQUEST['action'] == 'update-plugin' && !empty($_REQUEST['plugin'])) { 
  60. //figure out which plugin we are updating 
  61. $plugin = urldecode(trim($_REQUEST['plugin'])); 
  62.  
  63. $slug = str_replace('.php', '', basename($plugin)); 
  64. $addon = pmpro_getAddonBySlug($slug); 
  65. if(!empty($addon) && !pmpro_license_isValid()) { 
  66. $msg = __('You must enter a valid PMPro Plus License Key under Settings > PMPro License to update this add on.', 'paid-memberships-pro'); 
  67. echo '<div class="error"><p>' . $msg . '</p></div>';  
  68.  
  69. //can exit WP now 
  70. exit; 
  71. }  
  72.  
  73. /** 
  74. TODO:  
  75. * Check for PMPro Plug plugins 
  76. * If a plus plugin is found, check the PMPro license key 
  77. * If the key is missing or invalid, throw an error 
  78. * Show appropriate footer and exit... maybe do something else to keep plugin update from happening 
  79. */