-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathcfs.php
110 lines (81 loc) · 2.34 KB
/
cfs.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
102
103
104
105
106
107
108
109
110
<?php
/*
Plugin Name: Custom Field Suite
Description: Visually add custom fields to your WordPress edit pages.
Version: 2.6.7
Author: Matt Gibbs
Text Domain: cfs
Domain Path: /languages/
*/
class Custom_Field_Suite
{
public $api;
public $form;
public $fields;
public $field_group;
private static $instance;
function __construct() {
// setup variables
define( 'CFS_VERSION', '2.6.7' );
define( 'CFS_DIR', dirname( __FILE__ ) );
define( 'CFS_URL', plugins_url( '', __FILE__ ) );
// get the gears turning
include( CFS_DIR . '/includes/init.php' );
}
/**
* Singleton
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Public API methods
*/
function get( $field_name = false, $post_id = false, $options = [] ) {
return CFS()->api->get( $field_name, $post_id, $options );
}
function get_field_info( $field_name = false, $post_id = false ) {
return CFS()->api->get_field_info( $field_name, $post_id );
}
function get_reverse_related( $post_id, $options = [] ) {
return CFS()->api->get_reverse_related( $post_id, $options );
}
function save( $field_data = [], $post_data = [], $options = [] ) {
return CFS()->api->save_fields( $field_data, $post_data, $options );
}
function find_fields( $params = [] ) {
return CFS()->api->find_input_fields( $params );
}
function form( $params = [] ) {
ob_start();
CFS()->form->render( $params );
return ob_get_clean();
}
/**
* Render a field's admin settings HTML
*/
function field_html( $field ) {
include( CFS_DIR . '/templates/field_html.php' );
}
/**
* Trigger the field type "html" method
*/
function create_field( $field ) {
$defaults = [
'type' => 'text',
'input_name' => '',
'input_class' => '',
'options' => [],
'value' => '',
];
$field = (object) array_merge( $defaults, (array) $field );
CFS()->fields[ $field->type ]->html( $field );
}
}
function CFS() {
return Custom_Field_Suite::instance();
}
$cfs = CFS();