This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
forked from BeAPI/acf-svg-icon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
acf-svg-icon.php
executable file
·79 lines (68 loc) · 1.82 KB
/
acf-svg-icon.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
<?php
/*
Plugin Name: Advanced Custom Fields: SVG Icon [MODIFIED]
Version: 3.0.0
Description: Add an ACF SVG icon selector.
Domain Path: languages
Text Domain: acf-svg-icon
*/
if (!defined('ABSPATH')) {
die();
}
define('ACF_SVG_ICON_VER', '3.0.0');
define('ACF_SVG_ICON_URL', plugin_dir_url(__FILE__));
define('ACF_SVG_ICON_DIR', plugin_dir_path(__FILE__));
class acf_field_svg_icon_plugin
{
/**
* Constructor.
*
* Load plugin's translation and register acf svg fields.
*
* @since 1.0.0
*/
public function __construct()
{
add_action('init', [__CLASS__, 'load_translation'], 1);
// Register ACF fields
add_action('acf/include_field_types', [__CLASS__, 'register_field_v5']);
}
/**
* Load plugin translation.
*
* @since 1.0.0
*/
public static function load_translation()
{
load_plugin_textdomain('acf-svg-icon', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/**
* Register SVG icon field for ACF v5 or v5.6 depending on ACF version.
*
* @since 1.0.0
*/
public static function register_field_v5()
{
$version = version_compare(acf_get_setting('version'), '5.6.O', '>=') ? 56 : 5;
// Include the corresponding files
include_once sprintf('%sfields/acf-base.php', ACF_SVG_ICON_DIR);
include_once sprintf('%sfields/acf-%s.php', ACF_SVG_ICON_DIR, $version);
/**
* Instantiate the corresponding class
* @see acf_field_svg_icon_56
* @see acf_field_svg_icon_5
*/
$klass = sprintf('acf_field_svg_icon_%s', $version);
new $klass();
}
}
/**
* Init plugin.
*
* @since 1.0.0
*/
function acf_field_svg_icon()
{
new acf_field_svg_icon_plugin();
}
add_action('plugins_loaded', 'acf_field_svg_icon');