1414
1515class EF_Custom_Status extends EF_Module {
1616 use Block_Editor_Compatible;
17+ use EF_Module_With_View;
1718
1819 var $ module ;
1920
@@ -80,7 +81,8 @@ function init() {
8081 add_action ( 'admin_init ' , array ( $ this , 'register_settings ' ) );
8182
8283 // Load CSS and JS resources that we probably need
83- add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'action_admin_enqueue_scripts ' ) );
84+ add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'enqueue_admin_scripts ' ) );
85+ add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'enqueue_admin_styles ' ) );
8486 add_action ( 'admin_notices ' , array ( $ this , 'no_js_notice ' ) );
8587 add_action ( 'admin_print_scripts ' , array ( $ this , 'post_admin_header ' ) );
8688
@@ -282,7 +284,7 @@ function disable_custom_statuses_for_post_type( $post_type = null ) {
282284 * - jQuery Sortable plugin is used for drag and dropping custom statuses
283285 * - We have other custom code for Quick Edit and JS niceties
284286 */
285- function action_admin_enqueue_scripts () {
287+ function enqueue_admin_scripts () {
286288 if ( $ this ->disable_custom_statuses_for_post_type () ) {
287289 return ;
288290 }
@@ -301,13 +303,13 @@ function action_admin_enqueue_scripts() {
301303 }
302304
303305 // Load Javascript we need to use on the configuration views (jQuery Sortable and Quick Edit)
304- if ( $ this ->is_whitelisted_settings_view ( $ this -> module -> name ) ) {
306+ if ( $ this ->is_current_module_settings_view ( ) ) {
305307 wp_enqueue_script ( 'jquery-ui-sortable ' );
306308 wp_enqueue_script ( 'edit-flow-custom-status-configure ' , $ this ->module_url . 'lib/custom-status-configure.js ' , array ( 'jquery ' , 'jquery-ui-sortable ' , 'edit-flow-settings-js ' ), EDIT_FLOW_VERSION , true );
307309 }
308310
309311 // Custom javascript to modify the post status dropdown where it shows up
310- if ( $ this ->is_whitelisted_page () ) {
312+ if ( $ this ->is_custom_status_view () ) {
311313 wp_enqueue_script ( 'edit_flow-custom_status ' , $ this ->module_url . 'lib/custom-status.js ' , array ( 'jquery ' ,'post ' ), EDIT_FLOW_VERSION , true );
312314 wp_localize_script ('edit_flow-custom_status ' , '__ef_localize_custom_status ' , array (
313315 'no_change ' => esc_html__ ( "— No Change — " , 'edit-flow ' ),
@@ -319,16 +321,20 @@ function action_admin_enqueue_scripts() {
319321 'cancel ' => esc_html__ ( 'Cancel ' , 'edit-flow ' ),
320322 ));
321323 }
324+ }
322325
323-
326+ public function enqueue_admin_styles () {
327+ if ( $ this ->is_custom_status_view () ) {
328+ wp_enqueue_style ( 'edit_flow-custom_status ' , $ this ->module_url . 'lib/custom-status.css ' , false , EDIT_FLOW_VERSION , 'all ' );
329+ }
324330 }
325331
326332 /**
327333 * Displays a notice to users if they have JS disabled
328334 * Javascript is needed for custom statuses to be fully functional
329335 */
330336 function no_js_notice () {
331- if ( $ this ->is_whitelisted_page () ) :
337+ if ( $ this ->is_custom_status_view () ) :
332338 ?>
333339 <style type="text/css">
334340 /* Hide post status dropdown by default in case of JS issues **/
@@ -346,12 +352,14 @@ function no_js_notice() {
346352 endif ;
347353 }
348354
349- /**
355+ /**
350356 * Check whether custom status stuff should be loaded on this page
351357 *
352358 * @todo migrate this to the base module class
353359 */
354360 function is_whitelisted_page () {
361+ _deprecated_function ( 'is_whitelisted_page ' , '0.9.4 ' , 'is_custom_status_view ' );
362+
355363 global $ pagenow ;
356364
357365 if ( !in_array ( $ this ->get_current_post_type (), $ this ->get_post_types_for_module ( $ this ->module ) ) )
@@ -381,7 +389,7 @@ function post_admin_header() {
381389 wp_get_current_user () ;
382390
383391 // Only add the script to Edit Post and Edit Page pages -- don't want to bog down the rest of the admin with unnecessary javascript
384- if ( $ this ->is_whitelisted_page () ) {
392+ if ( $ this ->is_custom_status_view () ) {
385393
386394 $ custom_statuses = $ this ->get_custom_statuses ();
387395
@@ -1747,6 +1755,33 @@ public function fix_post_row_actions( $actions, $post ) {
17471755 $ actions ['view ' ] = '<a href=" ' . esc_url ( $ preview_link ) . '" title=" ' . esc_attr ( sprintf ( __ ( 'Preview “%s” ' ), $ post ->post_title ) ) . '" rel="permalink"> ' . __ ( 'Preview ' ) . '</a> ' ;
17481756 return $ actions ;
17491757 }
1758+
1759+ /**
1760+ * Check whether current view is relavant to this module and whether the user has access to it
1761+ *
1762+ * @return bool
1763+ */
1764+ public function is_custom_status_view () {
1765+
1766+ if ( $ this ->is_current_module_settings_view () ) {
1767+ return true ;
1768+ }
1769+
1770+ if ( ! $ this ->is_active_view ( array ( 'post.php ' , 'edit.php ' , 'post-new.php ' , 'page.php ' , 'edit-pages.php ' , 'page-new.php ' ) ) ) {
1771+ return false ;
1772+ }
1773+
1774+ $ post_type_obj = get_post_type_object ( $ this ->get_current_post_type () );
1775+
1776+ if ( $ post_type_obj
1777+ && ( ! current_user_can ( $ post_type_obj ->cap ->edit_posts )
1778+ || ! $ this ->is_supported_post_type () ) ) {
1779+ return false ;
1780+ }
1781+
1782+ return true ;
1783+ }
1784+
17501785}
17511786
17521787}
0 commit comments