Changeset 2754282
- Timestamp:
- 07/11/2022 12:35:28 AM (3 years ago)
- Location:
- tracking-code-for-google-analytics
- Files:
-
- 2 added
- 6 deleted
- 10 edited
- 1 copied
-
tags/2.0.1 (copied) (copied from tracking-code-for-google-analytics/trunk)
-
tags/2.0.1/.wp-env.json (added)
-
tags/2.0.1/CHANGELOG.md (deleted)
-
tags/2.0.1/CONTRIBUTING.md (deleted)
-
tags/2.0.1/inc/admin.php (modified) (2 diffs)
-
tags/2.0.1/inc/public.php (modified) (1 diff)
-
tags/2.0.1/inc/tracking-id.php (modified) (2 diffs)
-
tags/2.0.1/phpstan.neon.dist (deleted)
-
tags/2.0.1/readme.txt (modified) (5 diffs)
-
tags/2.0.1/tracking-code-for-google-analytics.php (modified) (1 diff)
-
trunk/.wp-env.json (added)
-
trunk/CHANGELOG.md (deleted)
-
trunk/CONTRIBUTING.md (deleted)
-
trunk/inc/admin.php (modified) (2 diffs)
-
trunk/inc/public.php (modified) (1 diff)
-
trunk/inc/tracking-id.php (modified) (2 diffs)
-
trunk/phpstan.neon.dist (deleted)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/tracking-code-for-google-analytics.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tracking-code-for-google-analytics/tags/2.0.1/inc/admin.php
r2734362 r2754282 6 6 */ 7 7 8 // If this file is called directly, abort. 9 if ( ! defined( 'WPINC' ) ) { 10 die; 11 } 8 namespace Tracking_Code_For_Google_Analytics; 12 9 13 add_action( 'admin_init', 'tracking_code_for_google_analytics_add_settings_field', 10, 0 ); 10 use function Tracking_Code_For_Google_Analytics\get_the_id; 11 use const Tracking_Code_For_Google_Analytics\CONFIG_NAME; 12 use const Tracking_Code_For_Google_Analytics\FILTER_NAME; 13 use const Tracking_Code_For_Google_Analytics\OPTION_NAME; 14 15 add_action( 'admin_init', __NAMESPACE__ . '\register_setting' ); 14 16 /** 15 * Register the settings field for the measurementID.17 * Register the settings field for the tracking ID. 16 18 * 17 19 * @return void 20 * 18 21 * @since 1.0.0 19 22 */ 20 function tracking_code_for_google_analytics_add_settings_field() : void {23 function register_setting() : void { 21 24 \add_settings_field( 22 25 'tracking_code_for_google_analytics_id_field', 23 26 esc_html__( 'Google Analytics', 'tracking-code-for-google-analytics' ), 24 'tracking_code_for_google_analytics_text_settings_field',27 __NAMESPACE__ . '\input_field', 25 28 'general', 26 29 'default', 27 30 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 measurementID 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' : '', 33 36 ) 34 37 ); 35 38 36 register_setting(39 \register_setting( 37 40 'general', 38 'tracking_code_for_google_analytics',41 OPTION_NAME, 39 42 array( 40 43 'type' => 'string', 41 'description' => esc_html__( 'Google Analytics measurementID', 'tracking-code-for-google-analytics' ),44 'description' => esc_html__( 'Google Analytics tracking ID', 'tracking-code-for-google-analytics' ), 42 45 'sanitize_callback' => 'sanitize_text_field', 43 46 'show_in_rest' => true, … … 48 51 49 52 /** 50 * Text field for measurement ID.53 * WordPress admin input field. 51 54 * 52 * @param array $args The field settings. 55 * @param array<string> $args The field settings. 56 * 53 57 * @return void 58 * 54 59 * @since 1.0.0 55 60 */ 56 function tracking_code_for_google_analytics_text_settings_field( array $args ) : void {61 function input_field( array $args ) : void { 57 62 $args = wp_parse_args( 58 63 $args, -
tracking-code-for-google-analytics/tags/2.0.1/inc/public.php
r2734362 r2754282 6 6 */ 7 7 8 // If this file is called directly, abort. 9 if ( ! defined( 'WPINC' ) ) { 10 die; 11 } 8 namespace Tracking_Code_For_Google_Analytics; 12 9 13 add_action( 'wp_head', 'tracking_code_for_google_analytics_do_the_script', 1, 0 ); 10 use function Tracking_Code_For_Google_Analytics\get_the_id; 11 12 add_action( 'wp_head', __NAMESPACE__ . '\global_site_tag' ); 14 13 /** 15 * Output the tracking code snippet tothe frontend.14 * Maybe print the tracking code snippet on the frontend. 16 15 * 17 16 * @return void 17 * 18 18 * @since 1.0.0 19 19 */ 20 function tracking_code_for_google_analytics_do_the_script() : void {21 $tracking_id = tracking_code_for_google_analytics_id();20 function global_site_tag() : void { 21 $tracking_id = get_the_id(); 22 22 23 // Bail early if empty. 23 24 if ( '' === $tracking_id ) { 24 25 return; -
tracking-code-for-google-analytics/tags/2.0.1/inc/tracking-id.php
r2734362 r2754282 6 6 */ 7 7 8 // If this file is called directly, abort. 9 if ( ! defined( 'WPINC' ) ) { 10 die; 11 } 8 namespace Tracking_Code_For_Google_Analytics; 9 10 use const Tracking_Code_For_Google_Analytics\CONFIG_NAME; 11 use const Tracking_Code_For_Google_Analytics\FILTER_NAME; 12 use const Tracking_Code_For_Google_Analytics\OPTION_NAME; 12 13 13 14 /** … … 17 18 * @since 1.1.0 18 19 */ 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' ); 20 function 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 } 24 31 25 32 /** 26 * Filter the tracking_id variable to support other methods of setting this value.33 * Define the tracking ID in with a filter. 27 34 * 28 * @param string $tracking_id The Google Analytics measurement ID. 35 * @param string $tracking_id The Google Analytics tracking ID. 36 * 29 37 * @return string 38 * 30 39 * @since 1.0.0 31 40 */ 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 } 33 44 34 45 /** 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. 36 49 * 37 * @see https://www.wpbeginner.com/glossary/wp-config-php/ 38 * @since 1.1.0 50 * @since 1.0.0 39 51 */ 40 $tracking_id = defined( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID' ) ? \TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID : $tracking_id;52 return get_option( OPTION_NAME, '' ); 41 53 42 return $tracking_id;43 54 } -
tracking-code-for-google-analytics/tags/2.0.1/readme.txt
r2734362 r2754282 6 6 Tested up to: 6.0.0 7 7 Requires PHP: 7.2 8 Stable tag: 1.1.08 Stable tag: 2.0.1 9 9 License: GPLv3 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 18 18 ### Composer 19 19 20 `composer require claytoncollie/tracking-code-for-google-analytics` 20 ```php 21 composer require claytoncollie/tracking-code-for-google-analytics 22 ``` 21 23 22 24 ### Filters … … 24 26 If you want to set the tracking ID without using the wp-admin user interface, use the filter below. 25 27 26 ` 28 ```php 27 29 add_filter( 28 30 'tracking_code_for_google_analytics_id', … … 30 32 * Set Google Analytics tracking ID. 31 33 * 32 * @param string $tracking_id MeasurementID.34 * @param string $tracking_id Tracking ID. 33 35 * 34 36 * @return string 35 37 */ 36 function ( $tracking_id ) { 37 return 'UA-7654321'; 38 function ( string $tracking_id ) : string { 39 $tracking_id = 'UA-7654321'; 40 return $tracking_id; 38 41 } 39 42 ); 40 ` 43 ``` 44 45 ### Definitions 41 46 42 47 You can also define the tracking ID in your wp-config.php file with the following snippet. 43 48 44 ` 49 ```php 45 50 define( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID', 'UA-7654321' ); 46 ` 51 ``` 47 52 48 53 ### Contributing … … 86 91 == Changelog == 87 92 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 88 110 = 1.1.0 = 89 111 * 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 7 7 * Author URI: https://github.com/claytoncollie 8 8 * Text Domain: tracking-code-for-google-analytics 9 * Version: 1.1.09 * Version: 2.0.1 10 10 * 11 11 * @package Tracking_Code_For_Google_Analytics 12 12 */ 13 13 14 // If this file is called directly, abort. 15 if ( ! defined( 'WPINC' ) ) { 16 die; 17 } 14 namespace Tracking_Code_For_Google_Analytics; 15 16 const OPTION_NAME = 'tracking_code_for_google_analytics'; 17 const FILTER_NAME = 'tracking_code_for_google_analytics_id'; 18 const CONFIG_NAME = 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID'; 18 19 19 20 require_once __DIR__ . '/inc/tracking-id.php'; -
tracking-code-for-google-analytics/trunk/inc/admin.php
r2734362 r2754282 6 6 */ 7 7 8 // If this file is called directly, abort. 9 if ( ! defined( 'WPINC' ) ) { 10 die; 11 } 8 namespace Tracking_Code_For_Google_Analytics; 12 9 13 add_action( 'admin_init', 'tracking_code_for_google_analytics_add_settings_field', 10, 0 ); 10 use function Tracking_Code_For_Google_Analytics\get_the_id; 11 use const Tracking_Code_For_Google_Analytics\CONFIG_NAME; 12 use const Tracking_Code_For_Google_Analytics\FILTER_NAME; 13 use const Tracking_Code_For_Google_Analytics\OPTION_NAME; 14 15 add_action( 'admin_init', __NAMESPACE__ . '\register_setting' ); 14 16 /** 15 * Register the settings field for the measurementID.17 * Register the settings field for the tracking ID. 16 18 * 17 19 * @return void 20 * 18 21 * @since 1.0.0 19 22 */ 20 function tracking_code_for_google_analytics_add_settings_field() : void {23 function register_setting() : void { 21 24 \add_settings_field( 22 25 'tracking_code_for_google_analytics_id_field', 23 26 esc_html__( 'Google Analytics', 'tracking-code-for-google-analytics' ), 24 'tracking_code_for_google_analytics_text_settings_field',27 __NAMESPACE__ . '\input_field', 25 28 'general', 26 29 'default', 27 30 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 measurementID 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' : '', 33 36 ) 34 37 ); 35 38 36 register_setting(39 \register_setting( 37 40 'general', 38 'tracking_code_for_google_analytics',41 OPTION_NAME, 39 42 array( 40 43 'type' => 'string', 41 'description' => esc_html__( 'Google Analytics measurementID', 'tracking-code-for-google-analytics' ),44 'description' => esc_html__( 'Google Analytics tracking ID', 'tracking-code-for-google-analytics' ), 42 45 'sanitize_callback' => 'sanitize_text_field', 43 46 'show_in_rest' => true, … … 48 51 49 52 /** 50 * Text field for measurement ID.53 * WordPress admin input field. 51 54 * 52 * @param array $args The field settings. 55 * @param array<string> $args The field settings. 56 * 53 57 * @return void 58 * 54 59 * @since 1.0.0 55 60 */ 56 function tracking_code_for_google_analytics_text_settings_field( array $args ) : void {61 function input_field( array $args ) : void { 57 62 $args = wp_parse_args( 58 63 $args, -
tracking-code-for-google-analytics/trunk/inc/public.php
r2734362 r2754282 6 6 */ 7 7 8 // If this file is called directly, abort. 9 if ( ! defined( 'WPINC' ) ) { 10 die; 11 } 8 namespace Tracking_Code_For_Google_Analytics; 12 9 13 add_action( 'wp_head', 'tracking_code_for_google_analytics_do_the_script', 1, 0 ); 10 use function Tracking_Code_For_Google_Analytics\get_the_id; 11 12 add_action( 'wp_head', __NAMESPACE__ . '\global_site_tag' ); 14 13 /** 15 * Output the tracking code snippet tothe frontend.14 * Maybe print the tracking code snippet on the frontend. 16 15 * 17 16 * @return void 17 * 18 18 * @since 1.0.0 19 19 */ 20 function tracking_code_for_google_analytics_do_the_script() : void {21 $tracking_id = tracking_code_for_google_analytics_id();20 function global_site_tag() : void { 21 $tracking_id = get_the_id(); 22 22 23 // Bail early if empty. 23 24 if ( '' === $tracking_id ) { 24 25 return; -
tracking-code-for-google-analytics/trunk/inc/tracking-id.php
r2734362 r2754282 6 6 */ 7 7 8 // If this file is called directly, abort. 9 if ( ! defined( 'WPINC' ) ) { 10 die; 11 } 8 namespace Tracking_Code_For_Google_Analytics; 9 10 use const Tracking_Code_For_Google_Analytics\CONFIG_NAME; 11 use const Tracking_Code_For_Google_Analytics\FILTER_NAME; 12 use const Tracking_Code_For_Google_Analytics\OPTION_NAME; 12 13 13 14 /** … … 17 18 * @since 1.1.0 18 19 */ 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' ); 20 function 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 } 24 31 25 32 /** 26 * Filter the tracking_id variable to support other methods of setting this value.33 * Define the tracking ID in with a filter. 27 34 * 28 * @param string $tracking_id The Google Analytics measurement ID. 35 * @param string $tracking_id The Google Analytics tracking ID. 36 * 29 37 * @return string 38 * 30 39 * @since 1.0.0 31 40 */ 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 } 33 44 34 45 /** 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. 36 49 * 37 * @see https://www.wpbeginner.com/glossary/wp-config-php/ 38 * @since 1.1.0 50 * @since 1.0.0 39 51 */ 40 $tracking_id = defined( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID' ) ? \TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID : $tracking_id;52 return get_option( OPTION_NAME, '' ); 41 53 42 return $tracking_id;43 54 } -
tracking-code-for-google-analytics/trunk/readme.txt
r2734362 r2754282 6 6 Tested up to: 6.0.0 7 7 Requires PHP: 7.2 8 Stable tag: 1.1.08 Stable tag: 2.0.1 9 9 License: GPLv3 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 18 18 ### Composer 19 19 20 `composer require claytoncollie/tracking-code-for-google-analytics` 20 ```php 21 composer require claytoncollie/tracking-code-for-google-analytics 22 ``` 21 23 22 24 ### Filters … … 24 26 If you want to set the tracking ID without using the wp-admin user interface, use the filter below. 25 27 26 ` 28 ```php 27 29 add_filter( 28 30 'tracking_code_for_google_analytics_id', … … 30 32 * Set Google Analytics tracking ID. 31 33 * 32 * @param string $tracking_id MeasurementID.34 * @param string $tracking_id Tracking ID. 33 35 * 34 36 * @return string 35 37 */ 36 function ( $tracking_id ) { 37 return 'UA-7654321'; 38 function ( string $tracking_id ) : string { 39 $tracking_id = 'UA-7654321'; 40 return $tracking_id; 38 41 } 39 42 ); 40 ` 43 ``` 44 45 ### Definitions 41 46 42 47 You can also define the tracking ID in your wp-config.php file with the following snippet. 43 48 44 ` 49 ```php 45 50 define( 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID', 'UA-7654321' ); 46 ` 51 ``` 47 52 48 53 ### Contributing … … 86 91 == Changelog == 87 92 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 88 110 = 1.1.0 = 89 111 * Add ability to define tracking in wp-config.php -
tracking-code-for-google-analytics/trunk/tracking-code-for-google-analytics.php
r2734362 r2754282 7 7 * Author URI: https://github.com/claytoncollie 8 8 * Text Domain: tracking-code-for-google-analytics 9 * Version: 1.1.09 * Version: 2.0.1 10 10 * 11 11 * @package Tracking_Code_For_Google_Analytics 12 12 */ 13 13 14 // If this file is called directly, abort. 15 if ( ! defined( 'WPINC' ) ) { 16 die; 17 } 14 namespace Tracking_Code_For_Google_Analytics; 15 16 const OPTION_NAME = 'tracking_code_for_google_analytics'; 17 const FILTER_NAME = 'tracking_code_for_google_analytics_id'; 18 const CONFIG_NAME = 'TRACKING_CODE_FOR_GOOGLE_ANALYTICS_ID'; 18 19 19 20 require_once __DIR__ . '/inc/tracking-id.php';
Note: See TracChangeset
for help on using the changeset viewer.