-
Notifications
You must be signed in to change notification settings - Fork 0
/
disable-sync-repeater-option-for-acfml.php
65 lines (54 loc) · 1.96 KB
/
disable-sync-repeater-option-for-acfml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Plugin Name: Disable Sync Repeater Option for ACFML
* Plugin URI: https://github.com/timohubois/disable-sync-repeater-option-for-acfml/
* Description: Disables the sync repeater option of ACFML.
* Version: 1.0
* Requires at least: 5.0
* Requires PHP: 8.0
* Author: Timo Hubois
* Author URI: https://pixelsaft.wtf
* Text Domain: disable-sync-repeater-option-for-acfml
* Domain Path: /languages
* License: GPLv3 or later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
defined('ABSPATH') || exit;
/*
* Define the default value for the repeater sync checkbox.
*
* @see https://wpml.org/documentation/support/wpml-coding-api/wpml-constants/#acfml_repeater_sync_default
*/
if (!defined('ACFML_REPEATER_SYNC_DEFAULT')) {
define('ACFML_REPEATER_SYNC_DEFAULT', false);
}
/*
* Remove the meta box that displays the repeater sync checkbox in the post edit screen.
*/
add_action('add_meta_boxes', function (): void {
if (!class_exists('ACFML\Repeater\Sync\CheckboxUI') || !defined('ACFML\Repeater\Sync\CheckboxUI::META_BOX_ID')) {
return;
}
global $pagenow;
$metaBoxId = \ACFML\Repeater\Sync\CheckboxUI::META_BOX_ID;
$isOnPostEdit = isset($pagenow) && 'post.php' === $pagenow;
$screen = get_current_screen();
$postType = $screen->post_type ?? null;
if (!$isOnPostEdit || $postType === null) {
return;
}
remove_meta_box($metaBoxId, $postType, 'normal');
}, 11);
/*
* Delete the option that stores the sync status.
*/
add_action('plugins_loaded', function (): void {
if (!is_admin() || !class_exists('ACFML\Repeater\Sync\CheckboxOption') || !defined('ACFML\Repeater\Sync\CheckboxOption::SYNCHRONISE_WP_OPTION_NAME')) {
return;
}
$optionName = \ACFML\Repeater\Sync\CheckboxOption::SYNCHRONISE_WP_OPTION_NAME;
if (get_option($optionName) === false) {
return;
}
delete_option($optionName);
});