load_extensions(); } if ( Astra_Ext_Extension::is_active( 'advanced-headers' ) || Astra_Ext_Extension::is_active( 'advanced-hooks' ) ) { add_action( 'admin_bar_menu', array( $this, 'add_admin_menu' ), 90 ); add_action( 'wp_head', array( $this, 'print_style' ) ); } } /** * Load Extensions * * @return void */ public function load_extensions() { $enabled_extension = Astra_Ext_Extension::get_enabled_addons(); $default_extensions = Astra_Ext_Extension::get_default_addons(); $enabled_extension = $enabled_extension + $default_extensions; if ( 0 < count( $enabled_extension ) ) { if ( isset( $enabled_extension['all'] ) ) { unset( $enabled_extension['all'] ); } foreach ( $enabled_extension as $slug => $value ) { if ( false == $value ) { continue; } $extension_path = ASTRA_EXT_DIR . 'addons/' . esc_attr( $slug ) . '/class-astra-ext-' . esc_attr( $slug ) . '.php'; $extension_path = apply_filters( 'astra_addon_path', $extension_path, $slug ); // Check for the extension. if ( file_exists( $extension_path ) ) { require_once $extension_path; } } } } /** * Add Admin menu item * * @param object WP_Admin_Bar $admin_bar Admin bar. * @return void * @since 4.0.0 */ public function add_admin_menu( $admin_bar ) { if ( is_admin() ) { return; } // Check if current user can have edit access. if ( ! current_user_can( 'edit_posts' ) ) { return; } $custom_layout_addon_active = Astra_Ext_Extension::is_active( 'advanced-hooks' ) ? true : false; $page_headers_addon_active = Astra_Ext_Extension::is_active( 'advanced-headers' ) ? true : false; $post_id = get_the_ID() ? get_the_ID() : 0; $current_post = $post_id ? get_post( $post_id, OBJECT ) : false; $has_shortcode = ( is_object( $current_post ) && has_shortcode( $current_post->post_content, 'astra_custom_layout' ) ) ? true : false; if ( $custom_layout_addon_active || $page_headers_addon_active || $has_shortcode ) { $custom_layouts = false; if ( $custom_layout_addon_active ) { $option = array( 'location' => 'ast-advanced-hook-location', 'exclusion' => 'ast-advanced-hook-exclusion', 'users' => 'ast-advanced-hook-users', ); $custom_layouts = Astra_Target_Rules_Fields::get_instance()->get_posts_by_conditions( ASTRA_ADVANCED_HOOKS_POST_TYPE, $option ); } $page_headers = false; if ( $page_headers_addon_active ) { $option = array( 'location' => 'ast-advanced-headers-location', 'exclusion' => 'ast-advanced-headers-exclusion', 'users' => 'ast-advanced-headers-users', 'page_meta' => 'adv-header-id-meta', ); $page_headers = Astra_Target_Rules_Fields::get_instance()->get_posts_by_conditions( 'astra_adv_header', $option ); } $branding_logo = ' '; if ( false !== Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra', 'icon' ) ) { $branding_logo = ''; } if ( $custom_layouts || $page_headers || $has_shortcode ) { $admin_bar->add_node( array( 'id' => 'astra-advanced-layouts', 'title' => ' ' . $branding_logo . ' ', ) ); } if ( is_array( $custom_layouts ) && ! empty( $custom_layouts ) ) { $admin_bar->add_group( array( 'id' => 'ast_custom_layouts_group', 'parent' => 'astra-advanced-layouts', ) ); $admin_bar->add_node( array( 'id' => 'custom-layout-title', 'parent' => 'ast_custom_layouts_group', 'title' => esc_html__( 'Edit Layout', 'astra-addon' ), ) ); // Add dynamic layouts assigned on current location. foreach ( $custom_layouts as $post_id => $post_data ) { $post_type = get_post_type(); if ( ASTRA_ADVANCED_HOOKS_POST_TYPE != $post_type ) { $layout_title = get_the_title( $post_id ); $admin_bar->add_node( array( 'id' => 'edit-custom-layout-' . esc_attr( $post_id ), 'href' => esc_url( get_edit_post_link( $post_id ) ), 'title' => $layout_title ? esc_attr( $layout_title ) : esc_html__( 'Untitled', 'astra-addon' ), // Display "Untitled" text if no title is set. 'parent' => 'ast_custom_layouts_group', ) ); } } } if ( is_array( $page_headers ) && ! empty( $page_headers ) ) { $admin_bar->add_group( array( 'id' => 'ast_page_headers_group', 'parent' => 'astra-advanced-layouts', ) ); $admin_bar->add_node( array( 'id' => 'page-headers-title', 'parent' => 'ast_page_headers_group', 'title' => esc_html__( 'Edit Page Header', 'astra-addon' ), ) ); // Add dynamic headers assigned on current location. foreach ( $page_headers as $post_id => $post_data ) { $post_type = get_post_type(); if ( 'astra_adv_header' != $post_type ) { $layout_title = get_the_title( $post_id ); $admin_bar->add_node( array( 'id' => 'edit-page-header-' . esc_attr( $post_id ), 'href' => esc_url( get_edit_post_link( $post_id ) ), 'title' => $layout_title ? esc_attr( $layout_title ) : esc_html__( 'Untitled', 'astra-addon' ), // Display "Untitled" text if no title is set. 'parent' => 'ast_page_headers_group', ) ); } } } if ( $has_shortcode ) { $pattern = get_shortcode_regex( array( 'astra_custom_layout' ) ); if ( preg_match_all( '/' . $pattern . '/s', $current_post->post_content, $matches ) ) { $output = array(); foreach ( $matches[0] as $key => $value ) { $as_string = str_replace( ' ', '&', trim( $matches[3][ $key ] ) ); // $matches[3] return the shortcode attribute as string & replace space with '&' for parse_str() function. $as_string = str_replace( '"', '', $as_string ); parse_str( $as_string, $sub_attrs ); $output[] = $sub_attrs; // Get all shortcode attribute keys. } if ( ! empty( $output ) ) { $admin_bar->add_group( array( 'id' => 'ast_cl_shortcode_group', 'parent' => 'astra-advanced-layouts', ) ); $admin_bar->add_node( array( 'id' => 'cl-shortcode-title', 'parent' => 'ast_cl_shortcode_group', 'title' => esc_html__( 'Edit Shortcode Layouts', 'astra-addon' ), ) ); foreach ( $output as $key => $value ) { foreach ( $value as $attr_key => $attr_val ) { $cl_layout_id = absint( $attr_val ); $layout_title = get_the_title( $cl_layout_id ); $admin_bar->add_node( array( 'id' => 'edit-cl-shortcode-layout-' . esc_attr( $cl_layout_id ), 'href' => esc_url( get_edit_post_link( $cl_layout_id ) ), 'title' => esc_attr( $layout_title ), 'parent' => 'ast_cl_shortcode_group', ) ); } } } } } } } /** * Print style. * * Adds custom CSS to the HEAD html tag. The CSS for admin bar Astra's trigger. * * Fired by `wp_head` filter. * * @since 4.0.0 */ public function print_style() { if ( is_user_logged_in() ) { ?>