-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrm-field-boilerplate.php
59 lines (51 loc) · 1.53 KB
/
frm-field-boilerplate.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: Formidable Forms Field Boilerplate
Description: Create a custom field type in Formidable Forms.
Version: 1.0
Plugin URI: https://formidableforms.com/
Author URI: https://formidableforms.com/
Author: Strategy11
*/
// TODO: replace 'prefix_' and 'Prefix' with your own.
// TODO: replace 'new-type' with the slug for your field.
/**
* Add the autoloader.
*/
function prefix_load_formidable_field() {
spl_autoload_register( 'prefix_forms_autoloader' );
}
add_action( 'plugins_loaded', 'prefix_load_formidable_field' );
/**
* @since 3.0
*/
function prefix_forms_autoloader( $class_name ) {
// Only load Prefix classes here
if ( ! preg_match( '/^Prefix.+$/', $class_name ) ) {
return;
}
$filepath = dirname( __FILE__ );
$filepath .= '/' . $class_name . '.php';
if ( file_exists( $filepath ) ) {
require( $filepath );
}
}
/**
* Tell Formidable where to find the new field type.
* @return string The name of the new class that extends FrmFieldType.
*/
function prefix_get_field_type_class( $class, $field_type ) {
if ( $field_type === 'new-type' ) { // Replace 'new-type' with your field slug.
$class = 'PrefixFieldNewType'; // Set your class name here.
}
return $class;
}
add_filter( 'frm_get_field_type_class', 'prefix_get_field_type_class', 10, 2 );
function prefix_add_new_field( $fields ) {
$fields['new-type'] = array(
'name' => 'My Field',
'icon' => 'frm_icon_font frm_pencil_icon', // Set the class for a custom icon here.
);
return $fields;
}
add_filter( 'frm_available_fields', 'prefix_add_new_field' );