forked from winteragency/acf-native-fields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acf-native-fields.php
59 lines (46 loc) · 1.66 KB
/
acf-native-fields.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
<?php
/*
Plugin Name: ACF Native Fields
Plugin URI: https://github.com/winteragency/acf-native-fields
Description: An interface to move native WordPress fields and options into ACF for a cleaner editor layout
Version: 1.1.0
Author: Winter
Author URI: https://winteragency.se
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.en.html
*/
if(!defined('ABSPATH')) exit;
class ACF_Native_Fields {
static $instance = false;
function __construct() {
// Init plugin (check requirements etc)
add_action('admin_init', array($this, 'admin_init'));
// Add native field type to ACF
add_action('acf/include_field_types', array($this, 'include_native_field_type'));
}
public function admin_init() {
load_plugin_textdomain('acf-native-fields', false, dirname(plugin_basename(__FILE__)) . '/lang/');
// Require ACF
if (current_user_can('activate_plugins') && !is_plugin_active('advanced-custom-fields/acf.php') && !is_plugin_active('advanced-custom-fields-pro/acf.php')) {
add_action('admin_notices', array($this, 'require_acf'));
deactivate_plugins(plugin_basename( __FILE__ ));
if(isset($_GET['activate'])) {
unset($_GET['activate']);
}
}
}
public function require_acf() { ?>
<div class="error"><p><?php _e('ACF Native Fields requires Advanced Custom Fields v5+ to be installed and activated.', 'acf-native-fields'); ?></p></div><?php
}
public function include_native_field_type() {
require(dirname(__FILE__) . '/acf-native-field-type.php');
new acf_field_native();
}
static function &instance() {
if(false === self::$instance) {
self::$instance = new ACF_Native_Fields();
}
return self::$instance;
}
}
new ACF_Native_Fields();