-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.php
101 lines (82 loc) · 2.88 KB
/
plugin.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Plugin Name: Toggle ACF flexible layouts.
* Description: Toggle ACF flexible layouts for better usability when managing flexible layouts.
* Version: 1.0.3
* Author: Timi-Artturi Mäkelä
* Author URI: https://github.com/Liblastic
* License: GPL-3.0
* Text Domain: acf-toggle-flexible-layouts
* Domain Path: /languages
*/
namespace Geniem;
/**
* Class AcfToggleFlexibleLayouts
*/
class AcfToggleFlexibleLayouts {
/**
* Plugin constructor
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', [ $this, 'acf_toggle_flexible_layouts_scripts_and_styles' ] );
add_action( 'plugins_loaded', [ $this, 'load_plugin_textdomain' ] );
}
/**
* Scripts and styles.
*/
public function acf_toggle_flexible_layouts_scripts_and_styles() {
// Plugin version.
$plugin_data = get_plugin_data( __FILE__ );
$plugin_version = $plugin_data['Version'];
// Register script.
wp_register_script( 'acf_close_flexible', plugin_dir_url( __FILE__ ) . '/assets/dist/admin.js', '', $plugin_version );
// Localize the script with new data
$localization_data = [
'data' => $this->button_data(),
'localized_string' => $this->localized_strings(),
];
// Add strings to script.
wp_localize_script( 'acf_close_flexible', 'localization_data', $localization_data );
// Enqueued script with localized data.
wp_enqueue_script( 'acf_close_flexible' );
}
/**
* Button data.
*
* @return void
*/
public function button_data() {
$data = [
'wrapper_classes' => 'acf-field',
'toggle_button_classes' => 'close-flexible',
'arrow_up' => '▼',
'arrow_down' => '▲',
];
// Filter localized strings.
apply_filters( 'geniem/toggle_flexible_layouts/button_data', $data );
return $data;
}
/**
* Define plugin localized strings passed to the javascript.
*
* @return array An array of localized strings.
*/
public function localized_strings() {
// Localized strings.
$localized_strings = [
'show_text' => __( 'Show all layouts', 'acf-toggle-flexible-layouts' ),
'hide_text' => __( 'Hide all layouts', 'acf-toggle-flexible-layouts' ),
];
// Filter localized strings.
apply_filters( 'geniem/toggle_flexible_layouts/localized_strings', $localized_strings );
return $localized_strings;
}
/**
* Load Plugin Text Domain
* note: no full path [plugin_folder]/languages
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'acf-toggle-flexible-layouts', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
}
new AcfToggleFlexibleLayouts();