Plugin Directory

Changeset 2578624


Ignore:
Timestamp:
08/05/2021 10:08:02 AM (5 years ago)
Author:
piwikpro
Message:

Version 1.1.0

Location:
piwik-pro
Files:
76 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • piwik-pro/trunk/.htaccess

    r2516197 r2578624  
    77    Require all denied
    88</IfModule>
    9 
    10 <FilesMatch "^(sync\.js|async\.js)$">
    11     <IfModule !mod_authz_core.c>
    12         Allow from all
    13     </IfModule>
    14 
    15     <IfModule mod_authz_core.c>
    16         Require all granted
    17     </IfModule>
    18 </FilesMatch>
  • piwik-pro/trunk/README.txt

    r2522592 r2578624  
    33Tags: Piwik PRO, Piwik, analytics, website stats
    44Requires at least: 5.7
    5 Tested up to: 5.7.1
    6 Stable tag: 1.0.2
     5Tested up to: 5.8
     6Stable tag: 1.1.0
    77Requires PHP: 7.4
    88License: GPLv3
     
    54542. If this command returns `true`, then you can safely use your custom name.
    5555
     56= How to support the Content Security Policy mechanism? =
     57
     58Content Security Policy restricts third-party tools from loading codes on the website and allows to fetch only approved origins of content. To support Content Security Policy mechanism, you need to add a `nonce` value as an attribute to containers and scripts that these containers load.
     59
     60To add a `nonce` value, follow these steps:
     61
     621. Add to a `function.php` file in yours theme the following code:
     63
     64`add_filter( 'piwik_pro_nonce', function() { return wp_create_nonce( time() ); } );`
     65
     66For more information, read our article about [Content Security Policy](https://developers.piwik.pro/en/latest/tag_manager/content_security_policy.html).
     67
    5668== Installation ==
    5769
     
    93105== Changelog ==
    94106
     107= 1.1.0 =
     108**Release date: 05.08.2021**
     109
     110* Fix: Removed fallback to display async snippet in footer if `wp_body_open()` function is don't implemented in the theme.
     111* Add: Added `piwik_pro_nonce` filter to enable passing `nonce` variable to scripts.
     112* Add: Added `nonce` variable to `dataLayer` to enable in sync scripts usage.
     113* Fix: Changed snippets rendering from files to inline scripts.
     114* Fix: Updated screenshot file.
     115
    95116= 1.0.2 =
    96117**Release date: 28.04.2021**
  • piwik-pro/trunk/includes/Plugin.php

    r2522592 r2578624  
    3030if ( ! class_exists( __NAMESPACE__ . '\Plugin' ) ) {
    3131    class Plugin extends \Clearcode\Framework\v6_1_2\Plugin {
    32         protected $nonce = '';
     32        protected $settings = [];
     33        protected $defaults = [
     34            'url' => '',
     35            'id' => '',
     36            'layer' => 'dataLayer',
     37            'sync' => false,
     38            'async' => true,
     39        ];
    3340
    34         public function activation() {
    35             add_option( Settings::OPTION, [
    36                 'url' => '',
    37                 'id' => '',
    38                 'layer' => 'dataLayer',
    39                 'sync' => false,
    40                 'async' => true
    41             ] );
     41        public function activation() {
     42            add_option( Settings::OPTION, $this->defaults );
    4243        }
    4344
    4445        public function deactivation() {}
    4546
    46         protected function __construct( $file ) {
    47             parent::__construct( $file );
     47        public function action_init() {
     48            if ( false === get_option( Settings::OPTION ) ) $this->activation();
     49            new Settings();
    4850
    49             if ( false === get_option( Settings::OPTION ) ) $this->activation();
    50 
    51             $this->nonce = bin2hex( random_bytes( 4 ) );
    52             new Settings();
     51            $this->settings = get_option( Settings::OPTION, $this->defaults );
     52            $this->settings[ 'nonce' ] = apply_filters( 'piwik_pro_nonce', '' );
    5353        }
    5454
     
    6464        }
    6565
    66         public function action_wp_enqueue_scripts() {
    67             if ( ! $settings = get_option( Settings::OPTION ) ) return;
    68             foreach ( [ 'url', 'id' ] as $key ) if ( ! $settings[ $key ] ) return;
     66        public function action_wp_head() {
     67            foreach ( [ 'url', 'id', 'layer', 'sync' ] as $key ) if ( ! $this->settings[ $key ] ) return;
    6968
    70             foreach ( [ 'sync', 'async' ] as $position => $container )
    71                 if ( $settings[ $container ] )
    72                     wp_enqueue_script(
    73                         self::get( 'slug' ) . "-$container",
    74                         self::get( 'url' ) . "assets/js/$container.js",
    75                         [],
    76                         '',
    77                         $position
    78                     );
    79         }
    80 
    81         public function filter_script_loader_tag( $tag, $handle, $src ) {
    82             if ( $settings = get_option( Settings::OPTION ) )
    83                 foreach ( [ 'sync', 'async' ] as $container )
    84                     if ( self::get( 'slug' ) . "-$container" === $handle )
    85                         $tag = ( ( ( $settings[ 'sync' ] and 'sync' === $container ) or
    86                             ( ! $settings[ 'sync' ] and 'sync' !== $container ) ) ?
    87                             wp_get_inline_script_tag( $this->render( 'var', [
    88                                 'name' => Settings::OPTION,
    89                                 'value' => json_encode( array_merge( $settings, [ 'nonce' => $this->nonce ] ) )
    90                             ] ), [ 'type' => 'text/javascript' ] ) : '' ) .
    91                             wp_get_script_tag( [
    92                                 'type' => 'text/javascript',
    93                                 'src' => $src,
    94                                 'nonce' => $this->nonce
    95                         ] ) . ( 'async' === $container ? $this->render( 'noscript', $settings ) : '' );
    96 
    97             return $tag;
     69            echo wp_get_inline_script_tag(
     70                ( $this->settings[ 'nonce' ] ? $this->render( 'nonce', $this->settings ) : '' ) .
     71                $this->render( 'sync', $this->settings ),
     72                $this->settings[ 'nonce' ] ? [ 'nonce' => $this->settings[ 'nonce' ] ] : []
     73            );
    9874        }
    9975
    10076        public function action_wp_body_open() {
    101             if ( ! $settings = get_option( Settings::OPTION ) ) return;
    102             if ( ! $settings[ 'async' ] ) return;
     77            foreach ( [ 'url', 'id', 'layer', 'async' ] as $key ) if ( ! $this->settings[ $key ] ) return;
    10378
    104             wp_print_scripts( self::get( 'slug' ) . '-async' );
     79            echo wp_get_inline_script_tag(
     80                $this->render( 'async', $this->settings ),
     81                $this->settings[ 'nonce' ] ? [ 'nonce' => $this->settings[ 'nonce' ] ] : []
     82            ) . $this->render( 'noscript', $this->settings );
    10583        }
    10684
  • piwik-pro/trunk/plugin.php

    r2522592 r2578624  
    55 * Plugin URI:        https://wordpress.org/plugins/piwik-pro/
    66 * Description:       Adds the Piwik PRO container (with tracking code) to your WordPress site.
    7  * Version:           1.0.2
     7 * Version:           1.1.0
    88 * Requires at least: 5.7
    99 * Requires PHP:      7.4
  • piwik-pro/trunk/vendor/clearcode/wordpress-settings/src/v1_1_1/Settings.php

    r2516197 r2578624  
    2626use Clearcode\Framework\v6_1_2\Filterer;
    2727use Clearcode\Framework\v6_1_2\Templater;
     28use function get_option;
    2829
    2930defined( 'ABSPATH' ) or exit;
Note: See TracChangeset for help on using the changeset viewer.