-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaypal-shortcodes.php
136 lines (103 loc) · 5.53 KB
/
paypal-shortcodes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/*
Plugin Name: Paypal Shortcode
Plugin URI: http://wordpress.org/extend/plugins/paypal-shortcodes/
Description:
Author: SWERgroup
Version: 0.4
Author URI: http://swergroup.com/
Copyright (C) 2007+ Paolo Tresso / SWERgroup (http://swergroup.com/)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if( ! array_key_exists( 'swer-paypal-shortcodes', $GLOBALS ) ) {
class SWER_paypal_shortcodes{
function __construct(){
add_shortcode('paypal', array( $this, 'swer_paypal_shortcode') );
add_action( 'admin_init', array( &$this, '_admin_init' ) );
}
function _admin_init(){
add_settings_section( 'swer_paypal_shortcode', 'PayPal Shortcode', array( &$this, 'options_header'), 'writing');
add_settings_field( 'swer_paypal_email', 'Email', array( &$this, 'options_paypal_email'), 'writing', 'swer_paypal_shortcode');
register_setting( 'writing', 'swer_paypal_email' );
add_settings_field( 'swer_paypal_currency', 'Currency', array( &$this, 'options_paypal_currency'), 'writing', 'swer_paypal_shortcode');
register_setting( 'writing', 'swer_paypal_currency' );
add_settings_field( 'swer_paypal_text_add', 'ADD Text', array( &$this, 'options_paypal_text_add'), 'writing', 'swer_paypal_shortcode');
register_setting( 'writing', 'swer_paypal_text_add' );
add_settings_field( 'swer_paypal_text_view', 'VIEW Text', array( &$this, 'options_paypal_text_view'), 'writing', 'swer_paypal_shortcode');
register_setting( 'writing', 'swer_paypal_text_view' );
}
function options_header(){
echo 'Add Item: <code>[paypal type="add" name="Item Name" amount="12.99"]</code>. View Items: <code>[paypal type="view"]</code>';
}
function options_paypal_email(){
$mail = get_option( 'swer_paypal_email' );
$value = ($mail!='') ? $mail : '';
echo '<input type="text" name="swer_paypal_email" id="swer_paypal_email" value="'.$value.'"/>';
}
function options_paypal_currency(){
$mail = get_option( 'swer_paypal_currency' );
$value = ($mail!='') ? $mail : '';
echo '<input type="text" name="swer_paypal_currency" id="swer_paypal_currency" value="'.$value.'"/>';
}
function options_paypal_text_add(){
$text = get_option( 'swer_paypal_text_add' );
$value = ( $text!=='' ) ? $text : '';
echo '<input type="text" name="swer_paypal_text_add" id="swer_paypal_text_add" value="'.$value.'"/>';
}
function options_paypal_text_view(){
$text = get_option( 'swer_paypal_text_view' );
$value = ( $text!=='' ) ? $text : '';
echo '<input type="text" name="swer_paypal_text_view" id="swer_paypal_text_view" value="'.$value.'"/>';
}
// [paypal type="add" name="Item Name" amount="12.99"]
// [paypal type="view"]
function swer_paypal_shortcode($atts) {
extract( shortcode_atts( array(
'type' => 'paynow',
'name' => '',
'amount' => ''
), $atts ) );
switch( $type ):
case "add":
case "paynow":
$code = '
<form name="paypal-cart" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="'.get_option('swer_paypal_email',true).'">
<input type="hidden" name="currency_code" value="'.get_option('swer_paypal_currency',true).'">
<input type="hidden" name="item_name" value="'.$name.'">
<input type="hidden" name="amount" value="'.$amount.'">
<input type="hidden" name="no_shipping" value="2" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="bn" value="IC_Sample" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="'.get_option('swer_paypal_text_add',true).'">
<input type="hidden" name="add" value="1">
</form>';
break;
case "view":
$code = '
<form name="_xclick" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="'.get_option('swer_paypal_email',true).'">
<input type="image" src="https://www.paypal.com/en_US/i/btn/view_cart_new.gif" border="0" name="submit" alt="'.get_option('swer_paypal_text_view',true).'">
<input type="hidden" name="display" value="1">
</form>
';
break;
endswitch;
return $code;
}
}
$GLOBALS['swer-paypal-shortcodes'] = new SWER_paypal_shortcodes();
}
?>