Changeset 973049
- Timestamp:
- 08/26/2014 08:37:42 AM (12 years ago)
- Location:
- mg-donations/trunk
- Files:
-
- 6 added
- 4 deleted
- 5 edited
-
includes/admin (added)
-
includes/admin/class-mg-dn-admin-menu.php (added)
-
includes/admin/class-mg-dn-list-table-donation-cause.php (added)
-
includes/admin/class-mg-dn-list-table-donation.php (added)
-
includes/admin/class-mg-dn-post-editor-donation-cause.php (added)
-
includes/admin/class-mg-dn-settings-ui.php (added)
-
includes/class-mg-dn-admin-menu.php (deleted)
-
includes/class-mg-dn-installer.php (modified) (1 diff)
-
includes/class-mg-dn-list-table-donation-cause.php (deleted)
-
includes/class-mg-dn-list-table-donation.php (deleted)
-
includes/class-mg-dn-paypal.php (modified) (3 diffs)
-
includes/class-mg-dn-post-editor-donation-cause.php (deleted)
-
includes/class-mg-dn-settings.php (modified) (3 diffs)
-
plugin.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
mg-donations/trunk/includes/class-mg-dn-installer.php
r971226 r973049 9 9 $this->plugin = $mg_dn_plugin; 10 10 11 register_activation_hook($this->plugin->path['PLUGIN_FILE'], array($this, ' install'));11 register_activation_hook($this->plugin->path['PLUGIN_FILE'], array($this, 'activation')); 12 12 } 13 13 14 public function install() {15 $this->plugin->settings->setup _factory_settings();14 public function activation() { 15 $this->plugin->settings->setup(); 16 16 17 17 // Refresh permalinks -
mg-donations/trunk/includes/class-mg-dn-paypal.php
r971226 r973049 7 7 private $recipient_email; 8 8 private $currency; 9 private $ confirm_page;10 private $cancel_ page;9 private $return_url; 10 private $cancel_url; 11 11 private $return_button_text; 12 private $return_link_text; 12 13 13 14 public function __construct($cfg) { … … 16 17 $this->recipient_email = $cfg['recipient_email']; 17 18 $this->currency = $cfg['currency']; 18 $this-> confirm_page = $cfg['confirm_page'];19 $this->cancel_ page = $cfg['cancel_page'];20 $this->return_ button_text = $cfg['return_button_text'];19 $this->return_url = $cfg['return_url']; 20 $this->cancel_url = $cfg['cancel_url']; 21 $this->return_link_text = $cfg['return_link_text']; 21 22 22 23 add_action('mg_dn_ipn', array($this, 'ipn_listener')); … … 35 36 <input type="hidden" name="item_number" value="<?php echo esc_attr($cause_id); ?>"> 36 37 37 <?php if (!empty($this-> confirm_page)): ?>38 <input type="hidden" name="return" value="<?php echo esc_url($this-> confirm_page); ?>">38 <?php if (!empty($this->return_url)): ?> 39 <input type="hidden" name="return" value="<?php echo esc_url($this->return_url); ?>"> 39 40 <?php endif; ?> 40 <?php if (!empty($this->cancel_ page)): ?>41 <input type="hidden" name=" return" value="<?php echo esc_url($this->cancel_page); ?>">41 <?php if (!empty($this->cancel_url)): ?> 42 <input type="hidden" name="cancel_return" value="<?php echo esc_url($this->cancel_url); ?>"> 42 43 <?php endif; ?> 43 44 <input type="hidden" name="cbt" value="<?php echo esc_attr($this->return_button_text); ?>"> 44 <?php if (!empty($this->return_link_text)): ?> 45 <input type="hidden" name="cbt" value="<?php echo esc_attr($this->return_link_text); ?>"> 46 <?php endif; ?> 45 47 46 48 <?php mg_dn_get_template("buttons/$button_template", $button_args); ?> -
mg-donations/trunk/includes/class-mg-dn-settings.php
r971226 r973049 3 3 class mg_dn_Settings { 4 4 5 const OPTION_GROUP = 'mg_dn';6 5 const OPTION_NAME = 'mg_dn'; 7 6 8 7 public function __construct() { 9 add_action('admin_init', array($this, 'setup'));10 add_action('admin_notices', array($this, 'user_feedback'));11 8 } 12 9 … … 15 12 } 16 13 17 public function setup() { 18 register_setting(self::OPTION_GROUP, self::OPTION_NAME, array($this, 'sanitize')); 19 20 add_settings_section( 21 'mg_dn_settings_section_general', 22 'General', 23 '', // callback 24 'mg_dn_settings_page' 25 ); 26 27 add_settings_field( 28 'mg_dn_settings_field_recipient_email', 29 'PayPal Email', 30 array($this, 'render_control_recipient_email'), 31 'mg_dn_settings_page', 32 'mg_dn_settings_section_general' 33 //$args 34 ); 35 36 add_settings_field( 37 'mg_dn_settings_field_currency', 38 'Currency', 39 array($this, 'render_control_currency'), 40 'mg_dn_settings_page', 41 'mg_dn_settings_section_general' 42 //$args 43 ); 44 45 add_settings_field( 46 'mg_dn_settings_field_return_button_text', 47 'Return Button Text', 48 array($this, 'render_control_return_button_text'), 49 'mg_dn_settings_page', 50 'mg_dn_settings_section_general' 51 //$args 52 ); 53 54 add_settings_field( 55 'mg_dn_settings_field_sandbox', 56 'PayPal Sandbox', 57 array($this, 'render_control_sandbox'), 58 'mg_dn_settings_page', 59 'mg_dn_settings_section_general' 60 //$args 61 ); 62 63 add_settings_field( 64 'mg_dn_settings_field_debug', 65 'Enable Debug', 66 array($this, 'render_control_debug'), 67 'mg_dn_settings_page', 68 'mg_dn_settings_section_general' 69 //$args 14 public function get_option_name() { 15 return self::OPTION_NAME; 16 } 17 18 public function get_factory_settings() { 19 return array( 20 'recipient_email' => '', 21 'currency' => 'EUR', 22 'sandbox' => false, 23 'debug' => false, 24 'return_url' => '', 25 'cancel_url' => '', 26 'return_link_text' => '' 70 27 ); 71 28 } 72 29 73 public function settings_page() { 74 $this->settings = $this->get(); 75 ?> 76 <div class="wrap"> 77 <form action="options.php" method="POST"> 78 <?php settings_fields(self::OPTION_GROUP); ?> 79 <?php do_settings_sections('mg_dn_settings_page'); ?> 80 <?php submit_button(__('Save Changes'), 'primary', 'Update'); ?> 81 <?php submit_button(__( 'Restore Factory Settings'), 'secondary', 'restore_factory_settings'); ?> 82 </form> 83 </div> 84 <?php 85 } 86 87 public function get_page() { 88 return array($this, 'settings_page'); 89 } 90 91 public function render_control_recipient_email() { 92 ?> 93 <input type="text" name="<?php echo self::OPTION_NAME . '[recipient_email]'; ?>" value="<?php echo esc_attr($this->settings['recipient_email']); ?>" size="40"> 94 <?php 95 } 96 97 public function render_control_currency() { 30 public function sanitize($new_settings) { 31 $settings = $this->get(); 32 33 $settings['sandbox'] = empty($new_settings['sandbox']) ? false : true; 34 $settings['debug'] = empty($new_settings['debug']) ? false : true; 35 36 if (is_email($new_settings['recipient_email'])) 37 $settings['recipient_email'] = $new_settings['recipient_email']; 38 else 39 add_settings_error('mg_dn', 'ko_invalid_email', __('The PayPal email is invalid', 'mg_dn'), 'error'); 40 98 41 global $mg_dn_plugin; 99 $currencies = $mg_dn_plugin->money->get_currencies(); 100 $current_currency = $this->settings['currency']; 101 ?> 102 <select name="<?php echo self::OPTION_NAME . '[currency]'; ?>"> 103 <?php foreach ($currencies as $code => $info): ?> 104 <option value="<?php echo esc_attr($code); ?>"<?php selected($current_currency, $code); ?>><?php echo esc_html($info['name'] . " ({$info['sign']})"); ?></option> 105 <?php endforeach; ?> 106 </select> 107 <?php 108 } 109 110 public function render_control_return_button_text() { 111 ?> 112 <input type="text" name="<?php echo self::OPTION_NAME . '[return_button_text]'; ?>" value="<?php echo esc_attr($this->settings['return_button_text']); ?>" size="40"> 113 <?php 114 } 115 116 public function render_control_sandbox() { 117 ?> 118 <input type="checkbox" name="<?php echo self::OPTION_NAME . '[sandbox]'; ?>" value="yes"<?php checked($this->settings['sandbox'], true); ?>> 119 <?php 120 } 121 122 public function render_control_debug() { 123 ?> 124 <input type="checkbox" name="<?php echo self::OPTION_NAME . '[debug]'; ?>" value="yes"<?php checked($this->settings['debug'], true); ?>> 125 <?php 126 } 127 128 public function sanitize($new_settings) { 129 if (isset($_POST['restore_factory_settings'])) 130 $settings = $this->get_factory_settings(); 131 else { 132 $settings = $this->get(); 133 134 $settings['sandbox'] = empty($new_settings['sandbox']) ? false : true; 135 $settings['debug'] = empty($new_settings['debug']) ? false : true; 136 137 if (is_email($new_settings['recipient_email'])) 138 $settings['recipient_email'] = $new_settings['recipient_email']; 139 else 140 add_settings_error('mg_dn', 'ko_invalid_email', __('The PayPal email is invalid', 'mg_dn'), 'error'); 141 142 global $mg_dn_plugin; 143 if (in_array($new_settings['currency'], array_keys($mg_dn_plugin->money->get_currencies()))) 144 $settings['currency'] = $new_settings['currency']; 145 else 146 add_settings_error('mg_dn', 'ko_invalid_currency', __('The currency is invalid', 'mg_dn'), 'error'); 147 148 $settings['return_button_text'] = sanitize_text_field($new_settings['return_button_text']); 149 } 42 if (in_array($new_settings['currency'], array_keys($mg_dn_plugin->money->get_currencies()))) 43 $settings['currency'] = $new_settings['currency']; 44 else 45 add_settings_error('mg_dn', 'ko_invalid_currency', __('The currency is invalid', 'mg_dn'), 'error'); 150 46 151 if (count(get_settings_errors('mg_dn')) === 0) 152 add_settings_error('mg_dn', 'ok', __('Settings saved', 'mg_dn'), 'updated'); 47 $settings['return_url'] = esc_url_raw($new_settings['return_url'], array('http', 'https')); 48 $settings['cancel_url'] = esc_url_raw($new_settings['cancel_url'], array('http', 'https')); 49 $settings['return_link_text'] = sanitize_text_field($new_settings['return_link_text']); 153 50 154 51 return $settings; 155 }156 157 private function get_factory_settings() {158 return array(159 'debug' => false,160 'sandbox' => false,161 'recipient_email' => '',162 'currency' => 'EUR',163 'return_button_text' => 'Return to site'164 //'confirm_page' => 0, //'http://donations.wp-labs.dev/donation-confirmation-page/',165 //'cancel_page' => 0, 'http://donations.wp-labs.dev/donation-cancel-page/',166 );167 }168 169 public function setup_factory_settings() {170 add_option(self::OPTION_NAME, $this->get_factory_settings());171 52 } 172 53 … … 175 56 } 176 57 177 public function user_feedback() { 178 settings_errors('mg_dn'); 58 public function setup() { 59 $factory_settings = $this->get_factory_settings(); 60 $curr_settings = get_option(self::OPTION_NAME); 61 62 if ($curr_settings === false) { 63 add_option(self::OPTION_NAME, $factory_settings); // This is a fresh install 64 } 65 else { 66 // Remove from the current settings all the key that are not present in factory settings 67 foreach (array_keys($curr_settings) as $key) 68 if (!key_exists($key, $factory_settings)) 69 unset($curr_settings[$key]); 70 71 // Add to current settings all the new keys in factory settings 72 foreach (array_keys($factory_settings) as $key) 73 if (!key_exists($key, $curr_settings)) 74 $curr_settings[$key] = $factory_settings[$key]; 75 76 update_option(self::OPTION_NAME, $curr_settings); 77 } 179 78 } 180 79 -
mg-donations/trunk/plugin.php
r971226 r973049 4 4 Plugin URI: http://mgiulio.info/projects/mg-donations 5 5 Description: Donations 6 Version: 1. 0-beta6 Version: 1.1 7 7 Author: Giulio 'mgiulio' Mainardi 8 8 Author URI: http://mgiulio.info … … 35 35 36 36 $class_path = $this->path['INCLUDES']; 37 37 38 if (strpos($class_name, 'mg_dn_Widget') === 0) 38 39 $class_path .= 'widgets/'; 40 else if (in_array($class_name, array( 41 'mg_dn_Admin_Menu', 42 'mg_dn_List_Table_Donation', 43 'mg_dn_List_Table_Donation_Cause', 44 'mg_dn_Post_Editor_Donation_Cause', 45 'mg_dn_Settings_UI', 46 ))) 47 $class_path .= 'admin/'; 48 39 49 40 50 require $class_path . $class_file; … … 43 53 public function bootstrap() { 44 54 $this->settings = new mg_dn_Settings(); 45 46 new mg_dn_Admin_Menu();47 55 48 56 $this->money = new mg_dn_Money(); … … 66 74 67 75 private function on_admin() { 76 new mg_dn_Admin_Menu(new mg_dn_Settings_UI($this->settings)); 68 77 new mg_dn_List_Table_Donation_Cause(); 78 new mg_dn_List_Table_Donation(); 69 79 new mg_dn_Post_Editor_Donation_Cause(); 70 new mg_dn_List_Table_Donation();71 80 72 81 add_action('admin_enqueue_scripts', array($this, 'inject_scripts_styles')); … … 78 87 $settings = $this->settings->get(); 79 88 80 foreach (array('debug', 'sandbox', 'recipient_email', 'currency', /* 'confirm_page', 'cancel_page', */ 'return_button_text') as $key) 81 $args[$key] = $settings[$key]; 82 $args['confirm_page'] = ''; // get page url 83 $args['cancel_page'] = ''; // get page url 84 85 $this->paypal = new mg_dn_PayPal($args); 89 $this->paypal = new mg_dn_PayPal($settings); 86 90 87 91 add_action('wp_enqueue_scripts', array($this, 'inject_scripts_styles')); -
mg-donations/trunk/readme.txt
r971226 r973049 21 21 == Changelog == 22 22 23 = 1.1 = 24 * Feature: implement PayPal return and cancel urls 25 23 26 = 1.0-beta = 24 27 * First release
Note: See TracChangeset
for help on using the changeset viewer.