register_location(
'front-page',
array(
'label' => __( 'Front Page', 'bongoto' ),
'group' => 'single',
'edit_in_content' => true,
'multiple' => false,
'public' => true,
)
);
}
add_action( 'elementor/theme/register_locations', 'bongoto_elementor_register_locations' );
/**
* 3) Add body class when Elementor controls the current template location.
* Purely cosmetic hint so you can adjust small CSS differences if needed.
*/
function bongoto_elementor_body_class( $classes ) {
if ( function_exists( 'elementor_theme_do_location' ) && elementor_theme_do_location( 'front-page' ) ) {
$classes[] = 'elementor-controls-front-page';
}
return $classes;
}
add_filter( 'body_class', 'bongoto_elementor_body_class' );
/**
* 4) Admin notice recommending Elementor (dismissible per-user).
*/
function bongoto_elementor_recommend_notice() {
// Only admins.
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
// Hide if Elementor active.
if ( bongoto_elementor_is_active() ) {
return;
}
// Dismissed?
$user_id = get_current_user_id();
if ( get_user_meta( $user_id, 'bongoto_dismiss_elementor_notice', true ) ) {
return;
}
$dismiss_url = wp_nonce_url(
add_query_arg( array( 'bongoto_dismiss_elementor' => 1 ) ),
'bongoto_dismiss_elementor'
);
echo '
';
}
add_action( 'admin_notices', 'bongoto_elementor_recommend_notice' );
function bongoto_elementor_handle_notice_dismiss() {
if ( isset( $_GET['bongoto_dismiss_elementor'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ?? '' ) ), 'bongoto_dismiss_elementor' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
update_user_meta( get_current_user_id(), 'bongoto_dismiss_elementor_notice', 1 );
wp_safe_redirect( remove_query_arg( array( 'bongoto_dismiss_elementor', '_wpnonce' ) ) );
exit;
}
}
add_action( 'admin_init', 'bongoto_elementor_handle_notice_dismiss' );
/**
* 5) Provide a programmatic "Elementor Canvas" template for pages if users
* pick the bundled page template file (page-templates/template-elementor-canvas.php).
* The physical template file will be provided separately in page-templates/.
*
* This section ensures the editor is tidy if Elementor is present; otherwise
* the template simply acts as a blank full-width wrapper.
*/
function bongoto_register_page_templates( $post_templates ) {
$post_templates['page-templates/template-elementor-canvas.php'] = __( 'Elementor Canvas (Bongoto)', 'bongoto' );
return $post_templates;
}
add_filter( 'theme_page_templates', 'bongoto_register_page_templates' );
function bongoto_load_custom_page_template( $template ) {
if ( is_singular( 'page' ) ) {
$chosen = get_page_template_slug( get_queried_object_id() );
if ( 'page-templates/template-elementor-canvas.php' === $chosen ) {
$path = trailingslashit( get_template_directory() ) . 'page-templates/template-elementor-canvas.php';
if ( file_exists( $path ) ) {
return $path;
}
}
}
return $template;
}
add_filter( 'template_include', 'bongoto_load_custom_page_template' );
/**
* 6) Slight compatibility tweak: remove default wp-block-styles front-end if Elementor
* handles styling heavily. We keep it enabled by default for hybrid block usage.
* Uncomment to disable in your child theme if desired.
*/
// add_action( 'wp_enqueue_scripts', function() {
// if ( bongoto_elementor_is_active() ) {
// wp_dequeue_style( 'wp-block-library' );
// wp_dequeue_style( 'wp-block-library-theme' );
// }
// }, 100 );