Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate ACF settings in modules tab #1154

Merged
merged 1 commit into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 29 additions & 67 deletions modules/acf/src/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ public function __construct() {
add_action( 'acf/input/admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
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' ) );

add_filter( 'qtranslate_admin_config', array( $this, 'filter_qtranslate_admin_config' ) );
add_filter( 'plugin_action_links_' . plugin_basename( ACF_QTRANSLATE_PLUGIN ), array(
$this,
'plugin_action_links'
) );
add_action( 'qtranslate_configuration', array( $this, 'display_settings' ) );
add_action( 'qtranslate_update_settings', array( $this, 'update_settings' ) );
}

/**
Expand Down Expand Up @@ -158,19 +155,6 @@ public function admin_head() {
}
}

/**
* Add settings link on plugin page
*
* @param array $links
*
* @return array
*/
public function plugin_action_links( $links ) {
array_unshift( $links, '<a href="options-general.php?page=acf-qtranslate">Settings</a>' );

return $links;
}

/**
* Enable the display of the LSB on ACF Options pages
*
Expand Down Expand Up @@ -241,94 +225,72 @@ public function filter_qtranslate_admin_config( $config ) {
* Retrieve the value of a plugin setting
*
* @param string $name
* @param $default
* @param mixed $default
*
* @return |null
* @return mixed
*/
function get_plugin_setting( $name, $default = null ) {
$options = get_option( 'acf_qtranslate' );
if ( isset( $options[ $name ] ) === true ) {
if ( isset( $options[ $name ] ) ) {
return $options[ $name ];
}

return $default;
}

/**
* Register the options page with the Wordpress menu
*/
function admin_menu() {
add_options_page( 'ACF qTranslate', 'ACF qTranslate', 'manage_options', 'acf-qtranslate', array(
$this,
'options_page'
) );
}

/**
* Register settings and default fields
*/
function admin_init() {
register_setting( 'acf_qtranslate', 'acf_qtranslate' );
register_setting( 'settings-qtranslate-acf', 'acf_qtranslate' );

// Define a placeholder for the fields without title or content.
add_settings_section(
'qtranslatex_section',
'qTranslate-X',
array( $this, 'render_section_qtranslatex' ),
'acf_qtranslate'
'section-acf',
'',
'__return_false',
'settings-qtranslate-acf'
);

add_settings_field(
'translate_standard_field_types',
'Enable translation for Standard Field Types',
array( $this, 'render_setting_translate_standard_field_types' ),
'acf_qtranslate',
'qtranslatex_section'
'settings-qtranslate-acf',
'section-acf'
);

add_settings_field(
'show_language_tabs',
'Display language tabs',
array( $this, 'render_setting_show_language_tabs' ),
'acf_qtranslate',
'qtranslatex_section'
'settings-qtranslate-acf',
'section-acf'
);

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

/**
* Render the options page
*/
function options_page() {
?>
<form action="options.php" method="post">
<h2>ACF qTranslate Settings</h2>
<br>
<?php

settings_fields( 'acf_qtranslate' );
do_settings_sections( 'acf_qtranslate' );
submit_button();

?>
</form>
<?php
function display_settings() {
QTX_Admin_Settings::open_section( 'acf' );
wp_nonce_field( 'acf', 'nonce_acf', false );
do_settings_sections( 'settings-qtranslate-acf' );
QTX_Admin_Settings::close_section( 'acf' );
}

/**
* Render the qTranslate-XT section
*/
function render_section_qtranslatex() {
?>
The following options represent additional functionality that is available when
using qTranslate-XT. This functionality is off by default and must be enabled below.
<?php
function update_settings() {
// The nonce allows to validate the settings tab was displayed but also to have checkbox fields only.
if ( ! isset( $_POST['nonce_acf'] ) || ! wp_verify_nonce( $_POST['nonce_acf'], 'acf' ) ) {
return;
}
$options = isset( $_POST['acf_qtranslate'] ) ? $_POST['acf_qtranslate'] : null;
update_option( 'acf_qtranslate', $options );
}

/**
Expand Down
1 change: 1 addition & 0 deletions modules/qtx_admin_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ protected static function get_builtin_setup() {
'name' => 'ACF',
'plugins' => [ 'advanced-custom-fields/acf.php', 'advanced-custom-fields-pro/acf.php' ],
'incompatible' => 'acf-qtranslate/acf-qtranslate.php',
'has_settings' => true,
],
[
'id' => 'all-in-one-seo-pack',
Expand Down