Plugin Directory

Changeset 1974560


Ignore:
Timestamp:
11/15/2018 01:54:23 AM (7 years ago)
Author:
androswong418
Message:

fix: move to new web-monetization standard and add coil advert option

Location:
wp-web-monetization/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-web-monetization/trunk/inject.js

    r1878800 r1974560  
    11window.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  })
    1111}
  • wp-web-monetization/trunk/wordpress-web-monetization.php

    r1878800 r1974560  
    1616
    1717  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');
    1820    wp_register_script('inject', plugins_url( '/', __FILE__ ) . 'inject.js');
     21    wp_enqueue_script('polyfill');
     22    wp_enqueue_script('coil');
    1923    wp_enqueue_script('inject');
    2024    $dataToBePassed = array(
    21      get_option('payment_pointer_option')
     25     get_option('payment_pointer_option'),
     26     get_option('add_coil_advert_option')
    2227    );
    2328    wp_localize_script( 'inject', 'php_vars', $dataToBePassed );
     
    6368    {
    6469        // 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        );
    6674        ?>
    6775        <div class="wrap">
     
    8492    public function page_init()
    8593    {
    86         register_setting(
    87             'my_option_group', // Option group
    88             'payment_pointer_option', // Option name
    89             array( $this, 'sanitize' ) // Sanitize
    90         );
    9194
    9295        add_settings_section(
     
    104107            'setting_section_id' // Section
    105108        );
     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       
    106126    }
    107127
     
    132152     * Get the settings option array and print one of its values
    133153     */
     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
    134164    public function payment_pointer_callback()
    135165    {
     166        $options = get_option('payment_pointer_option');
    136167        printf(
    137168            '<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']) : ''
    139170        );
    140171    }
Note: See TracChangeset for help on using the changeset viewer.