Created
December 13, 2013 03:37
-
-
Save ounziw/7939459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Show Warning Message on Dashboard | |
Plugin URI: http://www.rescuework.jp/ | |
Description: Displays warning messages on your WP's dashboard. | |
Author: Fumito MIZUNO | |
Version: 1.0 | |
License: GPL 2.0 or later http://www.gnu.org/licenses/gpl.html | |
*/ | |
/** | |
* OunziwShowMessage | |
* | |
*/ | |
class OunziwShowMessage { | |
protected $htmlformat = '<div class="%s"><p>%s</p></div>'; | |
protected $output = ''; | |
/** | |
* __construct | |
* | |
* @access protected | |
* @return void | |
*/ | |
function __construct() { | |
add_action( 'all_admin_notices', array( $this, 'echoOutput' ) ); | |
} | |
/** | |
* setOutput | |
* | |
* @param mixed $message | |
* @param string $divclass | |
* @access public | |
* @return void | |
*/ | |
function setOutput($message,$divclass='error') { | |
$divclass = sanitize_html_class($divclass,'error'); | |
$message = wp_kses_post($message); | |
$this->output .= sprintf($this->htmlformat,$divclass,$message); | |
} | |
/** | |
* echoOutput | |
* | |
* @access public | |
* @return void | |
*/ | |
function echoOutput() { | |
echo $this->output; | |
} | |
} | |
/** | |
* OunziwCreateMessage | |
* | |
*/ | |
class OunziwCreateMessage { | |
protected $obj; | |
protected $message; | |
/** | |
* __construct | |
* | |
* @param OunziwShowMessage $obj | |
* @access protected | |
* @return void | |
*/ | |
function __construct(OunziwShowMessage $obj) { | |
$this->obj = $obj; | |
$this->addMessage(); | |
} | |
/** | |
* addMessage | |
* | |
* @final | |
* @access protected | |
* @return void | |
*/ | |
final protected function addMessage(){ | |
if ($this->check()) { | |
$this->setMessage(); | |
$this->obj->setOutput($this->message); | |
} | |
} | |
/** | |
* check | |
* | |
* @access protected | |
* @return void | |
*/ | |
protected function check(){ | |
return file_exists(ABSPATH . 'wp-admin/install.php'); | |
} | |
/** | |
* setMessage | |
* | |
* @access protected | |
* @return void | |
*/ | |
protected function setMessage(){ | |
$this->message = __('wp-admin/install.php exists! Delete this file.'); | |
} | |
} | |
$obj = new OunziwShowMessage; | |
new OunziwCreateMessage($obj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Show Warning Message on Dashboard | |
Plugin URI: http://www.rescuework.jp/ | |
Description: Displays warning messages on your WP's dashboard. | |
Author: Fumito MIZUNO | |
Version: 1.0 | |
License: GPL 2.0 or later http://www.gnu.org/licenses/gpl.html | |
*/ | |
class childShowMessage extends OunziwShowMessage{ | |
function returnOutput() { | |
ob_start(); | |
parent::echoOutput(); | |
$output = ob_get_clean(); | |
return $output; | |
} | |
} | |
class MessageTest extends PHPUnit_Framework_TestCase { | |
protected $obj; | |
function setUp() { | |
$this->obj = new childShowMessage; | |
} | |
function testOutput() { | |
$message = 'Message'; | |
$expected = '<div class="error"><p>Message</p></div>'; | |
$this->obj->setOutput($message); | |
$output = $this->obj->returnOutput(); | |
$this->assertEquals($expected, $output); | |
} | |
function testDefaultClass() { | |
$message = 'Message'; | |
$divclass = ''; | |
$expected = '<div class="error"><p>Message</p></div>'; | |
$this->obj->setOutput($message,$divclass); | |
$output = $this->obj->returnOutput(); | |
$this->assertEquals($expected, $output); | |
} | |
function testEscapeClass() { | |
$message = 'Message'; | |
$divclass = '<script>error</script>'; | |
$expected = '<div class="scripterrorscript"><p>Message</p></div>'; | |
$this->obj->setOutput($message,$divclass); | |
$output = $this->obj->returnOutput(); | |
$this->assertEquals($expected, $output); | |
} | |
function testEscapeMessage() { | |
$message = '<script>Message</script>'; | |
$expected = '<div class="error"><p>Message</p></div>'; | |
$this->obj->setOutput($message); | |
$output = $this->obj->returnOutput(); | |
$this->assertEquals($expected, $output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment