block_editor_check_function = 'use_block_editor_for_post';
} elseif ( function_exists( 'gutenberg_can_edit_post' ) && defined( 'GUTENBERG_VERSION' ) ) {
$this->block_editor_check_function = 'gutenberg_can_edit_post';
}
if ( ! function_exists( $this->block_editor_check_function ) ) {
return;
}
$post_type = $typenow;
if ( 'edit.php' === $pagenow && '' === $typenow ) {
$post_type = 'post';
}
if ( is_admin() ) {
if ( $this->is_fb_enabled( $post_type ) ) {
// Alter the add new dropdown.
add_action( 'admin_print_footer_scripts-edit.php', [ $this, 'edit_dropdown' ], 10 );
}
if ( $this->is_fb_enabled( $post_type ) || 'admin-ajax.php' === $pagenow ) {
// Add Gutenberg edit link.
add_filter( 'page_row_actions', [ $this, 'add_edit_link' ], 10, 2 );
add_filter( 'post_row_actions', [ $this, 'add_edit_link' ], 10, 2 );
// Update edit link if required.
add_filter( 'get_edit_post_link', [ $this, 'update_edit_link' ], 10, 3 );
}
}
add_action( 'admin_print_footer_scripts-post-new.php', [ $this, 'adopt_to_builder' ], 10 );
add_action( 'admin_print_footer_scripts-post.php', [ $this, 'adopt_to_builder' ], 10 );
// Make sure G only loads with get variable if FB is new default.
add_filter( $this->block_editor_check_function, [ $this, 'replace_gutenberg' ], 99, 1 );
}
/**
* Adopts to the chosen builder. Will add FB button to Gutenberg and trigger FB activation.
*
* @since 1.7
* @access public
* @return void
*/
public function adopt_to_builder() {
global $post_type, $post;
if ( $this->is_fb_enabled( $post_type ) && is_object( $post ) ) {
if ( isset( $_GET['fb-be-editor'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
?>
ID, 'raw' ) );
$button = '' . esc_html__( 'Edit With Back-end Builder', 'fusion-builder' ) . '';
?>
is_fb_enabled( $post_type ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return $use_block_editor;
}
return false;
}
/**
* Add edit dropdown to the all posts/pages screens.
*
* @since 1.7
* @access public
* @return void
*/
public function edit_dropdown() {
global $typenow;
$post_type_check = $this->block_editor_check_function . '_type';
if ( ! $post_type_check( $typenow ) ) {
return;
}
$options = get_option( 'fusion_builder_settings', [] );
$builder_type = isset( $options['enable_builder_ui_by_default'] ) ? $options['enable_builder_ui_by_default'] : 'backend';
$edit = 'post' !== $typenow ? 'post-new.php?post_type=' . $typenow : 'post-new.php';
$fb_url = add_query_arg( 'fb-be-editor', '', $edit );
$gutenberg_url = add_query_arg( 'gutenberg-editor', '', $edit );
$load_live_builder = apply_filters( 'fusion_load_live_editor', true ) && current_user_can( apply_filters( 'awb_role_manager_access_capability', 'edit_', get_post_type( $typenow ), 'live_builder_edit' ) );
$load_backend_builder = current_user_can( apply_filters( 'awb_role_manager_access_capability', 'edit_', get_post_type( $typenow ), 'backend_builder_edit' ) );
$edit = 'live' === $builder_type && $load_live_builder ? '#' : $edit;
$class = 'live' === $builder_type && $load_live_builder ? ' awb-default-post-live' : '';
$page_title_action_template = '';
$page_title_action_template .= '' . esc_html__( 'Add New', 'fusion-builder' ) . '';
$page_title_action_template .= '';
$page_title_action_template .= '';
if ( $load_backend_builder ) {
$page_title_action_template .= '' . esc_html__( 'Back-end Builder', 'fusion-builder' ) . '';
}
if ( $load_live_builder ) {
$page_title_action_template .= '' . esc_html__( 'Live Builder', 'fusion-builder' ) . '';
}
$page_title_action_template .= '' . esc_html__( 'Gutenberg Editor', 'fusion-builder' ) . '';
$page_title_action_template .= '';
$page_title_action_template .= '';
?>
block_editor_check_function ) || ( isset( $_GET['post_status'] ) && 'trash' === $_GET['post_status'] ) || $this->is_live_edit_disabled( $post ) || ! current_user_can( 'edit_post', $post->ID ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return $actions;
}
$edit_url = get_edit_post_link( $post->ID, 'raw' );
$options = get_option( 'fusion_builder_settings', [] );
$builder_type = isset( $options['enable_builder_ui_by_default'] ) ? $options['enable_builder_ui_by_default'] : 'backend';
$fb_live_url = add_query_arg( 'fb-edit', '1', get_permalink( $post->ID ) );
$gutenberg_url = add_query_arg( 'gutenberg-editor', '', $edit_url );
$load_live_builder = apply_filters( 'fusion_load_live_editor', true ) && current_user_can( apply_filters( 'awb_role_manager_access_capability', 'edit_', get_post_type( $post->ID ), 'live_builder_edit' ) );
$load_backend_builder = current_user_can( apply_filters( 'awb_role_manager_access_capability', 'edit_', get_post_type( $post->ID ), 'backend_builder_edit' ) );
$edit_action = [];
// Build the classic edit action. See also: WP_Posts_List_Table::handle_row_actions().
$title = _draft_or_post_title( $post->ID );
// If auto activation is set to backend builder.
if ( $load_live_builder && 'backend' === $builder_type ) {
$edit_action['fusion_builder_live'] = sprintf(
'%s',
esc_url( $fb_live_url ),
esc_attr(
sprintf(
/* translators: %s: post title */
__( 'Edit “%s” in Live Builder', 'fusion-builder' ),
$title
)
),
esc_html__( 'Live Builder', 'fusion-builder' )
);
}
// If auto activation is set to live builder.
if ( $edit_url && $load_backend_builder && 'live' === $builder_type ) {
$edit_action['fusion_builder_backend'] = sprintf(
'%s',
esc_url( $edit_url ),
esc_attr(
sprintf(
/* translators: %s: post title */
__( 'Edit “%s” in Back-end Builder', 'fusion-builder' ),
$title
)
),
esc_html__( 'Back-end Builder', 'fusion-builder' )
);
}
$edit_action['gutenberg'] = sprintf(
'%s',
esc_url( $gutenberg_url ),
esc_attr(
sprintf(
/* translators: %s: post title */
__( 'Edit “%s” in the Gutenberg editor', 'fusion-builder' ),
$title
)
),
esc_html__( 'Gutenberg Editor', 'fusion-builder' )
);
// Insert the Gutenberg Edit action after the Edit action.
$actions_keys = array_keys( $actions );
$edit_offset = array_search( 'edit', $actions_keys, true );
$actions = array_merge(
array_slice( $actions, 0, $edit_offset + 1 ),
$edit_action,
array_slice( $actions, $edit_offset + 1 )
);
return $actions;
}
/**
* Check if live editing should be available for the post type.
*
* @since 2.2
* @access public
* @param object $post Post to check.
* @return bool
*/
public function is_live_edit_disabled( $post ) {
// Disabled post types.
$disabled = [ 'fusion_icons' ];
return isset( $post ) && in_array( $post->post_type, $disabled, true ) ? true : false;
}
/**
* Check if FB is activated for the post type.
*
* @since 1.7
* @access public
* @param string $post_type Post type to check.
* @return bool
*/
public function is_fb_enabled( $post_type ) {
if ( $post_type ) {
return in_array( $post_type, FusionBuilder::allowed_post_types(), true );
}
return false;
}
}