本文整理汇总了PHP中GADWP_Tools::set_cache方法的典型用法代码示例。如果您正苦于以下问题:PHP GADWP_Tools::set_cache方法的具体用法?PHP GADWP_Tools::set_cache怎么用?PHP GADWP_Tools::set_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GADWP_Tools
的用法示例。
在下文中一共展示了GADWP_Tools::set_cache方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajax_set_error
/**
* Ajax handler for storing JavaScript Errors
*
* @return json|int
*/
public function ajax_set_error()
{
if (!isset($_POST['gadwp_security_set_error']) || !(wp_verify_nonce($_POST['gadwp_security_set_error'], 'gadwp_backend_item_reports') || wp_verify_nonce($_POST['gadwp_security_set_error'], 'gadwp_frontend_item_reports'))) {
wp_die(-40);
}
GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($_POST['response']), 24 * 60 * 60);
wp_die();
}
示例2: general_settings_network
public static function general_settings_network()
{
$gadwp = GADWP();
global $wp_version;
if (!current_user_can('manage_network_options')) {
return;
}
$options = self::update_options('network');
/*
* Include GAPI
*/
echo '<div id="gapi-warning" class="updated"><p>' . __('Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', 'google-analytics-dashboard-for-wp') . ' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=gadwp">Library conflicts between WordPress plugins</a></p></div>';
if (null === $gadwp->gapi_controller) {
$gadwp->gapi_controller = new GADWP_GAPI_Controller();
}
echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
if (isset($_POST['ga_dash_code'])) {
if (!stripos('x' . $_POST['ga_dash_code'], 'UA-', 1) == 1) {
try {
$gadwp->gapi_controller->client->authenticate($_POST['ga_dash_code']);
$gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
$gadwp->config->options['automatic_updates_minorversion'] = 1;
$gadwp->config->set_plugin_options(true);
$options = self::update_options('network');
$message = "<div class='updated'><p>" . __("Plugin authorization succeeded.", 'google-analytics-dashboard-for-wp') . "</p></div>";
if (is_multisite()) {
// Cleanup errors on the entire network
foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) {
switch_to_blog($blog['blog_id']);
GADWP_Tools::delete_cache('gapi_errors');
restore_current_blog();
}
} else {
GADWP_Tools::delete_cache('gapi_errors');
}
if ($gadwp->config->options['ga_dash_token'] && $gadwp->gapi_controller->client->getAccessToken()) {
if (!empty($gadwp->config->options['ga_dash_profile_list'])) {
$profiles = $gadwp->config->options['ga_dash_profile_list'];
} else {
$profiles = $gadwp->gapi_controller->refresh_profiles();
}
if ($profiles) {
$gadwp->config->options['ga_dash_profile_list'] = $profiles;
if (isset($gadwp->config->options['ga_dash_tableid_jail']) && !$gadwp->config->options['ga_dash_tableid_jail']) {
$profile = GADWP_Tools::guess_default_domain($profiles);
$gadwp->config->options['ga_dash_tableid_jail'] = $profile;
$gadwp->config->options['ga_dash_tableid'] = $profile;
}
$gadwp->config->set_plugin_options(true);
$options = self::update_options('network');
}
}
} catch (Google_IO_Exception $e) {
GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $gadwp->gapi_controller->error_timeout);
return false;
} catch (Google_Service_Exception $e) {
GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $gadwp->gapi_controller->error_timeout);
GADWP_Tools::set_cache('gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout);
return $e->getCode();
} catch (Exception $e) {
GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e) . "\nResponseHttpCode:" . $e->getCode(), $gadwp->gapi_controller->error_timeout);
$gadwp->gapi_controller->reset_token(false);
}
} else {
$message = "<div class='error'><p>" . __("The access code is <strong>NOT</strong> your <strong>Tracking ID</strong> (UA-XXXXX-X). Try again, and use the red link to get your access code", 'google-analytics-dashboard-for-wp') . ".</p></div>";
}
}
if (isset($_POST['Refresh'])) {
if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
$gadwp->config->options['ga_dash_profile_list'] = array();
$message = "<div class='updated'><p>" . __("Properties refreshed.", 'google-analytics-dashboard-for-wp') . "</p></div>";
$options = self::update_options('network');
if ($gadwp->config->options['ga_dash_token'] && $gadwp->gapi_controller->client->getAccessToken()) {
if (!empty($gadwp->config->options['ga_dash_profile_list'])) {
$profiles = $gadwp->config->options['ga_dash_profile_list'];
} else {
$profiles = $gadwp->gapi_controller->refresh_profiles();
}
if ($profiles) {
$gadwp->config->options['ga_dash_profile_list'] = $profiles;
if (isset($gadwp->config->options['ga_dash_tableid_jail']) && !$gadwp->config->options['ga_dash_tableid_jail']) {
$profile = GADWP_Tools::guess_default_domain($profiles);
$gadwp->config->options['ga_dash_tableid_jail'] = $profile;
$gadwp->config->options['ga_dash_tableid'] = $profile;
}
$gadwp->config->set_plugin_options(true);
$options = self::update_options('network');
}
}
} else {
$message = "<div class='error'><p>" . __("Cheating Huh?", 'google-analytics-dashboard-for-wp') . "</p></div>";
}
}
if (isset($_POST['Clear'])) {
if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
GADWP_Tools::clear_cache();
$message = "<div class='updated'><p>" . __("Cleared Cache.", 'google-analytics-dashboard-for-wp') . "</p></div>";
} else {
$message = "<div class='error'><p>" . __("Cheating Huh?", 'google-analytics-dashboard-for-wp') . "</p></div>";
}
//.........这里部分代码省略.........
示例3: get_realtime
/**
* Analytics data for backend reports (Real-Time)
*
* @param
* $projectId
* @return array|int
*/
private function get_realtime($projectId)
{
$metrics = 'rt:activeUsers';
$dimensions = 'rt:pagePath,rt:source,rt:keyword,rt:trafficType,rt:visitorType,rt:pageTitle';
try {
$serial = 'qr_realtimecache_' . $this->get_serial($projectId);
$transient = GADWP_Tools::get_cache($serial);
if ($transient === false) {
if ($this->gapi_errors_handler()) {
return -23;
}
$data = $this->service->data_realtime->get('ga:' . $projectId, $metrics, array('dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId));
GADWP_Tools::set_cache($serial, $data, 55);
$this->gadwp->config->options['api_backoff'] = 0;
$this->gadwp->config->set_plugin_options();
} else {
$data = $transient;
}
} catch (Google_Service_Exception $e) {
GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
GADWP_Tools::set_cache('gapi_errors', array($e->getCode(), (array) $e->getErrors()), $this->error_timeout);
return $e->getCode();
} catch (Exception $e) {
GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
return $e->getCode();
}
if ($data->getRows() < 1) {
return -21;
}
$i = 0;
$gadwp_data = $data;
foreach ($data->getRows() as $row) {
$gadwp_data->rows[$i] = array_map('esc_html', $row);
$i++;
}
return $gadwp_data;
}