Last active
November 23, 2016 00:22
-
-
Save zenware/0c6f1dffc79d9901df716786cb250fe2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* @package Tripwire | |
* @version 0.1 | |
*/ | |
/* | |
Plugin Name: Tripwire | |
Plugin URI: http://wordpress.org/plugins/tripwire/ | |
Description: This plugin creates a checksum of all the files in the Wordpress site root. And alerts the site owner if anything has changed. | |
Version: 0.1 | |
Author: Jay Looney | |
Author URI: https://www.jaylooney.us/ | |
License: GPL2 | |
License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
if (!class_exists('Tripwire')) { | |
add_action('admin_menu', 'Tripwire::init'); | |
register_activation_hook(__FILE__, 'Tripwire::activate'); | |
abstract class Tripwire { | |
public static function init() { | |
add_plugins_page('Tripwire Setup', 'Tripwire', 'activate_plugins', 'tripwire', 'Tripwire::plugin_page_html'); | |
} | |
public static function plugin_page_html() { | |
echo ' | |
<div class="wrap"> | |
<p>Hello from the Tripwire Plugin Menu</p> | |
</div> | |
'; | |
} | |
public static function activate() { | |
$access_type = get_filesystem_method(); | |
if ($access_type === 'direct') { | |
/* We can attempt interaction with the filesystem */ | |
} else { | |
add_action('admin_notice', 'Tripwire::filesystem_notice'); | |
} | |
} | |
public static function filesystem_notice() { | |
$url = wp_nonce_url(admin_url('plugins.php?page=tripwire'), 'activate-filesystem'); | |
echo " | |
<div class=\"notice notice-info\"> | |
<p class=\"tw-notice\"><a href=\"$url\">Tripwire needs Filesystem Permissions.</a></p> | |
</div> | |
"; | |
} | |
} | |
} | |
if (!class_exists('Tripwire_Widget')) { | |
add_action('wp_dashboard_setup', 'Tripwire_Widget::init'); | |
class Tripwire_Widget { | |
const WID = 'tripwire-widget'; | |
const WNAME = 'Tripwire'; | |
public static function init() { | |
wp_add_dashboard_widget(self::WID, self::WNAME, 'Tripwire_Widget::widget_html'); | |
add_action('admin_enqueue_scripts', 'Tripwire_Widget::widget_css'); | |
} | |
public static function widget_css() { | |
echo ' | |
<style type="text/css"> | |
.tw-error { | |
background-color: pink; | |
} | |
li.tw-listitem span:first-child { | |
float: none; | |
} | |
li.tw-listitem span { | |
float: right; | |
} | |
</style> | |
'; | |
} | |
public static function widget_html() { | |
echo ' | |
<h3>File Status</h3> | |
<ul class="tw-list"> | |
<li class="tw-listitem"><span>tripwire.php</span> <span>60b725f | 60b725f</span></li> | |
<li class="tw-listitem tw-error"><span>hello.php</span> <span>3b5d5c3 | d41d8cd</span></li> | |
<li class="tw-listitem"><span>akismet.php</span> <span>2cd6ee2 | 2cd6ee2</span></li> | |
</ul> | |
'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment