gtm4wp_wp_loaded

The Google Tag Manager for WordPress gtm4wp wp loaded function.

Description

gtm4wp_wp_loaded(); 

Usage

  1. if ( !function_exists( 'gtm4wp_wp_loaded' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-tag-manager-for-wordpress/public/frontend.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gtm4wp_wp_loaded(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/public/frontend.php  
  1. function gtm4wp_wp_loaded() { 
  2. global $gtm4wp_options; 
  3.  
  4. if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] ) { 
  5. $gtm4wp_sessionid = array_key_exists( "gtm4wp_sessoionid", $_COOKIE ) ? $_COOKIE[ "gtm4wp_sessoionid" ] : ""; 
  6. // this is needed so that nobody can do a hack by editing our cookie 
  7. $gtm4wp_sessionid = str_replace( "'", "", trim( basename( $gtm4wp_sessionid ) ) ); 
  8.  
  9. if ( "" === $gtm4wp_sessionid ) { 
  10. $gtm4wp_sessionid = substr( md5( date( "Ymd_His" ).rand() ), 0, 20 ); 
  11. setcookie( "gtm4wp_sessoionid", $gtm4wp_sessionid, time()+(60*60*24*365*2) ); 
  12.  
  13. $weatherdata = get_transient( 'gtm4wp-weatherdata-'.$gtm4wp_sessionid ); 
  14.  
  15. if ( false === $weatherdata ) { 
  16. $gtm4wp_geodata = wp_remote_get( 'http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'] ); 
  17.  
  18. if ( is_array( $gtm4wp_geodata ) && ( 200 == $gtm4wp_geodata[ "response" ][ "code" ] ) ) { 
  19. $gtm4wp_geodata = unserialize( $gtm4wp_geodata[ "body" ] ); 
  20.  
  21. if ( array_key_exists( 'geoplugin_latitude', $gtm4wp_geodata ) && array_key_exists( 'geoplugin_longitude', $gtm4wp_geodata ) ) { 
  22. $weatherdata = wp_remote_get( 'http://api.openweathermap.org/data/2.5/weather?appid=' . $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHEROWMAPI ] . '&lat=' . $gtm4wp_geodata[ "geoplugin_latitude" ] . '&lon=' . $gtm4wp_geodata[ "geoplugin_longitude" ] . '&units=' . ($gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHERUNITS ] == 0 ? 'metric' : 'imperial') ); 
  23.  
  24. if ( is_array( $weatherdata ) && ( 200 == $weatherdata[ "response" ][ "code" ] ) ) { 
  25. $weatherdata = @json_decode( $weatherdata[ "body" ] ); 
  26.  
  27. if ( is_object( $weatherdata ) ) { 
  28. set_transient( 'gtm4wp-weatherdata-'.$gtm4wp_sessionid, $weatherdata, 60 * 60 );