Skip to content

Commit

Permalink
Merge pull request #11 from NeilWJames/master
Browse files Browse the repository at this point in the history
Implement Members Role based Permissions into WP Document Revisions and update to WPCS 3.0
  • Loading branch information
benbalter authored Dec 6, 2023
2 parents f292e67 + 4cbff27 commit 6a7233a
Show file tree
Hide file tree
Showing 25 changed files with 591 additions and 189 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Based on https://github.com/wp-document-revisions/wp-document-revisions
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

phpcs:
runs-on: ubuntu-latest
env:
TRAVIS_BUILD_DIR: ${{ github.workspace }}
strategy:
matrix:
php_version: [7.4]
steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: mysqli

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: phpcs
run: scripts/phpcs
2 changes: 1 addition & 1 deletion 3d-party-encryption.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
Plugin Name: WP Document Revisions - File Encryption Code Sample
Plugin URI: https://github.com/benbalter/WP-Document-Revisions-Code-Cookbook
Plugin URI: https://github.com/wp-document-revisions/WP-Document-Revisions-Code-Cookbook
Description: Code sample to demonstrate third-party resting encryption on file upload / download
Version: 1.0
Author: Benjamin J. Balter
Expand Down
3 changes: 1 addition & 2 deletions audit-trail.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
Plugin Name: WP Document Revisions - Audit Trail Code Sample
Plugin URI: https://github.com/benbalter/WP-Document-Revisions-Code-Cookbook
Plugin URI: https://github.com/wp-document-revisions/WP-Document-Revisions-Code-Cookbook
Description: Code sample to demonstrate check-in/check-out audit trail functionality
Version: 1.0
Author: Benjamin J. Balter
Expand Down Expand Up @@ -48,7 +48,6 @@ function wpdr_get_downloads( $post_ID ) {
wpdr_sort( $downloads, 'timestamp' );

return $downloads;

}

/**
Expand Down
2 changes: 0 additions & 2 deletions bulk-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
function wpdr_get_files( $directory, $extension ) {

return glob( $directory . '*.' . $extension );

}

/**
Expand Down Expand Up @@ -180,4 +179,3 @@ function upload_rewrite_url( $file ) {
// debug info.
echo '<p>' . esc_html( "$file added as $doc_name" ) . '</p>';
}

34 changes: 15 additions & 19 deletions change-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function __construct() {

// appending.
add_action( 'save_post_document', array( &$this, 'append_changes_to_revision_summary' ), 20, 1 );

}
/**
* Makes all WPDR functions accessible as $this->wpdr->{function}
Expand Down Expand Up @@ -86,36 +85,34 @@ public function track_title_changes( $post_ID ) {
do_action( 'document_title_changed', $post_ID, $old, $new );

// translators: %1$s is the old title, %2$s is the new title.
$this->document_change_list[] = sprintf( __( 'Title changed from "%1$s" to "%2$s"', 'wp_document_revisions' ), $old->post_title, $new->post_title );

$this->document_change_list[] = sprintf( __( 'Title changed from "%1$s" to "%2$s"', 'wp-document-revisions' ), $old->post_title, $new->post_title );
}

/**
* Tracks when a post status changes
*
* @param string $new the new status.
* @param string $old the old status.
* @param object $post the post object.
* @param string $new_s the new status.
* @param string $old_s the old status.
* @param object $post the post object.
*/
public function track_status_changes( $new, $old, $post ) {
public function track_status_changes( $new_s, $old_s, $post ) {

if ( $this->dont_track( $post->ID ) ) {
return false;
}

if ( 'new' === $old || 'auto_draft' === $old ) {
if ( 'new' === $old_s || 'auto_draft' === $old_s ) {
return false;
}

if ( $new === $old ) {
if ( $new_s === $old_s ) {
return false;
}

do_action( 'document_visibility_changed', $post->ID, $old, $new );
do_action( 'document_visibility_changed', $post->ID, $old_s, $new_s );

// translators: %1$s is the old status, %2$s is the new status.
$this->document_change_list[] = sprintf( __( 'Visibility changed from "%1$s" to "%2$s"', 'wp_document_revisions' ), $old, $new );

$this->document_change_list[] = sprintf( __( 'Visibility changed from "%1$s" to "%2$s"', 'wp-document-revisions' ), $old_s, $new_s );
}

/**
Expand Down Expand Up @@ -166,15 +163,15 @@ public function build_taxonomy_change_list( $object_id, $terms, $tt_ids, $taxono
if ( ! count( $terms_fmt ) ) {
$terms_formatted = $last;
} else {
$terms_formatted = implode( ', ', $terms_fmt ) . __( ' and ', 'wp_document_revisions' ) . $last;
$terms_formatted = implode( ', ', $terms_fmt ) . __( ' and ', 'wp-document-revisions' ) . $last;
}

// translators: %1$s is the list of terms added.
$add = sprintf( __( ' %1$s added', 'wp_document_revisions' ), $terms_formatted );
$add = sprintf( __( ' %1$s added', 'wp-document-revisions' ), $terms_formatted );

if ( ! empty( $removed_tt_ids ) ) {
// translators: separator between added and removed..
$sep = __( ',', 'wp_document_revisions' );
$sep = __( ',', 'wp-document-revisions' );
}
}

Expand All @@ -192,16 +189,16 @@ public function build_taxonomy_change_list( $object_id, $terms, $tt_ids, $taxono
if ( ! count( $terms_fmt ) ) {
$terms_formatted = $last;
} else {
$terms_formatted = implode( ', ', $terms_fmt ) . __( ' and ', 'wp_document_revisions' ) . $last;
$terms_formatted = implode( ', ', $terms_fmt ) . __( ' and ', 'wp-document-revisions' ) . $last;
}

// translators: %1$s is the list of terms removed.
$rem = sprintf( __( ' %1$s removed', 'wp_document_revisions' ), $terms_formatted );
$rem = sprintf( __( ' %1$s removed', 'wp-document-revisions' ), $terms_formatted );
}

if ( '' !== $add || '' !== $rem ) {
// translators: %1$s is the taxonomy's name, %2$s is the list of terms added, %3$s is the separator, %3$s is the list of terms removed.
$message = sprintf( __( '%1$s:%2$s%3$s%4$s', 'wp_document_revisions' ), $taxonomy_formatted, $add, $sep, $rem );
$message = sprintf( __( '%1$s:%2$s%3$s%4$s', 'wp-document-revisions' ), $taxonomy_formatted, $add, $sep, $rem );

$this->document_change_list[] = $message;
}
Expand Down Expand Up @@ -263,7 +260,6 @@ public function append_changes_to_revision_summary( $post_ID ) {

// reset in case another post is also being saved for some reason.
$this->document_change_list = array();

}

/**
Expand Down
30 changes: 30 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "wp-document-revisions/wp-document-revisions-code-cookbook",
"description": "Sample Code for Common WP Document Revision Implementations.",
"license": "GPLv3",
"authors": [
{
"name": "Ben Balter",
"email": "[email protected]"
}
],
"require": {
},
"require-dev": {
"phpcsstandards/phpcsutils": "^1.0",
"phpcsstandards/phpcsextra": "^1.1.0",
"wp-coding-standards/wpcs": "~3.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"yoast/phpunit-polyfills": "*",
"phpcompatibility/php-compatibility": "*",
"phpcompatibility/phpcompatibility-paragonie": "*",
"phpcompatibility/phpcompatibility-wp": "*"
},
"config": {
"bin-dir": "bin",
"vendor-dir": "vendor",
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
66 changes: 33 additions & 33 deletions deprecated/recently-revised-widget.php
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
<?php
/*
Plugin Name: WP Document Revisions - Recently Revised Widget
Plugin URI: https://github.com/benbalter/WP-Document-Revisions-Code-Cookbook
Description: Code sample to demonstrate a widget of recently revised files
Version: 1.0
Author: Benjamin J. Balter
Author URI: http://ben.balter.com
License: GPL2
*/


/**
* Plugin Name: WP Document Revisions - Recently Revised Widget
* Plugin URI: https://github.com/wp-document-revisions/WP-Document-Revisions-Code-Cookbook
* Description: Code sample to demonstrate a widget of recently revised files
* Version: 1.0
* Author: Benjamin J. Balter
* Author URI: http://ben.balter.com
* License: GPL2
*
* @package WP-Document-Revisions-Code-Cookbook
*/

/**
* NOTE: An updated version of this widget is now included with WP Document Revisions by default
* As a result, this file is no longer maintained
*
*/

// phpcs:disable
class wpdr_recently_revised_widget extends WP_Widget {

function __construct() {
public function __construct() {
parent::WP_Widget( 'wpdr_recently_revised_documents', $name = 'Recently Revised Documents' );
add_action( 'widgets_init', create_function( '', 'return register_widget("wpdr_recently_revised_documents");' ) );
}
function widget( $args, $instance ) {

public function widget( $args, $instance ) {

$wpdr = Document_Revisions::$instance;

extract( $args );
echo $before_widget;

echo $before_widget;

echo $before_title . 'Recently Revised Documents' . $after_title;

$query = array(
'post_type' => 'document',
'orderby' => 'modified',
'order' => 'DESC',
'post_type' => 'document',
'orderby' => 'modified',
'order' => 'DESC',
'numberposts' => '5',
'post_status' => array( 'private', 'publish', 'draft' ),
);

$documents = get_posts( $query );

echo "<ul>\n";
foreach ( $documents as $document ) {

//use our function to get post data to correct WP's author bug
$revision = $wpdr->get_latest_revision( $document->ID );

?>
?>
<li><a href="<?php echo get_edit_post_link( $revision->ID ); ?>"><?php echo $revision->post_title; ?></a><br />
<?php echo human_time_diff( strtotime( $revision->post_modified_gmt ) ); ?> ago by <?php echo get_the_author_meta( 'display_name', $revision->post_author ); ?>
</li>
<?php }

<?php
}

echo "</ul>\n";

echo $after_widget;

}

}

new wpdr_recently_revised_documents;
new wpdr_recently_revised_documents();
28 changes: 28 additions & 0 deletions deprecated/remove-date-from-permalink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
Plugin Name: WP Document Revisions - Remove Dates from Permalinks
Plugin URI: https://github.com/wp-document-revisions/WP-Document-Revisions-Code-Cookbook
Description: Removes the year and month from document permalinks
Version: 1.0
Author: Benjamin J. Balter
Author URI: http://ben.balter.com
License: GPL2
*
* @package WP Document Revisions Code Cookbook
*/

/**
* Strip date from permalink
*
* @param string $link Permalink URL.
* @param WP_Post $post The ID of the document being saved.
*/
function wpdr_remove_dates_from_permalink_filter( $link, $post ) {

$timestamp = '/' . substr( $post->post_date, 0, 7 ) . '/';
return str_replace( $timestamp, '/', $link );
}

add_filter( 'document_permalink', 'wpdr_remove_dates_from_permalink_filter', 10, 2 );

// Existing rules match documents with or without year/month parts.
2 changes: 1 addition & 1 deletion deprecated/remove-workflow-states.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
Plugin Name: WP Document Revisions - Remove Workflow State
Plugin URI: https://github.com/benbalter/WP-Document-Revisions-Code-Cookbook
Plugin URI: https://github.com/wp-document-revisions/WP-Document-Revisions-Code-Cookbook
Description: Removes Workflow State Taxonomy from Documents
Version: 1.0
Author: Benjamin J. Balter
Expand Down
Loading

0 comments on commit 6a7233a

Please sign in to comment.