Example #1
0
 function include_field($class_name = false, $file = false)
 {
     $field_file_paths = array($file, $this->get_base_path() . '/fields.php', $this->get_base_path() . '/includes/fields.php');
     foreach ($field_file_paths as $file_path) {
         if ($file_path && file_exists($file_path)) {
             require_once GWPerks::get_base_path() . '/model/field.php';
             require_once $file_path;
             $field_class = $class_name ? $class_name : $this->slug . 'Field';
             if (!class_exists($field_class)) {
                 return false;
             }
             $args = array('perk' => $this);
             if (is_callable(array($field_class, 'get_instance'))) {
                 $field_obj = call_user_func(array($field_class, 'get_instance'), $args);
             } else {
                 $field_obj = new $field_class($args);
             }
             return $field_obj;
         }
     }
     return false;
 }
Example #2
0
 public static function process_actions()
 {
     $action = gwget('action');
     $slug = gwget('slug');
     if (!$action) {
         return;
     }
     if ($action && $slug && !wp_verify_nonce(gwget('_wpnonce'), $slug)) {
         die(__('Oops! Doesn\'t look like you have permission to do this.', 'gravityperks'));
     }
     if (!in_array($action, array('activate', 'deactivate', 'delete'))) {
         die(__('What exactly are you trying to do?', 'gravityperks'));
     }
     $perks = GWPerks::get_installed_perks();
     foreach ($perks as $perk) {
         if ($perk->slug == $slug) {
             break;
         }
     }
     switch ($action) {
         case 'activate':
             $perk->activate();
             $message = 1;
             break;
         case 'deactivate':
             $perk->deactivate();
             $message = 2;
             break;
         case 'delete':
             $message = $perk->delete() ? 5 : 6;
     }
     wp_redirect(admin_url("admin.php?page=gwp_perks&message={$message}"));
 }
 public static function get_request_args($args = array())
 {
     return wp_parse_args($args, array('user-agent' => 'Gravity Perks ' . GWPerks::get_version(), 'timeout' => 15));
 }
 public static function get_options_from_installed_perks()
 {
     $perks = GWPerks::get_installed_perks();
     $all_perk_options = array();
     foreach ($perks as $perk) {
         $all_perk_options[] = $perk->get_save_options();
     }
     return $all_perk_options;
 }
 function prepare_items()
 {
     $perks = GWPerks::get_perks_listing();
     $this->is_valid_key = GWPerks::has_valid_key();
     if (!is_array($perks)) {
         $this->items = array();
         return;
     }
     $items = array();
     $total = count($perks);
     $page = gwget('paged') ? gwget('paged') : 1;
     $per_page = 10;
     $offset = $page * $per_page - $per_page;
     $cap = $total > $offset + $per_page ? $offset + $per_page : $total;
     for ($i = $offset; $i < $cap; $i++) {
         $items[$perks[$i]['slug']] = array('title' => $this->get_column_title($perks[$i]), 'description' => $perks[$i]['description'], 'slug' => $perks[$i]['slug'], 'version' => $perks[$i]['version']);
     }
     $this->items = $items;
     $this->set_pagination_args(array('total_items' => $total, 'per_page' => $per_page));
 }
    public static function settings_page()
    {
        $settings = get_site_option('gwp_settings') ? get_site_option('gwp_settings') : array();
        $is_submit = gwpost('gwp_settings_submit') == true;
        if (gwpost('uninstall')) {
            // uninstall functionality...
        } else {
            if (gwpost('gwp_settings_submit')) {
                check_admin_referer('update', 'gwp_settings');
                $new_license = trim(stripslashes(gwpost('gwp_license_key')));
                $old_license = trim(gwar($settings, 'license_key'));
                $is_diff_license = $new_license != $old_license;
                $settings = array_merge($settings, array('license_key' => trim(stripslashes($_POST['gwp_license_key']))));
                update_site_option('gwp_settings', $settings);
                // if a different license is entered, delete the 'gwp_has_valid_license' transient so the next 'has_valid_license'
                // check will do a fresh check to confirm new licenses' validity
                if ($is_diff_license) {
                    GWPerks::flush_license();
                }
            }
        }
        $is_license_valid = gwar($settings, 'license_key') && GWPerks::has_valid_license();
        ?>

        <?php 
        if ($is_submit && gwget('register') && $is_license_valid) {
            ?>
            <div class="updated"><p>
                <?php 
            printf(__('Awesome! Your now have unlimited access to <strong>all perks</strong> with automatic upgrades and support. %sLet\'s go install some perks!%s', 'gravityperks'), '<a href="' . GW_MANAGE_PERKS_URL . '&view=install">', '</a>');
            ?>
            </p></div>
        <?php 
        } elseif ($is_submit && !$is_license_valid) {
            ?>
            <div class="error"><p>
                <?php 
            _e('Oops! That doesn\'t appear to be a valid license.', 'gravityperks');
            ?>
            </p></div>
        <?php 
        }
        ?>

        <style type="text/css">
            .gform_tab_content input,
            .gform_tab_content textarea {
                outline-style: none;
                font-family: inherit;
                font-size: inherit;
                padding: 3px 5px;
            }
        </style>

        <form method="post" action="">

            <?php 
        wp_nonce_field('update', 'gwp_settings');
        ?>

            <h3><?php 
        _e('Gravity Perks Settings', 'gravityperks');
        ?>
</h3>

            <table class="form-table">
                <tr>
                    <th scope="row"><label for="gwp_license_key"><?php 
        _e('Gravity Perks License Key', 'gravityperks');
        ?>
</label></th>
                    <td>
                        <input type="password" id="gwp_license_key" name="gwp_license_key" value="<?php 
        echo !gwar($settings, 'license_key') ? '' : trim(esc_attr(gwar($settings, 'license_key')));
        ?>
" size="50" />
                        <?php 
        if (gwar($settings, 'license_key')) {
            if ($is_license_valid) {
                ?>

                                <?php 
                if (!version_compare(GFCommon::$version, '1.8', '>=')) {
                    ?>
                                    <img src="<?php 
                    echo GFCommon::get_base_url();
                    ?>
/images/tick.png" style="position:relative;top:2px" />
                                <?php 
                } else {
                    ?>
                                    <i class="fa fa-check gf_keystatus_valid"></i>
                                <?php 
                }
                ?>

                            <?php 
            } else {
                ?>

                                <?php 
                if (!version_compare(GFCommon::$version, '1.8', '>=')) {
                    ?>
                                    <img src="<?php 
                    echo GFCommon::get_base_url();
                    ?>
/images/cross.png" style="position:relative;top:2px" />
                                <?php 
                } else {
                    ?>
                                    <i class="fa fa-times gf_keystatus_invalid"></i>
                                <?php 
                }
                ?>

                            <?php 
            }
        }
        ?>

                        <p class="description" style="padding-top:0;">
                            <?php 
        if (!$is_license_valid) {
            ?>
                                <?php 
            _e('Register your copy of Gravity Perks for unlimited access to all perks, automatic upgrades and support!', 'gravityperks');
            ?>
                            <?php 
        } else {
            ?>
                                <?php 
            _e('Awesome! You have unlimited access to <strong>all perks</strong> with automatic upgrades and support.', 'gravityperks');
            ?>
                            <?php 
        }
        ?>
                        </p>

                    </td>
                </tr>
                <tr>
                    <td colspan="2" >
                        <input type="submit" name="gwp_settings_submit" class="button-primary" value="<?php 
        _e('Save Settings', 'gravityperks');
        ?>
" />
                    </td>
                </tr>
            </table>

        </form>

        <?php 
    }
 /**
  * Updates information on the "View version x.x details" page with custom data.
  * 
  * @uses api_request()
  * 
  * @param mixed $_data
  * @param string $_action
  * @param object $_args
  * @return object $_data
  */
 function plugins_api_filter($_data, $_action = '', $_args = null)
 {
     if ($_action != 'plugin_information' || !isset($_args->slug) || $_args->slug != $this->slug) {
         return $_data;
     }
     $to_send = array('slug' => $this->slug);
     $api_response = $this->api_request('plugin_information', $to_send);
     if (false !== $api_response) {
         $_data = $api_response;
         $_data->sections['changelog'] = GWPerks::format_changelog($_data->sections['changelog']);
     }
     return $_data;
 }