Plugin Directory

Changeset 472131


Ignore:
Timestamp:
12/07/2011 07:12:38 PM (14 years ago)
Author:
theorboman
Message:
  • Added the option to choose if the customer can alter the number of items to purchase.
  • Added the option to make collection of the customers' address mandatory.
Location:
easy-paypal-custom-fields
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • easy-paypal-custom-fields/tags/1.3/easy-paypal-custom-fields.php

    r438923 r472131  
    4242        'url' => ''
    4343    );
    44     update_option( 'rps_myplugin_options', $button );
     44    if( !get_option('rps_myplugin_options') ) {
     45        update_option( 'rps_myplugin_options', $button );
     46    }
    4547   
    4648    // Delete all the crap I made when people delete the plugin
  • easy-paypal-custom-fields/trunk/css/paypal.css

    r465303 r472131  
    7070    line-height: 13px !important;
    7171    font: 12px !important "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans", "Liberation Sans", Verdana, "Verdana Ref", sans-serif;
     72    font-weight: bold;
    7273    -webkit-border-radius: 12px !important;
    7374         -moz-border-radius: 12px !important;
    7475                    border-radius: 12px !important;
    75     -webkit-transition: none;
    76          -moz-transition: none;
    77              -o-transition: none;
    78                     transition: none;
    79     -webkit-background-clip: padding-box;   
    8076}
    8177
     
    150146    cursor: default;
    151147    margin-top: 1px;
    152     /* padding: 0.5em 0.9em; */
    153148    border-color: #000;
    154149    color: #fff;
  • easy-paypal-custom-fields/trunk/easy-paypal-custom-fields.php

    r465329 r472131  
    44Plugin URI: http://richardsweeney.com/blog/easy-paypal-custom-fields/
    55Description: This plugin uses custom fields to make creating a PayPal button super-easy. There is no complicated shortcut syntax to remember.
    6 Version: 2.0.1
     6Version: 2.0.2
    77Author: Richard Sweeney
    88Author URI: http://richardsweeney.com/
     
    4242    private $currency_array = array(
    4343        'Australian Dollar' => 'AUD',
    44         'Brazilian Real' => 'BRL',
    4544        'Canadian Dollar' => 'CAD',
    4645        'Czech Koruna'  => 'CZK',
    4746        'Danish Krone' => 'DKK',
    4847        'Euro' => 'EUR',
    49         'Hong Kong Dollar' => 'HKD',
    5048        'Hungarian Forint' => 'HUF',
    51         'Israeli New Sheqel' => 'ILS',
    5249        'Japanese Yen' => 'JPY',
    53         'Malaysian Ringgit' => 'MYR',
    54         'Mexican Peso' => 'MXN',
    5550        'Norwegian Krone' => 'NOK',
    5651        'New Zealand Dollar' => 'NZD',
    57         'Philippine Peso' => 'PHP',
    5852        'Polish Zloty' => 'PLN',
    5953        'Pound Sterling' => 'GBP',
     
    6155        'Swedish Krona' => 'SEK',
    6256        'Swiss Franc' => 'CHF',
    63         'Taiwan New Dollar' => 'TWD',
    64         'Thai Baht' => 'THB',
    65         'Turkish Lira' => 'TRY',
    6657        'U.S. Dollar' => 'USD'
    6758    );
     
    8374    );
    8475
    85     // used for checking against individual post meta - see loopy_meta()
     76    // used for checking against individual post meta - see get_the_post_meta()
    8677    private $some_meta = array(
    8778        'amount',
     
    8980        'item_no',
    9081        'textfield_checkbox',
    91         'textfield_title'
     82        'textfield_title',
     83        'quantity_checkbox',
     84        'require_address'
    9285        //'drop_down_title'
    9386    );
    9487   
    95     // Default values - used for checking against individual post meta - see loopy_meta()
     88    // Default values - used for checking against individual post meta - see get_the_post_meta()
    9689    private $default_meta = array(
    9790        'user_email',
     
    10598    // These variables are declared later
    10699    public $opts; // default options, declared in __construct()
    107     public $my_post_meta; // indivdual, additional post meta, declared in loopy_meta()
     100    public $my_post_meta; // indivdual, additional post meta, declared in get_the_post_meta()
    108101    public $paypal_button; // the button, declared in create_button()
    109102
     
    115108
    116109        // Define current version
    117         define( 'PAYPAL_VERSION', '2.0.1' );
     110        define( 'PAYPAL_VERSION', '2.0.2' );
    118111   
    119112        // Activation Hook
    120         register_activation_hook( __FILE__, array( &$this, 'plugin_activate' ) );
     113        register_activation_hook( __FILE__, array( &$this, 'activate_my_plugin' ) );
    121114   
    122115        // Add stylesheet to the admin pages & the front end
    123116        add_action( 'admin_print_styles-post.php', array( &$this, 'add_css' ) );
    124117        add_action( 'admin_print_styles-post-new.php', array( &$this, 'add_css' ) );
    125         add_action( 'template_redirect', array( &$this, 'add_css' ) );
     118        add_action( 'wp_print_styles', array( &$this, 'add_css' ) );
    126119       
    127120        // Add my JS to WP Admin
     
    129122       
    130123        // Create options page & menu item
    131         add_action( 'admin_menu', array( &$this, 'add_page' ) );
     124        add_action( 'admin_menu', array( &$this, 'add_my_options_page' ) );
    132125       
    133126        // Register and define the settings
    134         add_action( 'admin_init', array( &$this, 'admin_init' ) );
     127        add_action( 'admin_init', array( &$this, 'create_settings_sections' ) );
    135128
    136129        // Create paypal meta box
    137         add_action( 'add_meta_boxes', array( &$this, 'eppcf_meta_box' ) );
     130        add_action( 'add_meta_boxes', array( &$this, 'register_meta_box' ) );
    138131   
    139132        // Save post meta
     
    154147    * When the plugin is activated, add the default options
    155148    */
    156     public function plugin_activate() {
     149    public function activate_my_plugin() {
    157150   
    158151        // On plugin activation register the following options 
     
    170163       
    171164        // Uninstaller function callback
    172         register_uninstall_hook( __FILE__, array( &$this, 'plugin_uninstaller' ) );
    173    
    174     }
    175    
    176        
    177     /**
     165        register_uninstall_hook( __FILE__, array( &$this, 'uninstall_my_plugin' ) );
     166   
     167    }
     168   
     169       
     170 /**
    178171    * Uninstall function
    179172    */
    180     public function plugin_uninstaller() {
     173    public function uninstall_my_plugin() {
    181174           
    182175        // Get any custom post types
     
    216209   
    217210       
    218     /**
     211 /**
    219212    * Add custom CSS
    220213    */
    221214    public function add_css() {
    222         wp_enqueue_style( 'eppcf_css', plugin_dir_url(__FILE__) . 'css/paypal.css');
    223     }
    224    
    225     /**
     215        wp_enqueue_style( 'eppcf_css', plugin_dir_url(__FILE__) . 'css/paypal.css' );
     216    }
     217   
     218 /**
    226219    * Add custom JavaScript
    227220    */
     
    240233    */
    241234   
    242     public function loopy_meta( $meta_array ){
     235    public function get_the_post_meta( $meta_array ){
     236   
    243237        $post_meta_array = array();
    244         $post_meta_array['show'] = ( isset( $meta_array['show'] ) && !empty( $meta_array['show'] ) ) ? $meta_array['show'] : 'no';
    245         $post_meta_array['name'] = ( isset( $meta_array['name'] ) && !empty( $meta_array['name'] ) ) ? $meta_array['name'] : '';
     238        $post_meta_array['show'] = ( !empty( $meta_array['show'] ) ) ? $meta_array['show'] : 'no';
     239        $post_meta_array['name'] = ( !empty( $meta_array['name'] ) ) ? $meta_array['name'] : '';
     240       
    246241        foreach( $this->some_meta as $meta ){
    247242            $post_meta_array[$meta] = ( isset ( $meta_array[$meta] ) ) ? $meta_array[$meta] : '';
    248243        }
     244       
    249245        foreach( $this->default_meta as $default ){
    250246            $post_meta_array[$default] = ( isset( $meta_array[$default] ) && !empty( $meta_array[$default] ) ) ? $meta_array[$default] : $this->opts[$default];
    251247        }
     248       
     249       
    252250        // Backwards compatibility
    253251        // My old, stupid names for stuff => because I'm a dork.
     
    272270    */
    273271   
    274     public function add_page() {
     272    public function add_my_options_page() {
    275273        $ops = add_options_page(
    276274            'Easy PayPal Custom Fields',
     
    278276            'manage_options',
    279277            'easy-paypal-custom-fields',
    280             array( &$this, 'options_page' ) // callback function to draw the options page
     278            array( &$this, 'echo_options_page' ) // callback function to draw the options page
    281279        );
    282280        // Add plugin CSS to this page
     
    290288    */
    291289   
    292     public function options_page() {
     290    public function echo_options_page() {
    293291       
    294292        // Shorthand as there are some many checks to be made against button_type & theme
     
    354352   
    355353   
    356     public function admin_init(){
     354    public function create_settings_sections(){
    357355   
    358356        register_setting(
    359357            'rps_eppcf_options',
    360358            'rps_eppcf_options',
    361             array( $this, 'validate_options' )
     359            array( &$this, 'validate_options' )
    362360        );
    363361   
     
    365363            'rps_eppcf_main',
    366364            'Enter your default settings here',
    367             array( $this, 'settings_section_header' ),
     365            array( &$this, 'echo_settings_section_header' ),
    368366            'rps_eppcf_settings_page'
    369367        );
     
    373371                'id' => 'settings-input', //HTML ID tag for the section
    374372                'text' => 'PayPal username',  // Text to output for the section
    375                 'function' => array( $this, 'settings_input' ) // Callback function (to echo the form field)
     373                'function' => array( &$this, 'echo_settings_input' ) // Callback function (to echo the form field)
    376374            ),
    377375            array(
    378376                'id' => 'settings-curreny',
    379377                'text' => 'Default currency',
    380                 'function' => array( $this, 'settings_currency' )
     378                'function' => array( &$this, 'echo_settings_currency' )
    381379            ),
    382380            array(
    383381                'id' => 'settings-button-type',
    384382                'text' => 'Select a button type',
    385                 'function' => array( $this, 'settings_button_type' )
     383                'function' => array( &$this, 'echo_settings_button_type' )
    386384            ),
    387385            array(
    388386                'id' => 'settings-button-text',
    389387                'text' => 'Custom button text (optional)',
    390                 'function' => array( $this, 'settings_button_text' )
     388                'function' => array( &$this, 'echo_settings_button_text' )
    391389            ),
    392390            array(
    393391                'id' => 'settings-url',
    394392                'text' => 'Return URL (optional)',
    395                 'function' => array( $this, 'settings_url' )
     393                'function' => array( &$this, 'echo_settings_url' )
    396394            ),
    397395            array(
    398396                'id' => 'settings-post-type',
    399397                'text' => 'Select on which post type to display the Button',
    400                 'function' => array( $this, 'settings_post_type' )
     398                'function' => array( &$this, 'echo_settings_post_type' )
    401399            ),
    402400            array(
    403401                'id' => 'settings-theme',
    404402                'text' => 'Select a theme for the button',
    405                 'function' => array( $this, 'settings_theme' )
     403                'function' => array( &$this, 'echo_settings_theme' )
    406404            )
    407405        );
     
    430428    *   Draw settings page functions follow:
    431429    */
    432     public function settings_section_header() {
     430    public function echo_settings_section_header() {
    433431        // echo '<p><strong>Plugin Settings:</strong></p>';
    434432    }
    435433   
    436434
    437     public function settings_input() { ?>
     435    public function echo_settings_input() { ?>
    438436        <input placeholder="email@address.com" id="user-email" name="rps_eppcf_options[user_email]" type="text" value="<?php echo $this->opts['user_email']; ?>" />
    439437    <?php }
    440438   
    441439   
    442     public function settings_currency() { ?>
     440    public function echo_settings_currency() { ?>
    443441        <select id="currency" name="rps_eppcf_options[currency]">
    444442            <?php foreach( $this->currency_array as $key => $value ) : ?>
     
    449447   
    450448   
    451     public function settings_button_type() { ?>
     449    public function echo_settings_button_type() { ?>
    452450        <p>
    453451            <select id="button-type" name="rps_eppcf_options[button_type]">
     
    462460   
    463461   
    464     public function settings_button_text() { ?>
     462    public function echo_settings_button_text() { ?>
    465463        <input placeholder="eg. 'Buy CD'" id="button-text" name="rps_eppcf_options[button_text]" type="text" value="<?php echo $this->opts['button_text']; ?>" />
    466464    <?php }
    467465   
    468466   
    469     public function settings_url() { ?>
     467    public function echo_settings_url() { ?>
    470468        <input placeholder="The URL to return to after checkout" type="text" id="url" name="rps_eppcf_options[url]" value="<?php echo $this->opts['url']; ?>" />
    471469    <?php }
    472470   
    473471   
    474     public function settings_post_type() {
     472    public function echo_settings_post_type() {
    475473       
    476474        // Get any custom post types
     
    520518   
    521519   
    522     public function settings_theme() { ?>
     520    public function echo_settings_theme() { ?>
    523521        <p>
    524522            <select id="theme" name="rps_eppcf_options[theme]">
     
    606604    */
    607605   
    608     public function eppcf_meta_box() {
     606    public function register_meta_box() {
    609607       
    610608        // Loop through the selected post types & create the meta box on the selected pages
     
    614612                'rps_paypal_meta',
    615613                'Add Paypal Button',
    616                 array( &$this, 'eppcf_meta_box_callback' ),
     614                array( &$this, 'echo_meta_box' ),
    617615                $post_type,
    618616                'normal',
     
    628626    *    Callback function to draw the meta box on post / page / custom post type
    629627    */
    630     public function eppcf_meta_box_callback( $post ) {
     628    public function echo_meta_box( $post ) {
    631629       
    632630        // Get the current post meta & default settings
    633631        $rps_meta_array = get_post_meta( $post->ID, '_rps_eppcf_array', true );
    634         $this->loopy_meta( $rps_meta_array );
     632        $this->get_the_post_meta( $rps_meta_array );
    635633        ?>
    636634       
     
    667665           
    668666            <p>
     667                <span>Require customers' address</span>
     668                <label>
     669                    <input type="checkbox" id="require_address" name="require_address" value="true" <?php checked( $this->my_post_meta['require_address'], true ); ?> />
     670                    Yes
     671                </label>
     672            </p>
     673           
     674            <p>
     675                <span>Allow customer to select quantity</span>
     676                <label>
     677                    <input type="checkbox" id="quantity_checkbox" name="quantity_checkbox" value="true" <?php checked( $this->my_post_meta['quantity_checkbox'], true ); ?> />
     678                    Yes
     679                </label>
     680            </p>
     681           
     682            <p>
    669683                <span>Add a custom textfield</span>
    670684                <label>
    671685                    <input type="checkbox" id="textfield_checkbox" name="textfield_checkbox" value="true" <?php checked( $this->my_post_meta['textfield_checkbox'], true ); ?> />
    672                     Yes please
     686                    Yes
    673687                </label>
    674688            </p>
     
    794808        } else {
    795809            $eppcf_array['name'] = '';
    796         }   
    797        
    798         if( isset( $_POST['textfield_checkbox'] ) && $_POST['textfield_checkbox'] == 'true' ){
    799             $eppcf_array['textfield_checkbox'] = true;
    800         } else {
    801             $eppcf_array['textfield_checkbox'] = false;
     810        }
     811       
     812        $checkboxVals = array( 'require_address', 'textfield_checkbox', 'quantity_checkbox' );
     813       
     814        foreach( $checkboxVals as $checkboxVal ){
     815            if( isset( $_POST[ $checkboxVal ] ) && $_POST[ $checkboxVal ] == 'true' ){
     816                $eppcf_array[ $checkboxVal ] = true;
     817            } else {
     818                $eppcf_array[ $checkboxVal ] = false;
     819            }
    802820        }
    803821       
     
    869887        // Get post meta
    870888        $rps_meta_array = get_post_meta( $post->ID, '_rps_eppcf_array', true );
    871         $this->loopy_meta( $rps_meta_array );
     889        $this->get_the_post_meta( $rps_meta_array );
    872890       
    873891        // Shorthand
     
    881899            KISS
    882900        */
    883         $tf_i = 0;
     901        // $tf_i = 0;
    884902       
    885903        // If there are 2 additional textfields, they must have different IDs
     
    933951        }
    934952       
    935         if( $theme == 'use PayPal image - large' ) {
    936             if( $button_type == 'Buy Now' ) {
    937                 $args = array();
    938             } else if ( $button_type == 'Donations' ) {
    939                 $args = array( 'src' => 'btn_buynow_LG.gif' );
    940             }
    941         } else if( $theme == 'use PayPal image - small' ){
    942             if( $button_type == 'Buy Now' ) {
    943                 $args = array( 'src' => 'btn_buynow_SM.gif' );
    944             } else if( $button_type == 'Donations' ) {
    945                 $args = array( 'src' => 'btn_donate_SM.gif' );
    946             }
    947         } else if( $theme == 'light theme' ) {
    948             $args = array( 'type' => 'custom_theme', 'button_text' => $button_text );
    949         } else if( $theme == 'dark theme' ) {
    950             $args = array( 'type' => 'custom_theme', 'id' => 'rps-paypal-button-dark', 'button_text' => $button_text );
    951         } else if( $theme == 'blue theme' ) {
    952             $args = array( 'type' => 'custom_theme', 'id' => 'rps-paypal-button-blue', 'button_text' => $button_text );
    953         } else if( $theme == 'red theme' ) {
    954             $args = array( 'type' => 'custom_theme', 'id' => 'rps-paypal-button-red', 'button_text' => $button_text );
     953        switch( $theme ){
     954            case 'use PayPal image - large' :
     955                if( $button_type == 'Buy Now' ) {
     956                    $args = array();
     957                } else if ( $button_type == 'Donations' ) {
     958                    $args = array( 'src' => 'btn_buynow_LG.gif' );
     959                }
     960                break;
     961            case 'use PayPal image - small' :
     962                if( $button_type == 'Buy Now' ) {
     963                    $args = array( 'src' => 'btn_buynow_SM.gif' );
     964                } else if( $button_type == 'Donations' ) {
     965                    $args = array( 'src' => 'btn_donate_SM.gif' );
     966                }
     967                break;
     968            case 'light theme' :
     969                $args = array( 'type' => 'custom_theme', 'button_text' => $button_text );
     970                break;
     971            case 'dark theme' :
     972                $args = array( 'type' => 'custom_theme', 'id' => 'rps-paypal-button-dark', 'button_text' => $button_text );
     973                break;
     974            case 'blue theme' :
     975                $args = array( 'type' => 'custom_theme', 'id' => 'rps-paypal-button-blue', 'button_text' => $button_text );
     976                break;
     977            case 'red theme' :
     978                $args = array( 'type' => 'custom_theme', 'id' => 'rps-paypal-button-red', 'button_text' => $button_text );
     979                break;
    955980        }
    956981       
    957982        $button .= $this->type_of_button( $args );
    958983       
    959                
    960984        // Username (email address)
    961985        $button .= '<input type="hidden" name="business" value="' . antispambot( $this->my_post_meta['user_email'] ) .'" />';
     
    974998        $button .= '
    975999            <input type="hidden" name="amount" value="' . $this->my_post_meta['amount'] . '" />
    976             <input type="hidden" name="currency_code" value="' . $this->my_post_meta['currency'] . '" />
    977             <input type="hidden" name="shipping" value="' . $this->my_post_meta['postage'] . '" />
    978             <input type="hidden" name="rm" value="2" />
    979         ';
     1000            <input type="hidden" name="currency_code" value="' . $this->my_post_meta['currency'] . '" />';
     1001       
     1002        if( $button_type == 'Buy Now' ) {
     1003            $button .= '<input type="hidden" name="shipping" value="' . $this->my_post_meta['postage'] . '" />';
     1004        }
     1005       
     1006        $needAddress = ( $this->my_post_meta['require_address'] == true ) ? 2 : 1;
     1007       
     1008        $button .= '<input type="hidden" name="no_shipping" value="' . $needAddress - '">
     1009            <input type="hidden" name="rm" value="2" />';
     1010       
     1011        if( $button_type == 'Buy Now' && $this->my_post_meta['quantity_checkbox'] == true ) {
     1012            $button .= '<input type="hidden" name="undefined_quantity" value="1">';
     1013        }
    9801014       
    9811015        // Return url
     
    9921026    }
    9931027   
    994 /**
     1028   
     1029   
     1030 /**
    9951031    * Where the button should appear
    9961032    *
    9971033    * @param string the post content
    9981034    */
    999    
    10001035    public function display_button( $content ) {
    10011036   
     
    10031038        // Get the current post meta
    10041039        $rps_meta_array = get_post_meta( $post->ID, '_rps_eppcf_array', true );
    1005         $show = ( isset( $rps_meta_array['show'] ) && !empty( $rps_meta_array['show'] ) ) ? $rps_meta_array['show'] : 'no';
     1040        $show = ( isset( $rps_meta_array['show'] ) ) ? $rps_meta_array['show'] : 'no';
    10061041        // Create the button
    10071042        $this->create_button();
     
    10241059       
    10251060    }
    1026 
    1027 
    1028 /**
     1061   
     1062
     1063
     1064 /**
    10291065    * Create button shortcode
    10301066    */
    1031    
    10321067    function create_shortcode() {
    10331068        $this->create_button();
     
    10451080    * having to prefix all my functions makes it all super worth it.
    10461081    */
    1047 $rps_eppcf = new RPS_eppcf();
    1048 
     1082    $rps_eppcf = new RPS_eppcf();
    10491083   
    10501084?>
  • easy-paypal-custom-fields/trunk/readme.txt

    r465331 r472131  
    66Requires at least: 3.0
    77Tested up to: 3.2.1
    8 Stable tag: 2.0
     8Stable tag: 2.0.2
    99
    1010An easy-to-use plugin to add a PayPal 'donate' or 'buy now' button to your site.
     
    7474= 2.0 =
    7575
    76 * Completely rebuilt and optimized the (using OOP).
     76* Completely rebuilt and optimized the plugin (using OOP).
    7777* Added the option to add a custom textfield (displayed above the button).
    7878* Added support for opera CSS3 gradients for custom button themes.
     
    8282
    8383* Fixed backwards compatibility issues and a few wee bugs.
     84
     85= 2.0.2 =
     86
     87* Added the option to choose if the customer can alter the number of items to purchase.
     88* Added the option to make collection of the customers' address mandatory.
     89* Optimized code readability.
     90* Amended list of supported currency codes.
Note: See TracChangeset for help on using the changeset viewer.