Skip to content

Commit

Permalink
Merge branch 'release/0.20.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanDS committed May 27, 2020
2 parents 7f5b5ba + 6d6cd96 commit be77402
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 17 deletions.
26 changes: 24 additions & 2 deletions ssl-alp/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: seanleavey
Tags: logbook, coauthor, revisions, references, latex, tex, mathematics, wiki
Requires at least: 5.1.0
Tested up to: 5.3.2
Tested up to: 5.4.1
Requires PHP: 7.0.0
Stable tag: 0.19.0
Stable tag: 0.20.0
License: GNU General Public License v3 or later
License URI: LICENCE

Expand Down Expand Up @@ -79,6 +79,28 @@ on the ALP website.

== Changelog ==

= 0.20.0 =
- Fixed bug with terms on login. When logging in, users of blogs would have
their coauthor term added to the primary blog (usually site ID 1) because of
the hook 'check_coauthor_term_on_login' which creates the coauthor term if it
doesn't exist. This meant that users of secondary blogs who were not users of
the primary blog would still be available for selection as authors on the new
post screen of the primary blog. They would not however save correctly
because the users were not members of that blog; they would be silently
discard. This change fixes the creation of the coauthor terms to only create
terms on the blogs the user is a member of.

Existing sites running ALP may still have these terms, however. The rebuild
coauthor tool will later be updated to delete terms of users who are not
members of the blog.
- Fixed potential bug by not now checking post authors are consistent on newly
created auto-drafts.
- Added ability to hide revisions on post page and header. This requires the
latest release of the Labbook theme (1.2.0).

= 0.19.1 =
- Fixed an issue with creation of coauthor terms during a WordPress import.

= 0.19.0 =
- Removed the manual WP_Query SQL modifications for including coauthors in
search results, and replaced with a parameter based search. Due to this
Expand Down
4 changes: 2 additions & 2 deletions ssl-alp/alp.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Academic Labbook
* Plugin URI: https://alp.attackllama.com/
* Description: Turn WordPress into a collaborative academic labbook.
* Version: 0.19.0
* Version: 0.20.0
* Author: Sean Leavey
* Author URI: https://attackllama.com/
* License: GPL3
Expand All @@ -21,7 +21,7 @@
* Current plugin version.
*/

define( 'SSL_ALP_VERSION', '0.19.0' );
define( 'SSL_ALP_VERSION', '0.20.0' );

/**
* Plugin name and path
Expand Down
6 changes: 5 additions & 1 deletion ssl-alp/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ div.ssl-alp-tools-card {
background: #fff;
}

/* fix Gutenberg bug: https://github.com/WordPress/gutenberg/issues/10834 */
/* Fix Gutenberg help text bug: https://github.com/WordPress/gutenberg/issues/10834 */
.components-base-control .components-base-control__help {
margin-top: 0 !important;
}
.components-panel__row.ssl-alp-hide-revisions-panel,
.components-panel__row.ssl-alp-hide-crossreferences-panel {
margin-top: 10px !important;
}

.ssl-alp-text-added {
color: #006505;
Expand Down
27 changes: 20 additions & 7 deletions ssl-alp/includes/class-ssl-alp-coauthors.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public function register_hooks() {
// disable_disallow_insert_term_filter functions must also be updated.
$loader->add_filter( 'pre_insert_term', $this, 'disallow_insert_term', 10, 2 );

// Allow term creation during an import with the WordPress importer plugin.
$loader->add_filter( 'import_start', $this, 'disable_disallow_insert_term_filter' );
$loader->add_filter( 'import_end', $this, 'enable_disallow_insert_term_filter' );

// Delete any invalid coauthors when post terms are set.
$loader->add_action( 'added_term_relationship', $this, 'reject_invalid_coauthor_terms', 10, 3 );

Expand Down Expand Up @@ -435,7 +439,17 @@ public function delete_coauthor_term( $user ) {
* @param WP_User $user User object.
*/
public function check_coauthor_term_on_login( $user_login, $user ) {
$this->add_coauthor_term( $user );
if ( ! is_multisite() ) {
return;
}

// The hook that calls this function runs in the context of the network, whereas we want
// to ensure the terms are set only on the blogs the user is a member of.
foreach ( array_keys( get_blogs_of_user( $user->ID ) ) as $blog_id ) {
switch_to_blog( $blog_id );
$this->add_coauthor_term( $user );
restore_current_blog();
}
}

/**
Expand Down Expand Up @@ -991,10 +1005,8 @@ public function add_user_to_draft( $post_id, $post ) {
return;
}

// Get updated coauthors.
$coauthors = array( wp_get_current_user() );

$this->set_coauthors( $post, $coauthors );
// Set the draft's coauthors to the current user.
$this->set_coauthors( $post, array( wp_get_current_user() ) );
}

/**
Expand Down Expand Up @@ -1088,11 +1100,12 @@ public function check_post_author( $post_id, $term_ids, $tt_ids, $taxonomy ) {
// Get post.
$post = get_post( $post_id );

if ( wp_is_post_autosave( $post ) ) {
if ( ! $this->post_supports_coauthors( $post ) ) {
return;
}

if ( ! $this->post_supports_coauthors( $post ) ) {
if ( wp_is_post_autosave( $post ) || $this->is_post_autodraft( $post ) ) {
// Wait until the post is saved by the user.
return;
}

Expand Down
79 changes: 75 additions & 4 deletions ssl-alp/includes/class-ssl-alp-revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,22 @@ public function register_scripts() {
// Edit summary block editor plugin.
wp_register_script(
'ssl-alp-edit-summary-block-editor-js',
esc_url( SSL_ALP_BASE_URL . 'js/edit-summary/index.js' ),
esc_url( SSL_ALP_BASE_URL . 'js/revisions/edit-summary.js' ),
array(
'wp-edit-post',
'wp-plugins',
'wp-i18n',
'wp-element',
'wp-compose',
),
$this->get_version(),
true
);

// Hide revisions editor plugin.
wp_register_script(
'ssl-alp-hide-revisions-block-editor-js',
esc_url( SSL_ALP_BASE_URL . 'js/revisions/display.js' ),
array(
'wp-edit-post',
'wp-plugins',
Expand Down Expand Up @@ -125,6 +140,9 @@ public function register_hooks() {
// Register post meta for edit summaries.
$loader->add_action( 'init', $this, 'register_edit_summary_post_meta' );

// Register post meta flag to allow revisions to be hidden from the post page.
$loader->add_action( 'init', $this, 'register_hide_revisions_post_meta' );

// Register REST API endpoint for setting edit summaries with the block editor.
$loader->add_action( 'rest_api_init', $this, 'rest_register_edit_summary_route' );

Expand Down Expand Up @@ -201,8 +219,9 @@ public function enqueue_block_editor_scripts() {
$post = get_post();

if ( $this->edit_summary_allowed( $post ) ) {
// Enqueue block editor plugin script.
// Enqueue block editor plugin scripts.
wp_enqueue_script( 'ssl-alp-edit-summary-block-editor-js' );
wp_enqueue_script( 'ssl-alp-hide-revisions-block-editor-js' );
}
}

Expand Down Expand Up @@ -292,7 +311,7 @@ public function get_revision_edit_summary( $revision ) {
public function register_edit_summary_post_meta() {
// Edit summary.
register_post_meta(
'',
'', // All post types.
'ssl_alp_edit_summary',
array(
'type' => 'string',
Expand All @@ -305,7 +324,7 @@ public function register_edit_summary_post_meta() {

// Revert target post ID.
register_post_meta(
'',
'', // All post types.
'ssl_alp_edit_summary_revert_id',
array(
'type' => 'integer',
Expand All @@ -317,6 +336,31 @@ public function register_edit_summary_post_meta() {
);
}

/**
* Register the hide revisions post meta.
*
* This flag is used to avoid displaying post revisions on post pages. This
* can be used for example on posts for which the post history is of no
* interest or is intended to be hidden from the viewer, such as a front
* page.
*/
public function register_hide_revisions_post_meta() {
if ( ! get_option( 'ssl_alp_enable_edit_summaries' ) ) {
// Edit summaries disabled for posts.
return;
}

register_post_meta(
'', // All post types.
'ssl_alp_hide_revisions',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
)
);
}

/**
* Sanitize the specified edit summary.
*
Expand Down Expand Up @@ -1523,6 +1567,33 @@ private function unread_flag_unknown_error() {
);
}

/**
* Check if the specified post has revisions hidden.
*
* A post allows revisions shown on the theme if it is supported and the
* post has not had revisions hidden by setting the appropriate meta flag.
*
* @param WP_Post $post Post ID or post object. Defaults to global $post.
* @return boolean|null Whether revisions are enabled, or null if the
* edit summary system is disabled or the post type
* is not found.
*/
public function revisions_hidden( $post ) {
if ( ! get_option( 'ssl_alp_enable_edit_summaries' ) ) {
// Edit summaries are disabled.
return;
}

$post = get_post( $post );

if ( is_null( $post ) ) {
// Post is invalid.
return;
}

return (bool) get_post_meta( $post->ID, 'ssl_alp_hide_revisions', true );
}

/**
* Set post read status for users, optionally ignoring one.
*
Expand Down
1 change: 1 addition & 0 deletions ssl-alp/includes/class-ssl-alp-uninstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private static function delete_post_metas() {
self::delete_post_meta( 'ssl_alp_edit_summary' );
self::delete_post_meta( 'ssl_alp_edit_summary_revert_id' );
self::delete_post_meta( 'ssl_alp_hide_crossreferences_to' );
self::delete_post_meta( 'ssl_alp_hide_revisions' );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ssl-alp/js/references/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Cross-reference editor tools.
*
* This adds a checkbox to the sidebar when composing or editing a post which
* avoids cross-references from appearing under the post.
* when toggled avoids cross-references from appearing under the post.
*
* @package ssl-alp
*/
Expand Down
76 changes: 76 additions & 0 deletions ssl-alp/js/revisions/display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Revision editor tools.
*
* This adds a checkbox to the sidebar when composing or editing a post which
* when toggled avoids revision count and list from appearing on the post page.
*
* @package ssl-alp
*/

( function( wp ) {
const el = wp.element.createElement;
const __ = wp.i18n.__;
const Component = wp.element.Component;
const PluginPostStatusInfo = wp.editPost.PluginPostStatusInfo;
const CheckboxControl = wp.components.CheckboxControl;
const registerPlugin = wp.plugins.registerPlugin;
const compose = wp.compose.compose;
const withSelect = wp.data.withSelect;
const withDispatch = wp.data.withDispatch;

class RevisionDisplayPlugin extends Component {
render() {
const { hideRevisions, setHideRevisions } = this.props;

return el(
PluginPostStatusInfo,
{
className: 'ssl-alp-hide-revisions-panel'
},
el(
CheckboxControl,
{
name: 'ssl_alp_hide_revisions',
label: __( 'Hide revisions', 'ssl-alp' ),
help: __( 'Do not display revisions on the post page', 'ssl-alp' ),
checked: hideRevisions,
onChange: ( value ) => {
setHideRevisions( value );
}
}
)
);
}
}

const RevisionDisplayPluginHOC = compose( [
withSelect( ( select ) => {
const { getEditedPostAttribute } = select( 'core/editor' );

const editedPostAttributes = getEditedPostAttribute( 'meta' );
const hideRevisions = editedPostAttributes[ 'ssl_alp_hide_revisions' ];

return { hideRevisions };
} ),
withDispatch( ( dispatch ) => {
const { editPost } = dispatch( 'core/editor' );

return {
setHideRevisions: function( value ) {
editPost( {
meta: { ssl_alp_hide_revisions: value },
} );
}
}
} )
])( RevisionDisplayPlugin );

/**
* Register sidebar plugin with block editor.
*/
registerPlugin( 'ssl-alp-hide-revisions-plugin', {
render: RevisionDisplayPluginHOC
} );
} )(
window.wp
);
File renamed without changes.

0 comments on commit be77402

Please sign in to comment.