Plugin Directory

Changeset 2754282


Ignore:
Timestamp:
07/11/2022 12:35:28 AM (3 years ago)
Author:
claytoncollie
Message:

Update to version 2.0.1 from GitHub

Location:
tracking-code-for-google-analytics
Files:
2 added
6 deleted
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • tracking-code-for-google-analytics/tags/2.0.1/inc/admin.php

    r2734362 r2754282  
    66 */
    77
    8 // If this file is called directly, abort.
    9 if ( ! defined( 'WPINC' ) ) {
    10     die;
    11 }
     8namespace Tracking_Code_For_Google_Analytics;
    129
    13 add_action( 'admin_init', 'tracking_code_for_google_analytics_add_settings_field', 10, 0 );
     10use function Tracking_Code_For_Google_Analytics\get_the_id;
     11use const Tracking_Code_For_Google_Analytics\CONFIG_NAME;
     12use const Tracking_Code_For_Google_Analytics\FILTER_NAME;
     13use const Tracking_Code_For_Google_Analytics\OPTION_NAME;
     14
     15add_action( 'admin_init', __NAMESPACE__ . '\register_setting' );
    1416/**
    15  * Register the settings field for the measurement ID.
     17 * Register the settings field for the tracking ID.
    1618 *
    1719 * @return void
     20 *
    1821 * @since 1.0.0
    1922 */
    20 function tracking_code_for_google_analytics_add_settings_field() : void {
     23function register_setting() : void {
    2124    \add_settings_field(
    2225        'tracking_code_for_google_analytics_id_field',
    2326        esc_html__( 'Google Analytics', 'tracking-code-for-google-analytics' ),
    24         'tracking_code_for_google_analytics_text_settings_field',
     27        __NAMESPACE__ . '\input_field',
    2528        'general',
    2629        'default',
    2730        array(
    28             'id'          => 'tracking-code-for-google-analytics',
    29             'name'        => 'tracking_code_for_google_analytics',
    30             'value'       => tracking_code_for_google_analytics_id(),
    31             'description' => esc_html__( 'Enter your Google Analytics measurement ID eg. UA-1234567', 'tracking-code-for-google-analytics' ),
    32             'disabled'    => defined( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID' ) || has_filter( 'tracking_code_for_google_analytics_id' ) ? 'disabled' : '',
     31            'id'          => OPTION_NAME,
     32            'name'        => OPTION_NAME,
     33            'value'       => get_the_id(),
     34            'description' => esc_html__( 'Enter your Google Analytics tracking ID eg. UA-1234567', 'tracking-code-for-google-analytics' ),
     35            'disabled'    => defined( CONFIG_NAME ) || has_filter( FILTER_NAME ) ? 'disabled' : '',
    3336        )
    3437    );
    3538
    36     register_setting(
     39    \register_setting(
    3740        'general',
    38         'tracking_code_for_google_analytics',
     41        OPTION_NAME,
    3942        array(
    4043            'type'              => 'string',
    41             'description'       => esc_html__( 'Google Analytics measurement ID', 'tracking-code-for-google-analytics' ),
     44            'description'       => esc_html__( 'Google Analytics tracking ID', 'tracking-code-for-google-analytics' ),
    4245            'sanitize_callback' => 'sanitize_text_field',
    4346            'show_in_rest'      => true,
     
    4851
    4952/**
    50  * Text field for measurement ID.
     53 * WordPress admin input field.
    5154 *
    52  * @param array $args The field settings.
     55 * @param array<string> $args The field settings.
     56 *
    5357 * @return void
     58 *
    5459 * @since 1.0.0
    5560 */
    56 function tracking_code_for_google_analytics_text_settings_field( array $args ) : void {
     61function input_field( array $args ) : void {
    5762    $args = wp_parse_args(
    5863        $args,
  • tracking-code-for-google-analytics/tags/2.0.1/inc/public.php

    r2734362 r2754282  
    66 */
    77
    8 // If this file is called directly, abort.
    9 if ( ! defined( 'WPINC' ) ) {
    10     die;
    11 }
     8namespace Tracking_Code_For_Google_Analytics;
    129
    13 add_action( 'wp_head', 'tracking_code_for_google_analytics_do_the_script', 1, 0 );
     10use function Tracking_Code_For_Google_Analytics\get_the_id;
     11
     12add_action( 'wp_head', __NAMESPACE__ . '\global_site_tag' );
    1413/**
    15  * Output the tracking code snippet to the frontend.
     14 * Maybe print the tracking code snippet on the frontend.
    1615 *
    1716 * @return void
     17 *
    1818 * @since 1.0.0
    1919 */
    20 function tracking_code_for_google_analytics_do_the_script() : void {
    21     $tracking_id = tracking_code_for_google_analytics_id();
     20function global_site_tag() : void {
     21    $tracking_id = get_the_id();
    2222
     23    // Bail early if empty.
    2324    if ( '' === $tracking_id ) {
    2425        return;
  • tracking-code-for-google-analytics/tags/2.0.1/inc/tracking-id.php

    r2734362 r2754282  
    66 */
    77
    8 // If this file is called directly, abort.
    9 if ( ! defined( 'WPINC' ) ) {
    10     die;
    11 }
     8namespace Tracking_Code_For_Google_Analytics;
     9
     10use const Tracking_Code_For_Google_Analytics\CONFIG_NAME;
     11use const Tracking_Code_For_Google_Analytics\FILTER_NAME;
     12use const Tracking_Code_For_Google_Analytics\OPTION_NAME;
    1213
    1314/**
     
    1718 * @since 1.1.0
    1819 */
    19 function tracking_code_for_google_analytics_id() : string {
    20     $tracking_id = '';
    21 
    22     // Get option value from database.
    23     $tracking_id = get_option( 'tracking_code_for_google_analytics' );
     20function get_the_id() : string {
     21    /**
     22     * Define the tracking ID in your wp-config file.
     23     *
     24     * @see https://www.wpbeginner.com/glossary/wp-config-php/
     25     *
     26     * @since 1.1.0
     27     */
     28    if ( defined( CONFIG_NAME ) ) {
     29        return \TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID;
     30    }
    2431
    2532    /**
    26      * Filter the tracking_id variable to support other methods of setting this value.
     33     * Define the tracking ID in with a filter.
    2734     *
    28      * @param string $tracking_id The Google Analytics measurement ID.
     35     * @param string $tracking_id The Google Analytics tracking ID.
     36     *
    2937     * @return string
     38     *
    3039     * @since 1.0.0
    3140     */
    32     $tracking_id = apply_filters( 'tracking_code_for_google_analytics_id', $tracking_id );
     41    if ( has_filter( FILTER_NAME ) ) {
     42        return apply_filters( FILTER_NAME, '' );
     43    }
    3344
    3445    /**
    35      * In addition to the filter above, this plugin also supports wp-config definitions.
     46     * If we are not defining the tracking ID with a definition in our wp-config file,
     47     * and we are not defining the tracking ID with a PHP filter,
     48     * then we will query the tracking ID from the database.
    3649     *
    37      * @see https://www.wpbeginner.com/glossary/wp-config-php/
    38      * @since 1.1.0
     50     * @since 1.0.0
    3951     */
    40     $tracking_id = defined( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID' ) ? \TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID : $tracking_id;
     52    return get_option( OPTION_NAME, '' );
    4153
    42     return $tracking_id;
    4354}
  • tracking-code-for-google-analytics/tags/2.0.1/readme.txt

    r2734362 r2754282  
    66Tested up to: 6.0.0
    77Requires PHP: 7.2
    8 Stable tag: 1.1.0
     8Stable tag: 2.0.1
    99License: GPLv3 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1818### Composer
    1919
    20 `composer require claytoncollie/tracking-code-for-google-analytics`
     20```php
     21composer require claytoncollie/tracking-code-for-google-analytics
     22```
    2123
    2224### Filters
     
    2426If you want to set the tracking ID without using the wp-admin user interface, use the filter below.
    2527
    26 `
     28```php
    2729add_filter(
    2830    'tracking_code_for_google_analytics_id',
     
    3032     * Set Google Analytics tracking ID.
    3133     *
    32      * @param string $tracking_id Measurement ID.
     34     * @param string $tracking_id Tracking ID.
    3335     *
    3436     * @return string
    3537     */
    36     function ( $tracking_id ) {
    37         return 'UA-7654321';
     38    function ( string $tracking_id ) : string {
     39        $tracking_id = 'UA-7654321';
     40        return $tracking_id;
    3841    }
    3942);
    40 `
     43```
     44
     45### Definitions
    4146
    4247You can also define the tracking ID in your wp-config.php file with the following snippet.
    4348
    44 `
     49```php
    4550define( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID', 'UA-7654321' );
    46 `
     51```
    4752
    4853### Contributing
     
    8691== Changelog ==
    8792
     93= 2.0.0 =
     94* Major version. Possible breaking changes. Test locally before updating.
     95* Change callback names. Possible breaking change.
     96* Bump PHP required version to 7.2
     97* Add PHP Namespaces
     98* Add PHP parameter type hinting
     99* Add PHP return type hinting
     100* Add automated static analysis GitHub action
     101* Add automated code linting GitHub action
     102* Add automated acceptance tests GitHub action
     103* Add automated WordPress version checker  GitHub action
     104* Add donation link to Coinbase
     105* Fix URLs in readme files
     106* Fix markdown syntax for changelog in readme.txt
     107* Ignore phpstan config from deployed plugin
     108* Ignore CONTRIBUTING.md from deployed plugin
     109
    88110= 1.1.0 =
    89111* Add ability to define tracking in wp-config.php
  • tracking-code-for-google-analytics/tags/2.0.1/tracking-code-for-google-analytics.php

    r2734362 r2754282  
    77 * Author URI:      https://github.com/claytoncollie
    88 * Text Domain:     tracking-code-for-google-analytics
    9  * Version:         1.1.0
     9 * Version:         2.0.1
    1010 *
    1111 * @package         Tracking_Code_For_Google_Analytics
    1212 */
    1313
    14 // If this file is called directly, abort.
    15 if ( ! defined( 'WPINC' ) ) {
    16     die;
    17 }
     14namespace Tracking_Code_For_Google_Analytics;
     15
     16const OPTION_NAME = 'tracking_code_for_google_analytics';
     17const FILTER_NAME = 'tracking_code_for_google_analytics_id';
     18const CONFIG_NAME = 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID';
    1819
    1920require_once __DIR__ . '/inc/tracking-id.php';
  • tracking-code-for-google-analytics/trunk/inc/admin.php

    r2734362 r2754282  
    66 */
    77
    8 // If this file is called directly, abort.
    9 if ( ! defined( 'WPINC' ) ) {
    10     die;
    11 }
     8namespace Tracking_Code_For_Google_Analytics;
    129
    13 add_action( 'admin_init', 'tracking_code_for_google_analytics_add_settings_field', 10, 0 );
     10use function Tracking_Code_For_Google_Analytics\get_the_id;
     11use const Tracking_Code_For_Google_Analytics\CONFIG_NAME;
     12use const Tracking_Code_For_Google_Analytics\FILTER_NAME;
     13use const Tracking_Code_For_Google_Analytics\OPTION_NAME;
     14
     15add_action( 'admin_init', __NAMESPACE__ . '\register_setting' );
    1416/**
    15  * Register the settings field for the measurement ID.
     17 * Register the settings field for the tracking ID.
    1618 *
    1719 * @return void
     20 *
    1821 * @since 1.0.0
    1922 */
    20 function tracking_code_for_google_analytics_add_settings_field() : void {
     23function register_setting() : void {
    2124    \add_settings_field(
    2225        'tracking_code_for_google_analytics_id_field',
    2326        esc_html__( 'Google Analytics', 'tracking-code-for-google-analytics' ),
    24         'tracking_code_for_google_analytics_text_settings_field',
     27        __NAMESPACE__ . '\input_field',
    2528        'general',
    2629        'default',
    2730        array(
    28             'id'          => 'tracking-code-for-google-analytics',
    29             'name'        => 'tracking_code_for_google_analytics',
    30             'value'       => tracking_code_for_google_analytics_id(),
    31             'description' => esc_html__( 'Enter your Google Analytics measurement ID eg. UA-1234567', 'tracking-code-for-google-analytics' ),
    32             'disabled'    => defined( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID' ) || has_filter( 'tracking_code_for_google_analytics_id' ) ? 'disabled' : '',
     31            'id'          => OPTION_NAME,
     32            'name'        => OPTION_NAME,
     33            'value'       => get_the_id(),
     34            'description' => esc_html__( 'Enter your Google Analytics tracking ID eg. UA-1234567', 'tracking-code-for-google-analytics' ),
     35            'disabled'    => defined( CONFIG_NAME ) || has_filter( FILTER_NAME ) ? 'disabled' : '',
    3336        )
    3437    );
    3538
    36     register_setting(
     39    \register_setting(
    3740        'general',
    38         'tracking_code_for_google_analytics',
     41        OPTION_NAME,
    3942        array(
    4043            'type'              => 'string',
    41             'description'       => esc_html__( 'Google Analytics measurement ID', 'tracking-code-for-google-analytics' ),
     44            'description'       => esc_html__( 'Google Analytics tracking ID', 'tracking-code-for-google-analytics' ),
    4245            'sanitize_callback' => 'sanitize_text_field',
    4346            'show_in_rest'      => true,
     
    4851
    4952/**
    50  * Text field for measurement ID.
     53 * WordPress admin input field.
    5154 *
    52  * @param array $args The field settings.
     55 * @param array<string> $args The field settings.
     56 *
    5357 * @return void
     58 *
    5459 * @since 1.0.0
    5560 */
    56 function tracking_code_for_google_analytics_text_settings_field( array $args ) : void {
     61function input_field( array $args ) : void {
    5762    $args = wp_parse_args(
    5863        $args,
  • tracking-code-for-google-analytics/trunk/inc/public.php

    r2734362 r2754282  
    66 */
    77
    8 // If this file is called directly, abort.
    9 if ( ! defined( 'WPINC' ) ) {
    10     die;
    11 }
     8namespace Tracking_Code_For_Google_Analytics;
    129
    13 add_action( 'wp_head', 'tracking_code_for_google_analytics_do_the_script', 1, 0 );
     10use function Tracking_Code_For_Google_Analytics\get_the_id;
     11
     12add_action( 'wp_head', __NAMESPACE__ . '\global_site_tag' );
    1413/**
    15  * Output the tracking code snippet to the frontend.
     14 * Maybe print the tracking code snippet on the frontend.
    1615 *
    1716 * @return void
     17 *
    1818 * @since 1.0.0
    1919 */
    20 function tracking_code_for_google_analytics_do_the_script() : void {
    21     $tracking_id = tracking_code_for_google_analytics_id();
     20function global_site_tag() : void {
     21    $tracking_id = get_the_id();
    2222
     23    // Bail early if empty.
    2324    if ( '' === $tracking_id ) {
    2425        return;
  • tracking-code-for-google-analytics/trunk/inc/tracking-id.php

    r2734362 r2754282  
    66 */
    77
    8 // If this file is called directly, abort.
    9 if ( ! defined( 'WPINC' ) ) {
    10     die;
    11 }
     8namespace Tracking_Code_For_Google_Analytics;
     9
     10use const Tracking_Code_For_Google_Analytics\CONFIG_NAME;
     11use const Tracking_Code_For_Google_Analytics\FILTER_NAME;
     12use const Tracking_Code_For_Google_Analytics\OPTION_NAME;
    1213
    1314/**
     
    1718 * @since 1.1.0
    1819 */
    19 function tracking_code_for_google_analytics_id() : string {
    20     $tracking_id = '';
    21 
    22     // Get option value from database.
    23     $tracking_id = get_option( 'tracking_code_for_google_analytics' );
     20function get_the_id() : string {
     21    /**
     22     * Define the tracking ID in your wp-config file.
     23     *
     24     * @see https://www.wpbeginner.com/glossary/wp-config-php/
     25     *
     26     * @since 1.1.0
     27     */
     28    if ( defined( CONFIG_NAME ) ) {
     29        return \TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID;
     30    }
    2431
    2532    /**
    26      * Filter the tracking_id variable to support other methods of setting this value.
     33     * Define the tracking ID in with a filter.
    2734     *
    28      * @param string $tracking_id The Google Analytics measurement ID.
     35     * @param string $tracking_id The Google Analytics tracking ID.
     36     *
    2937     * @return string
     38     *
    3039     * @since 1.0.0
    3140     */
    32     $tracking_id = apply_filters( 'tracking_code_for_google_analytics_id', $tracking_id );
     41    if ( has_filter( FILTER_NAME ) ) {
     42        return apply_filters( FILTER_NAME, '' );
     43    }
    3344
    3445    /**
    35      * In addition to the filter above, this plugin also supports wp-config definitions.
     46     * If we are not defining the tracking ID with a definition in our wp-config file,
     47     * and we are not defining the tracking ID with a PHP filter,
     48     * then we will query the tracking ID from the database.
    3649     *
    37      * @see https://www.wpbeginner.com/glossary/wp-config-php/
    38      * @since 1.1.0
     50     * @since 1.0.0
    3951     */
    40     $tracking_id = defined( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID' ) ? \TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID : $tracking_id;
     52    return get_option( OPTION_NAME, '' );
    4153
    42     return $tracking_id;
    4354}
  • tracking-code-for-google-analytics/trunk/readme.txt

    r2734362 r2754282  
    66Tested up to: 6.0.0
    77Requires PHP: 7.2
    8 Stable tag: 1.1.0
     8Stable tag: 2.0.1
    99License: GPLv3 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1818### Composer
    1919
    20 `composer require claytoncollie/tracking-code-for-google-analytics`
     20```php
     21composer require claytoncollie/tracking-code-for-google-analytics
     22```
    2123
    2224### Filters
     
    2426If you want to set the tracking ID without using the wp-admin user interface, use the filter below.
    2527
    26 `
     28```php
    2729add_filter(
    2830    'tracking_code_for_google_analytics_id',
     
    3032     * Set Google Analytics tracking ID.
    3133     *
    32      * @param string $tracking_id Measurement ID.
     34     * @param string $tracking_id Tracking ID.
    3335     *
    3436     * @return string
    3537     */
    36     function ( $tracking_id ) {
    37         return 'UA-7654321';
     38    function ( string $tracking_id ) : string {
     39        $tracking_id = 'UA-7654321';
     40        return $tracking_id;
    3841    }
    3942);
    40 `
     43```
     44
     45### Definitions
    4146
    4247You can also define the tracking ID in your wp-config.php file with the following snippet.
    4348
    44 `
     49```php
    4550define( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID', 'UA-7654321' );
    46 `
     51```
    4752
    4853### Contributing
     
    8691== Changelog ==
    8792
     93= 2.0.0 =
     94* Major version. Possible breaking changes. Test locally before updating.
     95* Change callback names. Possible breaking change.
     96* Bump PHP required version to 7.2
     97* Add PHP Namespaces
     98* Add PHP parameter type hinting
     99* Add PHP return type hinting
     100* Add automated static analysis GitHub action
     101* Add automated code linting GitHub action
     102* Add automated acceptance tests GitHub action
     103* Add automated WordPress version checker  GitHub action
     104* Add donation link to Coinbase
     105* Fix URLs in readme files
     106* Fix markdown syntax for changelog in readme.txt
     107* Ignore phpstan config from deployed plugin
     108* Ignore CONTRIBUTING.md from deployed plugin
     109
    88110= 1.1.0 =
    89111* Add ability to define tracking in wp-config.php
  • tracking-code-for-google-analytics/trunk/tracking-code-for-google-analytics.php

    r2734362 r2754282  
    77 * Author URI:      https://github.com/claytoncollie
    88 * Text Domain:     tracking-code-for-google-analytics
    9  * Version:         1.1.0
     9 * Version:         2.0.1
    1010 *
    1111 * @package         Tracking_Code_For_Google_Analytics
    1212 */
    1313
    14 // If this file is called directly, abort.
    15 if ( ! defined( 'WPINC' ) ) {
    16     die;
    17 }
     14namespace Tracking_Code_For_Google_Analytics;
     15
     16const OPTION_NAME = 'tracking_code_for_google_analytics';
     17const FILTER_NAME = 'tracking_code_for_google_analytics_id';
     18const CONFIG_NAME = 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID';
    1819
    1920require_once __DIR__ . '/inc/tracking-id.php';
Note: See TracChangeset for help on using the changeset viewer.