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 );
}
}
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, 2 );
}
/**
* 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 Avada 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;
}
$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 );
$live_editor = apply_filters( 'fusion_load_live_editor', true );
$page_title_action_template = '';
$page_title_action_template .= '' . esc_html__( 'Add New', 'fusion-builder' ) . '';
$page_title_action_template .= '';
$page_title_action_template .= '';
$page_title_action_template .= '' . esc_html__( 'Avada Builder', 'fusion-builder' ) . '';
if ( $live_editor ) {
$page_title_action_template .= '' . esc_html__( 'Avada Live', '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 ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return $actions;
}
$edit_url = get_edit_post_link( $post->ID, 'raw' );
$fb_live_url = add_query_arg( 'fb-edit', '1', get_permalink( $post->ID ) );
$gutenberg_url = add_query_arg( 'gutenberg-editor', '', $edit_url );
$live_editor = apply_filters( 'fusion_load_live_editor', true );
$edit_action = [];
// Build the classic edit action. See also: WP_Posts_List_Table::handle_row_actions().
$title = _draft_or_post_title( $post->ID );
if ( $live_editor ) {
$edit_action['fusion_builder_live'] = sprintf(
'%s',
esc_url( $fb_live_url ),
esc_attr(
sprintf(
/* translators: %s: post title */
__( 'Edit “%s” in Avada Live', 'fusion-builder' ),
$title
)
),
esc_html__( 'Avada Live', '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;
}
}