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

Scope module assets ( v2 ) #487

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
435447b
Add method `is_module_view`
Jan 29, 2018
970c89e
Deprecate `is_whitelisted_settings_view()` in favor of `is_module_set…
Jan 29, 2018
89206dc
Add style & script interfaces to improve method name consistency
Jan 29, 2018
e0c2aef
Add `Edit_Flow_Module_With_View` interface
Jan 29, 2018
bf67dcb
Accept $module_name in `is_module_settings_view`
Jan 29, 2018
9b2698a
Refactor calendar asset enqueuing
Jan 29, 2018
a46ed47
Refactor custom-status asset enqueuing
Jan 29, 2018
ab8bdef
Deprecate `is_whitelisted_functional_view()` method
Jan 29, 2018
49b7a9b
Pull method up & rename it to `is_module_edit_view()` for reusability
Jan 29, 2018
3785a7f
Refactor notification asset enqueuing
Jan 29, 2018
55d435b
Use `is_module_settings_view()` instead of `is_whitelisted_settings_v…
Jan 30, 2018
8a0ca71
Improve function naming: `is_module_edit_view` -> `is_active_view`
Jan 30, 2018
b70164f
Add `is_current_module_settings_view` to help easily target the curre…
Jan 30, 2018
bd4885d
Rename `is_current_module_view` to `is_calendar_view`
Jan 30, 2018
4e17907
Remove `is_module_view()` method because it’s no longer used
Jan 30, 2018
64abafa
Improve custom status `is_current_module_view` method
Jan 30, 2018
98aabcd
Refactor editorial metadata asset enqueuing
Jan 30, 2018
e938ca2
Notification assets are only needed in settings and active editor view
Jan 30, 2018
65aca1e
Refactor user groups asset enqueuing
Jan 30, 2018
cdce333
Improve comment at `is_whitelisted_functional_view` method
Jan 30, 2018
eecb486
Move deprecated methods down
Jan 30, 2018
bb31689
Rename `is_current_module_view()` to `is_custom_status_view()`
Jan 30, 2018
f8fd8f1
Remove unused Edit_Flow_Module_With_View interface
Jan 30, 2018
3ce044f
Use is_current_module_settings_view method instead of is_module_setti…
Jan 30, 2018
ec35e5b
Merge branch 'master' of https://github.com/Automattic/Edit-Flow into…
Jan 30, 2018
496ce93
Use `is_custom_status_view` to check if is active view
Jan 30, 2018
9c9da87
Extract a EF_Module_With_View trait
Jan 30, 2018
accc76c
Utilize trait `EF_Module_With_View`
Jan 30, 2018
23a6a3c
Refactor story budget asset enqueuing
Jan 30, 2018
d9862ef
Rename Edit_Flow_**** to EF_****_Interface
Jan 30, 2018
dac767f
Update comments
Jan 31, 2018
79eda84
Call a Trait a Trait
Jan 31, 2018
96387f0
Add more comments
Jan 31, 2018
dc9bf6b
Remove Trait, use regular Classes instead
Jan 31, 2018
235ae9e
Check for module settings view in EF_Custom_Status
Jan 31, 2018
b470e94
Refactor editorial comments asset enqueuing
Jan 31, 2018
cfbca15
Set the post_type to post if edit.php OR post-new.php
Jan 31, 2018
a38177c
Merge branch 'master' of https://github.com/Automattic/Edit-Flow into…
Feb 5, 2018
2de212d
Merge branch 'master' of https://github.com/Automattic/Edit-Flow into…
Feb 23, 2018
9da539a
Merge branch 'fix-351-scope-assets' of github.com:justnorris/Edit-Flo…
Dec 21, 2018
3228baf
Change the test to test only the view
Dec 21, 2018
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
181 changes: 181 additions & 0 deletions common/php/class-module-with-view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php


class EF_Module_With_View extends EF_Module {


/**
* Whether or not the current page is an Edit Flow settings view (either main or module)
* Determination is based on $pagenow, $_GET['page'], and the module's $settings_slug
* If there's no module name specified, it will return true against all Edit Flow settings views
*
* @since 0.8.3
*
* @param string $slug (Optional) Module name to check against
* @return bool true if is module settings view
*/
public function is_module_settings_view( $slug = false ) {
global $pagenow, $edit_flow;

// All of the settings views are based on admin.php and a $_GET['page'] parameter
if ( $pagenow !== 'admin.php' || ! isset( $_GET['page'] ) )
return false;

$settings_view_slugs = array();
// Load all of the modules that have a settings slug/ callback for the settings page
foreach ( $edit_flow->modules as $mod_name => $mod_data ) {
if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' && $mod_data->configure_page_cb )
$settings_view_slugs[] = $mod_data->settings_slug;
}

// The current page better be in the array of registered settings view slugs
if ( empty( $settings_view_slugs ) || ! in_array( $_GET['page'], $settings_view_slugs ) ) {
return false;
}

if ( $slug && $edit_flow->modules->{$slug}->settings_slug !== $_GET['page'] ) {
return false;
}

return true;
}

/**
* Check whether if we're at module settings view
* for the current module based on `is_module_settings_view` method
*
* @return bool
*/
public function is_current_module_settings_view() {
return $this->is_module_settings_view( $this->module->name );
}


/**
* Check for admin page and whether the current post type is supported
* @param array $allowed_pages
*
* @return bool
*/
function is_active_view( $allowed_pages = array( 'edit.php', 'post.php', 'post-new.php' ) ) {
return ( $this->is_admin_page( $allowed_pages ) && $this->is_supported_post_type() );
}


/**
* Check whether the current post type is supported for $this module
*
* @return bool
*/
public function is_supported_post_type() {
$post_type = $this->get_current_post_type();

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

/**
* Checks for the current post type
*
* @since 0.7
* @return string|null $post_type The post type we've found, or null if no post type
*/
function get_current_post_type() {
global $post, $typenow, $pagenow, $current_screen;
//get_post() needs a variable
$post_id = isset( $_REQUEST['post'] ) ? (int) $_REQUEST['post'] : false;

if ( $post && $post->post_type ) {
$post_type = $post->post_type;
} elseif ( $typenow ) {
$post_type = $typenow;
} elseif ( $current_screen && ! empty( $current_screen->post_type ) ) {
$post_type = $current_screen->post_type;
} elseif ( isset( $_REQUEST['post_type'] ) ) {
$post_type = sanitize_key( $_REQUEST['post_type'] );
} elseif ( 'post.php' == $pagenow
&& $post_id
&& ! empty( get_post( $post_id )->post_type ) ) {
$post_type = get_post( $post_id )->post_type;
} elseif ( in_array( $pagenow, array('edit.php', 'post-new.php' ) ) && empty( $_REQUEST['post_type'] ) ) {
$post_type = 'post';
} else {
$post_type = null;
}

return $post_type;
}

/**
* Check whether currently viewing the desired admin page
*
* @param array $allowed_pages
*
* @return bool
*/
public function is_admin_page( $allowed_pages = array( 'edit.php', 'post.php', 'post-new.php' ) ) {
global $pagenow;

return ( $pagenow && in_array( $pagenow, $allowed_pages, true ) );
}


/**
* Shorthand for `is_active_view` to check for list type views ( list of posts pages, custom post types )
*
* @see is_active_view
* @return bool
*/
public function is_active_list_view() {
return $this->is_active_view( array( 'edit.php' ) );
}

/**
* Shorthand for `is_active_view` to check for editor mode
*
* @see is_active_view
* @return bool
*/
public function is_active_editor_view() {
return $this->is_active_view( array( 'post.php', 'posts-new.php' ) );
}


/**
* This method was supposed to check whether or not the current page is a user-facing Edit Flow View
* But it was never implemented
*
* It is now deprecated in favor of `$this->is_active_view`
* @see EF_Module::is_active_view()
* @since 0.7
* @deprecated 0.8.3
*
* @param string $module_name (Optional) Module name to check against
*/
public function is_whitelisted_functional_view( $module_name = null ) {
_deprecated_function( __FUNCTION__, '0.8.3', 'is_active_view' );

return true;
}

/**
* Whether or not the current page is an Edit Flow settings view (either main or module)
* Determination is based on $pagenow, $_GET['page'], and the module's $settings_slug
* If there's no module name specified, it will return true against all Edit Flow settings views
*
* @since 0.7
* @deprecated 0.8.3
*
* @param string $module_name (Optional) Module name to check against
* @return bool $is_settings_view Return true if it is
*/
public function is_whitelisted_settings_view( $module_name = null ) {
_deprecated_function( 'is_whitelisted_settings_view', '0.8.3', 'is_module_settings_view' );

return $this->is_module_settings_view( $module_name );
}

}
83 changes: 2 additions & 81 deletions common/php/class-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,38 +208,7 @@ function enqueue_datepicker_resources() {
wp_enqueue_style( 'jquery-ui-theme', EDIT_FLOW_URL . 'common/css/jquery.ui.theme.css', false, EDIT_FLOW_VERSION, 'screen' );
}

/**
* Checks for the current post type
*
* @since 0.7
* @return string|null $post_type The post type we've found, or null if no post type
*/
function get_current_post_type() {
global $post, $typenow, $pagenow, $current_screen;
//get_post() needs a variable
$post_id = isset( $_REQUEST['post'] ) ? (int)$_REQUEST['post'] : false;

if ( $post && $post->post_type ) {
$post_type = $post->post_type;
} elseif ( $typenow ) {
$post_type = $typenow;
} elseif ( $current_screen && !empty( $current_screen->post_type ) ) {
$post_type = $current_screen->post_type;
} elseif ( isset( $_REQUEST['post_type'] ) ) {
$post_type = sanitize_key( $_REQUEST['post_type'] );
} elseif ( 'post.php' == $pagenow
&& $post_id
&& !empty( get_post( $post_id )->post_type ) ) {
$post_type = get_post( $post_id )->post_type;
} elseif ( 'edit.php' == $pagenow && empty( $_REQUEST['post_type'] ) ) {
$post_type = 'post';
} else {
$post_type = null;
}

return $post_type;
}

/**
* Wrapper for the get_user_meta() function so we can replace it if we need to
*
Expand Down Expand Up @@ -296,55 +265,6 @@ function print_ajax_response( $status, $message = '' ) {
exit;
}

/**
* Whether or not the current page is a user-facing Edit Flow View
* @todo Think of a creative way to make this work
*
* @since 0.7
*
* @param string $module_name (Optional) Module name to check against
*/
function is_whitelisted_functional_view( $module_name = null ) {

// @todo complete this method

return true;
}

/**
* Whether or not the current page is an Edit Flow settings view (either main or module)
* Determination is based on $pagenow, $_GET['page'], and the module's $settings_slug
* If there's no module name specified, it will return true against all Edit Flow settings views
*
* @since 0.7
*
* @param string $module_name (Optional) Module name to check against
* @return bool $is_settings_view Return true if it is
*/
function is_whitelisted_settings_view( $module_name = null ) {
global $pagenow, $edit_flow;

// All of the settings views are based on admin.php and a $_GET['page'] parameter
if ( $pagenow != 'admin.php' || !isset( $_GET['page'] ) )
return false;

// Load all of the modules that have a settings slug/ callback for the settings page
foreach ( $edit_flow->modules as $mod_name => $mod_data ) {
if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' && $mod_data->configure_page_cb )
$settings_view_slugs[] = $mod_data->settings_slug;
}

// The current page better be in the array of registered settings view slugs
if ( !in_array( $_GET['page'], $settings_view_slugs ) )
return false;

if ( $module_name && $edit_flow->modules->$module_name->settings_slug != $_GET['page'] )
return false;

return true;
}


/**
* This is a hack, Hack, HACK!!!
* Encode all of the given arguments as a serialized array, and then base64_encode
Expand Down Expand Up @@ -573,6 +493,7 @@ function upgrade_074_term_descriptions( $taxonomy ) {
wp_update_term( $term->term_id, $taxonomy, array( 'description' => $new_description ) );
}
}



}
}
9 changes: 8 additions & 1 deletion edit_flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ private function load_modules() {

// Edit Flow base module
require_once( EDIT_FLOW_ROOT . '/common/php/class-module.php' );


/*
* Include interfaces:
*/
require_once( EDIT_FLOW_ROOT . '/interfaces/EF_Script_Interface.php' );
require_once( EDIT_FLOW_ROOT . '/interfaces/EF_Style_Interface.php' );
require_once( EDIT_FLOW_ROOT . '/common/php/class-module-with-view.php' );

// Scan the modules directory and include any modules that exist there
$module_dirs = scandir( EDIT_FLOW_ROOT . '/modules/' );
$class_names = array();
Expand Down
9 changes: 9 additions & 0 deletions interfaces/EF_Script_Interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Interface EF_Script_Interface
* A very simple interface tor equire a method `enqueue_admin_scripts()`
*/
interface EF_Script_Interface {
public function enqueue_admin_scripts();
}
9 changes: 9 additions & 0 deletions interfaces/EF_Style_Interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Interface EF_Style_Interface
* A very simple interface tor equire a method `enqueue_admin_styles()`
*/
interface EF_Style_Interface {
public function enqueue_admin_styles();
}
Loading