Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
WYSIWYG updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
funkjedi committed Oct 23, 2016
1 parent 74a0c67 commit c9cf7de
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 52 deletions.
2 changes: 1 addition & 1 deletion acf-qtranslate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Advanced Custom Fields: qTranslate
Plugin URI: http://github.com/funkjedi/acf-qtranslate
Description: Provides multilingual versions of the text, text area, and wysiwyg fields.
Version: 1.7.10
Version: 1.7.11
Author: funkjedi
Author URI: http://funkjedi.com
License: GPLv2 or later
Expand Down
10 changes: 5 additions & 5 deletions assets/acf_5/qtranslatex.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
qTranslateConfig.qtx.addContentHookC(field, form);

if (jQuery(field).hasClass('wp-editor-area')) {
qTranslateConfig.qtx.addContentHooksTinyMCE();
//qTranslateConfig.qtx.addContentHooksTinyMCE();

// We must manually trigger load event so that the
// loadTinyMceHooks function which calls setEditorHooks is executed
Expand All @@ -74,19 +74,19 @@

});

qTranslateConfig.qtx.addContentHooksTinyMCE();
//qTranslateConfig.qtx.addContentHooksTinyMCE();

// Watch and remove content hooks when fields are removed
// however ACF removes the elements from the DOM early so
// we must hook into handler and perform updates there
var _hooked_repeater_remove = acf.fields.repeater.remove;
acf.fields.repeater.remove = function(event) {
var row = event.$el.closest('.acf-row');
acf.fields.repeater.remove = function($el) {
var row = ($el.$el || $el).closest('.acf-row'); // support old versions of ACF5PRO as well
row.find(_.toArray(field_types).join(',')).filter('.qtranxs-translatable').each(function() {
qTranslateConfig.qtx.removeContentHook(this);
});
// call the original handler
_hooked_repeater_remove.call(this, event);
_hooked_repeater_remove.call(this, $el);
};

});
Expand Down
2 changes: 1 addition & 1 deletion assets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
margin-top: -6px;
}

.multi-language-field .wp-switch-editor {
.multi-language-field > .wp-switch-editor {
float: right;
position: relative;
top: 1px;
Expand Down
4 changes: 2 additions & 2 deletions assets/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jQuery(function($) {
var id = $(this).attr( 'data-wp-editor-id' );
if (id) { // WP 4.3
window.switchEditors.go(id, editor);
} else { // WP < 4.3
switchEditors.switchto(this);
} else { // WP < 4.3
switchEditors.switchto(this);
}
});
});
Expand Down
5 changes: 5 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac

== Changelog ==

= 1.7.11 =
* Core: Enable support for ACF included within theme
* Bug Fix: Fixed do_action support when removing repeater rows
* Bug Fix: Removing qTranslateConfig.qtx.addContentHooksTinyMCE calls

= 1.7.10 =
* Bug Fix: (HeikoMamerow) ACF5 File compatibility fix
* Bug Fix: (Tusko) ACF5 Image compatibility fix
Expand Down
109 changes: 68 additions & 41 deletions src/acf_5/fields/wysiwyg.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,8 @@ function __construct($plugin) {
'default_value' => '',
);

// Create an acf version of the_content filter (acf_the_content)
if( !empty($GLOBALS['wp_embed']) ) {
add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
}

add_filter( 'acf_the_content', 'capital_P_dangit', 11 );
add_filter( 'acf_the_content', 'wptexturize' );
add_filter( 'acf_the_content', 'convert_smilies' );
add_filter( 'acf_the_content', 'convert_chars' );
add_filter( 'acf_the_content', 'wpautop' );
add_filter( 'acf_the_content', 'shortcode_unautop' );
add_filter( 'acf_the_content', 'prepend_attachment' );
add_filter( 'acf_the_content', 'do_shortcode', 11);
// add acf_the_content filters
$this->add_filters();

// actions
add_action('acf/input/admin_footer', array($this, 'input_admin_footer'));
Expand All @@ -68,51 +56,89 @@ function __construct($plugin) {
*/
function render_field($field) {

// global
global $wp_version;


// enqueue
acf_enqueue_uploader();


// vars
$id = uniqid('acf-editor-');
//$id = $field['id'] . '-' . uniqid();
$mode = 'html';
$default_editor = 'html';
$show_tabs = true;
$button = '';


// get height
$height = acf_get_user_setting('wysiwyg_height', 300);
$height = max( $height, 300 ); // minimum height is 300


// detect mode
// case: visual tab only
if ($field['tabs'] == 'visual') {
$mode = 'tmce';
if( !user_can_richedit() ) {

$show_tabs = false;
}
// case: text tab only
elseif ($field['tabs'] == 'text') {

} elseif( $field['tabs'] == 'visual' ) {

// case: visual tab only
$default_editor = 'tinymce';
$show_tabs = false;

} elseif( $field['tabs'] == 'text' ) {

// case: text tab only
$show_tabs = false;

} elseif( wp_default_editor() == 'tinymce' ) {

// case: both tabs
$default_editor = 'tinymce';

}
// case: both tabs
elseif (wp_default_editor() == 'tinymce') {
$mode = 'tmce';


// must be logged in tp upload
if( !current_user_can('upload_files') ) {

$field['media_upload'] = 0;

}


// mode
$switch_class = ($mode === 'html') ? 'html-active' : 'tmce-active';
$switch_class = ($default_editor === 'html') ? 'html-active' : 'tmce-active';


// filter value for editor
remove_all_filters('acf_the_editor_content');

global $q_config, $wp_version;

remove_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 );
remove_filter( 'acf_the_editor_content', 'wp_htmledit_pre', 10, 1 );
remove_filter( 'acf_the_editor_content', 'wp_richedit_pre', 10, 1 );


// WP 4.3
if( version_compare($wp_version, '4.3', '>=' ) ) {
add_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 );

add_filter( 'acf_the_editor_content', 'format_for_editor', 10, 2 );

$button = 'data-wp-editor-id="' . $id . '"';

// WP < 4.3
} else {
$function = ($mode === 'html') ? 'wp_htmledit_pre' : 'wp_richedit_pre';
add_filter('acf_the_editor_content', $function, 10, 1);

$function = ($default_editor === 'html') ? 'wp_htmledit_pre' : 'wp_richedit_pre';

add_filter('acf_the_editor_content', $function, 10, 1);

$button = 'onclick="switchEditors.switchto(this);"';

}



global $q_config;

$languages = qtrans_getSortedLanguages(true);
$values = qtrans_split($field['value'], $quicktags = true);
$currentLanguage = $this->plugin->get_active_language();
Expand All @@ -126,23 +152,24 @@ function render_field($field) {

$uid = uniqid('acf-editor-');
foreach ($languages as $language):

$id = $uid . "-$language";
$name = $field['name'] . "[$language]";
$class = $switch_class;
if ($language === $currentLanguage) {
$class .= ' current-language';
}

// WP 4.3
if( version_compare($wp_version, '4.3', '>=' ) ) {
$button = 'data-wp-editor-id="' . $id . '"';
$button = 'data-wp-editor-id="' . $id . '"';
// WP < 4.3
} else {
$button = 'onclick="switchEditors.switchto(this);"';
} else {
$button = 'onclick="switchEditors.switchto(this);"';
}
$value = apply_filters('acf_the_editor_content', $values[$language], $mode);

$value = apply_filters('acf_the_editor_content', $values[$language], $default_editor);

?>
<div id="wp-<?php echo $id; ?>-wrap" class="acf-editor-wrap wp-core-ui wp-editor-wrap <?php echo $class; ?>" data-toolbar="<?php echo $field['toolbar']; ?>" data-upload="<?php echo $field['media_upload']; ?>" data-language="<?php echo $language; ?>">
<div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools hide-if-no-js">
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class acf_qtranslate_plugin {
* @return void
*/
public function __construct() {
add_action('plugins_loaded', array($this, 'plugins_loaded'), 3);
add_action('after_setup_theme', array($this, 'after_setup_theme'), 3);
add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('admin_menu', array($this, 'admin_menu'));
add_action('admin_init', array($this, 'admin_init'));
Expand All @@ -26,7 +26,7 @@ public function __construct() {
* Setup plugin if Advanced Custom Fields is enabled.
* @return void
*/
public function plugins_loaded() {
public function after_setup_theme() {
if ($this->acf_enabled() && $this->qtranslate_variant_enabled()) {

// setup qtranslate fields for ACF 4
Expand Down

0 comments on commit c9cf7de

Please sign in to comment.