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

Sidebar Plugin for Block Editor Integration #790

Merged
merged 111 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 110 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
f0159c5
feat: add changes from proof of concept
laras126 Apr 20, 2021
15196c3
fix: add rest base
laras126 Apr 20, 2021
1437ba9
fix: path and rest_base for tax
laras126 Apr 20, 2021
5fa553b
fix: rest base
laras126 Apr 20, 2021
8c66439
WIP: added stylesheet, autofix
laras126 Apr 21, 2021
8e506c5
feat: styling
laras126 Apr 21, 2021
1bc5350
refact: move authors selection to component file
laras126 Apr 21, 2021
33b6d5e
feat: saving terms is working
laras126 Apr 21, 2021
4cd0d39
test: move fixtures
laras126 Apr 26, 2021
cc834b3
test: rename dir
laras126 Apr 26, 2021
d52536f
test: add unhappy path tests
laras126 Apr 26, 2021
82f7d43
test: rename
laras126 Apr 26, 2021
2b8a1cc
chore: add scripts
laras126 Apr 26, 2021
e2709cf
refact: rename fns, organizing
laras126 Apr 26, 2021
46a730a
chore: build
laras126 Apr 26, 2021
883e87c
feat: add endpoint scaffold
laras126 Apr 27, 2021
0efdf26
feat: hook up data for endpoint
laras126 Apr 27, 2021
1cb844a
refact: add regex for query in endpoint
laras126 Apr 27, 2021
86156ff
WIP: fetch in on filter change
laras126 Apr 27, 2021
f562ffd
feat: show search response in combobox
laras126 Apr 27, 2021
873ebbc
fix; rename
laras126 Apr 27, 2021
de19e28
feat: add route for single author
laras126 Apr 27, 2021
1fe06b9
test: test for adding endpoints
laras126 Apr 28, 2021
9480121
feat: add post request, use namespace
laras126 Apr 28, 2021
1be03c9
test: stub test cases
laras126 Apr 28, 2021
5409370
test: adding coverage and improvements
laras126 Apr 29, 2021
3bbf0c5
test: add tests for callback methods, updates to methods
laras126 Apr 29, 2021
ed7a09a
wip: refactoring for using endpoints
laras126 Apr 29, 2021
5a0ca8d
fix: response for no authors found
laras126 Apr 29, 2021
d80239e
feat: update from UI working
laras126 Apr 29, 2021
d20e56c
fix: add spinner, auto format js
laras126 Apr 29, 2021
0abb419
chore: remove unused tests, methods
laras126 Apr 30, 2021
b4b5ea6
chore: remove one more
laras126 Apr 30, 2021
dab7d6f
fix: buggy moveItem
laras126 Apr 30, 2021
c55a28b
refact: remove setstate from reordering method
laras126 Apr 30, 2021
56a29ad
feat: removeItem method
laras126 Apr 30, 2021
58db632
fix: rm old method
laras126 Apr 30, 2021
224134b
wip: refact to include display name in authorlist
laras126 Apr 30, 2021
240e3b7
refact: add method for add item
laras126 Apr 30, 2021
a273a47
feat: useeffect working, add response for update endpoint
laras126 Apr 30, 2021
a2998d0
feat: add placeholder for updated indication
laras126 Apr 30, 2021
e4ad74e
refact: basic store setup
laras126 May 3, 2021
b586798
feat: update store on clicks
laras126 May 4, 2021
0bfc098
wip; updateauthors
laras126 May 4, 2021
5b229b4
refact: organize fns
laras126 May 7, 2021
6cf2072
refact: consolidate api calls, format js
laras126 May 7, 2021
2685da8
chore: format js
laras126 May 7, 2021
50e5052
test: update tests and add mock data
laras126 May 7, 2021
f047012
chorr: comments and cleanup
laras126 May 10, 2021
79d238e
chore: endpoint and test clean up
laras126 May 10, 2021
edf2d35
test: separate method for update
laras126 May 10, 2021
8c855c0
feat: basic filter logic to enable
laras126 May 10, 2021
37d783d
feat: add filter, start on tests
laras126 May 10, 2021
0cd5189
fix: use get_param
laras126 May 10, 2021
39b0d97
fix: bug
laras126 May 11, 2021
5c42719
feat: brittle css to hide author select
laras126 May 11, 2021
b261ec2
fix: test and naming
laras126 May 14, 2021
0ce4739
fix: better length check with boolean
laras126 May 14, 2021
349fd25
fix: typo
laras126 May 14, 2021
5728acb
test: phpcf and test for metabox logic
laras126 May 14, 2021
9731c13
fix: add logic for coauthors user and post type in editor assets method
laras126 May 14, 2021
03d821f
chore: comment
laras126 May 14, 2021
6658042
fix: disable remove and move buttons for single author
laras126 May 14, 2021
b248690
chore: built assets
laras126 May 14, 2021
29b26c8
fix: remove old code
laras126 May 14, 2021
1304d0a
Merge branch 'master' into sidebar-integration
laras126 May 14, 2021
400d45a
fix: typo
laras126 May 14, 2021
31e2686
fix: remove logs / dumps
laras126 May 14, 2021
02004bc
fix: remove vscode file
laras126 May 14, 2021
f232f11
fix: typo
laras126 May 24, 2021
c463f25
test: use [] for array syntax, add structure for more tests
laras126 May 24, 2021
3a4238e
feat: stub of methods to remove author link
laras126 May 24, 2021
bb45017
refact: use helper method to return filter value
laras126 May 25, 2021
c827d0e
feat: authors link removal and test
laras126 May 25, 2021
ee1cf25
chore: remove brittle CSS
laras126 May 25, 2021
1d1e49f
test: coathors endpoint perms
laras126 May 28, 2021
59c6d4d
fix: use useeffect when authors updates
laras126 May 28, 2021
0bc6ac7
Resolve "Hide core author meta box with _links entry, and remove brit…
ethitter Jun 11, 2021
eafbe32
Update permissions callback
ethitter Jun 21, 2021
b3c4b8e
Protect read-only endpoints
ethitter Jun 21, 2021
50d595b
Update test
ethitter Jun 21, 2021
3c1acb1
Fix test for PHP 7.2
ethitter Jun 21, 2021
263ddc1
Class constants cannot set visibility in PHP 7.0 and earlier
ethitter Jun 21, 2021
e8dc33b
Fix PHP compatibility
ethitter Jun 21, 2021
ec3e31f
Cannot type in PHP < 7
ethitter Jun 21, 2021
ba2e58d
Null coalescing operator added in PHP 7.0
ethitter Jun 21, 2021
f359835
Fix tests
ethitter Jun 21, 2021
1a909b8
Not supported before PHP 7
ethitter Jun 21, 2021
8b0eb2e
Fix test
ethitter Jun 21, 2021
30aac63
🤦‍♂️
ethitter Jun 21, 2021
aebdbbe
Randomize value to allow for multiple changes
ethitter Jun 21, 2021
9008d5b
Don't remove metabox from non-Gutenberg post types.
ethitter Jul 15, 2021
0939ea5
Merge branch 'master' of https://github.com/Automattic/Co-Authors-Plu…
aaronjorbin Jul 30, 2021
751033a
Doc: readme
laras126 Jan 27, 2022
48eaf91
Merge branch 'master' into sidebar-integration
laras126 Jan 27, 2022
d5d6eb2
chore: add type hints
laras126 Jan 27, 2022
49bb6df
Chore: Auto fix / format
laras126 Jan 27, 2022
642c86c
Chore: Update wp-scripts package
laras126 Jan 27, 2022
2678e6c
Chore: Linter fixes, build
laras126 Jan 27, 2022
7b79e29
chore: version
laras126 Jan 27, 2022
499cbee
chore: version
laras126 Jan 27, 2022
ac67cf4
Try: remove type hints
laras126 Jan 31, 2022
9f56799
fix: account for new posts using block editor logic
laras126 Mar 18, 2022
6f08ebc
refact: use is_block_editor
laras126 Mar 18, 2022
a3a0aa8
refact: remove more logic since sidebar is enabled by default
laras126 Mar 18, 2022
e1a30a4
chore: add santize email
laras126 Mar 18, 2022
fde1116
chore: add default for pre 5.0
laras126 Mar 31, 2022
c5c5e54
chore: phpcs
laras126 Mar 31, 2022
d3e3110
doc: comment
laras126 Mar 31, 2022
b51852c
test: update failure msg
laras126 Mar 31, 2022
18c72fc
chore: remove unused constant
laras126 Apr 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
wpcom-helper.php
/composer.lock
/vendor
node_modules
1 change: 1 addition & 0 deletions build/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives'), 'version' => 'afa86f1dcc6c53850df1932fcd09e58c');
1 change: 1 addition & 0 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/style-index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 66 additions & 7 deletions co-authors-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
Author - user with the role of author
*/

define( 'COAUTHORS_PLUS_VERSION', '3.4.92' );
define( 'COAUTHORS_PLUS_VERSION', '3.5.0' );

require_once dirname( __FILE__ ) . '/template-tags.php';
require_once dirname( __FILE__ ) . '/deprecated.php';

require_once dirname( __FILE__ ) . '/php/class-coauthors-template-filters.php';
require_once dirname( __FILE__ ) . '/php/class-coauthors-endpoint.php';
require_once dirname( __FILE__ ) . '/php/integrations/amp.php';

if ( defined( 'WP_CLI' ) && WP_CLI ) {
Expand Down Expand Up @@ -66,6 +67,12 @@ class CoAuthors_Plus {

var $to_be_filtered_caps = array();

/**
* Block editor functionality in the sidebar is
* disabled by default.
*/
const SIDEBAR_PLUGIN_ENABLED = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is outdated! Good catch – I'll update it momentarily.


/**
* __construct()
*/
Expand Down Expand Up @@ -136,6 +143,9 @@ function __construct() {

// Filter to display author image if exists instead of avatar
add_filter( 'pre_get_avatar_data', array( $this, 'filter_pre_get_avatar_data_url' ), 10, 2 );

// Block editor assets for the sidebar plugin.
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_sidebar_plugin_assets' ) );
}

/**
Expand Down Expand Up @@ -164,6 +174,50 @@ public function action_init() {

}

/**
* Determine if block editor sidebar integration should be loaded.
*
* @param WP_Post|int|null $post Post ID or object, null to use global.
* @return bool
*/
public function is_block_editor( $post = null ) {
$screen = get_current_screen();

// Pre-5.0 compatibility
if ( method_exists( $screen, 'is_block_editor' ) ) {
return $screen->is_block_editor();
} else {
return false;
}
}

/**
* When filter is set to enable block editor integration, enqueue assets
* for posts and users where Co Authors is enabled
*/
public function enqueue_sidebar_plugin_assets() {
if ( $this->is_post_type_enabled() && $this->current_user_can_set_authors() ) {
$asset = require dirname( __FILE__ ) . '/build/index.asset.php';

wp_register_script(
'coauthors-sidebar-js',
plugins_url( 'build/index.js', __FILE__ ),
$asset['dependencies'],
$asset['version']
);

wp_register_style(
'coauthors-sidebar-css',
plugins_url( 'build/style-index.css', __FILE__ ),
'',
$asset['version']
);

wp_enqueue_script( 'coauthors-sidebar-js' );
wp_enqueue_style( 'coauthors-sidebar-css' );
}
}

/**
* Register the 'author' taxonomy and add post type support
*/
Expand All @@ -178,7 +232,9 @@ public function action_init_late() {
'public' => false,
'sort' => true,
'args' => array( 'orderby' => 'term_order' ),
'show_in_rest' => true,
'show_ui' => false,
'rest_base' => 'coauthors',
);

// If we use the nasty SQL query, we need our custom callback. Otherwise, we still need to flush cache.
Expand Down Expand Up @@ -276,7 +332,7 @@ public function get_coauthor_by( $key, $value, $force = false ) {
if ( ! $user && ( 'login' == $key || 'slug' == $key ) ) {
// Re-try lookup without prefixed value if no results found.
$value = preg_replace( '#^cap\-#', '', $value );
$user = get_user_by( $key, $value );
$user = get_user_by( $key, $value );
}
if ( ! $user ) {
return false;
Expand Down Expand Up @@ -333,9 +389,10 @@ public function remove_authors_box() {
* Adds a custom 'Authors' box
*/
public function add_coauthors_box() {

if ( $this->is_post_type_enabled() && $this->current_user_can_set_authors() ) {
add_meta_box( $this->coauthors_meta_box_name, apply_filters( 'coauthors_meta_box_title', __( 'Authors', 'co-authors-plus' ) ), array( $this, 'coauthors_meta_box' ), get_post_type(), apply_filters( 'coauthors_meta_box_context', 'side' ), apply_filters( 'coauthors_meta_box_priority', 'high' ) );
if ( false === $this->is_block_editor() ) {
add_meta_box( $this->coauthors_meta_box_name, apply_filters( 'coauthors_meta_box_title', __( 'Authors', 'co-authors-plus' ) ), array( $this, 'coauthors_meta_box' ), get_post_type(), apply_filters( 'coauthors_meta_box_context', 'side' ), apply_filters( 'coauthors_meta_box_priority', 'high' ) );
}
}
}

Expand Down Expand Up @@ -548,7 +605,6 @@ function _update_users_posts_count( $tt_ids, $taxonomy ) {
$tt_ids = implode( ', ', array_map( 'intval', $tt_ids ) );
$term_ids = $wpdb->get_results( "SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)" ); // phpcs:ignore


foreach ( (array) $term_ids as $term_id_result ) {
$term = get_term_by( 'id', $term_id_result->term_id, $this->coauthor_taxonomy );
$this->update_author_term_post_count( $term );
Expand Down Expand Up @@ -919,7 +975,8 @@ public function add_coauthors( $post_id, $coauthors, $append = false, $query_typ
$coauthors = array_unique( array_merge( $existing_coauthors, $coauthors ) );
$coauthor_objects = array();
foreach ( $coauthors as &$author_name ) {
$field = apply_filters( 'coauthors_post_get_coauthor_by_field', $query_type, $author_name );
$field = apply_filters( 'coauthors_post_get_coauthor_by_field', $query_type, $author_name );

$author = $this->get_coauthor_by( $field, $author_name );
$coauthor_objects[] = $author;
$term = $this->update_author_term( $author );
Expand Down Expand Up @@ -1006,6 +1063,7 @@ function delete_user_action( $delete_id ) {
*
* @since 2.6
* @props kingkool68, http://wordpress.org/support/topic/plugin-co-authors-plus-making-authors-sortable
* @props kingkool68, http://wordpress.org/support/topic/plugin-co-authors-plus-making-authors-sortable
*/
function filter_wp_get_object_terms( $terms, $object_ids, $taxonomies, $args ) {
if ( ! isset( $_REQUEST['bulk_edit'] ) || $this->coauthor_taxonomy !== $taxonomies ) {
Expand Down Expand Up @@ -1796,7 +1854,8 @@ public function filter_pre_get_avatar_data_url( $args, $id ) {
}

global $coauthors_plus;
$coauthors_plus = new CoAuthors_Plus();
$coauthors_plus = new CoAuthors_Plus();
$coauthors_endpoint = new CoAuthors\API\Endpoints( $coauthors_plus );

if ( ! function_exists( 'wp_notify_postauthor' ) ) :
/**
Expand Down
Loading