Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,408 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
use TCB\Lightspeed\Css;
use TCB\Lightspeed\JS;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class TCB_Symbol_Template
*/
class TCB_Symbol_Template {
/**
* Symbols regular expression it matches the symbols config
*/
const SYMBOL_CONFIG_REGEX = '/__CONFIG_post_symbol__{[^\d]*(\d*)[^}]*}__CONFIG_post_symbol__/';
/**
* Symbols regular expression it matches the symbols shortcode
*/
const SYMBOL_SHORTCODE_REGEX = '/thrive_symbol id=\'(\d*)\'/';
private static $instances = [];
private static $exportable_meta = [
'tve_updated_post',
'tve_custom_css',
'tve_globals',
];
/**
* @param $symbol_id
*
* @return TCB_Symbol_Template
*/
public static function get_instance( $symbol_id = null ) {
if ( empty( self::$instances[ $symbol_id ] ) ) {
self::$instances[ $symbol_id ] = new self( $symbol_id );
}
return self::$instances[ $symbol_id ];
}
public function __construct( $symbol_id ) {
$this->ID = (int) $symbol_id;
$this->post = get_post( $symbol_id );
}
/**
* Stores symbol types that contain states
*
* @var string[]
*/
public static $symbol_with_states = [ 'header' ];
/**
* Render the symbol content
*
* @param array $config
* @param bool $do_shortcodes
*
* @return mixed|string
*/
public static function render_content( $config = [], $do_shortcodes = false ) {
static::enter_symbol_render();
$symbol_id = ( ! empty( $config ) && isset( $config['id'] ) ) ? $config['id'] : get_the_ID();
$content = static::content( $symbol_id );
/* prepare Events configuration */
tve_parse_events( $content );
/**
* Filter that allows skipping `do_shortcode` in various cases. Example: when exporting a symbol, do_shortcode should NOT be called,
* even though `wp_doing_ajax() === true`
*
* @param bool $do_shortcodes initial value
* @param int $symbol_id current symbol ID
* @param array $config configuration object passed to the method
*
* @return bool whether or not it should execute the shortcode functions
*/
$do_shortcodes = apply_filters( 'tcb_symbol_do_shortcodes', wp_doing_ajax() || $do_shortcodes, $symbol_id, $config );
if ( $do_shortcodes ) {
$content = shortcode_unautop( $content );
$GLOBALS['symbol_id'] = $symbol_id;
$content = do_shortcode( $content );
unset( $GLOBALS['symbol_id'] );
//apply thrive shortcodes
$keep_config = isset( $config['tve_shortcode_config'] ) ? $config['tve_shortcode_config'] : true;
$content = tve_thrive_shortcodes( $content, $keep_config );
/* render the content added through WP Editor (element: "WordPress Content") */
$content = tve_do_wp_shortcodes( $content, is_editor_page() );
}
/**
* This only needs to be executed on frontend. Do not execute it in the editor page or when ajax-loading the symbols in the editor
*/
if ( ! is_editor_page() && ! wp_doing_ajax() ) {
$content = tve_restore_script_tags( $content );
/**
* IF yoast is active do not store the parsed styles in the global cache - it will mess up the post queries
*/
$yoast_seo_active = is_plugin_active( 'wordpress-seo/wp-seo.php' );
$content = tve_get_shared_styles( $content, '', true, ! $yoast_seo_active ) . $content;
//Removes the color palette configuration code from the symbol in frontend
$content = tcb_clean_frontend_content( $content );
//if it has custom icons make sure that font family is loaded
if ( tve_get_post_meta( $symbol_id, 'thrive_icon_pack' ) ) {
TCB_Icon_Manager::enqueue_icon_pack();
}
}
$content = apply_filters( 'tcb_symbol_template', $content );
$content = preg_replace( '!\s+!', ' ', $content );
static::exit_symbol_render();
return $content;
}
/**
* Include the start of the html content
*/
public static function body_open() {
include TVE_TCB_ROOT_PATH . 'inc/views/symbols/symbol-body-open.php';
}
/**
* Include the end of the html content
*/
public static function body_close() {
include TVE_TCB_ROOT_PATH . 'inc/views/symbols/symbol-body-close.php';
}
/**
* Get the content from the symbol
*
* @param int $symbol_id
*
* @return mixed|string
*/
public static function content( $symbol_id ) {
$content = get_post_meta( (int) $symbol_id, 'tve_updated_post', true );
return apply_filters( 'tcb_symbol_content', $content );
}
/**
* Get css for symbol
*
* @param $config
*
* @return string
*/
public static function tcb_symbol_get_css( $config ) {
$symbol_id = ( ! empty( $config ) && isset( $config['id'] ) ) ? $config['id'] : 0;
$css = "<style class='tve-symbol-custom-style'>" . static::css( $symbol_id ) . '</style>';
$lightspeed = Css::get_instance( $symbol_id );
if ( $lightspeed->should_load_optimized_styles() ) {
$css = $lightspeed->get_optimized_styles() . $css;
} else {
Css::enqueue_flat();
}
return $css;
}
/**
* Get the css for a symbol
*
* @param int $id
*
* @return mixed|string
*/
public static function css( $id ) {
$css = trim( get_post_meta( (int) $id, 'tve_custom_css', true ) );
$css = TCB\Lightspeed\Fonts::parse_google_fonts( $css );
/* If we want to change the symbol css just before is being inserted in the page */
$css = apply_filters( 'tcb_symbol_css_before', $css, $id );
return tve_prepare_global_variables_for_front( $css );
}
/**
* @param $symbol_type
*
* @return string
*/
public static function symbol_state_class( $symbol_type ) {
$cls = '';
if ( in_array( $symbol_type, static::$symbol_with_states, true ) ) {
$cls = 'tve-default-state';
}
return $cls;
}
/**
* Render symbol shortcode content
*
* @param array $config
* @param boolean $wrap
*
* @return string
*/
public static function symbol_render_shortcode( $config, $wrap = false ) {
$content = '';
if ( ! empty( $config['id'] ) ) {
$symbol_id = $config['id'];
$post = get_post( $symbol_id );
if ( $post instanceof WP_Post && $post->post_status === 'publish' ) {
$content = static::render_content( $config, $wrap );
$css = static::tcb_symbol_get_css( $config );
$type = substr( TCB_Symbols_Taxonomy::get_symbol_type( $symbol_id ), 0, - 1 );
$js_modules = '';
if ( TCB_Utils::is_rest() || wp_doing_ajax() ) {
/* we should return this inline when we retrieve the symbol with ajax */
$js_modules = JS::get_instance( $symbol_id )->load_modules( true );
} else {
JS::get_instance( $symbol_id )->enqueue_scripts();
}
/**
* forcing this type allows knowing better whether is a gutenberg block
*/
if ( strpos( $type, 'gutenberg' ) !== false ) {
$type = 'gutenberg_block';
}
$shortcode_class = in_array( $type, static::$symbol_with_states, true ) ? 'tve-default-state' : '';
$name = is_editor_page_raw() ? ' data-name="' . esc_attr( $post->post_title ) . '"' : '';
$content = '<div class="thrive-shortcode-html thrive-symbol-shortcode ' . $shortcode_class . '"' . $name . static::data_attr( $symbol_id ) . '>' . $css . $js_modules . $content . '</div>';
if ( $wrap ) {
$extra_classes = get_post_meta( $symbol_id, 'tve_extra_class', true );
$classes = array( 'thrv_wrapper', 'thrv_symbol', 'thrive-shortcode', "thrv_$type", 'tve_no_drag', "thrv_symbol_$symbol_id", $extra_classes, static::symbol_state_class( $type ) );
$content = TCB_Utils::wrap_content( $content, 'div', "thrive-$type",
$classes,
array(
'data-id' => $symbol_id,
'data-selector' => ".thrv_symbol_$symbol_id",
'data-shortcode' => "thrive_$type",
'data-tcb-elem-type' => $type,
'data-element-name' => ucfirst( $type ),
) );
}
}
}
return $content;
}
/**
* Check if a symbol is rendering right now
*
* @return bool
*/
public static function is_outside_symbol_render() {
return empty( $GLOBALS[ TCB_RENDERING_SYMBOL ] );
}
/**
* Mark that we started rendering a symbol
*/
public static function enter_symbol_render() {
$GLOBALS[ TCB_RENDERING_SYMBOL ] = true;
}
/**
* Mark that we finished rendering a symbol
*/
public static function exit_symbol_render() {
$GLOBALS[ TCB_RENDERING_SYMBOL ] = false;
}
/**
* Return class for symbol element on it's page
*
* @return array
*/
public static function get_edit_symbol_vars() {
$type = TCB_Symbols_Taxonomy::get_symbol_type( get_the_ID() );
$is_hf = $type === 'headers' || $type === 'footers';
if ( $is_hf ) {
$type = substr( $type, 0, - 1 );
}
return [
'css_class' => $is_hf ? 'thrv_' . $type : '',
'type' => $type,
];
}
public static function data_attr( $symbol_id ) {
$globals = get_post_meta( $symbol_id, 'tve_globals', true );
if ( empty( $globals ) ) {
$globals = [];
}
/**
* backwards compat stuff
*/
if ( ! isset( $globals['data-tve-scroll'] ) ) {
$scroll_behaviour = get_post_meta( $symbol_id, 'tcb_scroll_behaviour', true );
if ( $scroll_behaviour ) {
if ( $scroll_behaviour !== 'static' ) {
$globals['data-tve-scroll'] = json_encode( [
'disabled' => [],
'mode' => $scroll_behaviour === 'scroll_up' ? 'appear' : 'sticky',
] );
update_post_meta( $symbol_id, 'tve_globals', $globals );
}
delete_post_meta( $symbol_id, 'tcb_scroll_behaviour' );
}
}
$attr = ' data-symbol-id="' . (int) $symbol_id . '"';
foreach ( $globals as $k => $value ) {
if ( strncmp( $k, 'data-', 5 ) === 0 ) {
$attr .= ' ' . $k . '="' . esc_attr( $value ) . '"';
}
}
return $attr;
}
/**
* Create new symbol based on import data
*
* @param array $data
* @param string $section_type
*
* @return int|WP_Error
*/
public static function import( $data, $section_type = null ) {
$symbol_id = wp_insert_post( [
'post_title' => sanitize_title( $data['post_title'] ) . ' ' . __( '(Imported)', 'thrive-cb' ) . '#' . mt_rand( 0, 10000 ),
'post_type' => TCB_Symbols_Post_Type::SYMBOL_POST_TYPE,
'post_status' => 'publish',
'meta_input' => $data['meta_input'],
] );
if ( ! empty( $data['ID'] ) ) {
$css = $data['meta_input']['tve_custom_css'];
/* replace the old selector with the new one */
$css = str_replace( 'thrv_symbol_' . $data['ID'], 'thrv_symbol_' . $symbol_id, $css );
update_post_meta( $symbol_id, 'tve_custom_css', $css );
}
if ( $section_type !== null ) {
wp_set_object_terms( $symbol_id, [ $section_type . 's' ], TCB_Symbols_Taxonomy::SYMBOLS_TAXONOMY, true );
}
return $symbol_id;
}
/**
* Export symbol data
*
* @return array
*/
public function export() {
$data = [
'ID' => $this->ID,
'post_title' => $this->post->post_title,
'meta_input' => [],
];
foreach ( static::$exportable_meta as $key ) {
$data['meta_input'][ $key ] = get_post_meta( $this->ID, $key, true );
}
return $data;
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package TCB2.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
/**
* Class TCB_Symbols_Block
*/
class TCB_Symbols_Block {
const NAME = 'architect-block';
static public function init() {
if ( static::can_use_blocks() ) {
TCB_Symbols_Block::hooks();
TCB_Symbols_Block::register_block();
}
}
static public function can_use_blocks() {
return function_exists( 'register_block_type' );
}
static public function hooks() {
global $wp_version;
add_filter( version_compare( $wp_version, '5.7.9', '>' ) ? 'block_categories_all' : 'block_categories', [ __CLASS__, 'register_block_category' ], 10, 2 );
}
static public function register_block() {
$asset_file = include TVE_TCB_ROOT_PATH . 'blocks/build/block.asset.php';
// Register our block script with WordPress
wp_register_script( 'tar-block-editor', TVE_EDITOR_URL . 'blocks/build/block.js', $asset_file['dependencies'], $asset_file['version'], false );
register_block_type(
'thrive/' . self::NAME,
array(
'render_callback' => 'TCB_Symbols_Block::render_block',
'editor_script' => 'tar-block-editor',
'editor_style' => 'tar-block-editor',
)
);
wp_localize_script( 'tar-block-editor', 'TAR_Block',
array(
'block_preview' => tve_editor_url() . '/admin/assets/images/block-preview.png',
)
);
}
static public function render_block( $attributes ) {
if ( isset( $attributes['selectedBlock'] ) && ! is_admin() ) {
return TCB_Symbol_Template::symbol_render_shortcode( [
'id' => $attributes['selectedBlock'],
], true );
}
return '';
}
static public function register_block_category( $categories, $post ) {
$category_slugs = wp_list_pluck( $categories, 'slug' );
return in_array( 'thrive', $category_slugs, true ) ? $categories : array_merge(
array(
array(
'slug' => 'thrive',
'title' => __( 'Thrive Library', 'thrive-cb' ),
'icon' => '',
),
),
$categories
);
}
}

View File

@@ -0,0 +1,130 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class TCB_Symbols_Dashboard
*/
class TCB_Symbols_Dashboard {
/**
* @var string
*/
private $_symbols_dashboard_page = 'tcb_symbols_dashboard';
private $_tcb_admin_dashboard = 'tcb_admin_dashboard';
/**
* Setup everything for the symbols dashboard
*
* TCB_Symbols_Dashboard constructor.
*/
public function __construct() {
$this->hooks();
$this->includes();
}
public function includes() {
}
/**
* Hooks used for the symbol dashboard
*/
public function hooks() {
//add dashboard page so we can access it
add_action( 'admin_menu', [ $this, 'admin_menu' ] );
//add symbols card in thrive dashboard
add_action( 'current_screen', [ $this, 'dash_features' ] );
}
/**
* Add symbols card in thrive dashboard
*/
public function dash_features() {
/**
* if screen = main dashboard then enable and display the feature
*/
if ( tve_get_current_screen_key() === 'toplevel_page_tve_dash_section' ) {
add_filter( 'tve_dash_filter_features', [ $this, 'admin_symbols_feature' ] );
add_filter( 'tve_dash_features', [ $this, 'admin_enable_feature' ] );
}
}
/**
* Add new feature ( card ) to thrive dashboard
*
* @param array $features
*
* @return mixed
*/
public function admin_symbols_feature( $features ) {
if ( tcb_has_external_cap() ) {
$features['symbols_manager'] = array(
'icon' => 'tvd-ct-symbols-icon',
'title' => __( 'Global Elements', 'thrive-cb' ),
'description' => __( 'Create and manage templates, symbols, notification toasts, headers and footers', 'thrive-cb' ),
'btn_link' => add_query_arg( 'page', $this->_tcb_admin_dashboard . '#templatessymbols', admin_url( 'admin.php' ) ),
'btn_text' => __( 'Manage Global Elements', 'thrive-cb' ),
);
}
return $features;
}
/**
* Enable feature ( card ) in thrive dashboard
*
* @param array $features
*
* @return mixed
*/
public function admin_enable_feature( $features ) {
$features['symbols_manager'] = true;
return $features;
}
/**
* Create page for symbols dashboard
*/
public function admin_menu() {
add_submenu_page( '', __( 'Symbols', 'thrive-cb' ), __( 'Symbols', 'thrive-cb' ), tcb_has_external_cap( true ), $this->_symbols_dashboard_page, [
$this,
'admin_symbols_dashboard',
] );
}
/**
* Include the file for the symbols dashboard
*/
public function admin_symbols_dashboard() {
include TVE_TCB_ROOT_PATH . 'inc/views/symbols/symbols-dashboard.php';
}
}
global $tcb_symbol_dashboard;
/**
* Main instance of TCB Symbols Dashboard
*
* @return TCB_Symbols_Dashboard
*/
function tcb_symbol_dashboard() {
global $tcb_symbol_dashboard;
if ( ! $tcb_symbol_dashboard ) {
$tcb_symbol_dashboard = new TCB_Symbols_Dashboard();
}
return $tcb_symbol_dashboard;
}
tcb_symbol_dashboard();

View File

@@ -0,0 +1,200 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class TCB_Symbols_Post_Type
*/
class TCB_Symbols_Post_Type {
/**
* Symbol custom post type
*/
const SYMBOL_POST_TYPE = 'tcb_symbol';
/**
* The folder where to save the thumbnails ( previews )
*/
const SYMBOL_THUMBS_FOLDER = 'symbols';
/**
* Symbol template file
*
* @var string
*/
private $_template = 'symbol-content.php';
/**
* Section template file ( header or footer )
*
* @var string
*/
private $_section_template = 'section-content.php';
/**
* TCB_Symbols_Post_Type constructor.
*/
public function __construct() {
$this->init();
}
/**
* Adds action for register another post type
*/
public function init() {
add_action( 'init', [ $this, 'add_symbol_post_type' ], 5 );
add_filter( 'tcb_custom_post_layouts', [ $this, 'symbol_layout' ], 10, 3 );
add_filter( 'tcb_post_types', [ $this, 'edit_symbol_post_type' ], 10, 3 );
add_filter( 'thrive_theme_allow_body_class', [ $this, 'theme_body_class' ], 99, 1 );
add_filter( 'tve_dash_exclude_post_types_from_index', [ $this, 'exclude_from_index' ] );
}
/**
* Register symbol post type
*/
public function add_symbol_post_type() {
if ( post_type_exists( self::SYMBOL_POST_TYPE ) ) {
return;
}
register_post_type( self::SYMBOL_POST_TYPE, array(
'publicly_queryable' => true,
'public' => true,
'query_var' => false,
'description' => __( 'Thrive Symbol', 'thrive-cb' ),
'rewrite' => false,
'labels' => array(
'name' => __( 'Thrive Symbols', 'thrive-cb' ),
'singular_name' => __( 'Thrive Symbol', 'thrive-cb' ),
'add_new_item' => __( 'Add New Thrive Symbol', 'thrive-cb' ),
'edit_item' => __( 'Edit Thrive Symbol', 'thrive-cb' ),
),
'show_in_nav_menus' => false,
'show_in_menu' => false,
'exclude_from_search' => true,
'show_in_rest' => true,
'has_archive' => false,
'_edit_link' => 'post.php?post=%d',
'map_meta_cap' => true,
'capabilities' => [
'edit_others_posts' => TVE_DASH_EDIT_CPT_CAPABILITY,
'edit_published_posts' => TVE_DASH_EDIT_CPT_CAPABILITY,
],
) );
/**
* We need to include frontend scripts if the user wants to edit a symbol when he has a product with TAR( TL, TQB, etc ) and TAR is inactive or not installed
*/
if ( ! has_action( 'wp_enqueue_scripts', 'tve_frontend_enqueue_scripts' ) ) {
add_action( 'wp_enqueue_scripts', 'tve_frontend_enqueue_scripts' );
}
}
/**
* Edit symbols when TAR is inactive and the user has products with TAR capabilities ( TL, TQB, TU, etc )
*
* @param $post_types
*
* @return mixed
*/
public function edit_symbol_post_type( $post_types ) {
if ( isset( $post_types['force_whitelist'] ) ) {
$post_types['force_whitelist'][] = self::SYMBOL_POST_TYPE;
}
return $post_types;
}
/**
* Render symbol layout
*
* @param array $layouts
* @param int $post_id
* @param string $post_type
*
* @return mixed
*/
public function symbol_layout( $layouts, $post_id, $post_type ) {
if ( $post_type === self::SYMBOL_POST_TYPE ) {
//added here to prevent google indexing
if ( ! is_user_logged_in() || ! TCB_Product::has_post_access( $post_id ) ) {
wp_redirect( home_url() );
exit();
}
$type = TCB_Symbols_Taxonomy::get_symbol_type( get_the_ID() );
$template = ( $type === 'headers' || $type === 'footers' ) ? $this->_section_template : $this->_template;
$file_path = TVE_TCB_ROOT_PATH . 'inc/views/symbols/' . $template;
if ( ! is_file( $file_path ) ) {
return $layouts;
}
$layouts['symbol_template'] = $file_path;
}
return $layouts;
}
/**
* Prevent adding ttb classes while editing symbols
*
* @param $allow_theme_classes
*
* @return false
*/
public function theme_body_class( $allow_theme_classes ) {
$post_type = get_post_type();
if ( self::SYMBOL_POST_TYPE === $post_type ) {
$allow_theme_classes = false;
}
return $allow_theme_classes;
}
/**
* Remove symbols from google index
*
* @param $post_types
*
* @return mixed
*/
public function exclude_from_index( $post_types ) {
$post_types[] = static::SYMBOL_POST_TYPE;
return $post_types;
}
}
global $tcb_symbol;
/**
* Main instance of TCB Symbols Post Type
*
* @return TCB_Symbols_Post_Type
*/
function tcb_symbol() {
global $tcb_symbol;
if ( ! $tcb_symbol ) {
$tcb_symbol = new TCB_Symbols_Post_Type();
}
return $tcb_symbol;
}
tcb_symbol();

View File

@@ -0,0 +1,208 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
class TCB_Symbols_Taxonomy {
const SYMBOLS_TAXONOMY = 'tcb_symbols_tax';
private $_default_terms;
public function __construct() {
$this->init();
}
public function init() {
add_action( 'init', [ $this, 'register_symbols_tax' ] );
add_filter( 'tcb_main_frame_localize', [ $this, 'terms_localization' ] );
}
public function register_symbols_tax() {
$tax_labels = $this->get_labels();
register_taxonomy( self::SYMBOLS_TAXONOMY, [ TCB_Symbols_Post_Type::SYMBOL_POST_TYPE ], [
'hierarchical' => true,
'labels' => $tax_labels,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => [ 'slug' => 'tcb_symbol' ],
'show_in_rest' => true,
] );
register_taxonomy_for_object_type( self::SYMBOLS_TAXONOMY, TCB_Symbols_Post_Type::SYMBOL_POST_TYPE );
$this->insert_default_terms();
}
public function insert_default_terms() {
$terms = [ 'Headers', 'Footers', 'Gutenberg block' ];
foreach ( $terms as $term ) {
$exists = term_exists( $term, self::SYMBOLS_TAXONOMY );
if ( $exists !== 0 && $exists !== null ) {
$term_id = $exists['term_id'];
} else {
$term_insert = wp_insert_term( $term, TCB_Symbols_Taxonomy::SYMBOLS_TAXONOMY );
if ( ! is_wp_error( $term_insert ) ) {
$term_id = $term_insert['term_id'];
}
}
if ( isset( $term_id ) ) {
$this->add_default_term( $term_id );
}
}
}
public function get_default_terms() {
//take only h&f because others can be deleted in time
return array_splice( $this->_default_terms, 0, 2 );
}
public function add_default_term( $term_id ) {
$this->_default_terms[] = $term_id;
}
public function get_labels() {
$default_labels = array(
'name' => __( 'Symbols', 'thrive-cb' ),
'singular_name' => __( 'Symbol', 'thrive-cb' ),
'search_items' => __( 'Search Symbols', 'thrive-cb' ),
'all_items' => __( 'All Symbols', 'thrive-cb' ),
'parent_item' => __( 'Parent Symbol', 'thrive-cb' ),
'parent_item_colon' => __( 'Parent Symbol', 'thrive-cb' ),
'edit_item' => __( 'Edit Symbol', 'thrive-cb' ),
'update_item' => __( 'Update Symbol', 'thrive-cb' ),
'add_new_item' => __( 'Add New Symbol', 'thrive-cb' ),
'new_item_name' => __( 'New Symbol Name', 'thrive-cb' ),
'menu_name' => __( 'Symbols', 'thrive-cb' ),
);
return apply_filters( 'tcb_symbols_tax_labels', $default_labels );
}
/**
* Get the symbols taxonomies split by the fact if they are tax for sections or for normal symbols
*
* @param bool $show_tax_terms
*
* @return array|int|WP_Error
*/
public function get_symbols_tax_terms( $show_tax_terms = false ) {
$result = [];
$section_terms = [];
$terms = get_terms( [
'order' => 'DESC',
'orderby' => 'term_id',
'taxonomy' => self::SYMBOLS_TAXONOMY,
'hide_empty' => false,
] );
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->name, [ 'Headers', 'Footers' ] ) ) {
$result[] = $term;
} else {
$section_terms[] = $term;
}
}
if ( $show_tax_terms ) {
return $section_terms;
}
return $result;
}
/**
* Add categories to localization for tcb editor
*
* @param array $data
*
* @return mixed
*/
public function terms_localization( $data ) {
$data['symbols_tax_terms'] = $this->get_symbols_tax_terms();
$data['sections_tax_terms'] = $this->get_symbols_tax_terms( true );
$data['symbols_rest_terms'] = rest_url( sprintf( '%s/%s', 'wp/v2', self::SYMBOLS_TAXONOMY ) );
$data['symbols_rest_nonce'] = TCB_Utils::create_nonce();
$data['symbol_type'] = static::get_symbol_type( get_the_ID() );
return $data;
}
/**
* Get symbol type based on the category
*
* @param $symbol_id
*
* @return bool
*/
public static function get_symbol_type( $symbol_id = 0 ) {
$type = false;
if ( ! empty( $symbol_id ) ) {
$terms = get_the_terms( $symbol_id, self::SYMBOLS_TAXONOMY );
if ( ! empty( $terms ) ) {
$type = $terms[0]->slug;
}
}
return $type;
}
/**
* Returns a term id by name from the symbols taxonomy
*
* @param string $slug
*
* @return int
*/
public static function get_term_id( $slug ) {
$term = get_term_by( 'slug', $slug, static::SYMBOLS_TAXONOMY );
return ( $term ) ? $term->term_id : 0;
}
/**
* Add symbol to taxonomy
*
* @param int $id
* @param string $tax_slug
*/
public static function add_to_tax( $id, $tax_slug ) {
$term_id = static::get_term_id( $tax_slug );
wp_set_post_terms( $id, [ $term_id ], TCB_Symbols_Taxonomy::SYMBOLS_TAXONOMY );
}
}
global $tcb_symbol_taxonomy;
/**
* Main instance of TCB Symbols Dashboard
*
* @return TCB_Symbols_Taxonomy
*/
function tcb_symbol_taxonomy() {
global $tcb_symbol_taxonomy;
if ( ! $tcb_symbol_taxonomy ) {
$tcb_symbol_taxonomy = new TCB_Symbols_Taxonomy();
}
return $tcb_symbol_taxonomy;
}
tcb_symbol_taxonomy();