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

Commit

Permalink
Drop support for qTranslate variants; Add plugins_loaded support back.
Browse files Browse the repository at this point in the history
  • Loading branch information
funkjedi committed Nov 21, 2016
1 parent d88e028 commit 513c282
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 232 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.16
Version: 1.7.17
Author: funkjedi
Author URI: http://funkjedi.com
License: GPLv2 or later
Expand Down
33 changes: 0 additions & 33 deletions compatibility/ppqtranslate.php

This file was deleted.

19 changes: 9 additions & 10 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.6.1
Version: 1.7.16
Stable tag: 1.7.16
Version: 1.7.17
Stable tag: 1.7.17
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -13,7 +13,7 @@ Provides qTranslate compatible ACF field types for Text, Text Area, WYSIWYG, Ima

== Description ==

This plugin provides qTranslate (qTranslate-X, qTranslate Plus and mqTranslate) compatible ACF4 and ACF5PRO field types for Text, Text Area, WYSIWYG, Image and File. When adding a field to a field group these new field types will be listed under the qTranslate category in the Field Type dropdown.
This plugin provides qTranslate-X compatible ACF4 and ACF5PRO field types for Text, Text Area, WYSIWYG, Image and File. When adding a field to a field group these new field types will be listed under the qTranslate category in the Field Type dropdown.

= Field Types =
* qTranslate Text (type text, api returns text)
Expand All @@ -22,8 +22,7 @@ This plugin provides qTranslate (qTranslate-X, qTranslate Plus and mqTranslate)
* qTranslate Image (upload an image, api returns the url)
* qTranslate File (upload a file, api returns the url)

= qTranslate-X =
If using qTranslate-X the standard Text, Text Area and WYSIWYG field types can be enabled for translation.
The standard Text, Text Area and WYSIWYG field types can also be enabled for translation.

= Bug Submission =
https://github.com/funkjedi/acf-qtranslate/issues/
Expand All @@ -38,12 +37,8 @@ https://github.com/funkjedi/acf-qtranslate/issues/
* [ACF](https://wordpress.org/plugins/advanced-custom-fields/)
* [ACF5PRO](http://www.advancedcustomfields.com/pro/)

= Requires qTranslate (or qTranslate-based) Plugin =
* [qTranslate](https://wordpress.org/extend/plugins/qtranslate/)
= Requires qTranslate-X Plugin =
* [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/)
* [qTranslate Plus](https://wordpress.org/plugins/qtranslate-xp/)
* [mqTranslate](https://wordpress.org/plugins/mqtranslate/)
* [zTranslate](https://wordpress.org/extend/plugins/ztranslate/)


== Frequently Asked Questions ==
Expand All @@ -59,6 +54,10 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac

== Changelog ==

= 1.7.17 =
* Core: Initialize on either `plugins_loaded` or `after_setup_theme`
* Core: Drop support for qTranslate Plus, mqTranslate, and zTranslate

= 1.7.16 =
* Bug Fix: Fixed ACF4 support for standard WYSIWYG field
* Bug Fix: Updated ACF4 qTranslate WYSIWYG field
Expand Down
53 changes: 0 additions & 53 deletions src/mqtranslate.php

This file was deleted.

88 changes: 9 additions & 79 deletions src/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class acf_qtranslate_plugin {
* @return void
*/
public function __construct() {
add_action('after_setup_theme', array($this, 'after_setup_theme'), -10);
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_menu', array($this, 'admin_menu'));
Expand All @@ -28,8 +29,10 @@ public function __construct() {
* Setup plugin if Advanced Custom Fields is enabled.
* @return void
*/
public function after_setup_theme() {
if ($this->acf_enabled() && $this->qtranslate_variant_enabled()) {
public function init() {
static $plugin_loaded;

if (!$plugin_loaded && $this->acf_enabled() && $this->qtranslatex_enabled()) {

// setup qtranslate fields for ACF 4
if ($this->acf_major_version() === 4) {
Expand All @@ -43,52 +46,13 @@ public function after_setup_theme() {
$this->acf = new acf_qtranslate_acf_5($this);
}

// setup mqtranslate integration
if ($this->mqtranslate_enabled()) {
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/mqtranslate.php';
new acf_qtranslate_mqtranslate($this, $this->acf);
}

// setup ppqtranslate integration
if ($this->ppqtranslate_enabled()) {
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/ppqtranslate.php';
new acf_qtranslate_ppqtranslate($this, $this->acf);
}

// setup qtranslatex integration
if ($this->qtranslatex_enabled()) {
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/qtranslatex.php';
new acf_qtranslate_qtranslatex($this, $this->acf);
}
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/qtranslatex.php';
new acf_qtranslate_qtranslatex($this, $this->acf);

}
}
$plugin_loaded = true;

/**
* Check whether the plugin is active by checking the active_plugins list.
*
* @param string $plugin Base plugin path from plugins directory.
* @return bool True, if in the active plugins list. False, not in the list.
*/
public function is_plugin_active($plugin) {
return in_array($plugin, (array)get_option('active_plugins', array())) || $this->is_plugin_active_for_network($plugin);
}

/**
* Check whether the plugin is active for the entire network.
*
* @param string $plugin Base plugin path from plugins directory.
* @return bool True, if active for the network, otherwise false.
*/
public function is_plugin_active_for_network($plugin) {
if (!is_multisite()) {
return false;
}
$plugins = get_site_option('active_sitewide_plugins');
if (isset($plugins[$plugin])) {
return true;
}
return false;
}

/**
Expand All @@ -110,47 +74,13 @@ public function acf_major_version() {
return (int) acf()->settings['version'][0];
}

/**
* Check if a qTranslate variant is enabled.
* @return boolean
*/
public function qtranslate_variant_enabled() {
$plugins = array(
'qtranslate/qtranslate.php',
'ztranslate/ztranslate.php',
'mqtranslate/mqtranslate.php',
'qtranslate-x/qtranslate.php',
'qtranslate-xp/ppqtranslate.php',
);
foreach ($plugins as $identifier) {
if ($this->is_plugin_active($identifier)) {
return true;
}
}
return false;
}

/**
* Check if qTranslate Plus is enabled.
*/
public function ppqtranslate_enabled() {
return function_exists('ppqtrans_getLanguage');
}

/**
* Check if qTranslate-X is enabled.
*/
public function qtranslatex_enabled() {
return function_exists('qtranxf_getLanguage');
}

/**
* Check if mqTranslate is enabled.
*/
public function mqtranslate_enabled() {
return function_exists('mqtrans_currentUserCanEdit');
}

/**
* Get the active language.
*/
Expand Down
56 changes: 0 additions & 56 deletions src/ppqtranslate.php

This file was deleted.

0 comments on commit 513c282

Please sign in to comment.