I'm trying to show a warning based on robots being set to noindex or nofollow. I've copied the PHP Version quickicons plugin.
Here's my php file.
<?php
/**
* @package Joomla.Plugin
* @subpackage Quickicon.phpversioncheck
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Plugin to check if the robots configuration is correct filled in.
*
* @since 3.7.0
*/
class PlgQuickiconKoyRobots extends JPlugin
{
/**
* Application object.
*
* @var JApplicationCms
* @since 3.7.0
*/
protected $app;
/**
* Load plugin language files automatically
*
* @var boolean
* @since 3.7.0
*/
protected $autoloadLanguage = true;
/**
* Check what Robots.txt is set to and display an error if it's hiding the site.
*
* @param string $context The calling context
*
* @return void
*
* @since 3.7.0
*/
public function onGetIcons($context)
{
if (!$this->shouldDisplayMessage())
{
return;
}
// $app = JFactory::getApplication();
// $robots = $app->get('robots');
$robots = $this->app->get('robots');
/*
Blank = index, follow
noindex, follow
index, nofollow
noindex, nofollow
*/
// $app->enqueueMessage('This is an error', 'error');
$this->app->enqueueMessage('This is an error', 'error');
if ($robots == "noindex, follow"){
// Add a message to the message queue
$this->app->enqueueMessage(JText::_('PLG_QUICKICONS_KOY_ROBOTS_NO_INDEX_FOLLOW'), 'error');
}
if ($robots == "index, nofollow"){
// Add a message to the message queue
$this->app->enqueueMessage(JText::_('PLG_QUICKICONS_KOY_ROBOTS_NO_INDEX_NO_FOLLOW'), 'error');
}
if ($robots == "noindex, nofollow"){
// Add a message to the message queue
$this->app->enqueueMessage(JText::_('PLG_QUICKICONS_KOY_ROBOTS_INDEX_NO_FOLLOW'), 'error');
}
}
/**
* Determines if the message should be displayed
*
* @return boolean
*
* @since 3.7.0
*/
private function shouldDisplayMessage()
{
// Only on admin app
if (!$this->app->isClient('administrator'))
{
return false;
}
// Only if authenticated
if (JFactory::getUser()->guest)
{
return false;
}
// Only on HTML documents
if ($this->app->getDocument()->getType() !== 'html')
{
return false;
}
// Only on full page requests
if ($this->app->input->getCmd('tmpl', 'index') === 'component')
{
return false;
}
// Only to com_cpanel
if ($this->app->input->get('option') !== 'com_cpanel')
{
return false;
}
return true;
}
}
It installs correctly and all of the language files show, so I'm pretty sure the error is within this file.
- No message displays.
- The plugin is activated.
- The robots text is set to a value that should show (noindex, nofollow)
- I am on the dashboard.