Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franz-josef-kaiser/4362855 to your computer and use it in GitHub Desktop.
Save franz-josef-kaiser/4362855 to your computer and use it in GitHub Desktop.
Show the last X recently edited files in a dashboard widget
<?php
defined( 'ABSPATH' ) OR exit;
/**
* Plugin Name: (#64910) (Dashboard Widget) Last edited files
* Description: Lists the last edited files in a dashboard widget
* Author: Franz Josef Kaiser <wecodemore@gmail.com>
* Author URL: https://plus.google.com/107110219316412982437
* License: MIT
*/
if (
( defined( 'DISALLOW_FILE_EDIT' ) AND DISALLOW_FILE_EDIT )
OR
( defined( 'DISALLOW_FILE_MODS' ) AND DISALLOW_FILE_MODS )
)
add_action( 'plugins_loaded', array( 'file_mods_monitor', 'init' ) );
/**
* Adds a Dashboard Widget that holds the last edited files
* @package WordPress
* @author Franz Josef Kaiser <wecodemore@gmail.com>
* @version 2012-23-12.1114
*/
class file_mods_monitor
{
/**
* Instance of the object
* @static
* @var \file_mods_monitor object
*/
protected static $inst;
/**
* Number of files to show
* @var int
*/
public $num_files = 20;
/**
* Init, instantiates the object
* @static
* @return \file_mods_monitor An instance of the object
*/
public static function init()
{
is_null( self :: $inst ) AND self :: $inst = new self;
return self :: $inst;
}
/**
* Constructor
* @return \file_mods_monitor
*/
public function __construct()
{
add_filter( 'pre_update_option_recently_edited', array( $this, 'amount_files' ), 10, 2 );
add_action( 'wp_dashboard_setup', array( $this, 'add_widget' ) );
}
/**
* Adds the widget to the dashboard
* @return void
*/
public function add_widget()
{
wp_add_dashboard_widget(
'recently_edited_files'
,'Recently edited files'
,array( $this, 'widget_content' )
);
}
/**
* Show the last edited files
* Callback for wp_add_dashboard_widget()
* @return string
*/
public function widget_content()
{
$files = (array) get_option( 'recently_edited' );
var_dump( $files );
$table = new WP_List_Table( $files );
$table->display();
}
/**
* Pre Option update callback to alter the amount of files
* saved inside the `recently_edited` option table entry.
* @param array $new_val
* @param array $old_val
* @return array $new_val
*/
public function amount_files( $new_val, $old_val )
{
return array_slice(
array_unique( array_merge( $new_val, $old_val ) )
,0
,$this->num_files
);
}
} // END \file_mods_monitor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment