Skip to content

Commit

Permalink
Attempt to use the new block editor loading filter for styles and scr…
Browse files Browse the repository at this point in the history
…ipts
  • Loading branch information
ingeniumed committed Jun 20, 2024
1 parent b7d70af commit c853882
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
37 changes: 28 additions & 9 deletions modules/custom-status/custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,24 @@ function action_admin_enqueue_scripts() {
return;
}

// Load block editor assets and return early.
if ( $this->is_block_editor() ) {
global $post;
// Assets for block editor UI.
add_action( 'enqueue_block_editor_assets', array( $this, 'load_scripts_for_block_editor') );

wp_enqueue_style( 'edit-flow-block-custom-status-styles', EDIT_FLOW_URL . 'blocks/dist/custom-status.editor.build.css', false, EDIT_FLOW_VERSION );
wp_enqueue_script( 'edit-flow-block-custom-status-script', EDIT_FLOW_URL . 'blocks/dist/custom-status.build.js', array( 'wp-blocks', 'wp-element', 'wp-edit-post', 'wp-plugins', 'wp-components' ), EDIT_FLOW_VERSION );
// Assets for iframed block editor and editor UI.
add_action( 'enqueue_block_editor_assets', array( $this, 'load_styles_for_block_editor') );

$custom_statuses = apply_filters( 'ef_custom_status_list', $this->get_custom_statuses(), $post );
// // Load block editor assets and return early.
// if ( $this->is_block_editor() ) {
// global $post;

wp_localize_script( 'edit-flow-block-custom-status-script', 'EditFlowCustomStatuses', array_values( $custom_statuses ) );
return;
}
// wp_enqueue_style( 'edit-flow-block-custom-status-styles', EDIT_FLOW_URL . 'blocks/dist/custom-status.editor.build.css', false, EDIT_FLOW_VERSION );
// wp_enqueue_script( 'edit-flow-block-custom-status-script', EDIT_FLOW_URL . 'blocks/dist/custom-status.build.js', array( 'wp-blocks', 'wp-element', 'wp-edit-post', 'wp-plugins', 'wp-components' ), EDIT_FLOW_VERSION );

// $custom_statuses = apply_filters( 'ef_custom_status_list', $this->get_custom_statuses(), $post );

// wp_localize_script( 'edit-flow-block-custom-status-script', 'EditFlowCustomStatuses', array_values( $custom_statuses ) );
// 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 All @@ -321,7 +327,20 @@ function action_admin_enqueue_scripts() {
));
}

}

function load_scripts_for_block_editor(){
global $post;

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

$custom_statuses = apply_filters( 'ef_custom_status_list', $this->get_custom_statuses(), $post );

wp_localize_script( 'edit-flow-block-custom-status-script', 'EditFlowCustomStatuses', array_values( $custom_statuses ) );
}

function load_styles_for_block_editor(){
wp_enqueue_style( 'edit-flow-block-custom-status-styles', EDIT_FLOW_URL . 'blocks/dist/custom-status.editor.build.css', false, EDIT_FLOW_VERSION );
}

/**
Expand Down
12 changes: 12 additions & 0 deletions modules/custom-status/lib/custom-status-blockified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function setup() {
if ( EditFlowCustomStatuses ) {
const statuses = EditFlowCustomStatuses.map( status => ( {
label: status.name,
value: status.slug,
} ) );

console.log( statuses );
}
}

setup();

0 comments on commit c853882

Please sign in to comment.