gglstmp_add_site

The Google Sitemap by BestWebSoft gglstmp add site function.

Description

gglstmp_add_site( $gglstmp_wmt, $gglstmp_sv ); 

Parameters (2)

0. $gglstmp_wmt
The gglstmp wmt.
1. $gglstmp_sv
The gglstmp sv.

Usage

  1. if ( !function_exists( 'gglstmp_add_site' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-sitemap-by-bestwebsoft/google-sitemap-plugin.php'; 
  3.  
  4. // The gglstmp wmt. 
  5. $gglstmp_wmt = null; 
  6.  
  7. // The gglstmp sv. 
  8. $gglstmp_sv = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = gglstmp_add_site($gglstmp_wmt, $gglstmp_sv); 
  12.  

Defined (1)

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

/google-sitemap-plugin.php  
  1. function gglstmp_add_site( $gglstmp_wmt, $gglstmp_sv ) { 
  2. global $gglstmp_settings; 
  3.  
  4. $gglstmp_sv_method = 'META'; 
  5. $gglstmp_sv_type = 'SITE'; 
  6. $gglstmp_url_home = home_url( '/' ); 
  7. $gglstmp_instruction_url = 'https://docs.google.com/document/d/1VOJx_OaasVskCqi9fsAbUmxfsckoagPU5Py97yjha9w/edit'; 
  8.  
  9. echo '<h3 style="font-size: 1em;">' . sprintf( __( 'Site info for %s', 'google-sitemap-plugin' ), '<a href="' . $gglstmp_url_home . '" target="_blank">' . $gglstmp_url_home . '</a>' ) . ':</h3><div class="gglstmp_wmt_content">'; 
  10.  
  11. try { 
  12. $gglstmp_wmt->sites->add( $gglstmp_url_home ); 
  13. printf( '<div>%s.</div>', __( 'The site has been added to Google Webmaster Tools', 'google-sitemap-plugin' ) ); 
  14. } catch ( Google_Service_Exception $e ) { 
  15. $gglstmp_wmt_error = $e->getErrors(); 
  16. if ( isset( $gglstmp_wmt_error[0]['message'] ) ) { 
  17. printf( '<div>%s</div>', $gglstmp_wmt_error[0]['message'] ); 
  18. } else { 
  19. printf( '<div>%s.</div>', __( 'Anerroroccurred while adding the site in Google Webmaster Tools', 'google-sitemap-plugin' ) ); 
  20. printf( '<div>%s - <a target="_blank" href="%s">%s</a>.</div>', __( "The site couldn't be added. Please, add the site manually", 'google-sitemap-plugin' ), $gglstmp_instruction_url, __( 'View the Instruction', 'google-sitemap-plugin' ) ); 
  21. echo '</div><!-- .gglstmp_wmt_content -->'; 
  22. return; 
  23.  
  24. try { 
  25. $gglstmp_sv_get_token_request_site = new Google_Service_SiteVerification_SiteVerificationWebResourceGettokenRequestSite; 
  26. $gglstmp_sv_get_token_request_site->setIdentifier( $gglstmp_url_home ); 
  27. $gglstmp_sv_get_token_request_site->setType( $gglstmp_sv_type ); 
  28. $gglstmp_sv_get_token_request = new Google_Service_SiteVerification_SiteVerificationWebResourceGettokenRequest; 
  29. $gglstmp_sv_get_token_request->setSite( $gglstmp_sv_get_token_request_site ); 
  30. $gglstmp_sv_get_token_request->setVerificationMethod( $gglstmp_sv_method ); 
  31. $gglstmp_getToken = $gglstmp_sv->webResource->getToken( $gglstmp_sv_get_token_request ); 
  32. $gglstmp_settings['site_vererification_code'] = htmlspecialchars( $gglstmp_getToken['token'] ); 
  33. if ( preg_match( '|^<meta name="google-site-verification" content="(.*)" />$|', $gglstmp_settings['site_vererification_code'] ) ) { 
  34. update_option( 'gglstmp_settings', $gglstmp_settings ); 
  35. printf( '<div>%s.</div>', __( 'Verification code has been successfully received and added to the site', 'google-sitemap-plugin' ) ); 
  36. } else { 
  37. printf( '<div>%s.</div>', __( 'Verification code has been successfully received but has not been added to the site', 'google-sitemap-plugin' ) ); 
  38. } catch ( Google_Service_Exception $e ) { 
  39. $getErrors = $e->getErrors(); 
  40. if ( isset( $getErrors[0]['message'] ) ) { 
  41. printf( '<div>%s</div>', $getErrors[0]['message'] ); 
  42. } else { 
  43. printf( '<div>%s.</div>', __( 'Anerrorhas occurred when receiving the verification code site in Google Webmaster', 'google-sitemap-plugin' ) ); 
  44. printf( '<div>%s - <a target="_blank" href="%s">%s</a>.</div>', __( "The site couldn't be verified. Please, verify the site manually", 'google-sitemap-plugin' ), $gglstmp_instruction_url, __( 'View the Instruction', 'google-sitemap-plugin' ) ); 
  45. echo '</div><!-- .gglstmp_wmt_content -->'; 
  46. return; 
  47.  
  48. try { 
  49. $gglstmp_wmt_resource_site = new Google_Service_SiteVerification_SiteVerificationWebResourceResourceSite; 
  50. $gglstmp_wmt_resource_site->setIdentifier( $gglstmp_url_home ); 
  51. $gglstmp_wmt_resource_site->setType( $gglstmp_sv_type ); 
  52. $gglstmp_wmt_resource = new Google_Service_SiteVerification_SiteVerificationWebResourceResource; 
  53. $gglstmp_wmt_resource->setSite( $gglstmp_wmt_resource_site ); 
  54. $gglstmp_sv->webResource->insert( $gglstmp_sv_method, $gglstmp_wmt_resource ); 
  55. printf( '<div>%s.</div>', __( 'The site has been successfully verified in Google Webmaster Tools', 'google-sitemap-plugin' ) ); 
  56. } catch ( Google_Service_Exception $e ) { 
  57. $getErrors = $e->getErrors(); 
  58. if ( isset( $getErrors[0]['message'] ) ) { 
  59. printf( '<div>%s</div>', $getErrors[0]['message'] ); 
  60. } else { 
  61. printf( '<div>%s.</div>', __( 'An unexpectederroroccurred when verifying site in Google Webmaster Tools', 'google-sitemap-plugin' ) ); 
  62. printf( '<div>%s - <a target="_blank" href="%s">%s</a>.</div>', __( "The site couldn't be verified. Please, verify the site manually", 'google-sitemap-plugin' ), $gglstmp_instruction_url, __( 'View the Instruction', 'google-sitemap-plugin' ) ); 
  63. echo '</div><!-- .gglstmp_wmt_content -->'; 
  64. return; 
  65.  
  66. if ( isset( $gglstmp_settings['sitemap']['loc'] ) ) { 
  67. $gglstmp_url_sitemap = $gglstmp_settings['sitemap']['loc']; 
  68. $gglstmp_check_sitemap = gglstmp_check_sitemap( $gglstmp_url_sitemap ); 
  69. if ( $gglstmp_check_sitemap['code'] == 200 ) { 
  70. try { 
  71. $gglstmp_wmt->sitemaps->submit( $gglstmp_url_home, $gglstmp_url_sitemap ); 
  72. printf( '<div>%s.</div>', __( 'The sitemap file has been successfully added to Google Webmaster Tools', 'google-sitemap-plugin' ) ); 
  73. } catch ( Google_Service_Exception $e ) { 
  74. $gglstmp_wmt_error = $e->getErrors(); 
  75. if ( isset( $gglstmp_wmt_error[0]['message'] ) ) { 
  76. printf( '<div>%s</div>', $gglstmp_wmt_error[0]['message'] ); 
  77. } else { 
  78. printf( '<div>%s.</div>', __( 'Anerroroccurred while adding the sitemap file in Google Webmaster Tools', 'google-sitemap-plugin' ) ); 
  79. printf( '<div>%s - <a target="_blank" href="%s">%s</a>.</div>', __( "The sitemap file couldn't be added. Please, add the sitemap file manually", 'google-sitemap-plugin' ), $gglstmp_instruction_url, __( 'View the Instruction', 'google-sitemap-plugin' ) ); 
  80. } else { 
  81. printf( '<div>%s.</div>', sprintf( __( 'Error 404. The sitemap file %s not found', 'google-sitemap-plugin' ), sprintf( '(<a href="%s">%s</a>)', $gglstmp_settings['sitemap']['loc'], $gglstmp_settings['sitemap']['file'] ) ) ); 
  82. } else { 
  83. printf( '<div>%s.</div>', __( 'The sitemap file not found', 'google-sitemap-plugin' ) ); 
  84. echo '</div><!-- .gglstmp_wmt_content -->';