post_type) { return; } if (function_exists('add_ux_builder_post_type')) { add_ux_builder_post_type($this->post_type); } $this->post_type_build_adminbar_link(); } function taxonomy_layout_support() { if (!$this->taxonomy) { return; } $this->taxonomy_build_adminbar_link(); $this->taxonomy_build_template(); $this->term_taxonomy_meta_box(); } function post_id_layout_support() { if (!$this->post_id) { return; } $this->post_id_layout_build_template(); $this->post_id_layout_build_adminbar_link(); } function post_type_layout_support() { if (!$this->post_type) { return; } $this->post_type_layout_build_template(); $this->post_type_layout_build_adminbar_link(); $this->post_meta_box(); } function post_type_archive_layout_support() { if (!$this->post_type) { return; } $this->post_type_archive_build_template(); $this->post_type_archive_build_adminbar_link(); } function taxonomy_build_adminbar_link() { if (!$this->taxonomy) { return; } add_action('wp_before_admin_bar_render', function () { global $wp_admin_bar; if (!is_archive()) { return; } $queried_object = get_queried_object(); if (!isset($queried_object->taxonomy) or $queried_object->taxonomy !== $this->taxonomy) { return; } // find template_block_id $template_block_id = false; global $adminz; $taxonomy_layout_support = $adminz['Flatsome']->settings['taxonomy_layout_support'] ?? []; foreach ((array) $taxonomy_layout_support as $key => $value) { if ($value['key'] == $queried_object->taxonomy) { $template_block_id = $value['value']; break; } } if ($template_block_id) { $template_block_id = self::post_type_get_block_id($template_block_id); $wp_admin_bar->add_menu(array( 'parent' => 'edit', 'id' => 'edit_uxbuilder', 'title' => 'Edit ' . get_the_title($template_block_id) . 'with UX Builder', 'href' => ux_builder_edit_url($template_block_id), )); } }); } function post_type_build_adminbar_link() { add_action('wp_before_admin_bar_render', function () { global $wp_admin_bar; global $post; if (!is_page() && !is_single()) { return; } if (!current_user_can('edit_post', $post->ID)) { return; } if (get_post_type() != $this->post_type) return; $wp_admin_bar->add_menu(array( 'parent' => 'edit', 'id' => 'edit_uxbuilder', 'title' => 'Edit content with UX Builder', 'href' => ux_builder_edit_url($post->ID), )); }); } function post_id_layout_build_adminbar_link() { add_action('wp_before_admin_bar_render', function () { global $wp_admin_bar; global $post; if (!is_page() && !is_single()) { return; } if (!current_user_can('edit_post', $post->ID)) { return; } if (get_the_ID() != $this->post_id) return; $wp_admin_bar->add_menu(array( 'parent' => 'edit', 'id' => 'edit_uxbuilder_product_layout', 'title' => 'Edit ' . get_the_title(str_replace('block_id_', '', $this->template_block_id)) . ' with UX Builder', 'href' => ux_builder_edit_url($post->ID, self::post_type_get_block_id($this->template_block_id)), )); }); } function post_type_layout_build_adminbar_link() { add_action('wp_before_admin_bar_render', function () { global $wp_admin_bar; global $post; if (!is_page() && !is_single()) { return; } if (!current_user_can('edit_post', $post->ID)) { return; } if (get_post_type() != $this->post_type) return; $wp_admin_bar->add_menu(array( 'parent' => 'edit', 'id' => 'edit_uxbuilder_product_layout', 'title' => 'Edit ' . get_the_title(str_replace('block_id_', '', $this->template_block_id)) . ' with UX Builder', 'href' => ux_builder_edit_url($post->ID, self::post_type_get_block_id($this->template_block_id)), )); }); } function post_type_archive_build_adminbar_link() { add_action('wp_before_admin_bar_render', function () { global $wp_admin_bar; if (!is_post_type_archive($this->post_type)) { return; } // find template_block_id $template_block_id = false; global $adminz; $post_type_archive_template = $adminz['Flatsome']->settings['post_type_archive_template'] ?? []; foreach ((array) $post_type_archive_template as $key => $value) { if ($value['key'] == $this->post_type) { $template_block_id = $value['value']; break; } } if ($template_block_id) { $template_block_id = self::post_type_get_block_id($template_block_id); $wp_admin_bar->add_menu(array( 'parent' => 'edit', 'id' => 'edit_uxbuilder_archive', 'title' => 'Edit ' . get_the_title($template_block_id) . ' with UX Builder', 'href' => ux_builder_edit_url($template_block_id), )); } }); } function taxonomy_build_template() { if (!$this->taxonomy) { return; } $filter_name = 'taxonomy_template'; if ($this->taxonomy == 'category') { $filter_name = 'category_template'; } add_filter($filter_name, function ($template, $type, $templates) { $queried_object = get_queried_object(); if (($queried_object->taxonomy ?? '') == $this->taxonomy) { // find template_block_id $template_block_id = false; global $adminz; $taxonomy_layout_support = $adminz['Flatsome']->settings['taxonomy_layout_support'] ?? []; foreach ((array) $taxonomy_layout_support as $key => $value) { if ($value['key'] == $queried_object->taxonomy) { $template_block_id = $value['value']; break; } } if ($template_block_id = self::post_type_get_block_id($template_block_id)) { $key = 'adminz_fl_term_block_id_' . $queried_object->term_id; $GLOBALS[$key] = $template_block_id; // save block id to global $source = $this->source; $source = $source ? $source : 'index.php'; $template = ADMINZ_DIR . "includes/file/flatsome_taxonomy_templates/" . $source; } } return $template; }, 10, 3); } function post_id_layout_build_template() { if (!$this->post_id) { return; } add_filter('template_include', function ($template) { if (get_the_ID() == $this->post_id) { // find template_block_id $template_block_id = false; global $adminz; $post_id_template = $adminz['Flatsome']->settings['post_id_template'] ?? []; foreach ((array)$post_id_template as $key => $value) { if ($value['key'] == $this->post_id) { $template_block_id = $value['value']; break; } } if ($template_block_id = self::post_id_get_block_id($template_block_id)) { $key = 'adminz_fl_single_block_id_' . get_the_ID(); $GLOBALS[$key] = $template_block_id; } // $source = $this->source; $source = $source ? $source : 'index.php'; $template = ADMINZ_DIR . "includes/file/flatsome_post_id_templates/" . $source; } return $template; }, 10); } function post_type_layout_build_template() { add_filter('single_template', function ($template, $type, $templates) { if (is_single() && get_post_type() == $this->post_type) { // find template_block_id $template_block_id = false; global $adminz; $post_type_template = $adminz['Flatsome']->settings['post_type_template'] ?? []; foreach ((array)$post_type_template as $key => $value) { if ($value['key'] == $this->post_type) { $template_block_id = $value['value']; break; } } if ($template_block_id = self::post_type_get_block_id($template_block_id)) { $key = 'adminz_fl_single_block_id_' . get_the_ID(); $GLOBALS[$key] = $template_block_id; $source = $this->source; $source = $source ? $source : 'index.php'; $template = ADMINZ_DIR . "includes/file/flatsome_post_type_templates/" . $source; } } return $template; }, 10, 3); } function post_type_archive_build_template() { add_filter('archive_template', function ($template, $type, $templates) { if (is_post_type_archive($this->post_type)) { // find template_block_id $template_block_id = false; global $adminz; $post_type_archive_template = $adminz['Flatsome']->settings['post_type_archive_template'] ?? []; foreach ((array) $post_type_archive_template as $key => $value) { if ($value['key'] == $this->post_type) { $template_block_id = $value['value']; break; } } if ($template_block_id = self::post_type_get_block_id($template_block_id)) { $key = 'adminz_fl_archive_block_id_' . get_post_type(); $GLOBALS[$key] = $template_block_id; $source = $this->source; $source = $source ? $source : 'index.php'; $template = ADMINZ_DIR . "includes/file/flatsome_post_type_archive_templates/" . $source; } } return $template; }, 10, 3); } function save_custom_taxonomy_metabox($term_id) { if (isset($_POST['tax_template_block_id'])) { $custom_value = sanitize_text_field($_POST['tax_template_block_id']); update_term_meta($term_id, 'tax_template_block_id', $custom_value); } } function term_taxonomy_meta_box() { if (!$this->taxonomy) { return; } add_action("{$this->taxonomy}_add_form_fields", function () { ob_start(); ?>
Uxbuilder Layout Support - Taxonomy
Uxbuilder Layout Support - Taxonomy
'; echo '
'; echo '
Enabled by Administrator Z. Goto Tool/ Administratorz/ Flatsome/ Uxbuilder Layout Support
'; }, 'book', // Custom post type 'side', // Where to display the metabox (e.g., 'normal', 'side', 'advanced') 'default' // Priority ); }); // save metadata add_action('save_post', function ($post_id) use ($taxonomy) { if (get_post_type($post_id) == $this->post_type && current_user_can('edit_post', $post_id)) { if (isset($_POST['template_block_id'])) { $selected_block_id = sanitize_text_field($_POST['template_block_id']); update_post_meta($post_id, 'template_block_id', $selected_block_id); } } }); } public static function taxonomy_get_block_id($template_block_id) { $queried_object = get_queried_object(); // ghi đè giá trị if ($a = get_term_meta($queried_object->term_id, 'tax_template_block_id', true)) { $template_block_id = $a; } $a = str_replace('block_id_', '', $template_block_id); if ($a) { return $a; } return false; } // lấy block id theo setting từ options public static function post_id_get_block_id($template_block_id) { $return = (int) $template_block_id; global $post; // update_post_meta($post_id, 'template_block_id', $selected_block_id); if ($meta = get_post_meta($post->ID, 'template_block_id', true)) { $return = $meta; return $return; } // $_value = "taxonomy_".$_tax; if (strpos($template_block_id, "taxonomy_") === 0) { $taxonomy = str_replace("taxonomy_", "", $template_block_id); $_terms = wp_get_post_terms($post->ID, $taxonomy); $_terms = array_reverse($_terms); if (!empty($_terms) and is_array($_terms)) { foreach ($_terms as $kt => $term) { //update_term_meta($term_id, $taxonomy.'_block_id', $_POST[$taxonomy.'_block_id']); if ($_block_id = get_term_meta($term->term_id, $taxonomy . '_block_id', true)) { $return = $_block_id; return $return; } } } } // $_value = "block_id_".$block_id; if (strpos($template_block_id, "block_id_") === 0) { $return = str_replace("block_id_", "", $template_block_id); return $return; } return $return; } // lấy block id theo setting từ options public static function post_type_get_block_id($template_block_id) { $return = (int) $template_block_id; global $post; // update_post_meta($post_id, 'template_block_id', $selected_block_id); if ($meta = get_post_meta($post->ID, 'template_block_id', true)) { $return = $meta; return $return; } // $_value = "taxonomy_".$_tax; if (strpos($template_block_id, "taxonomy_") === 0) { $taxonomy = str_replace("taxonomy_", "", $template_block_id); $_terms = wp_get_post_terms($post->ID, $taxonomy); $_terms = array_reverse($_terms); if (!empty($_terms) and is_array($_terms)) { foreach ($_terms as $kt => $term) { //update_term_meta($term_id, $taxonomy.'_block_id', $_POST[$taxonomy.'_block_id']); if ($_block_id = get_term_meta($term->term_id, $taxonomy . '_block_id', true)) { $return = $_block_id; return $return; } } } } // $_value = "block_id_".$block_id; if (strpos($template_block_id, "block_id_") === 0) { $return = str_replace("block_id_", "", $template_block_id); return $return; } return $return; } }