_audit->data)) {
$this->_error = true;
return;
}
if ($this->_audit->sq_analytics_gsc_connected) {
if (isset($this->_audit->data->sq_analytics_gsc->keyword) && $this->_audit->data->sq_analytics_gsc->keyword <> '' &&
isset($this->_audit->data->sq_analytics_gsc->clicks)) {
$this->_keyword = $this->_audit->data->sq_analytics_gsc->keyword;
$this->_clicks = $this->_audit->data->sq_analytics_gsc->clicks;
}elseif (isset($this->_audit->data->sq_seo_keywords->value)) {
$this->_keyword = $this->_audit->data->sq_seo_keywords->value;
$this->_clicks = 0;
}
} else {
$this->_error = true;
}
}
public function setTasks($tasks) {
parent::setTasks($tasks);
$this->_tasks[$this->_category] = array(
'clicks' => array(
'title' => __("Clicks from Search Engine", _SQ_PLUGIN_NAME_),
'description' => "",
),
);
}
/*********************************************/
/**
* Check if the Google Search Console is connected
* @return string
*/
public function getHeader() {
$header = '
';
if (!$this->_audit->sq_analytics_gsc_connected) {
$header .= '' . __('Connect Google Search', _SQ_PLUGIN_NAME_) . '';
} elseif ($this->_keyword) {
$header .= '' . __('Keyword', _SQ_PLUGIN_NAME_) . ': ' . $this->_keyword . '
';
$header .= '' . __('Do a research', _SQ_PLUGIN_NAME_) . '';
} else {
if (isset($this->_post->ID)) {
$edit_link = SQ_Classes_Helpers_Tools::getAdminUrl('post.php?post=' . (int)$this->_post->ID . '&action=edit');
if ($this->_post->post_type <> 'profile') {
$edit_link = get_edit_post_link($this->_post->ID, false);
}
$header .= '' . __('No Keyword Found', _SQ_PLUGIN_NAME_) . '
';
$header .= '' . __('Do a research', _SQ_PLUGIN_NAME_) . '';
if (isset($this->_post->ID)) {
$header .= '' . __('Optimize for a keyword', _SQ_PLUGIN_NAME_) . '';
}
}
}
$header .= '';
return $header;
}
/**
* Keyword optimization required
* @param $title
* @return string
*/
public function getTitle($title) {
parent::getTitle($title);
if ($this->_error && !$this->_audit->sq_analytics_gsc_connected) {
$title = __("Connect to Google Search Console", _SQ_PLUGIN_NAME_);
}
if ($this->_error && !$this->_keyword) {
$title = __("Optimize the page for a keyword", _SQ_PLUGIN_NAME_);
}
return $title;
}
/**
* Show the value for this page
* @return bool|int
*/
public function getValue() {
if (!$this->isError()) {
return number_format((int)$this->_clicks, 0, '','.');
}
return false;
}
/**
* Check if there are clicks on this page
* @return bool|WP_Error
*/
public function checkclicks($task) {
if ($this->_clicks !== false) {
$task['completed'] = ($this->_clicks >= self::CLICKS_MINVAL);
return $task;
}
$task['error'] = true;
return $task;
}
}