Skip to content

Commit

Permalink
ACF: simplify module init (#1139)
Browse files Browse the repository at this point in the history
Remove `acf_qtranslate_qtranslatex` object, it is implicit with the module.
  • Loading branch information
herrvigg committed Mar 27, 2022
1 parent e3c50c7 commit a1974c0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 80 deletions.
54 changes: 36 additions & 18 deletions modules/acf/src/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class acf_qtranslate_plugin {
*/
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'init' ), 3 );
add_action( 'after_setup_theme', array( $this, 'init' ), - 10 );
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' ), - 10 );
add_action( 'admin_footer', array( $this, 'admin_footer' ), -10 );
add_action( 'admin_head', array( $this, 'admin_head' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );

Expand All @@ -32,19 +33,12 @@ public function __construct() {
* @return void
*/
public function init() {
static $plugin_loaded;

if ( ! $plugin_loaded && $this->acf_enabled() && $this->qtranslatex_enabled() ) {
// setup qtranslate fields for ACF 5
static $plugin_loaded = false;
if ( ! $plugin_loaded && $this->acf_enabled() ) {
if ( $this->acf_major_version() === 5 ) {
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/acf.php';
$this->acf = new acf_qtranslate_acf_5( $this );
}

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

$plugin_loaded = true;
}
}
Expand Down Expand Up @@ -80,13 +74,6 @@ public function acf_major_version() {
return (int) $this->acf_version();
}

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

/**
* Get the active language
*
Expand Down Expand Up @@ -140,6 +127,37 @@ public function admin_footer() {
<?php
}

/**
* Add additional styles and scripts to head
*/
public function admin_head() {
// Hide the language tabs if they shouldn't be displayed
$show_language_tabs = $this->get_plugin_setting( 'show_language_tabs' );
if ( ! $show_language_tabs ) {
?>
<style>
.multi-language-field {
margin-top: 0 !important;
}

.multi-language-field .wp-switch-editor[data-language] {
display: none !important;
}
</style>
<?php
}

// Enable translation of standard field types
$translate_standard_field_types = $this->get_plugin_setting( 'translate_standard_field_types' );
if ( $translate_standard_field_types ) {
?>
<script>
var acf_qtranslate_translate_standard_field_types = <?= json_encode( $translate_standard_field_types ) ?>;
</script>
<?php
}
}

/**
* Add settings link on plugin page
*
Expand Down
62 changes: 0 additions & 62 deletions modules/acf/src/qtranslatex.php

This file was deleted.

0 comments on commit a1974c0

Please sign in to comment.