Changeset 1974560
- Timestamp:
- 11/15/2018 01:54:23 AM (7 years ago)
- Location:
- wp-web-monetization/trunk
- Files:
-
- 2 edited
-
inject.js (modified) (1 diff)
-
wordpress-web-monetization.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-web-monetization/trunk/inject.js
r1878800 r1974560 1 1 window.onload = function() { 2 // Inject window.monetize into your own payment pointer. 3 if(window.monetize) {4 var receiver = (php_vars && php_vars[0].payment_pointer) || ''5 return window.monetize({ receiver })6 } else {7 // Show error box to say window.monetize is not defined and to turn it on in admin page.8 alert('Your extension is not turned on or downloaded. Please download a web monetization extention.')9 return new Error('window.monetize is not defined!')10 } 2 3 const paymentPointer = (php_vars && php_vars[0].payment_pointer) || '' 4 const addCoilAdvert = (php_vars && php_vars[0].add_coil_advert) || false 5 console.log('paymentPointer', paymentPointer) 6 console.log('addCoilADvert', addCoilAdvert) 7 window.WebMonetizationScripts.donate({ 8 paymentPointer, 9 addCoilAdvert 10 }) 11 11 } -
wp-web-monetization/trunk/wordpress-web-monetization.php
r1878800 r1974560 16 16 17 17 public function custom_js_register() { 18 wp_register_script('polyfill', 'https://polyfill.webmonetization.org/polyfill.js'); 19 wp_register_script('coil', 'https://cdn.coil.com/donate.js'); 18 20 wp_register_script('inject', plugins_url( '/', __FILE__ ) . 'inject.js'); 21 wp_enqueue_script('polyfill'); 22 wp_enqueue_script('coil'); 19 23 wp_enqueue_script('inject'); 20 24 $dataToBePassed = array( 21 get_option('payment_pointer_option') 25 get_option('payment_pointer_option'), 26 get_option('add_coil_advert_option') 22 27 ); 23 28 wp_localize_script( 'inject', 'php_vars', $dataToBePassed ); … … 63 68 { 64 69 // Set class property 65 $this->options = get_option( 'payment_pointer_option' ); 70 $this->options = array( 71 'payment_pointer'=> get_option( 'payment_pointer_option' ), 72 'add_coil_advert'=> get_option('add_coil_advert_option') 73 ); 66 74 ?> 67 75 <div class="wrap"> … … 84 92 public function page_init() 85 93 { 86 register_setting(87 'my_option_group', // Option group88 'payment_pointer_option', // Option name89 array( $this, 'sanitize' ) // Sanitize90 );91 94 92 95 add_settings_section( … … 104 107 'setting_section_id' // Section 105 108 ); 109 add_settings_field( 110 'add_coil_advert', 111 'Advertise Coil', 112 array($this, 'add_coil_advert_callback'), 113 'web-monetization-admin', 114 'setting_section_id' 115 ); 116 register_setting( 117 'my_option_group', // Option group 118 'payment_pointer_option', // Option name 119 array( $this, 'sanitize' ) // Sanitize 120 ); 121 register_setting( 122 'my_option_group', 123 'add_coil_advert_option' 124 ); 125 106 126 } 107 127 … … 132 152 * Get the settings option array and print one of its values 133 153 */ 154 public function add_coil_advert_callback() 155 { 156 $options = get_option( 'add_coil_advert_option' ); 157 echo "<script>console.log( \"PHP DEBUG: $options\" );</script>"; 158 $html = '<input type="checkbox" id="add_coil_advert" name="add_coil_advert_option[add_coil_advert]" value="1"' . checked( 1, $options['add_coil_advert'], false ) . '/>'; 159 $html .= '<label for="add_coil_advert">This displays a widget that advertises Coil to those who do not have a subscription.</label>'; 160 161 echo $html; 162 } 163 134 164 public function payment_pointer_callback() 135 165 { 166 $options = get_option('payment_pointer_option'); 136 167 printf( 137 168 '<input type="text" id="payment_pointer" name="payment_pointer_option[payment_pointer]" value="%s" />', 138 isset( $this->options['payment_pointer'] ) ? esc_attr( $ this->options['payment_pointer']) : ''169 isset( $this->options['payment_pointer'] ) ? esc_attr( $options['payment_pointer']) : '' 139 170 ); 140 171 }
Note: See TracChangeset
for help on using the changeset viewer.