PluginProbe
Custom Fields for Gutenberg / 2.4.4
Custom Fields for Gutenberg v2.4.4
2.4.7 trunk 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.1.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 All 31 releases
custom-fields-gutenberg / custom-fields-gutenberg.php

custom-fields-gutenberg.php in Custom Fields for Gutenberg 2.4.4, at custom-fields-gutenberg.php

237 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Custom Fields for Gutenberg
4 Plugin URI: https://perishablepress.com/custom-fields-gutenberg/
5 Description: Restores the Custom Field meta box for the Gutenberg Block Editor.
6 Tags: gutenberg, custom fields, meta box, blocks
7 Author: Jeff Starr
8 Author URI: https://plugin-planet.com/
9 Donate link: https://monzillamedia.com/donate.html
10 Contributors: specialk
11 Requires at least: 4.7
12 Tested up to: 6.9
13 Stable tag: 2.4.4
14 Version: 2.4.4
15 Requires PHP: 5.6.20
16 Text Domain: custom-fields-gutenberg
17 Domain Path: /languages
18 License: GPL v2 or later
19 */
20
21 /*
22 This program is free software; you can redistribute it and/or
23 modify it under the terms of the GNU General Public License
24 as published by the Free Software Foundation; either version
25 2 of the License, or (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public License
33 with this program. If not, visit: https://www.gnu.org/licenses/
34
35 Copyright 2025 Monzilla Media. All rights reserved.
36 */
37
38 if (!defined('ABSPATH')) die();
39
40 if (!class_exists('G7G_CFG_CustomFields')) {
41
42 class G7G_CFG_CustomFields {
43
44 function __construct() {
45
46 $this->constants();
47 $this->includes();
48
49 register_activation_hook(__FILE__, 'g7g_cfg_dismiss_notice_activate');
50
51 add_action('admin_init', array($this, 'check_version'));
52 add_action('init', array($this, 'load_i18n'));
53 add_filter('plugin_action_links', array($this, 'action_links'), 10, 2);
54 add_filter('plugin_row_meta', array($this, 'plugin_links'), 10, 2);
55 add_filter('admin_footer_text', array($this, 'footer_text'), 10, 1);
56
57 add_action('admin_enqueue_scripts', 'g7g_cfg_enqueue_resources_admin');
58 add_action('admin_print_scripts', 'g7g_cfg_admin_print_scripts');
59 add_action('admin_notices', 'g7g_cfg_admin_notice');
60 add_action('admin_init', 'g7g_cfg_register_settings');
61 add_action('admin_init', 'g7g_cfg_reset_options');
62 add_action('admin_init', 'g7g_cfg_dismiss_notice_save');
63 add_action('admin_init', 'g7g_cfg_dismiss_notice_version');
64 add_action('admin_menu', 'g7g_cfg_menu_pages');
65
66 add_action('admin_init', 'g7g_cfg_acf_display_meta');
67 add_action('enqueue_block_editor_assets', 'g7g_cfg_load_assets_editor');
68 add_action('add_meta_boxes', 'g7g_cfg_add_meta_box');
69
70 }
71
72 function constants() {
73
74 if (!defined('G7G_CFG_VERSION')) define('G7G_CFG_VERSION', '2.4.4');
75 if (!defined('G7G_CFG_REQUIRE')) define('G7G_CFG_REQUIRE', '4.7');
76 if (!defined('G7G_CFG_AUTHOR')) define('G7G_CFG_AUTHOR', 'Jeff Starr');
77 if (!defined('G7G_CFG_NAME')) define('G7G_CFG_NAME', 'Custom Fields for Gutenberg');
78 if (!defined('G7G_CFG_HOME')) define('G7G_CFG_HOME', esc_url('https://perishablepress.com/custom-fields-gutenberg/'));
79 if (!defined('G7G_CFG_URL')) define('G7G_CFG_URL', plugin_dir_url(__FILE__));
80 if (!defined('G7G_CFG_DIR')) define('G7G_CFG_DIR', plugin_dir_path(__FILE__));
81 if (!defined('G7G_CFG_FILE')) define('G7G_CFG_FILE', plugin_basename(__FILE__));
82 if (!defined('G7G_CFG_SLUG')) define('G7G_CFG_SLUG', basename(dirname(__FILE__)));
83
84 }
85
86 function includes() {
87
88 if (is_admin()) {
89
90 require_once G7G_CFG_DIR .'inc/plugin-core.php';
91 require_once G7G_CFG_DIR .'inc/resources-enqueue.php';
92 require_once G7G_CFG_DIR .'inc/settings-display.php';
93 require_once G7G_CFG_DIR .'inc/settings-register.php';
94 require_once G7G_CFG_DIR .'inc/settings-reset.php';
95
96 }
97
98 }
99
100 function options() {
101
102 $options = array(
103
104 'acf_display_meta' => 0,
105 'exclude_protected' => 1,
106 'exclude_empty' => 0,
107 'exclude_fields' => ''
108
109 );
110
111 $types = g7g_cfg_get_post_types();
112
113 foreach($types as $type) {
114
115 extract($type); // name label
116
117 $options['post-type_'. $name] = 1;
118
119 }
120
121 return apply_filters('g7g_cfg_options', $options);
122
123 }
124
125 function action_links($links, $file) {
126
127 if ($file === G7G_CFG_FILE && (current_user_can('manage_options'))) {
128
129 $settings = '<a href="'. admin_url('options-general.php?page=g7g-cfg') .'">'. esc_html__('Settings', 'custom-fields-gutenberg') .'</a>';
130
131 array_unshift($links, $settings);
132
133 }
134
135 return $links;
136
137 }
138
139 function plugin_links($links, $file) {
140
141 if ($file === G7G_CFG_FILE) {
142
143 $home_href = 'https://perishablepress.com/custom-fields-gutenberg/';
144 $home_title = esc_attr__('Plugin Homepage', 'custom-fields-gutenberg');
145 $home_text = esc_html__('Homepage', 'custom-fields-gutenberg');
146
147 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
148
149 $rate_href = 'https://wordpress.org/support/plugin/'. G7G_CFG_SLUG .'/reviews/?rate=5#new-post';
150 $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'custom-fields-gutenberg');
151 $rate_text = esc_html__('Rate this plugin', 'custom-fields-gutenberg') .'&nbsp;&raquo;';
152
153 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
154
155 }
156
157 return $links;
158
159 }
160
161 function footer_text($text) {
162
163 $screen_id = g7g_cfg_get_current_screen_id();
164
165 $ids = array('settings_page_g7g-cfg');
166
167 if ($screen_id && apply_filters('g7g_cfg_admin_footer_text', in_array($screen_id, $ids))) {
168
169 $text = __('Like this plugin? Give it a', 'custom-fields-gutenberg');
170
171 $text .= ' <a target="_blank" rel="noopener noreferrer" href="https://wordpress.org/support/plugin/custom-fields-gutenberg/reviews/?rate=5#new-post">';
172
173 $text .= __('�
174
175
176
177
178 rating&nbsp;&raquo;', 'custom-fields-gutenberg') .'</a>';
179
180 }
181
182 return $text;
183
184 }
185
186 function check_version() {
187
188 $wp_version = get_bloginfo('version');
189
190 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
191
192 if (version_compare($wp_version, G7G_CFG_REQUIRE, '<')) {
193
194 if (is_plugin_active(G7G_CFG_FILE)) {
195
196 deactivate_plugins(G7G_CFG_FILE);
197
198 $msg = '<strong>'. G7G_CFG_NAME .'</strong> '. esc_html__('requires WordPress ', 'custom-fields-gutenberg') . G7G_CFG_REQUIRE;
199 $msg .= esc_html__(' or higher, and has been deactivated! ', 'custom-fields-gutenberg');
200 $msg .= esc_html__('Please return to the', 'custom-fields-gutenberg') .' <a href="'. admin_url() .'">';
201 $msg .= esc_html__('WP Admin Area', 'custom-fields-gutenberg') .'</a> ';
202 $msg .= esc_html__('to upgrade WordPress and try again.', 'custom-fields-gutenberg');
203
204 wp_die($msg);
205
206 }
207
208 }
209
210 }
211
212 }
213
214 function load_i18n() {
215
216 load_plugin_textdomain('custom-fields-gutenberg', false, dirname(G7G_CFG_FILE) .'/languages/');
217
218 }
219
220 function __clone() {
221
222 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'custom-fields-gutenberg'), G7G_CFG_VERSION);
223
224 }
225
226 function __wakeup() {
227
228 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'custom-fields-gutenberg'), G7G_CFG_VERSION);
229
230 }
231
232 }
233
234 $G7G_CFG_CustomFields = new G7G_CFG_CustomFields();
235
236 }
237