gglstmp_add_site

The Google Sitemap by BestWebSoft gglstmp add site function.

Description

gglstmp_add_site( $webmasters, $site_verification ); 

Parameters (2)

0. $webmasters
The webmasters.
1. $site_verification
The site verification.

Usage

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

Defined (1)

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

/google-sitemap-plugin.php  
  1. function gglstmp_add_site( $webmasters, $site_verification ) { 
  2. global $gglstmp_options; 
  3.  
  4. $instruction_url = 'https://docs.google.com/document/d/1VOJx_OaasVskCqi9fsAbUmxfsckoagPU5Py97yjha9w/'; 
  5. $home_url = home_url( '/' ); 
  6.  
  7. $return = '<table id="gglstmp_manage_table"><tr><th>' . __( 'Website', 'google-sitemap-plugin' ) . '</th> 
  8. <td><a href="' . $home_url . '" target="_blank">' . $home_url . '</a></td></tr>'; 
  9. try { 
  10. $webmasters->sites->add( $home_url ); 
  11. $return .= '<tr><th>' . __( 'Status', 'google-sitemap-plugin' ) . '</th> 
  12. <td class="gglstmp_success">' . __( 'Added', 'google-sitemap-plugin' ) . '</td></tr>'; 
  13. } catch ( Google_Service_Exception $e ) { 
  14. $error = $e->getErrors(); 
  15. $wmt_error = isset( $error[0]['message'] ) ? $error[0]['message'] : __( 'Unexpectederror, 'google-sitemap-plugin' ); 
  16. } catch ( Google_IO_Exception $e ) { 
  17. $wmt_error = $e->getMessage(); 
  18. } catch ( Google_Auth_Exception $e ) { 
  19. $wmt_error = true; 
  20. } catch ( Exception $e ) { 
  21. $wmt_error = $e->getMessage(); 
  22.  
  23. if ( ! empty( $wmt_error ) ) { 
  24. $return .= '<tr><th>' . __( 'Status', 'google-sitemap-plugin' ) . '</th>'; 
  25. if ( $wmt_error !== true ) 
  26. $return .= '<td><strong>' . __( 'Error', 'google-sitemap-plugin' ) . ':</strong> ' . $wmt_error . '</td></tr> 
  27. <tr><th></th>'; 
  28. $return .= '<td>' . __( "Manual verification required.", 'google-sitemap-plugin' ) . ' <a target="_blank" href="' . $instruction_url . '">' . __( 'Learn More', 'google-sitemap-plugin' ) . '</a></td></tr>'; 
  29. } else { 
  30.  
  31. try { 
  32. $gglstmp_sv_get_token_request_site = new Google_Service_SiteVerification_SiteVerificationWebResourceGettokenRequestSite; 
  33. $gglstmp_sv_get_token_request_site->setIdentifier( $home_url ); 
  34. $gglstmp_sv_get_token_request_site->setType( 'SITE' ); 
  35. $gglstmp_sv_get_token_request = new Google_Service_SiteVerification_SiteVerificationWebResourceGettokenRequest; 
  36. $gglstmp_sv_get_token_request->setSite( $gglstmp_sv_get_token_request_site ); 
  37. $gglstmp_sv_get_token_request->setVerificationMethod( 'META' ); 
  38. $getToken = $site_verification->webResource->getToken( $gglstmp_sv_get_token_request ); 
  39. $gglstmp_options['site_vererification_code'] = htmlspecialchars( $getToken['token'] ); 
  40. if ( preg_match( '|^<meta name="google-site-verification" content="(.*)" />$|', $gglstmp_options['site_vererification_code'] ) ) { 
  41. update_option( 'gglstmp_options', $gglstmp_options ); 
  42.  
  43. $return .= '<tr><th>' . __( 'Verification Code', 'google-sitemap-plugin' ) . '</th> 
  44. <td>' . __( 'Received and added to the site', 'google-sitemap-plugin' ) . '</td></tr>'; 
  45. } else { 
  46. $return .= '<tr><th>' . __( 'Verification Code', 'google-sitemap-plugin' ) . '</th> 
  47. <td>' . __( 'Received, but has not been added to the site', 'google-sitemap-plugin' ) . '</td></tr>'; 
  48. } catch ( Google_Service_Exception $e ) { 
  49. $error = $e->getErrors(); 
  50. $sv_error = isset( $error[0]['message'] ) ? $error[0]['message'] : __( 'Unexpectederror, 'google-sitemap-plugin' ); 
  51. } catch ( Google_IO_Exception $e ) { 
  52. $sv_error = $e->getMessage(); 
  53. } catch ( Google_Auth_Exception $e ) { 
  54. $sv_error = true; 
  55. } catch ( Exception $e ) { 
  56. $sv_error = $e->getMessage(); 
  57.  
  58. if ( ! empty( $sv_error ) ) {  
  59. if ( $sv_error !== true ) { 
  60. $return .= '<tr><th>' . __( 'Verification Code', 'google-sitemap-plugin' ) . '</th> 
  61. <td><strong>' . __( 'Error', 'google-sitemap-plugin' ) . ':</strong> ' . $sv_error . '</td></tr>'; 
  62.  
  63. $return .= '<tr><th>' . __( 'Verification Status', 'google-sitemap-plugin' ) . '</th> 
  64. <td>' . ___( "The site couldn't be verified. Manual verification required.", 'google-sitemap-plugin' ) . ' <a target="_blank" href="' . $instruction_url . '">' . __( 'Learn More', 'google-sitemap-plugin' ) . '</a></td></tr>'; 
  65. } else { 
  66.  
  67. try { 
  68. $gglstmp_wmt_resource_site = new Google_Service_SiteVerification_SiteVerificationWebResourceResourceSite; 
  69. $gglstmp_wmt_resource_site->setIdentifier( $home_url ); 
  70. $gglstmp_wmt_resource_site->setType( 'SITE' ); 
  71. $gglstmp_wmt_resource = new Google_Service_SiteVerification_SiteVerificationWebResourceResource; 
  72. $gglstmp_wmt_resource->setSite( $gglstmp_wmt_resource_site ); 
  73. $site_verification->webResource->insert( 'META', $gglstmp_wmt_resource ); 
  74.  
  75. $return .= '<tr><th>' . __( 'Verification Status', 'google-sitemap-plugin' ) . '</th> 
  76. <td class="gglstmp_success">' . ___( 'Verified', 'google-sitemap-plugin' ) . '</td></tr>'; 
  77. } catch ( Google_Service_Exception $e ) { 
  78. $error = $e->getErrors(); 
  79. $sv_error = isset( $error[0]['message'] ) ? $error[0]['message'] : __( 'Unexpectederror, 'google-sitemap-plugin' ); 
  80. } catch ( Google_IO_Exception $e ) { 
  81. $sv_error = $e->getMessage(); 
  82. } catch ( Google_Auth_Exception $e ) { 
  83. $sv_error = true; 
  84. } catch ( Exception $e ) { 
  85. $sv_error = $e->getMessage(); 
  86.  
  87. if ( ! empty( $sv_error ) ) { 
  88. $return .= '<tr><th>' . __( 'Verification Status', 'google-sitemap-plugin' ) . '</th>'; 
  89. if ( $sv_error !== true ) 
  90. $return .= '<td><strong>' . __( 'Error', 'google-sitemap-plugin' ) . ':</strong> ' . $sv_error . '</td></tr> 
  91. <tr><th></th>'; 
  92. $return .= '<td>' . __( "Manual verification required.", 'google-sitemap-plugin' ) . ' <a target="_blank" href="' . $instruction_url . '">' . __( 'Learn More', 'google-sitemap-plugin' ) . '</a></td></tr>'; 
  93. } else { 
  94.  
  95. $return .= '<tr><th>' . __( 'Sitemap Status', 'google-sitemap-plugin' ) . '</th>'; 
  96.  
  97. if ( isset( $gglstmp_options['sitemap']['loc'] ) ) { 
  98. $gglstmp_url_sitemap = $gglstmp_options['sitemap']['loc']; 
  99. $gglstmp_check_sitemap = gglstmp_check_sitemap( $gglstmp_url_sitemap ); 
  100. if ( $gglstmp_check_sitemap['code'] == 200 ) { 
  101. try { 
  102. $webmasters->sitemaps->submit( $home_url, $gglstmp_url_sitemap ); 
  103. $return .= '<td class="gglstmp_success">' . __( 'Added', 'google-sitemap-plugin' ) . '</td></tr>'; 
  104. } catch ( Google_Service_Exception $e ) { 
  105. $error = $e->getErrors(); 
  106. $wmt_error = isset( $error[0]['message'] ) ? $error[0]['message'] : __( 'Unexpectederror, 'google-sitemap-plugin' ); 
  107. } catch ( Google_IO_Exception $e ) { 
  108. $wmt_error = $e->getMessage(); 
  109. } catch ( Google_Auth_Exception $e ) { 
  110. $wmt_error = true; 
  111. } catch ( Exception $e ) { 
  112. $wmt_error = $e->getMessage(); 
  113. if ( ! empty( $wmt_error ) ) { 
  114. if ( $wmt_error !== true ) 
  115. $return .= '<td><strong>' . __( 'Error', 'google-sitemap-plugin' ) . ':</strong> ' . $wmt_error . '</td></tr> 
  116. <tr><th></th>'; 
  117. $return .= '<td>' . __( "Please add the sitemap file manually.", 'google-sitemap-plugin' ) . ' <a target="_blank" href="' . $instruction_url . '">' . __( 'Learn More', 'google-sitemap-plugin' ) . '</a></td></tr>'; 
  118. } else { 
  119. $return .= '<td><strong>' . __( 'Error 404', 'google-sitemap-plugin' ) . ':</strong> ' . sprintf( __( 'The sitemap file %s not found.', 'google-sitemap-plugin' ), sprintf( '(<a href="%s">%s</a>)', $gglstmp_options['sitemap']['loc'], $gglstmp_options['sitemap']['file'] ) ) . '</td></tr>'; 
  120. } else { 
  121. $return .= '<td><strong>' . __( 'Error', 'google-sitemap-plugin' ) . ':</strong> ' . __( 'The sitemap file not found.', 'google-sitemap-plugin' ) . '</td></tr>'; 
  122.  
  123. $return .= '</table>'; 
  124. return $return;