Cleanup: Remoción masiva de restos de WordPress y consolidación de archivos GKACHELE™
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Page editor control
|
||||
*
|
||||
* @package chromax
|
||||
* @since chromax 1.0
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WP_Customize_Control' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to create a custom tags control
|
||||
*/
|
||||
class Chromax_Page_Editor extends WP_Customize_Control {
|
||||
|
||||
/**
|
||||
* Flag to include sync scripts if needed
|
||||
*
|
||||
* @var bool|mixed
|
||||
*/
|
||||
private $needsync = false;
|
||||
|
||||
/**
|
||||
* Chromax_Page_Editor constructor.
|
||||
*
|
||||
* @param WP_Customize_Manager $manager Manager.
|
||||
* @param string $id Id.
|
||||
* @param array $args Constructor args.
|
||||
*/
|
||||
public function __construct( $manager, $id, $args = array() ) {
|
||||
parent::__construct( $manager, $id, $args );
|
||||
if ( ! empty( $args['needsync'] ) ) {
|
||||
$this->needsync = $args['needsync'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts
|
||||
*
|
||||
* @since 1.1.0
|
||||
* @access public
|
||||
* @updated Changed wp_enqueue_scripts order and dependencies.
|
||||
*/
|
||||
public function enqueue() {
|
||||
wp_enqueue_style( 'chromax_text_editor_css', get_template_directory_uri() . '/inc/customizer/controls/code/editor/css/chromax-page-editor.css', array(),'chromax');
|
||||
wp_enqueue_script(
|
||||
'chromax_text_editor', get_template_directory_uri() . '/inc/customizer/controls/code/editor/js/chromax-text-editor.js', array(
|
||||
'jquery',
|
||||
'customize-preview',
|
||||
),'chromax', true
|
||||
);
|
||||
if ( $this->needsync === true ) {
|
||||
wp_enqueue_script( 'chromax_controls_script', get_template_directory_uri() . '/inc/customizer/controls/code/editor/js/chromax-update-controls.js', array( 'jquery', 'chromax_text_editor' ),'chromax', true );
|
||||
wp_localize_script(
|
||||
'chromax_controls_script', 'requestpost', array(
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
'thumbnail_control' => 'chromax_feature_thumbnail', // name of image control that needs sync
|
||||
'editor_control' => 'Chromax_Page_Editor', // name of control (theme_mod) that needs sync
|
||||
'thumbnail_label' => esc_html__( 'About background', 'chromax' ), // name of thumbnail control
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the content on the theme customizer page
|
||||
*/
|
||||
public function render_content() {
|
||||
?>
|
||||
<label>
|
||||
<?php if ( ! empty( $this->label ) ) : ?>
|
||||
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
|
||||
<?php endif; ?>
|
||||
<input type="hidden" <?php $this->link(); ?> value="<?php echo esc_textarea( $this->value() ); ?>" id="<?php echo esc_attr( $this->id ); ?>" class="editorfield">
|
||||
<a onclick="javascript:WPEditorWidget.toggleEditor('<?php echo $this->id; ?>');" class="button edit-content-button"><?php _e( '(Edit)', 'chromax' ); ?></a>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*EDIT CONTENT CONTROL*/
|
||||
.button.edit-content-button,.edit-content-button{display:inline-flex;align-items:center;line-height:1;margin-bottom: 10px;}
|
||||
.edit-content-button:before{content: "\f464";opacity: 0.6;background-color: #ddd;padding: 8px;margin-left: -10px;margin-right: 7px;font-size: 18px;vertical-align: top;border-radius: 2px 0 0 2px;font-family: 'dashicons';}
|
||||
|
||||
/*--------------------------WIDGETS------------------------------------*/
|
||||
#wp-editor-widget-container{position:fixed;left:0;right:0;bottom:0;z-index:9999999;background:#f1f1f1;border-top:1px solid #ddd;}
|
||||
|
||||
|
||||
|
||||
@media screen and (min-width: 800px){
|
||||
#wp-editor-widget-container{
|
||||
left:300px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1667px){
|
||||
#wp-editor-widget-container{
|
||||
left:18%;
|
||||
}
|
||||
}
|
||||
|
||||
#wp-editor-widget-container .close{position:absolute;top:17px;right:7px;width:30px;height:30px;z-index:1000; text-decoration: none; opacity:0.4; text-align: center;}
|
||||
#wp-editor-widget-container .close{ opacity:0.7;}
|
||||
#wp-editor-widget-container .icon:after{font: 400 22px/45px dashicons; content: "\f335";color: #888;text-decoration: none!important; line-height: 30px}
|
||||
#wp-editor-widget-container .close:active{outline:0}
|
||||
#wp-editor-widget-container .editor{margin:50px}
|
||||
#available-widgets [class*=wp_editor_widget] .widget-title:before{content:"\f478"}
|
||||
|
||||
body.wp-customizer #wp-editor-widget-container{ bottom:-650px;}
|
||||
body.wp-customizer #wp-editor-widget-container.editoron{ bottom:0;}
|
||||
body.wp-customizer #wp-editor-widget-container .editor {margin: 10px; margin-top: 55px;}
|
||||
body.widgets_access .widget-position table tr:nth-child(3) {display: none;}
|
||||
|
||||
.customize-control .icons-selector .selector-category select,
|
||||
.customize-control .icons-selector .selector-search input[type=text] {
|
||||
line-height: 13px;
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector,
|
||||
.customize-control .icons-selector .selector {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selector {
|
||||
border: 1px solid #8c8f94;
|
||||
border-radius: 3px;
|
||||
height: 30px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selected-icon {
|
||||
width: 70%;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selected-icon i {
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selector-button {
|
||||
width: 28%;
|
||||
border-left: 1px solid #8c8f94;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selector-button i {
|
||||
line-height: 28px;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selector-popup {
|
||||
padding: 12px;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selector-arrows span,
|
||||
.customize-control .icons-selector .fip-box,
|
||||
.customize-control .icons-selector .selector-category select,
|
||||
.customize-control .icons-selector .selector-search input[type=text] {
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selector-pages {
|
||||
line-height: 14px;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selector-search i {
|
||||
top: 5px;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selector-arrows span i {
|
||||
width: auto;
|
||||
height: auto;
|
||||
line-height: 12px;
|
||||
}
|
||||
|
||||
.customize-control .icons-selector .selector-arrows span:hover i,
|
||||
.customize-control .icons-selector .fip-box:hover {
|
||||
color: #0073aa;
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* Sync functions for control.
|
||||
*
|
||||
* @package chromax
|
||||
* @since chromax 1.0
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Display editor for page editor control.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
function chromax_customize_editor() {
|
||||
?>
|
||||
<div id="wp-editor-widget-container" style="display: none;">
|
||||
<a class="close" href="javascript:WPEditorWidget.hideEditor();"><span class="icon"></span></a>
|
||||
<div class="editor">
|
||||
<?php
|
||||
$settings = array(
|
||||
'textarea_rows' => 55,
|
||||
'editor_height' => 260,
|
||||
);
|
||||
wp_editor( '', 'wpeditorwidget', $settings );
|
||||
?>
|
||||
<p><a href="javascript:WPEditorWidget.updateWidgetAndCloseEditor(true);" class="button button-primary"><?php _e( 'Save and close', 'chromax' ); ?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
add_action( 'customize_controls_print_footer_scripts', 'chromax_customize_editor', 1 );
|
||||
|
||||
/**
|
||||
* Sync frontpage content with customizer control
|
||||
*
|
||||
* @param string $value New value.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function chromax_sync_content_from_control( $value, $old_value = '' ) {
|
||||
$frontpage_id = get_option( 'page_on_front' );
|
||||
if ( ! empty( $frontpage_id ) && ! empty( $value ) ) {
|
||||
if ( ! wp_is_post_revision( $frontpage_id ) ) {
|
||||
|
||||
// update the post, which calls save_post again
|
||||
$post = array(
|
||||
'ID' => $frontpage_id,
|
||||
'post_content' => wp_kses_post( $value ),
|
||||
);
|
||||
|
||||
wp_update_post( $post );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
add_filter( 'pre_set_theme_mod_chromax_page_editor', 'chromax_sync_content_from_control', 10,2 );
|
||||
|
||||
|
||||
/**
|
||||
* Sync page thumbnail and content with customizer control
|
||||
*/
|
||||
function chromax_sync_control_from_page() {
|
||||
|
||||
$need_update = get_option( 'chromax_sync_needed' );
|
||||
if ( $need_update === false ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$frontpage_id = get_option( 'page_on_front' );
|
||||
if ( empty( $frontpage_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = get_post_field( 'post_content', $frontpage_id );
|
||||
set_theme_mod( 'Chromax_Page_Editor', $content );
|
||||
|
||||
$chromax_frontpage_featured = '';
|
||||
if ( has_post_thumbnail( $frontpage_id ) ) {
|
||||
$chromax_frontpage_featured = get_the_post_thumbnail_url( $frontpage_id );
|
||||
}
|
||||
set_theme_mod( 'chromax_feature_thumbnail', $chromax_frontpage_featured );
|
||||
|
||||
update_option( 'chromax_sync_needed', false );
|
||||
|
||||
}
|
||||
add_action( 'after_setup_theme', 'chromax_sync_control_from_page' );
|
||||
|
||||
|
||||
/**
|
||||
* Set flag to sync customizer control from page.
|
||||
*
|
||||
* @param string $post_id Post id.
|
||||
*/
|
||||
function chromax_trigger_sync( $post_id ) {
|
||||
if ( wp_is_post_revision( $post_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$frontpage_id = get_option( 'page_on_front' );
|
||||
if ( empty( $frontpage_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( intval( $post_id ) === intval( $frontpage_id ) ) {
|
||||
update_option( 'chromax_sync_needed' , true );
|
||||
};
|
||||
}
|
||||
add_action( 'save_post', 'chromax_trigger_sync', 10 );
|
||||
|
||||
/**
|
||||
* Sync frontpage thumbnail with customizer control
|
||||
*
|
||||
* @param string $value New value.
|
||||
* @param string $old_value Old value.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function chromax_sync_thumbnail_from_control( $value, $old_value ) {
|
||||
|
||||
$frontpage_id = get_option( 'page_on_front' );
|
||||
if ( ! empty( $frontpage_id ) ) {
|
||||
$thumbnail_id = attachment_url_to_postid( $value );
|
||||
update_post_meta( $frontpage_id, '_thumbnail_id', $thumbnail_id );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
add_filter( 'pre_set_theme_mod_chromax_feature_thumbnail', 'chromax_sync_thumbnail_from_control', 10, 2 );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Ajax call to sync page content and thumbnail when you switch to static frontpage
|
||||
*/
|
||||
function chromax_ajax_call() {
|
||||
$pid = $_POST['pid'];
|
||||
|
||||
$return_value = array();
|
||||
|
||||
$content = get_post_field( 'post_content', $pid );
|
||||
set_theme_mod( 'Chromax_Page_Editor', $content );
|
||||
|
||||
$chromax_frontpage_featured = '';
|
||||
if ( has_post_thumbnail( $pid ) ) {
|
||||
$chromax_frontpage_featured = get_the_post_thumbnail_url( $pid );
|
||||
}
|
||||
set_theme_mod( 'chromax_feature_thumbnail', $chromax_frontpage_featured );
|
||||
|
||||
$return_value['post_content'] = $content;
|
||||
$return_value['post_thumbnail'] = $chromax_frontpage_featured;
|
||||
echo json_encode( $return_value );
|
||||
|
||||
die();
|
||||
}
|
||||
add_action( 'wp_ajax_chromax_ajax_call', 'chromax_ajax_call' );
|
||||
|
||||
/**
|
||||
* chromax allow all HTML tags in TinyMce editor.
|
||||
*
|
||||
* @param array $init_array TinyMce settings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function chromax_override_mce_options( $init_array ) {
|
||||
$opts = '*[*]';
|
||||
$init_array['valid_elements'] = $opts;
|
||||
$init_array['extended_valid_elements'] = $opts;
|
||||
return $init_array;
|
||||
}
|
||||
add_filter( 'tiny_mce_before_init', 'chromax_override_mce_options' );
|
||||
|
||||
|
||||
/**
|
||||
* Filters for text format
|
||||
*/
|
||||
add_filter( 'chromax_text', 'wptexturize' );
|
||||
add_filter( 'chromax_text', 'convert_smilies' );
|
||||
add_filter( 'chromax_text', 'convert_chars' );
|
||||
add_filter( 'chromax_text', 'wpautop' );
|
||||
add_filter( 'chromax_text', 'shortcode_unautop' );
|
||||
add_filter( 'chromax_text', 'do_shortcode' );
|
||||
@@ -0,0 +1,115 @@
|
||||
/* global tinyMCE */
|
||||
/* global wp */
|
||||
|
||||
/* exported WPEditorWidget */
|
||||
var WPEditorWidget = {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
currentContentId: '',
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
wpFullOverlayOriginalZIndex: 0,
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
isVisible: false,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
toggleEditor: function(contentId){
|
||||
if ( this.isVisible === true ) {
|
||||
this.hideEditor();
|
||||
} else {
|
||||
this.showEditor(contentId);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Show the editor
|
||||
* @param string contentId
|
||||
*/
|
||||
showEditor: function(contentId) {
|
||||
this.isVisible = true;
|
||||
var overlay = jQuery('.wp-full-overlay');
|
||||
|
||||
jQuery('body.wp-customizer #wp-editor-widget-container').fadeIn(100).animate({'bottom':'0'});
|
||||
|
||||
this.currentContentId = contentId;
|
||||
this.wpFullOverlayOriginalZIndex = parseInt( overlay.css('zIndex') );
|
||||
overlay.css({ zIndex: 49000 });
|
||||
|
||||
this.setEditorContent(contentId);
|
||||
},
|
||||
|
||||
/**
|
||||
* Hide editor
|
||||
*/
|
||||
hideEditor: function() {
|
||||
this.isVisible = false;
|
||||
jQuery('body.wp-customizer #wp-editor-widget-container').animate({'bottom':'-650px'}).fadeOut();
|
||||
jQuery('.wp-full-overlay').css({ zIndex: this.wpFullOverlayOriginalZIndex });
|
||||
},
|
||||
|
||||
/**
|
||||
* Set editor content
|
||||
*/
|
||||
setEditorContent: function(contentId) {
|
||||
var editor = tinyMCE.EditorManager.get('wpeditorwidget');
|
||||
var content = jQuery('#'+ contentId).val();
|
||||
|
||||
if (typeof editor === 'object' && editor !== null) {
|
||||
editor.setContent(content);
|
||||
}
|
||||
jQuery('#wpeditorwidget').val(content);
|
||||
},
|
||||
|
||||
/**
|
||||
* Update widget and close the editor
|
||||
*/
|
||||
updateWidgetAndCloseEditor: function() {
|
||||
|
||||
jQuery('#wpeditorwidget-tmce').trigger('click');
|
||||
var editor = tinyMCE.EditorManager.get('wpeditorwidget');
|
||||
var content = editor.getContent();
|
||||
|
||||
if (typeof editor === 'undefined' || editor === null || editor.isHidden()) {
|
||||
content = jQuery('#wpeditorwidget').val();
|
||||
}
|
||||
|
||||
var contentId = jQuery('#'+ this.currentContentId);
|
||||
contentId.val(content);
|
||||
|
||||
|
||||
if ( contentId.attr('class') === 'editorfield') {
|
||||
var controlid = contentId.data('customize-setting-link');
|
||||
setTimeout(function(){
|
||||
wp.customize(controlid, function(obj) {
|
||||
obj.set(editor.getContent());
|
||||
} );
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
this.hideEditor();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
jQuery( document ).ready(function() {
|
||||
jQuery('.customize-section-back').on('click',function(){
|
||||
WPEditorWidget.hideEditor();
|
||||
});
|
||||
|
||||
var customize = wp.customize;
|
||||
customize.previewer.bind( 'trigger-close-editor', function( data ) {
|
||||
if( data === true ){
|
||||
WPEditorWidget.hideEditor();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
/* global requestpost */
|
||||
/* global wp */
|
||||
/* global WPEditorWidget */
|
||||
|
||||
( function( $ ) {
|
||||
'use strict';
|
||||
wp.customize( 'page_on_front', function( value ) {
|
||||
|
||||
value.bind( function( newval ) {
|
||||
|
||||
$.ajax({
|
||||
url: requestpost.ajaxurl,
|
||||
type: 'post',
|
||||
data: {
|
||||
action: 'chromax_ajax_call',
|
||||
pid: newval
|
||||
},
|
||||
success: function (result) {
|
||||
|
||||
if(result !== '' && result !== 'undefined' ){
|
||||
|
||||
result = JSON.parse(result);
|
||||
var content = result.post_content;
|
||||
jQuery( '#Chromax_Page_Editor' ).val(content);
|
||||
WPEditorWidget.setEditorContent('Chromax_Page_Editor');
|
||||
|
||||
if(result.post_thumbnail !== '' && result.post_thumbnail !== 'undefined'){
|
||||
wp.customize.instance(requestpost.thumbnail_control).set(result.post_thumbnail);
|
||||
var html = '<label for="chromax_feature_thumbnail-button">' +
|
||||
'<span class="customize-control-title">' + requestpost.thumbnail_label + '</span>' +
|
||||
'</label>' +
|
||||
'<div class="attachment-media-view attachment-media-view-image landscape">' +
|
||||
'<div class="thumbnail thumbnail-image">' +
|
||||
'<img class="attachment-thumb" src="'+result.post_thumbnail+'" draggable="false" alt=""> ' +
|
||||
'</div>' +
|
||||
'<div class="actions">' +
|
||||
'<button type="button" class="button remove-button">Remove</button>' +
|
||||
'<button type="button" class="button upload-button control-focus" id="chromax_feature_thumbnail-button">Change Image</button> ' +
|
||||
'<div style="clear:both"></div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
wp.customize.control(requestpost.thumbnail_control).container['0'].innerHTML = html;
|
||||
}
|
||||
|
||||
wp.customize.instance(requestpost.editor_control).previewer.refresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
} );
|
||||
} );
|
||||
} )( jQuery );
|
||||
Reference in New Issue
Block a user