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

Check module is enabled before compat init #537

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion common/php/class-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ class EF_Module {

function __construct() {}

/**
* Returns whether the current module is enabled.
*
* @since 0.9.1
*
* @return <code>true</code> if the module is enabled, <code>false</code> otherwise
*/
public function is_enabled() {
return $this->module->options->enabled === 'on';
}

/**
* Returns whether the module with the given name is enabled.
*
Expand All @@ -38,7 +49,7 @@ function __construct() {}
function module_enabled( $slug ) {
global $edit_flow;

return isset( $edit_flow->$slug ) && $edit_flow->$slug->module->options->enabled == 'on';
return isset( $edit_flow->$slug ) && $edit_flow->$slug->is_enabled();
}

/**
Expand Down
6 changes: 5 additions & 1 deletion common/php/trait-block-editor-compatible.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function __construct( $module_instance, $hooks = [] ) {
* @return void
*/
function action_init_for_admin() {
if ( ! $this->ef_module->is_enabled() ) {
return;
}

$this->check_active_plugins();

if ( $this->should_apply_compat() ) {
Expand Down Expand Up @@ -127,4 +131,4 @@ protected function should_apply_compat() {

return count( array_filter( $conditions, function( $c ) { return (bool) $c; } ) ) > 0;
}
}
}
8 changes: 4 additions & 4 deletions modules/custom-status/compat/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ class EF_Custom_Status_Block_Editor_Compat {
* @return void
*/
function action_admin_enqueue_scripts() {
if ( $this->ef_module->disable_custom_statuses_for_post_type() ) {
return;
}

/**
* WP_Screen::is_block_editor only available in 5.0. If it's available and is false it's safe to say we should only pass through to the module.
*/
if ( Block_Editor_Compatible::is_at_least_50() && ! get_current_screen()->is_block_editor() ) {
return $this->ef_module->action_admin_enqueue_scripts();
}

if ( $this->ef_module->disable_custom_statuses_for_post_type() ) {
return;
}

wp_enqueue_style( 'edit-flow-block-custom-status', EDIT_FLOW_URL . 'blocks/dist/custom-status.editor.build.css', false, EDIT_FLOW_VERSION );
wp_enqueue_script( 'edit-flow-block-custom-status', EDIT_FLOW_URL . 'blocks/dist/custom-status.build.js', array( 'wp-blocks', 'wp-element', 'wp-edit-post', 'wp-plugins', 'wp-components' ), EDIT_FLOW_VERSION );

Expand Down
9 changes: 6 additions & 3 deletions modules/custom-status/custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,13 @@ function disable_custom_statuses_for_post_type( $post_type = null ) {
if ( ! in_array( $pagenow, array( 'edit.php', 'post.php', 'post-new.php' ) ) )
return false;

if ( is_null( $post_type ) )
if ( is_null( $post_type ) ) {
$post_type = $this->get_current_post_type();
}

if ( $post_type && ! in_array( $post_type, $this->get_post_types_for_module( $this->module ) ) )
if ( $post_type && ! in_array( $post_type, $this->get_post_types_for_module( $this->module ) ) ) {
return true;
}

return false;
}
Expand All @@ -300,8 +302,9 @@ function disable_custom_statuses_for_post_type( $post_type = null ) {
function action_admin_enqueue_scripts() {
global $pagenow;

if ( $this->disable_custom_statuses_for_post_type() )
if ( $this->disable_custom_statuses_for_post_type() ) {
return;
}

// Load Javascript we need to use on the configuration views (jQuery Sortable and Quick Edit)
if ( $this->is_whitelisted_settings_view( $this->module->name ) ) {
Expand Down
6 changes: 3 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: batmoo, danielbachhuber, sbressler, automattic
Donate link: http://editflow.org/contribute/
Tags: edit flow, workflow, editorial, newsroom, management, journalism, post status, custom status, notifications, email, comments, editorial comments, usergroups, calendars, editorial calendar, story budget
Requires at least: 4.5
Requires PHP: 5.4
Tested up to: 5.0.3
Requires at least: 5.1
Requires PHP: 5.6
Tested up to: 5.3
Stable tag: 0.9

Redefining your editorial workflow.
Expand Down