bonny / WordPress-Simple-History

🔍🕵️‍♀️ WordPress audit log that track user changes in WordPress admin using a nice activity feed.
https://simple-history.com
309 stars 70 forks source link

Feature request: Metabox on the post editing page #163

Open twaiiiin opened 5 years ago

twaiiiin commented 5 years ago

Hello,

Feature request: A new metabox on the post editing page to see the changes made to this post. But that is maybe too much a duplicate with the "Revisions" metabox. What do you think about it?

Thank you for your great work.

bonny commented 5 years ago

I like the idea!

samjco commented 5 years ago

Here is my first try at it: Untested of course.

<?php
/*
* Add Simple history to a metabox on Page/Post
*/

//Define vars
$show_metabox_post_type = 'post'; //Show Metabox: all, post, page, or post type
$location ='side'; // Context
$priority = 'default'; // Priority

$filter_posttype = 'all'; //Filter by posttypes:  all, post, page, or post type
$filter_author = 123; //Author id(s)

/* Fire our meta box setup function on the post editor screen. */
add_action( 'load-post.php', 'simple_history_post_metabox_setup' );
add_action( 'load-post-new.php', 'simple_history_post_metabox_setup' );

/* Meta box setup function. */
function simple_history_post_metabox_setup() {

  /* Add meta boxes on the 'add_meta_boxes' hook. */
  add_action( 'add_meta_boxes', 'simple_history_post_meta_boxes' );
}
/* Create one or more meta boxes to be displayed on the post editor screen. */
function simple_history_post_meta_boxes() {

  add_meta_box(
    'sh-mb-post-class',      // Unique ID
    esc_html__( 'Simple History Box', 'shmb' ),    // Title
    'simple_history_post_class_meta_box',   // Callback function
    $show_metabox_post_type, 
    $location,         
    $priority   
  );

}

/* Display the post meta box. */
function simple_history_post_class_meta_box( $post ) { ?>

  <?php wp_nonce_field( basename( __FILE__ ), 'sh_post_class_nonce' ); ?>

  <p>
    <label for="sh-mb-post-class"><?php _e( "Current Logs for this Post", 'shmb' ); ?></label>
    <br />
    <p>
        <?php 
        /*
        For all possible queries refer to: https://codex.wordpress.org/Class_Reference/WP_Query
        */
        $args = array(
            'posts_per_page' => 5,
            'post_type' => array($filter_posttype),
            'orderby' => 'modified',
            'author' => array($filter_author),
        );
        $logQuery = new SimpleHistoryLogQuery();
        $queryResults = $logQuery->query( $args );
                 echo $queryResults;
        ?>
    <p> 
  </p>
<?php }
samjco commented 5 years ago

Actually I just view this: https://github.com/bonny/WordPress-Simple-History/blob/master/examples/examples.php

So if that can be tied into my above code, then we might have something sweet!

Also, need to wrap with if Simple History Class.

bonny commented 2 months ago

Giving this another thought after just 5 years :)

It would be pretty useful for websites with many users to see what edits other users has done to a page or post.

In the Gutenberg/Block Editor area this could probably be archived using SlotFills.