PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wordpress-seo/admin/google_search_console/class-gsc-settings.php

https://bitbucket.org/carloskikea/helpet
PHP | 104 lines | 37 code | 15 blank | 52 comment | 2 complexity | dce455cd9adf4ce2d40de0449f0cf942 MD5 | raw file
  1<?php
  2/**
  3 * WPSEO plugin file.
  4 *
  5 * @package WPSEO\Admin\Google_Search_Console
  6 */
  7
  8/**
  9 * Class WPSEO_GSC_Settings
 10 */
 11class WPSEO_GSC_Settings {
 12
 13	/**
 14	 * Clear all data from the database
 15	 *
 16	 * @param WPSEO_GSC_Service $service Service class instance.
 17	 */
 18	public static function clear_data( WPSEO_GSC_Service $service ) {
 19		// Remove issue and issue counts.
 20		self::remove();
 21
 22		// Removes the GSC options.
 23		self::remove_gsc_option();
 24
 25		// Clear the service data.
 26		$service->clear_data();
 27	}
 28
 29	/**
 30	 * Reloading all the issues
 31	 */
 32	public static function reload_issues() {
 33		// Remove issue and issue counts.
 34		self::remove();
 35	}
 36
 37	/**
 38	 * When authorization is successful return true, otherwise false
 39	 *
 40	 * @param string                  $authorization_code Code to validate.
 41	 * @param Yoast_Api_Google_Client $client             Client object instance.
 42	 *
 43	 * @return bool
 44	 */
 45	public static function validate_authorization( $authorization_code, Yoast_Api_Google_Client $client ) {
 46		return ( $authorization_code !== '' && $client->authenticate_client( $authorization_code ) );
 47	}
 48
 49	/**
 50	 * Get the GSC profile
 51	 *
 52	 * @return string
 53	 */
 54	public static function get_profile() {
 55		// Get option.
 56		$option = get_option( WPSEO_GSC::OPTION_WPSEO_GSC, array( 'profile' => '' ) );
 57
 58		// Set the profile.
 59		$profile = '';
 60		if ( ! empty( $option['profile'] ) ) {
 61			$profile = $option['profile'];
 62		}
 63
 64		// Return the profile.
 65		return trim( $profile, '/' );
 66	}
 67
 68	/**
 69	 * Removes the issue counts and all the issues from the options
 70	 */
 71	private static function remove() {
 72		// Remove the issue counts from the options.
 73		self::remove_issue_counts();
 74
 75		// Removing all issues from the database.
 76		self::remove_issues();
 77	}
 78
 79	/**
 80	 * Remove the issue counts
 81	 */
 82	private static function remove_issue_counts() {
 83		// Remove the options which are holding the counts.
 84		delete_option( WPSEO_GSC_Count::OPTION_CI_COUNTS );
 85		delete_option( WPSEO_GSC_Count::OPTION_CI_LAST_FETCH );
 86	}
 87
 88	/**
 89	 * Delete the issues and their meta data from the database
 90	 */
 91	private static function remove_issues() {
 92		global $wpdb;
 93
 94		// Remove local crawl issues by running a delete query.
 95		$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpseo-gsc-issues-%'" );
 96	}
 97
 98	/**
 99	 * Removes the options for GSC
100	 */
101	private static function remove_gsc_option() {
102		delete_option( WPSEO_GSC::OPTION_WPSEO_GSC );
103	}
104}