Plugin Directory

Changeset 3309525


Ignore:
Timestamp:
06/11/2025 05:34:32 AM (8 months ago)
Author:
matomoteam
Message:

Update to version 5.3.1 from GitHub (.)

Location:
matomo/trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • matomo/trunk/assets/js/asset_manager_core_js.js

    r3258789 r3309525  
    1 /* Matomo Javascript - cb=3967b01739c9861ba9da246d5bf73e9a*/
     1/* Matomo Javascript - cb=04b91cff3165f8f0de28f3124352978e*/
    22
    33/*!
  • matomo/trunk/classes/WpMatomo/Admin/PrivacySettings.php

    r2594597 r3309525  
    1717
    1818class PrivacySettings implements AdminSettingsInterface {
    19     const EXAMPLE_MINIMAL = '[matomo_opt_out]';
    20     const EXAMPLE_FULL    = '[matomo_opt_out language=de]';
     19    const EXAMPLE_MINIMAL = '[matomo_opt_out_form]';
     20    const EXAMPLE_FULL    = '[matomo_opt_out_form language=de]';
    2121
    2222    /**
  • matomo/trunk/classes/WpMatomo/Admin/SystemReport.php

    r3250097 r3309525  
    1919use Piwik\DeviceDetector\DeviceDetectorFactory;
    2020use Piwik\Filesystem;
     21use Piwik\Piwik;
    2122use Piwik\Plugin;
    2223use Piwik\Plugins\CoreAdminHome\API;
     
    2627use Piwik\Plugins\UserCountry\LocationProvider;
    2728use Piwik\Plugins\WordPress\WordPress;
     29use Piwik\Scheduler\Scheduler;
     30use Piwik\Scheduler\Task;
     31use Piwik\Scheduler\TaskLoader;
    2832use Piwik\SettingsPiwik;
    2933use Piwik\Tracker\Failures;
     
    7175    const TROUBLESHOOT_CLEAR_LOGS         = 'matomo_troubleshooting_action_clear_logs';
    7276    const TROUBLESHOOT_RUN_UPDATER        = 'matomo_troubleshooting_action_run_updater';
     77    const REGENERATE_TRACKING_CODE        = 'matomo_troubleshooting_action_regen_tracking_code';
     78    const RUN_SCHEDULED_TASK              = 'matomo_troubleshooting_action_run_task';
    7379
    7480    private $not_compatible_plugins = [
     
    230236                    $sync = new UserSync();
    231237                    $sync->sync_all();
     238                }
     239            }
     240
     241            if ( ! empty( $_POST[ self::REGENERATE_TRACKING_CODE ] ) ) {
     242                try {
     243                    Bootstrap::do_bootstrap();
     244
     245                    // regenerate tracker.js file in Matomo
     246                    Piwik::postEvent( 'CustomJsTracker.updateTracker' );
     247
     248                    // regenerate embed tracking code in MWP
     249                    $options                 = new WpMatomo\TrackingCode\GeneratorOptions( $this->settings );
     250                    $tracking_code_generator = new WpMatomo\TrackingCode\TrackingCodeGenerator( $this->settings, $options );
     251
     252                    $tracking_code_generator->update_tracking_code( true );
     253
     254                    echo '<div class="notice notice-success"><p>' . esc_html__( 'JavaScript tracking code regenerated successfully.', 'matomo' ) . '</p></div>';
     255                } catch ( \Exception $ex ) {
     256                    echo '<div class="error"><p>' . esc_html__( 'Matomo Error', 'matomo' ) . ': ' . esc_html( matomo_anonymize_value( $e->getMessage() . ' =>' . $this->logger->get_readable_trace( $e ) ) ) . '</p></div>';
     257                }
     258            }
     259
     260            if ( ! empty( $_POST[ self::RUN_SCHEDULED_TASK ] ) ) {
     261                try {
     262                    Bootstrap::do_bootstrap();
     263
     264                    if ( empty( $_POST['matomo_troubleshooting_run_task'] ) ) {
     265                        throw new \Exception( __( 'No task specified.', 'matomo' ) );
     266                    }
     267
     268                    $task_to_run = sanitize_text_field( wp_unslash( $_POST['matomo_troubleshooting_run_task'] ) );
     269
     270                    $scheduler = StaticContainer::get( Scheduler::class );
     271                    $message   = $scheduler->runTaskNow( $task_to_run );
     272
     273                    echo '<div class="notice notice-success"><p>' . esc_html__( 'Task ran successfully', 'matomo' ) . ': ' . esc_html( $message ) . '</p></div>';
     274                } catch ( \Exception $e ) {
     275                    echo '<div class="error"><p>' . esc_html__( 'Matomo Error', 'matomo' ) . ': ' . esc_html( matomo_anonymize_value( $e->getMessage() . ' =>' . $this->logger->get_readable_trace( $e ) ) ) . '</p></div>';
    232276                }
    233277            }
     
    319363        $matomo_has_exception_logs        = [];
    320364        $matomo_has_warning_and_no_errors = false;
    321 
    322         if ( empty( $matomo_active_tab ) ) {
     365        $matomo_scheduled_tasks           = [];
     366
     367        if ( empty( $matomo_active_tab ) ) { // system report
    323368            // phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting
    324369            $this->initial_error_reporting = @error_reporting();
     
    331376            $matomo_has_warning_and_no_errors = $this->has_only_warnings_no_error( $matomo_tables );
    332377            $matomo_has_exception_logs        = $this->logger->get_last_logged_entries();
     378        } else { // troubleshooting
     379            try {
     380                Bootstrap::do_bootstrap();
     381                $scheduler              = StaticContainer::get( Scheduler::class );
     382                $matomo_scheduled_tasks = $scheduler->getTaskList();
     383            } catch ( \Exception $e ) {
     384                $this->logger->log_exception( 'troubleshooting', $e );
     385            }
    333386        }
    334387
  • matomo/trunk/classes/WpMatomo/Admin/views/marketplace_setup_wizard.php

    r3100184 r3309525  
    121121                <p><?php echo sprintf( esc_html__( 'Download the %1$sMatomo Marketplace for WordPress%2$s plugin.', 'matomo' ), '<em>', '</em>' ); ?></p>
    122122
    123                 <a class="button-primary download-plugin" rel="noreferrer noopener" target="_blank" href="http://builds.matomo.org/matomo-marketplace-for-wordpress-latest.zip">
     123                <a class="button-primary download-plugin" rel="noreferrer noopener" target="_blank" href="https://builds.matomo.org/matomo-marketplace-for-wordpress-latest.zip">
    124124                    <?php esc_html_e( 'Download', 'matomo' ); ?>
    125125                </a>
  • matomo/trunk/classes/WpMatomo/Admin/views/systemreport.php

    r3221938 r3309525  
    3333/** @var string $matomo_active_tab */
    3434/** @var \WpMatomo\Settings $settings */
     35/** @var array $matomo_scheduled_tasks */
    3536
    3637if ( ! function_exists( 'matomo_format_value_text' ) ) {
     
    234235                       class='button-primary'
    235236                       title="<?php esc_attr_e( 'Force trigger a Matomo update in case it failed error', 'matomo' ); ?>"
    236                        value="<?php esc_html_e( 'Run Updater', 'matomo' ); ?>">
     237                       value="<?php esc_attr_e( 'Run Updater', 'matomo' ); ?>">
    237238                <label for="matomo_troubleshooting_update_from">Run updates from version:</label>
    238239                <input id="matomo_troubleshooting_update_from"
     
    247248                       class='button-primary'
    248249                       title="<?php esc_attr_e( 'Users are synced automatically. If for some reason a user cannot access Matomo pages even though the user has the permission, then triggering a manual sync may help to fix this issue immediately or it may show which error prevents the automatic syncing.', 'matomo' ); ?>"
    249                        value="<?php esc_html_e( 'Sync all users across sites / blogs', 'matomo' ); ?>">
     250                       value="<?php esc_attr_e( 'Sync all users across sites / blogs', 'matomo' ); ?>">
    250251                <br/><br/>
    251252                <input name="<?php echo esc_attr( SystemReport::TROUBLESHOOT_SYNC_ALL_SITES ); ?>" type="submit"
    252253                       title="<?php esc_attr_e( 'Sites / blogs are synced automatically. If for some reason Matomo is not showing up for a specific blog, then triggering a manual sync may help to fix this issue immediately or it may show which error prevents the automatic syncing.', 'matomo' ); ?>"
    253254                       class='button-primary'
    254                        value="<?php esc_html_e( 'Sync all sites (blogs)', 'matomo' ); ?>">
     255                       value="<?php esc_attr_e( 'Sync all sites (blogs)', 'matomo' ); ?>">
     256                <br/><br/>
    255257            <?php } ?>
     258            <input name="<?php echo esc_attr( SystemReport::REGENERATE_TRACKING_CODE ); ?>" type="submit"
     259                   class="button-primary"
     260                   title="<?php esc_attr_e( 'Force the cached tracking code to be regenerated. The tracking code is usually regenerated on update and after changing tracking settings, or if a Matomo plugin is installed/updated, but if you need to do it manually, you can do it here.', 'matomo' ); ?>"
     261                   value="<?php esc_attr_e( 'Regenerate tracking code', 'matomo' ); ?>">
     262            <br/>
     263            <br/>
     264
     265            <input name="<?php echo esc_attr( SystemReport::RUN_SCHEDULED_TASK ); ?>" type="submit"
     266                   class="button-primary"
     267                   title="<?php esc_attr_e( 'Run a scheduled task by name.', 'matomo' ); ?>"
     268                   value="<?php esc_attr_e( 'Run scheduled task', 'matomo' ); ?>"
     269                   />
     270            <label for="matomo_troubleshooting_run_task">Task to run:</label>
     271            <select
     272                id="matomo_troubleshooting_run_task"
     273                name="matomo_troubleshooting_run_task"
     274                title="<?php esc_attr_e( 'Pick a task to run', 'matomo' ); ?>"
     275            >
     276                <?php foreach ( $matomo_scheduled_tasks as $matomo_task ) { ?>
     277                <option value="<?php echo esc_attr( $matomo_task ); ?>"><?php echo esc_html( $matomo_task ); ?></option>
     278                <?php } ?>
     279            </select>
     280            <br/>
     281            <br/>
    256282        </form>
    257283
  • matomo/trunk/classes/WpMatomo/AjaxTracker.php

    r3250097 r3309525  
    9999        if ( ! $this->idSite ) {
    100100            $this->logger->log('ecommerce tracking could not find idSite, cannot send request');
    101             return; // not installed or synced yet
     101            return null; // not installed or synced yet
    102102        }
     103
     104        if ( $this->is_prerender() ) {
     105            // do not track if for some reason we are prerendering
     106            return null;
     107        }
     108
    103109        $args = array(
    104110            'method' => $method,
     
    113119        // 2) Never exit at any point
    114120
    115         $response = wp_remote_request( $url . '&bots=1', $args );
     121        $url = $url . '&bots=1';
     122
     123        $response = $this->wp_remote_request( $url, $args );
    116124
    117125        if (is_wp_error($response)) {
     
    125133        return strpos( $ex->getMessage(), 'setVisitorId() expects' ) === 0;
    126134    }
     135
     136    /**
     137     * See https://developer.chrome.com/docs/web-platform/prerender-pages
     138     * @return bool
     139     */
     140    private function is_prerender() {
     141        // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
     142        $purpose = strtolower( isset( $_SERVER['HTTP_SEC_PURPOSE'] ) ? wp_unslash( $_SERVER['HTTP_SEC_PURPOSE'] ) : '' );
     143        return strpos( $purpose, 'prefetch' ) !== false
     144            || strpos( $purpose, 'prerender' ) !== false;
     145    }
     146
     147    /**
     148     * for tests to override
     149     * @param string $url
     150     * @param array $args
     151     * @return array|\WP_Error
     152     */
     153    protected function wp_remote_request( $url, $args ) {
     154        return wp_remote_request( $url, $args );
     155    }
    127156}
  • matomo/trunk/classes/WpMatomo/Ecommerce/Base.php

    r3250097 r3309525  
    122122                }
    123123            }
     124
    124125            $this->ajax_tracker_calls = [];
    125126
  • matomo/trunk/classes/WpMatomo/Ecommerce/Woocommerce.php

    r3250097 r3309525  
    3636            $server_side_visitor_id->register_hooks();
    3737        }
     38
     39        // compatibility with the All In One SEO plugin
     40        add_filter( 'aioseo_schema_woocommerce_add_to_cart_skip_hooks', [ $this, 'aioseo_add_to_cart_skip' ] );
    3841
    3942        add_action( 'wp_head', [ $this, 'maybe_track_order_complete' ], 99999 );
     
    7275    }
    7376
     77    /**
     78     * The All In One SEO plugin temporarily adds products to the WooCommerce cart, calculates
     79     * some things, then empties the cart. This results in WooCommerce hooks being fired for
     80     * a cart change, even though the user never actually added anything to their cart.
     81     *
     82     * The All In One SEO plugin works around this by removing certain add_to_cart hooks
     83     * then re-adding them. To avoid tracking an ecommerce cart update during this temporary
     84     * cart addition, we have to tell AIOSEO to skip our add_to_cart hook.
     85     *
     86     * Note: this isn't documented in the AIOSEO plugin, so it's possible the way they do
     87     * this can change in the future.
     88     *
     89     * @param array $hooks_to_skip
     90     * @return array
     91     */
     92    public function aioseo_add_to_cart_skip( $hooks_to_skip ) {
     93        $hooks_to_skip[ __CLASS__ ] = 'on_cart_updated_safe';
     94        return $hooks_to_skip;
     95    }
     96
    7497    public function after_calculate_totals() {
    7598        if ( ! $this->track_next_totals_change ) {
     
    342365
    343366        $product = wc_get_product( $product_id );
     367        if ( ! is_object( $product ) ) {
     368            $order_id = $order ? $this->get_order_id( $order ) : 'unspecified';
     369            $this->logger->log( "Failed to get product for product ID = $product_id (order ID = $order_id)." );
     370            return;
     371        }
    344372
    345373        $pr         = $product_or_variation ? $product_or_variation : $product;
     
    436464            return $order->get_meta( $name );
    437465        } else {
    438             $id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
     466            $id = $this->get_order_id( $order );
    439467            return get_post_meta( $id, $name, true );
    440468        }
     
    451479                $order->update_meta_data( $name, $value );
    452480            } else {
    453                 $id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
     481                $id = $this->get_order_id( $order );
    454482                update_post_meta( $id, $name, $value );
    455483            }
     
    460488        }
    461489    }
     490
     491    private function get_order_id( $order ) {
     492        return method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
     493    }
    462494}
  • matomo/trunk/classes/WpMatomo/OptOut.php

    r2617445 r3309525  
    1919
    2020class OptOut {
     21    const OPT_OUT_DIV_ID = 'matomo-opt-out-form-embed';
     22
    2123    private $language = null;
    2224
    2325    public function register_hooks() {
    24         add_shortcode( 'matomo_opt_out', array( $this, 'show_opt_out' ) );
     26        add_shortcode( 'matomo_opt_out', [ $this, 'show_classic_opt_out' ] );
     27        add_shortcode( 'matomo_opt_out_form', [ $this, 'show_opt_out' ] );
    2528        add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) );
    2629        add_action( 'init', [ $this, 'load_block' ] );
     
    3841
    3942    public function show_opt_out( $atts ) {
    40         $a = shortcode_atts(
    41             [
    42                 'language' => null,
    43             ],
    44             $atts
    45         );
    46         if ( ! empty( $a['language'] ) && strlen( $a['language'] ) < 6 ) {
    47             $this->language = $a['language'];
    48         }
     43        $this->language = $this->get_language_from_atts( $atts );
     44        $this->language = isset( $this->language ) ? $this->language : 'auto';
     45
     46        $div_id = self::OPT_OUT_DIV_ID;
     47
     48        $url = 'app/index.php?module=CoreAdminHome&action=optOutJS&divId=' . $div_id . '&language=' . rawurlencode( $this->language ) . '&showIntro=1';
     49        $url = plugins_url( $url, MATOMO_ANALYTICS_FILE );
     50
     51        wp_enqueue_script( 'matomo_opt_out_form_js', $url, [], 1, true ); // output in the footer
     52
     53        // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
     54        $content = "<div id=\"$div_id\"></div>";
     55        return $content;
     56    }
     57
     58    public function show_classic_opt_out( $atts ) {
     59        $this->language = $this->get_language_from_atts( $atts );
    4960
    5061        try {
     
    115126        );
    116127    }
     128
     129    private function get_language_from_atts( $atts ) {
     130        $a = shortcode_atts(
     131            [
     132                'language' => null,
     133            ],
     134            $atts
     135        );
     136        if ( ! empty( $a['language'] ) && strlen( $a['language'] ) < 6 ) {
     137            return $a['language'];
     138        }
     139        return null;
     140    }
    117141}
  • matomo/trunk/classes/WpMatomo/TrackingCode/TrackingCodeGenerator.php

    r3148286 r3309525  
    6464    }
    6565
    66     public function update_tracking_code() {
    67         if ( $this->settings->is_current_tracking_code()
    68              && $this->settings->get_option( 'tracking_code' ) ) {
     66    public function update_tracking_code( $force = false ) {
     67        if (
     68            $this->settings->is_current_tracking_code()
     69            && $this->settings->get_option( 'tracking_code' )
     70            && ! $force
     71        ) {
    6972            return false;
    7073        }
     
    8184
    8285        if ( ! $idsite ) {
    83             $this->logger->log( 'Not found related idSite for blog ' . get_current_blog_id() );
     86            $this->logger->log( 'Found no related idSite for blog ' . get_current_blog_id() );
    8487
    8588            return false;
     
    322325        $script .= "var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    323326g.type='text/javascript'; g.async=true; g.src=" . wp_json_encode( $js_endpoint ) . '; s.parentNode.insertBefore(g,s);';
     327
     328        $script = <<<EOF
     329(function () {
     330function initTracking() {
     331$script
     332}
     333if (document.prerendering) {
     334    document.addEventListener('prerenderingchange', initTracking, {once: true});
     335} else {
     336    initTracking();
     337}
     338})();
     339EOF;
    324340
    325341        if ( function_exists( 'wp_get_inline_script_tag' ) ) {
  • matomo/trunk/classes/WpMatomo/Updater.php

    r3250097 r3309525  
    2121use Piwik\Version;
    2222use WP_Upgrader;
     23use WpMatomo\TrackingCode\GeneratorOptions;
     24use WpMatomo\TrackingCode\TrackingCodeGenerator;
    2325use WpMatomo\Updater\UpdateInProgressException;
    2426
     
    8385
    8486    public function update_if_needed() {
    85         $executed_updates = [];
    86 
    8787        $plugins_requiring_update = $this->get_plugins_requiring_update();
    88         foreach ( $plugins_requiring_update as $key => $plugin_version ) {
     88        if ( ! empty( $plugins_requiring_update ) ) {
    8989            try {
    9090                $this->update();
     
    9595            } catch ( Exception $e ) {
    9696                $this->logger->log_exception( 'plugin_update', $e );
    97                 continue;
    98             }
    99             $executed_updates[] = $key;
     97                return;
     98            }
    10099
    101100            // we're scheduling another update in case there are some dimensions to be updated or anything
     
    105104            wp_schedule_single_event( time() + 15, ScheduledTasks::EVENT_UPDATE );
    106105
    107             update_option( $key, $plugin_version );
    108 
    109106            // we make sure to delete cache even if no component was updated eg there may be translation updates etc
    110107            // and caches need to be invalidated
    111108            Filesystem::deleteAllCacheOnUpdate();
    112         }
    113 
    114         return $executed_updates;
     109
     110            $tracking_code_generator = new TrackingCodeGenerator( $this->settings, new GeneratorOptions( $this->settings ) );
     111            $tracking_code_generator->update_tracking_code( true );
     112        }
     113
     114        foreach ( $plugins_requiring_update as $key => $plugin_version ) {
     115            update_option( $key, $plugin_version );
     116        }
     117
     118        return array_keys( $plugins_requiring_update );
    115119    }
    116120
  • matomo/trunk/matomo.php

    r3258789 r3309525  
    55 * Author: Matomo
    66 * Author URI: https://matomo.org
    7  * Version: 5.3.0
     7 * Version: 5.3.1
    88 * Domain Path: /languages
    99 * WC requires at least: 2.4.0
    10  * WC tested up to: 9.7.1
     10 * WC tested up to: 9.9.3
    1111 *
    1212 * Matomo - free/libre analytics platform
  • matomo/trunk/plugins/WordPress/WordPress.php

    r3258789 r3309525  
    2020use Piwik\Plugin\Manager;
    2121use Piwik\Plugins\CoreHome\SystemSummary\Item;
     22use Piwik\Plugins\WordPress\Html\PluginUrlReplacer;
    2223use Piwik\Scheduler\Task;
    2324use Piwik\Url;
     
    356357    }
    357358
    358     public function onDispatchRequestEnd(&$result, $module, $action, $parameters) {
     359    public function onDispatchRequestEnd(&$result, $module, $action, $parameters)
     360    {
    359361        if (!empty($result) && is_string($result)) {
    360362            // https://wordpress.org/support/topic/bugged-favicon/#post-12995669
    361363            $result = str_replace('<link rel="mask-icon"', '<link rel="ignore-mask-icon-ignore"', $result);
    362364            $result = str_replace('plugins/CoreHome/images/applePinnedTab.svg', '', $result);
     365
     366            $pluginUrlReplacer = new PluginUrlReplacer();
     367            $result = $pluginUrlReplacer->replaceThirdPartyPluginUrls( $result );
    363368        }
    364369    }
  • matomo/trunk/readme.txt

    r3258789 r3309525  
    33Tags: matomo,analytics,statistics,stats,ecommerce
    44Requires at least: 4.8
    5 Tested up to: 6.7.2
    6 Stable tag: 5.3.0
     5Tested up to: 6.8.1
     6Stable tag: 5.3.1
    77Requires PHP: 7.2.5
    88License: GPLv3 or later
Note: See TracChangeset for help on using the changeset viewer.