Created
May 30, 2018 07:50
-
-
Save wpmudev-sls/18f4eb009c40a03bb897405177ad3074 to your computer and use it in GitHub Desktop.
[Post Indexer] - Custom Statistics Page
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: [Post Indexer] - Custom Statistics Page | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: For now only changes the posts lists number in the Recently Indesed Posts list | |
* Author: James Morris & Panos Lyrakis @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
if ( ! class_exists( 'WPMUDEV_PI_Statistics_Page' ) ) { | |
class WPMUDEV_PI_Statistics_Page { | |
private static $_instance = null; | |
private $indexed_limit; | |
public static function get_instance() { | |
if( is_null( self::$_instance ) ){ | |
self::$_instance = new WPMUDEV_PI_Statistics_Page(); | |
} | |
return self::$_instance; | |
} | |
private function __construct() { | |
$this->indexed_limit = 50; | |
add_action( 'admin_init', array( &$this, 'remove_original_page' ), 20 ); | |
} | |
public function remove_original_page() { | |
global $postindexeradmin; | |
remove_action( 'postindexer_statistics', array( $postindexeradmin, 'handle_statistics_page' ) ); | |
add_action( 'postindexer_statistics', array( &$this, 'handle_statistics_page' ) ); | |
} | |
public function handle_statistics_page() { | |
global $postindexeradmin; | |
add_action( 'postindexer_dashboard_left', array( $postindexeradmin, 'dashboard_news' ) ); | |
add_action( 'postindexer_dashboard_left', array( $postindexeradmin, 'dashboard_meta' ) ); | |
add_action( 'postindexer_dashboard_left', array( $postindexeradmin, 'dashboard_blog_stats' ) ); | |
if ( $postindexeradmin->model->blogs_for_rebuilding() ) { | |
$rebuild_queue = true; | |
add_action( 'postindexer_dashboard_right', array( $postindexeradmin, 'dashboard_rebuild_queue_stats' ) ); | |
} else { | |
$rebuild_queue = false; | |
} | |
add_action( 'postindexer_dashboard_right', array( $postindexeradmin, 'dashboard_post_type_stats' ) ); | |
add_action( 'postindexer_dashboard_right', array( &$this, 'dashboard_last_indexed_stats' ) ); | |
?> | |
<div id="icon-edit" class="icon32 icon32-posts-post"><br></div> | |
<h2><?php _e( 'Network Post Index Statistics', 'postindexer' ); ?></h2> | |
<?php | |
if ( $rebuild_queue ) { | |
// Show a rebuilding message and timer | |
?> | |
<div id='rebuildingmessage'> | |
<?php _e( 'You currently have items in your indexing queue.', 'postindexer' ); ?> | |
</div> | |
<?php | |
} | |
?> | |
<div id="dashboard-widgets-wrap"> | |
<div class="metabox-holder" id="dashboard-widgets"> | |
<div style="width: 49%;" class="postbox-container"> | |
<div class="meta-box-sortables ui-sortable" id="normal-sortables"> | |
<?php | |
do_action( 'postindexer_dashboard_left' ); | |
?> | |
</div> | |
</div> | |
<div style="width: 49%;" class="postbox-container"> | |
<div class="meta-box-sortables ui-sortable" id="side-sortables"> | |
<?php | |
do_action( 'postindexer_dashboard_right' ); | |
?> | |
</div> | |
</div> | |
<div style="display: none; width: 49%;" class="postbox-container"> | |
<div class="meta-box-sortables ui-sortable" id="column3-sortables" style=""> | |
</div> | |
</div> | |
<div style="display: none; width: 49%;" class="postbox-container"> | |
<div class="meta-box-sortables ui-sortable" id="column4-sortables" style=""> | |
</div> | |
</div> | |
</div> | |
<div class="clear"></div> | |
</div> | |
<?php | |
} | |
function dashboard_last_indexed_stats() { | |
?> | |
<div id="last-indexed-stats" class="postbox "> | |
<h3 class="hndle"><span><?php _e( 'Recently Indexed Posts', 'postindexer' ); ?></span></h3> | |
<div class="inside"> | |
<table class='widefat'> | |
<thead> | |
<tr> | |
<th scope="col"><?php _e( 'Post Title', 'postindexer' ); ?></th> | |
<th scope="col"><?php _e( 'Site', 'postindexer' ); ?></th> | |
</tr> | |
</thead> | |
<tfoot> | |
<tr> | |
<th scope="col"><?php _e( 'Post Title', 'postindexer' ); ?></th> | |
<th scope="col"><?php _e( 'Site', 'postindexer' ); ?></th> | |
</tr> | |
</tfoot> | |
<tbody> | |
<?php | |
$recent = $this->get_summary_recently_indexed_extnd(); | |
if ( ! empty( $recent ) ) { | |
?> | |
<?php | |
$class = 'alt'; | |
foreach ( $recent as $r ) { | |
switch_to_blog( $r->BLOG_ID ); | |
?> | |
<tr class='<?php echo $class; ?>'> | |
<td style='width: 75%;' valign=top><a href='<?php echo get_permalink( $r->ID ); ?>'> | |
<?php | |
echo get_the_title( $r->ID ); | |
?> | |
</a> | |
</td> | |
<td style='width: 25%;' valign=top><a href='<?php echo get_option( 'home' ); ?>'> | |
<?php | |
echo get_option( 'blogname' ); | |
?> | |
</a> | |
</td> | |
</tr> | |
<?php | |
restore_current_blog(); | |
if ( $class == '' ) { | |
$class = 'alt'; | |
} else { | |
$class = ''; | |
} | |
} | |
?> | |
<?php | |
} | |
?> | |
</tbody> | |
</table> | |
</div> | |
</div> | |
<?php | |
} | |
public function get_summary_recently_indexed_extnd() { | |
global $wpdb; | |
$sql = $wpdb->prepare( "SELECT * FROM ".$wpdb->base_prefix."network_posts ORDER BY post_modified_gmt DESC LIMIT %d", $this->indexed_limit ); | |
return $wpdb->get_results( $sql ); | |
} | |
} | |
add_action( 'plugins_loaded', function(){ | |
$GLOBALS['WPMUDEV_PI_Statistics_Page'] = WPMUDEV_PI_Statistics_Page::get_instance(); | |
}, 10 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment