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

Commit

Permalink
Added ability to display LSBs on specific pages
Browse files Browse the repository at this point in the history
  • Loading branch information
funkjedi committed Jan 29, 2017
1 parent 67f4dec commit 69b7751
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 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.19
Version: 1.7.20
Author: funkjedi
Author URI: http://funkjedi.com
License: GPLv2 or later
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: funkjedi
Tags: acf, advanced custom fields, qtranslate, add-on, admin
Requires at least: 3.5.0
Tested up to: 4.7.2
Version: 1.7.19
Stable tag: 1.7.19
Version: 1.7.20
Stable tag: 1.7.20
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -54,6 +54,9 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac

== Changelog ==

= 1.7.20 =
* Core: Added ability to display LSBs on specific pages

= 1.7.19 =
* Bug Fix: Fixed issue with saving File and Image fields after ACF 5.5.5 upgrade

Expand Down
57 changes: 53 additions & 4 deletions src/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct() {
add_action('plugins_loaded', array($this, 'init'), 3);
add_action('after_setup_theme', array($this, 'init'), -10);
add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('admin_footer', array($this, 'admin_footer'));
add_action('admin_footer', array($this, 'admin_footer'), -10);
add_action('admin_menu', array($this, 'admin_menu'));
add_action('admin_init', array($this, 'admin_init'));

Expand Down Expand Up @@ -101,7 +101,26 @@ public function admin_enqueue_scripts() {
* to include the LSB.
*/
public function admin_footer() {
echo '<span id="acf-qtranslate-lsb-shim" style="display:none">[:en]LSB[:]</span>';
?>
<script type="text/javascript">
(function($){
var anchors = {
'#post-body-content': 'prepend',
'#widgets-right': 'before',
'#posts-filter': 'prepend',
'#wpbody-content h1': 'after',
'#wpbody-content': 'prepend'
};
$.each(anchors, function(anchor, fn){
var $anchor = $(anchor);
if ($anchor.length) {
$anchor[fn]('<span id="acf-qtranslate-lsb-shim" style="display:none">[:en]LSB[:]</span>');
return false;
}
});
})(jQuery);
</script>
<?php
}

/**
Expand All @@ -121,9 +140,21 @@ public function plugin_action_links($links) {
*/
public function qtranslate_load_admin_page_config($config)
{
$pages = array(
'post.php' => '',
'admin.php' => 'page=',
);

foreach (explode("\n", $this->get_plugin_setting('show_on_pages')) as $page) {
$pages[$page] = '';
}

$config['acf-display-nodes'] = array(
'pages' => array('post.php' => '', 'admin.php' => 'page='),
'forms' => array(
'pages' => $pages,
'anchors' => array(
'acf-qtranslate-lsb-shim' => array('where' => 'after'),
),
'forms' => array(
'wpwrap' => array(
'fields' => array(
'lsb-shim' => array(
Expand Down Expand Up @@ -213,6 +244,14 @@ function admin_init() {
'acf_qtranslate',
'qtranslatex_section'
);

add_settings_field(
'show_on_pages',
'Display the LSB on the following pages',
array($this, 'render_setting_show_on_pages'),
'acf_qtranslate',
'qtranslatex_section'
);
}

/**
Expand Down Expand Up @@ -262,4 +301,14 @@ function render_setting_show_language_tabs() {
<?php
}

/**
* Render setting.
*/
function render_setting_show_on_pages() {
?>
<textarea name="acf_qtranslate[show_on_pages]" style="max-width:500px;width:100%;height:200px;padding-top:6px" placeholder="post.php"><?= esc_html($this->get_plugin_setting('show_on_pages')) ?></textarea><br>
<small>Enter each page on it's own line</small>
<?php
}

}

0 comments on commit 69b7751

Please sign in to comment.