예제 #1
0
    public static function load_perk_settings()
    {
        $perk = GWPerk::get_perk(gwget('slug'));
        $perk->load_perk_data();
        if (isset($_POST['gwp_save_settings'])) {
            $settings = $setting_keys = array();
            if (method_exists($perk, 'register_settings')) {
                $setting_keys = $perk->register_settings($perk);
                if (empty($setting_keys)) {
                    $setting_keys = array();
                }
            }
            $settings = self::get_submitted_settings($perk, $setting_keys);
            if (!empty($settings)) {
                GWPerk::save_perk_settings($perk->get_id(), $settings);
                $notice = new GWNotice(__('Settings saved successfully.', 'gravityperks'));
            } else {
                $notice = new GWNotice(__('Settings were not saved.', 'gravityperks'), array('class' => 'error'));
            }
        }
        $page_title = sprintf(__('%s Settings', 'gravityperks'), $perk->data['Name']);
        ?>

        <!DOCTYPE html>
        <html>

        <head>
        <title><?php 
        echo $page_title;
        ?>
</title>
        <?php 
        wp_print_styles(array('gwp-admin', 'wp-admin', 'buttons', 'colors-fresh'));
        wp_print_scripts(array('jquery', 'gwp-admin'));
        ?>
        </head>

        <body class="perk-iframe wp-core-ui">

            <div class="wrap perk-settings">
                <form action="" method="post">
                    <h1 class="page-title"><?php 
        echo $page_title;
        ?>
</h1>
                    <div class="content">
                        <?php 
        if (isset($notice)) {
            $notice->display();
        }
        $perk->settings();
        ?>
                    </div>
                    <div class="content-footer">
                        <input type="submit" id="gwp_save_settings" name="gwp_save_settings" class="button button-primary" value="<?php 
        _e('Save Settings', 'gravityperks');
        ?>
" />
                    </div>
                </form>
            </div>

            <script type="text/javascript">
            setTimeout('jQuery(".updated").slideUp();', 5000);
            </script>

        </body>
        </html>

        <?php 
        exit;
    }
예제 #2
0
 /**
  * Get perk setting, will automatically append the perk slug.
  *
  * @param mixed $key
  * @param mixed $settings
  */
 function get_setting($key, $settings = array())
 {
     if (empty($settings)) {
         $settings = GWPerk::get_perk_settings($this->get_id());
     }
     return gwar($settings, $this->get_id() . "_{$key}");
 }
 /**
  * Get all perk options or optionally specify a slug to get a specific perk's options.
  * If slug provided and no options found, return default perk options.
  *
  * @param mixed $slug Perk slug
  * @return Perk options array or array of of perk options arrays
  */
 public static function get_perk_options($slug = false)
 {
     $all_perk_options = get_option('gwp_perk_options');
     if (!$all_perk_options) {
         $all_perk_options = array();
     }
     if ($slug) {
         foreach ($all_perk_options as $perk_options) {
             if ($perk_options['slug'] == $slug) {
                 return $perk_options;
             }
         }
         require_once self::get_base_path() . '/model/perk.php';
         return GWPerk::get_default_perk_options($slug);
     }
     return $all_perk_options;
 }
 /**
  * Provides download package when installing and information on the "View version x.x details" page.
  *
  * @uses api_request()
  *
  * @param mixed $_data
  * @param string $_action
  * @param object $_args
  * @return object $_data
  */
 public function perks_plugins_api_filter($_data, $_action = '', $_args = null)
 {
     GravityPerks::log_debug('perks_plugins_api_filter() start. Retrieves download package and plugin info.');
     $plugin_file = isset($_args->slug) ? $_args->slug : gwget('plugin');
     if (strpos($plugin_file, '/') === false) {
         $plugin_file = sprintf('%1$s/%1$s.php', $plugin_file);
     }
     $is_perk = gwget('from') == 'gwp';
     if (!$is_perk) {
         $is_perk = GWPerk::is_perk($plugin_file);
     }
     GravityPerks::log_debug(print_r(compact('slug', 'is_perk'), true));
     if ($_action != 'plugin_information' || !$is_perk || !$plugin_file) {
         return $_data;
     }
     GravityPerks::log_debug('Yes! This is a perk.');
     $api_params = self::get_api_args(array('edd_action' => 'get_perk', 'plugin_file' => $plugin_file, 'license' => $this->license_key));
     $request_args = self::get_request_args(array('body' => urlencode_deep($api_params)));
     $request = wp_remote_post(GW_STORE_URL, $request_args);
     GravityPerks::log_debug('API Parameters: ' . print_r($api_params, true));
     GravityPerks::log_debug('Request Arguments: ' . print_r($request_args, true));
     GravityPerks::log_debug('Response from GW API: ' . print_r($request, true));
     if (is_wp_error($request)) {
         GravityPerks::log_debug('Rats! There was an error with the GW API response');
         return $_data;
     }
     $request = json_decode(wp_remote_retrieve_body($request));
     if (!$request) {
         GravityPerks::log_debug('Rats! There was an error with the GW API response');
         return $_data;
     }
     GravityPerks::log_debug('Ok! Everything looks good. Let\'s build the response needed for WordPress.');
     $request->is_perk = true;
     $request->sections = (array) maybe_unserialize($request->sections);
     $request->sections['changelog'] = GWPerks::format_changelog($request->sections['changelog']);
     // don't allow other plugins to override the $request this function returns, several plugins use the 'plugins_api'
     // filter incorrectly and return a hard 'false' rather than returning the $_data object when they do not need to modify
     // the request which results in our customized $request being overwritten (WPMU Dev Dashboard v3.3.2 is one example)
     remove_all_filters('plugins_api');
     // remove all the filters causes an infinite loop so add one dummy function so the loop can break itself
     add_filter('plugins_api', create_function('$_data', 'return $_data;'));
     // needed for testing on local
     add_filter('http_request_args', array($this, 'allow_unsecure_urls_on_localhost'));
     return $request;
 }
예제 #5
0
 function get_column_title($perk)
 {
     $title = '<strong>' . $perk['title'] . '</strong>';
     $title .= '<div class="row-actions-visible">';
     $actions = array();
     $snp_obj = new GWPerk($perk['slug']);
     if (!self::is_installed($perk['slug'])) {
         if ($this->is_valid_key) {
             $actions[] = '<span class="install"><a title="' . __('Install this perk', 'gravityperks') . '" href="' . $snp_obj->get_link_for('install') . '" onclick="gperk.confirmActionUrl(event, \'' . sprintf(__('Are you sure you want to install the %s perk?', 'gravityperks'), $perk['title']) . '\')">' . __('Install', 'gravityperks') . '</a></span>';
         } else {
             $actions[] = '<span class="install"><a title="' . __('Already purchased a license? Click here to enter it.', 'gravityperks') . '" href="' . $snp_obj->get_link_for('plugin_settings') . '">' . __('Enter License Key', 'gravityperks') . '</a></span>';
             $actions[] = '<span class="install"><a title="' . __('Click here to purchase a license!', 'gravityperks') . '" href="' . $snp_obj->get_link_for('purchase') . '" target="_blank">' . __('Purchase License', 'gravityperks') . '</a></span>';
         }
     } else {
         $actions[] = '<span class="installed">' . __('Installed', 'gravityperks') . '</span>';
     }
     $title .= implode(' | ', $actions);
     $title .= '</div>';
     return $title;
 }