Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WPML Support #12

Merged
merged 13 commits into from
May 22, 2024
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
php_version: [7.4]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
1 change: 1 addition & 0 deletions change-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ 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}
* Call here so that Doc Revs is loaded
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"require-dev": {
"phpcsstandards/phpcsutils": "^1.0",
"phpcsstandards/phpcsextra": "^1.1.0",
"wp-coding-standards/wpcs": "~3.0",
"phpcsstandards/phpcsextra": "^1.2.0",
"wp-coding-standards/wpcs": "~3.1",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"yoast/phpunit-polyfills": "*",
"phpcompatibility/php-compatibility": "*",
Expand Down
11 changes: 7 additions & 4 deletions phpcs.ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards">
<extensions>*/php</extensions>
<exclude-pattern>*.js</exclude-pattern>
<exclude-pattern>*.css</exclude-pattern>
<exclude-pattern>deprecated/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/vendor/autoload.php</exclude-pattern>
<file>*.php</file>
<rule ref="WordPress">
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
</rule>
Expand All @@ -21,6 +26,4 @@
</rule>
<config name="testVersion" value="7.4-"/>
<rule ref="PHPCompatibilityWP"/>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/vendor/autoload.php</exclude-pattern>
</ruleset>
</ruleset>
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sample code to help customize WP Document Revisions. Once adapted to your organizations needs the files in the cookbook should be dropped into your /wp-content/plugins/ directory (or a sub-directory thereof) and activated like any plugin would.
Sample code to help customize WP Document Revisions. Once adapted to your needs the files in the cookbook should be dropped into your /wp-content/plugins/ directory (or a sub-directory thereof) and activated like any plugin would be.

1. **Third Party Encryption** - example of how to integrate at rest encryption using third-party tools
1. **Audit Trail** - creates check in / check out audit trail
Expand All @@ -10,7 +10,13 @@ Sample code to help customize WP Document Revisions. Once adapted to your organi
1. **Rename Documents** - changes all references to "Documents" in the interface to any label of your choosing
1. **State Change Notification** - how to use document api to allow the author to receive notification whenever his or her document changes workflow states
1. **Taxonomy Permissions** - allows setting user-level permissions and access control based on document being in a given workflow state or other custom taxonomy such as department

Integration plugins that will integrate WP Document Revisions with other plugins.

1. **Role Permissions** - Integrates the Members plugin Content Permissions functionality into WP Document Revisions to provide role based document access.
1. **WPML Support** - Integrates WPML with WP Document Revisions to provide multi-language documents.

To use these integration plugins, the specific directory should be zipped (i.e. a single compressed file) and then loaded as a plugin and activated.

Code Cookbook Alumni (Deprecated functions now included with the plugin by default):

Expand Down
2 changes: 1 addition & 1 deletion scripts/phpcs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e

export PATH="$TRAVIS_BUILD_DIR/vendor/squizlabs/php_codesniffer/bin:$PATH"

phpcs --standard=phpcs.ruleset.xml -p -s --colors *.php */**.php -v
phpcs --standard=phpcs.ruleset.xml -p -s --colors . -v
11 changes: 6 additions & 5 deletions wpdr-role-permissions/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Contributors: nwjames
Tags: documents, document management, access, roles
Requires at least: 4.9
Requires PHP: 7.4
Tested up to: 6.4
Requires Plugins: wp-document-revisions, members
Tested up to: 6.5
Stable tag: 1.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Expand All @@ -12,7 +13,7 @@ Add-on to WP Document Revisions and Members plugins. Restrict access to roles de

== Description ==

This plugin is an integration between WP Document Revisions and Members plugins.
This plugin is an integration between WP Document Revisions and Members plugins.

By default all published documents are available to everyone.

Expand All @@ -22,15 +23,15 @@ When editing a document, this will provide an additional metabox to allow you to

If roles have been entered here, then a user will need to have at least one of those roles assigned to them to be able to access the document.

Note that
Note that
1. Administrators and users with `restrict_content` are allowed to see all content.
2. Standard WP Document Revisions permission controls are always applied.
This means that it is always necessary to have the Document Revisions permission necessary to do an operation. The Members permission control may then hide certain documents from these operations.
This means that it is always necessary to have the Document Revisions permission necessary to do an operation. The Members permission control may then hide certain documents from these operations.

== Installation ==

1. Download the Cookbook code from GitHub
2. Copy the `wpdr-role-permissions` directory to your plugins directory
2. Copy the `wpdr-role-permissions` directory to your plugins directory. This can be done by creating a zip file of the directory and loading that as a plugin.
3. Activate the plugin through the 'Plugins' menu in WordPress

== Role Permissions for WP Document Revisions Filters ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,14 @@ public function maybe_register_taxonomy() {
* @param string $role the role being reviewed (all will be reviewed in turn).
* @return array $caps the modified set of capabilities for the role.
*/
public function default_caps_filter( $caps, $role ) {
public function default_caps_filter( $caps, $role ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
// get terms in the selected taxonomy.
$terms = get_terms( $this->taxonomy, array( 'hide_empty' => false ) );
$terms = get_terms(
array(
'taxonomy' => $this->taxonomy,
'hide_empty' => false,
)
);

// build out term specific caps.
foreach ( $caps as $cap => $grant ) {
Expand Down Expand Up @@ -367,7 +372,12 @@ public function user_tax_query() {
$allcaps = $user->allcaps;

// get terms in the selected taxonomy.
$terms = get_terms( $this->taxonomy, array( 'hide_empty' => false ) );
$terms = get_terms(
array(
'taxonomy' => $this->taxonomy,
'hide_empty' => false,
)
);

// See any caps exist for user in term.
$user_terms = array();
Expand All @@ -394,32 +404,30 @@ public function user_tax_query() {
} else {
$user_tax_query = 'No access';
}
} elseif ( apply_filters( 'document_access_with_no_term', false ) ) {
// Can access documents with no taxonomy term.
$user_tax_query = array(
array(
'taxonomy' => $this->taxonomy,
'field' => 'term_taxonomy_id',
'terms' => $user_terms,
'operator' => 'IN',
),
array(
'taxonomy' => $this->taxonomy,
'operator' => 'NOT EXISTS',
),
'relation' => 'OR',
);
} else {
if ( apply_filters( 'document_access_with_no_term', false ) ) {
// Can access documents with no taxonomy term.
$user_tax_query = array(
array(
'taxonomy' => $this->taxonomy,
'field' => 'term_taxonomy_id',
'terms' => $user_terms,
'operator' => 'IN',
),
array(
'taxonomy' => $this->taxonomy,
'operator' => 'NOT EXISTS',
),
'relation' => 'OR',
);
} else {
$user_tax_query = array(
array(
'taxonomy' => $this->taxonomy,
'field' => 'term_taxonomy_id',
'terms' => $user_terms,
'operator' => 'IN',
),
);
}
$user_tax_query = array(
array(
'taxonomy' => $this->taxonomy,
'field' => 'term_taxonomy_id',
'terms' => $user_terms,
'operator' => 'IN',
),
);
}

wp_cache_set( 'wpdr_tax_query_' . $user->ID, $user_tax_query, '', ( WP_DEBUG ? 10 : 120 ) );
Expand Down Expand Up @@ -530,12 +538,10 @@ public function posts_results( $results, $query ) {

if ( is_array( $results ) ) {
$query->found_posts = count( $results );
} elseif ( null === $results ) {
$query->found_posts = 0;
} else {
if ( null === $results ) {
$query->found_posts = 0;
} else {
$query->found_posts = 1;
}
$query->found_posts = 1;
}
}
return $results;
Expand Down Expand Up @@ -629,9 +635,7 @@ public function admin_error_check() {
// translators: %s is the taxonomy.
echo esc_html( sprintf( __( 'WPDR Taxonomy Permissions requires published documents to have only one term entered for taxonomy %s.', 'wp-document-revisions' ), $this->taxonomy ) );
break;
default:
null;
};
}
?>
</p>
<p><?php esc_html_e( 'Your update has been cancelled and data is in its original state.', 'wp-document-revisions' ); ?></p>
Expand Down
Loading