Astra_SureCart::customize_admin_bar( WP_Admin_Bar $wp_admin_bar )
Method to add autoFocus query parameter to customize link.
Description
Parameters
- $wp_admin_bar
-
(WP_Admin_Bar) (Required) The WP_Admin_Bar instance.
Return
(void)
Source
File: inc/compatibility/surecart/class-astra-surecart.php
public function customize_admin_bar( $wp_admin_bar ) { if ( is_admin() || ! is_admin_bar_showing() ) { return; } // Show only when the user is a member of this site, or they're a super admin. if ( ! is_user_member_of_blog() && ! is_super_admin() ) { return; } // Get the customize node by ID. $node = $wp_admin_bar->get_node( 'customize' ); if ( $node ) { $post_type = get_post_type(); $page = is_singular() ? 'single' : 'archive'; // If the current page is SureCart shop page. if ( 'page' === $post_type && get_the_ID() == get_option( 'surecart_shop_page_id' ) ) { $page = 'archive'; $post_type = 'sc_product'; } // Check for surecart post type. if ( in_array( $post_type, array( 'sc_product', 'sc_collection', 'sc_upsell' ) ) ) { // Add custom parameter to the URL. $node->href = add_query_arg( 'autofocus[section]', "{$page}-posttype-{$post_type}", $node->href ); // Update the node with the modified URL. $wp_admin_bar->add_node( (array) $node ); } } }
Expand full source code Collapse full source code View on Trac
Changelog
Version | Description |
---|---|
4.7.3 | Introduced. |