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,164 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\UserTemplates;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
trait Has_Post_Type {
/**
* @var string[]
*/
public static $meta_key_list = [ 'name', 'content', 'type', 'css', 'media_css', 'thumb' ];
/**
* @return string
*/
public static function get_post_type_name() {
/**
* Allow other plugins to save templates under a different post type
*
* Used in ThriveApprentice when saving Certificate template
*
* @param string $post_type
*/
return apply_filters( 'tcb_user_templates_get_post_type_name', 'tve_user_template' );
}
/**
* @return string
*/
public static function get_post_type_prefix() {
return 'template_';
}
/**
* @return string|void
*/
public static function get_post_title() {
return __( 'User template', 'thrive-cb' );
}
public static function register_post_type() {
register_post_type( static::get_post_type_name(), [
'public' => isset( $_GET[ TVE_EDITOR_FLAG ] ),
'publicly_queryable' => is_user_logged_in(),
'query_var' => false,
'exclude_from_search' => true,
'rewrite' => false,
'_edit_link' => 'post.php?post=%d',
'map_meta_cap' => true,
'label' => static::get_post_title(),
'capabilities' => [
'edit_others_posts' => 'tve-edit-cpt',
'edit_published_posts' => 'tve-edit-cpt',
],
'show_in_nav_menus' => false,
'show_in_menu' => false,
'show_in_rest' => true,
'has_archive' => false,
] );
}
/**
* @param array $args
*
* @return int[]|\WP_Post[]
*/
public static function get_posts( $args = [] ) {
$default_args = [
'post_type' => static::get_post_type_name(),
'posts_per_page' => - 1,
'order' => 'ASC',
];
return get_posts( array_merge( $default_args, $args ) );
}
/**
* @return array
*/
public function get_post_data() {
if ( empty( get_post( $this->ID ) ) ) {
return [];
}
$category_id = wp_get_post_terms( $this->ID, static::get_taxonomy_name(), [ 'fields' => 'ids' ] );
$post_data = [
'id' => $this->ID,
'is_migrated' => get_post_meta( $this->ID, 'is_migrated', true ),
'id_category' => empty( $category_id ) || ! is_array( $category_id ) ? '' : $category_id[0],
'is_imported' => get_post_meta( $this->ID, 'tve_kit_imported', true ) //whether or not the template is from ImportContent/Design Pack
];
foreach ( static::$meta_key_list as $meta_key ) {
$post_data[ $meta_key ] = get_post_meta( $this->ID, static::get_post_type_prefix() . $meta_key, true );
}
return $post_data;
}
/**
* @param array $data
* @param bool $is_migrated
*
* @return int|\WP_Error
*/
public static function insert_post( $data, $is_migrated = false ) {
$meta_input = [];
foreach ( static::$meta_key_list as $meta_key ) {
$meta_input[ static::get_post_type_prefix() . $meta_key ] = $data[ $meta_key ];
}
if ( $is_migrated ) {
$meta_input['is_migrated'] = 1;
}
$post_id = wp_insert_post( [
'post_title' => static::get_post_title(),
'post_type' => static::get_post_type_name(),
'post_status' => 'publish',
'meta_input' => $meta_input,
] );
$category_id = empty( $data['id_category'] ) ? '' : $data['id_category'];
wp_set_object_terms( $post_id, Category::normalize_category_id( $category_id ), Category::get_taxonomy_name() );
return $post_id;
}
/**
* @param $data
*/
public function update_post( $data ) {
foreach ( static::$meta_key_list as $meta_key ) {
if ( isset( $data[ $meta_key ] ) ) {
update_post_meta( (int) $this->ID, static::get_post_type_prefix() . $meta_key, $data[ $meta_key ] );
}
}
if ( isset( $data['id_category'] ) ) {
wp_set_object_terms( (int) $this->ID, Category::normalize_category_id( $data['id_category'] ), Category::get_taxonomy_name() );
}
}
/**
* @param $name
*/
public function rename_post( $name ) {
update_post_meta( $this->ID, static::get_post_type_prefix() . 'name', $name );
}
public function delete_post() {
wp_delete_post( (int) $this->ID, true );
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\UserTemplates;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
trait Has_Preview {
/**
* @param array $image_file_data
* @param array $template
*
* @return array
*/
public static function upload_preview_image( $image_file_data, $template ) {
if ( ! function_exists( 'wp_handle_upload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
}
add_filter( 'upload_dir', 'tve_filter_upload_user_template_location' );
$preview_data = wp_handle_upload(
$image_file_data,
[
'action' => 'tcb_editor_ajax',
'unique_filename_callback' => sanitize_file_name( $template['name'] . '.png' ),
]
);
remove_filter( 'upload_dir', 'tve_filter_upload_user_template_location' );
return $preview_data;
}
/**
* @param string $image_file
*/
public static function resize_preview_image( $image_file ) {
$preview = wp_get_image_editor( $image_file );
if ( ! is_wp_error( $preview ) ) {
$preview->resize( static::get_resize_width(), null );
$preview->save( $image_file );
}
}
/**
* @param $name
*/
public static function delete_preview_image( $name ) {
/* black magic in case the name contains spaces */
$name = implode( '-', explode( ' ', $name ) );
$upload_dir = wp_upload_dir();
$file_name = $upload_dir['basedir'] . '/' . static::get_upload_dir_path() . '/' . $name . '.jpg';
@unlink( $file_name );
}
/**
* @return string
*/
public static function get_placeholder_url() {
return tve_editor_url( 'admin/assets/images/no-template-preview.jpg' );
}
/**
* @return array
*/
public static function get_placeholder_data() {
return [
'url' => static::get_placeholder_url(),
/* hardcoded sizes taken from 'no-template-preview.jpg' */
'h' => '120',
'w' => '250',
];
}
public static function get_resize_width() {
return 330;
}
public static function get_upload_dir_path() {
return 'thrive-visual-editor/user_templates';
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\UserTemplates;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
trait Has_Taxonomy {
/**
* @return string
*/
public static function get_taxonomy_name() {
return 'tve_user_template_category';
}
/**
* @return string
*/
public static function get_taxonomy_meta_key_prefix() {
return 'template_category_';
}
/**
* @return string|void
*/
public static function get_taxonomy_title() {
return __( 'User template category', 'thrive-cb' );
}
public static function register_taxonomy() {
register_taxonomy( static::get_taxonomy_name(), [ Template::get_post_type_name() ], [
'hierarchical' => false,
'show_ui' => false,
'show_in_nav_menus' => false,
'show_admin_column' => false,
'query_var' => false,
'show_in_rest' => false,
'public' => false,
] );
register_taxonomy_for_object_type( static::get_taxonomy_name(), Template::get_post_type_name() );
}
/**
* @return int[]|string|string[]|\WP_Error|\WP_Term[]
*/
public static function get_terms() {
return get_terms( [
'taxonomy' => static::get_taxonomy_name(),
'orderby' => 'id',
'hide_empty' => 0,
] );
}
/**
* @param $name
*
* @return array|int[]|\WP_Error
*/
public static function insert_term( $name ) {
return wp_insert_term( $name, static::get_taxonomy_name() );
}
/**
* @param $name
*/
public function rename_term( $name ) {
wp_update_term( $this->ID, static::get_taxonomy_name(), [ 'name' => $name ] );
}
public function delete_term() {
wp_delete_term( $this->ID, static::get_taxonomy_name() );
}
/**
* @param $key
*
* @return mixed
*/
public function get_meta( $key ) {
return get_term_meta( $this->ID, $key, true );
}
/**
* @param $key
* @param $value
*/
public function update_meta( $key, $value ) {
update_term_meta( $this->ID, $key, $value );
}
}