array( 'name' => __( 'UX Templates', 'flatsome' ), ), 'description' => '', 'public' => false, 'publicly_queryable' => false, 'show_ui' => false, 'show_in_menu' => false, 'query_var' => true, 'rewrite' => false, 'capability_type' => 'page', 'has_archive' => false, 'hierarchical' => false, 'menu_position' => null, 'menu_icon' => false, 'supports' => array( 'title', 'editor', 'author', 'thumbnail' ), 'taxonomies' => array(), ) ); } add_action( 'init', 'ux_builder_register_post_types' ); /** * Register breakpoints. */ function ux_builder_register_breakpoints() { // Add Ux Builder to posts and pages as default. add_ux_builder_post_type( 'post' ); add_ux_builder_post_type( 'page' ); // Register default breakpoints. add_ux_builder_breakpoint( 'sm', 550, 'Mobile', 'dashicons dashicons-smartphone' ); add_ux_builder_breakpoint( 'md', 850, 'Tablet', 'dashicons dashicons-tablet' ); add_ux_builder_breakpoint( 'lg', 1000, 'Desktop', 'dashicons dashicons-desktop' ); // Set "lg" as default breakpoint. set_default_ux_builder_breakpoint( 'lg' ); } add_action( 'init', 'ux_builder_register_breakpoints' ); /** * UX Builder admin setup, adds ux_builder_init hook */ function ux_builder_admin_setup() { do_action( 'ux_builder_init' ); } add_action( 'admin_init', 'ux_builder_admin_setup' ); /** * Add «Edit with UX Builder» button in * admin toolbar for registered post types. */ function ux_builder_admin_bar_link() { global $wp_admin_bar; global $post; global $wpdb; $is_woocommerce = function_exists( 'is_woocommerce' ); if ( ! is_page() && ! is_single() ) { return; } if ( ! current_user_can( 'edit_post', $post->ID ) ) { return; } // Do not show UX Builder link on homepage if it's Shop page. if ( $is_woocommerce && is_shop() && is_front_page() ) { return; } $post_types = get_ux_builder_post_types(); if ( array_key_exists( $post->post_type, $post_types ) ) { $wp_admin_bar->add_menu( array( 'parent' => 'edit', 'id' => 'edit_uxbuilder', 'title' => 'Edit with UX Builder', 'href' => ux_builder_edit_url( $post->ID ), ) ); } // Add link for editing custom product layout block. if ( $is_woocommerce && is_product() && array_key_exists( 'blocks', $post_types ) ) { $block = flatsome_product_block( $post->ID ); $the_post = $block ? get_post( $block['id'] ) : null; if ( $the_post ) { $wp_admin_bar->add_menu( array( 'parent' => 'edit', 'id' => 'edit_uxbuilder_product_layout', 'title' => 'Edit product layout with UX Builder', 'href' => ux_builder_edit_url( $post->ID, $block['id'] ), ) ); } } } add_action( 'wp_before_admin_bar_render', 'ux_builder_admin_bar_link' ); /** * Add editor tabs to top of edit page on registered post types. */ function ux_builder_meta_boxes() { global $post; if ( ! isset( $post ) || ! current_user_can( 'edit_post', $post->ID ) ) { return; } // Do not show UX Builder link on Shop page. if ( function_exists( 'is_woocommerce' ) && $post->ID == wc_get_page_id( 'shop' ) ) { return; } // Do not show UX Builder link on Posts Page. $page_for_posts = get_option( 'page_for_posts' ); if ( $post->ID == $page_for_posts ) { return; } $current_screen = get_current_screen()->id; $post_types = get_ux_builder_post_types(); if ( array_key_exists( $current_screen, $post_types ) ) { add_action( 'edit_form_top', 'ux_builder_edit_form_top' ); } } add_action( 'add_meta_boxes', 'ux_builder_meta_boxes' ); /** * Render the editor tabs. */ function ux_builder_edit_form_top() { global $post; ?>