register_location(
'front-page',
array(
'label' => __( 'Front Page', 'bongoto-shop' ),
'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.
*
* @param string[] $classes
* @return string[]
*/
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' );
/**
* Handle dismiss click for the Elementor notice.
*/
function bongoto_elementor_handle_notice_dismiss() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['bongoto_dismiss_elementor'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$nonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : '';
if ( wp_verify_nonce( $nonce, 'bongoto_dismiss_elementor' ) ) {
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 keeps the editor tidy if Elementor is present; otherwise
* the template simply acts as a blank full-width wrapper.
*
* @param array $post_templates
* @return array
*/
function bongoto_register_page_templates( $post_templates ) {
$post_templates['page-templates/template-elementor-canvas.php'] = __( 'Elementor Canvas (Bongoto Shop)', 'bongoto-shop' );
return $post_templates;
}
add_filter( 'theme_page_templates', 'bongoto_register_page_templates' );
/**
* Load our custom Elementor Canvas template file if selected.
*
* @param string $template
* @return string
*/
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) Optional tweak: if Elementor fully handles styles, you may disable
* the default block styles on the front-end. Keep enabled by default
* for hybrid block usage. Uncomment in a 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
);
*/