コード例 #1
0
ファイル: manage_perks.php プロジェクト: hansstam/makerfaire
 public static function ajax_manage_perk()
 {
     $request = parse_url(gwpost('request_url'));
     parse_str(gwar($request, 'query'), $request);
     if (empty($request)) {
         GWPerks::json_and_die(array('error' => __('There was an error managing this perk.', 'gravityperks')));
     }
     $action = gwar($request, 'action');
     $plugin = gwar($request, 'plugin');
     $_REQUEST['_wpnonce'] = gwar($request, '_wpnonce');
     // use some of WPs default plugin management functionality
     // @see wp-admin/plugins.php
     switch ($action) {
         case 'activate':
             if (!current_user_can('activate_plugins')) {
                 wp_die(__('You do not have sufficient permissions to activate plugins for this site.', 'gravityperks'));
             }
             check_admin_referer('activate-plugin_' . $plugin);
             $result = activate_plugin($plugin, null, is_network_admin());
             if (is_wp_error($result)) {
                 if ('unexpected_output' == $result->get_error_code()) {
                     $error_data = $result->get_error_data();
                 } else {
                     $error_data = $result;
                 }
                 GWPerks::json_and_die(array('error' => __('There was an error activating this perk.', 'gravityperks'), 'error_data' => $error_data));
             }
             if (!is_network_admin()) {
                 $recent = (array) get_option('recently_activated');
                 unset($recent[$plugin]);
                 update_option('recently_activated', $recent);
             }
             $perk_data = GWPerk::get_perk_data($plugin);
             GWPerks::json_and_die(array('success' => 1, 'listing_html' => self::get_perk_listing($plugin, $perk_data, true)));
             break;
         case 'deactivate':
             if (!current_user_can('activate_plugins')) {
                 wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.', 'gravityperks'));
             }
             check_admin_referer('deactivate-plugin_' . $plugin);
             if (!is_network_admin() && is_plugin_active_for_network($plugin)) {
                 GWPerks::json_and_die(array('error' => __('This perk can only be managed from the network admin\'s Plugins page.', 'gravityperks')));
             }
             deactivate_plugins($plugin, false, is_network_admin());
             if (!is_network_admin()) {
                 update_option('recently_activated', array($plugin => time()) + (array) get_option('recently_activated'));
             }
             $perk_data = GWPerk::get_perk_data($plugin);
             GWPerks::json_and_die(array('success' => 1, 'listing_html' => self::get_perk_listing($plugin, $perk_data, true)));
             break;
         case 'uninstall':
             if (!current_user_can('delete_plugins')) {
                 wp_die(__('You do not have sufficient permissions to delete plugins for this site.', 'gravityperks'));
             }
             check_admin_referer('uninstall-plugin_' . $plugin);
             deactivate_plugins($plugin, true);
             $perk = GWPerk::get_perk($plugin);
             $perk->uninstall();
             $result = delete_plugins(array($plugin));
             if ($result) {
                 $response = json_encode(array('success' => 1, 'listing_html' => ''));
             } else {
                 $response = __('ERROR');
             }
             die($response);
             break;
     }
     GWPerks::json_and_die(array('error' => __('There was an error managing this perk.', 'gravityperks')));
 }
コード例 #2
0
 public static function get_message($message_slug, $plugin_file = false)
 {
     $min_gravity_forms_version = self::$min_gravity_forms_version;
     $min_wp_version = self::$min_wp_version;
     // if a $plugin_file is provided AND it is not the same as the base plugin, let's assume it is a perk
     $is_perk = $plugin_file && $plugin_file != self::$basename;
     if ($is_perk) {
         require_once ABSPATH . 'wp-admin/includes/plugin.php';
         $perk = GWPerk::get_perk($plugin_file);
         $perk_data = GWPerk::get_perk_data($plugin_file);
         $min_gravity_forms_version = $perk->get_property('min_gravity_forms_version');
         $min_wp_version = $perk->get_property('min_wp_version');
     }
     switch ($message_slug) {
         case 'gravity_forms_required':
             if (isset($perk)) {
                 return sprintf(__('%1$s requires Gravity Forms %2$s or greater. Activate it now or %3$spurchase it today!%4$s', 'gravityperks'), $perk_data['Name'], $min_gravity_forms_version, '<a href="' . GW_GFORM_AFFILIATE_URL . '">', '</a>');
             } else {
                 return sprintf(__('Gravity Forms %1$s or greater is required. Activate it now or %2$spurchase it today!%3$s', 'gravityperks'), $min_gravity_forms_version, '<a href="' . GW_GFORM_AFFILIATE_URL . '">', '</a>');
             }
         case 'wp_required':
             if (isset($perk)) {
                 return sprintf(__('%1$s requires WordPress %2$s or greater. You must upgrade WordPress in order to use this perk.', 'gravityperks'), $perk_data['Name'], $min_wp_version);
             } else {
                 return sprintf(__('Gravity Perks requires WordPress %1$s or greater. You must upgrade WordPress in order to use Gravity Perks.', 'gravityperks'), $min_wp_version);
             }
         case 'gravity_perks_required':
             return sprintf(__('%1$s requires Gravity Perks %2$s or greater. Activate it now or %3$spurchase it today!%4$s', 'gravityperks'), $perk_data['Name'], $perk->get_property('min_gravity_perks_version'), '<a href="' . GW_BUY_GPERKS_URL . '" target="_blank">', '</a>');
         case 'register_gravity_perks':
             if (isset($perk)) {
                 return sprintf(__('%1$sRegister%2$s your copy of Gravity Perks to receive access to automatic upgrades and support for this perk. Need a license key? %3$sPurchase one now.%2$s', 'gravityperks'), '<a href="' . admin_url('admin.php?page=gf_settings&addon=Perks') . '">', '</a>', '<a href="' . GW_BUY_GPERKS_URL . '" target="_blank">');
             } else {
                 return sprintf(__('%1$sRegister%2$s your copy of Gravity Perks to receive access to automatic upgrades and support. Need a license key? %3$sPurchase one now.%2$s', 'gravityperks'), '<a href="' . admin_url('admin.php?page=gf_settings&addon=Perks') . '">', '</a>', '<a href="' . GW_BUY_GPERKS_URL . '" target="_blank">');
             }
     }
     return '';
 }