<?php if ( ! defined( 'ABSPATH' ) ) exit;
function ninja_forms_register_field($slug, $args = array()){
global $ninja_forms_fields;
if( !isset( $ninja_forms_fields ) ){
$ninja_forms_fields = array();
'default_label_pos' => '',
'display_function' => '',
'edit_autocomplete_off' => false,
'edit_conditional' => true,
'edit_custom_class' => true,
'edit_label_pos' => true,
'edit_placeholder' => false,
'edit_sub_post_process' => '',
'edit_sub_pre_process' => '',
'edit_sub_process' => '',
'label_pos_options' => '',
'sub_edit_function' => '',
// Parse incomming $args into an array and merge it with $defaults
$args = wp_parse_args( $args, $defaults );
foreach( $args as $key => $val ){
$ninja_forms_fields[$slug][$key] = $val;
function ninja_forms_register_field_type_group( $slug, $args ){
global $ninja_forms_field_type_groups;
foreach( $args as $key => $val ){
$ninja_forms_field_type_groups[$slug][$key] = $val;
function ninja_forms_register_tab( $slug, $args ){
global $ninja_forms_tabs;
if(!is_array($ninja_forms_tabs)){
$ninja_forms_tabs = array();
'disable_no_form_id' => false,
'display_function' => '',
'show_on_no_form_id' => true,
'show_tab_links' => true,
'show_this_tab_link' => true,
// Parse incomming $args into an array and merge it with $defaults
$args = wp_parse_args( $args, $defaults );
foreach( $args as $key => $val ){
$ninja_forms_tabs[$page][$slug][$key] = $val;
function ninja_forms_register_sidebar( $slug, $args ){
global $ninja_forms_sidebars;
if( !is_array($ninja_forms_sidebars ) ){
$ninja_forms_sidebars = array();
'display_function' => 'ninja_forms_sidebar_display_fields',
// Parse incomming $args into an array and merge it with $defaults
$args = wp_parse_args( $args, $defaults );
foreach( $args as $key => $val ){
$ninja_forms_sidebars[$page][$tab][$slug][$key] = $val;
function ninja_forms_register_sidebar_option( $slug, $args ){
global $ninja_forms_sidebars;
if( !is_array($ninja_forms_sidebars ) ){
$ninja_forms_sidebars = array();
'display_function' => '',
// Parse incomming $args into an array and merge it with $defaults
$args = wp_parse_args( $args, $defaults );
foreach( $args as $key => $val ){
$ninja_forms_sidebars[$page][$tab][$sidebar]['settings'][$slug][$key] = $val;
function ninja_forms_register_sidebar_options( $args ){
global $ninja_forms_sidebars;
foreach( $args['settings'] as $setting ){
'display_function' => '',
$slug = $setting['name'];
// Parse incomming $setting into an array and merge it with $defaults
$setting = wp_parse_args( $setting, $defaults );
foreach( $setting as $key => $val ){
$ninja_forms_sidebars[$page][$tab][$sidebar]['settings'][$slug][$key] = $val;
function ninja_forms_field_edit( $slug ){
global $ninja_forms_fields;
$function_name = $ninja_forms_fields[$slug]['edit_function'];
$arguments = func_get_args();
array_shift( $arguments ); // We need to remove the first arg ($function_name)
call_user_func_array( $function_name, $arguments );
//Screen option registration function
function ninja_forms_register_screen_option( $id, $args ){
global $ninja_forms_screen_options;
'display_function' => '',
// Parse incomming $args into an array and merge it with $defaults
$args = wp_parse_args( $args, $defaults );
if($page == '' AND $tab == ''){
$ninja_forms_screen_options['_universal_'][$id]['display_function'] = $display_function;
$ninja_forms_screen_options['_universal_'][$id]['save_function'] = $save_function;
}elseif($page != '' AND $tab == ''){
$ninja_forms_screen_options[$page]['_universal_'][$id]['display_function'] = $display_function;
$ninja_forms_screen_options[$page]['_universal_'][$id]['save_function'] = $save_function;
}elseif($page != '' AND $tab != ''){
$ninja_forms_screen_options[$page][$tab][$id]['display_function'] = $display_function;
$ninja_forms_screen_options[$page][$tab][$id]['save_function'] = $save_function;
//Help tab registration function
function ninja_forms_register_help_screen_tab( $id, $args ){
global $ninja_forms_help_screen_tabs;
'display_function' => '',
// Parse incomming $args into an array and merge it with $defaults
$args = wp_parse_args( $args, $defaults );
if($page == '' AND $tab == ''){
$ninja_forms_help_screen_tabs['_universal_'][$id]['title'] = $title;
$ninja_forms_help_screen_tabs['_universal_'][$id]['content'] = $display_function;
}elseif($page != '' AND $tab == ''){
$ninja_forms_help_screen_tabs[$page]['_universal_'][$id]['title'] = $title;
$ninja_forms_help_screen_tabs[$page]['_universal_'][$id]['content'] = $display_function;
}elseif($page != '' AND $tab != ''){
$ninja_forms_help_screen_tabs[$page][$tab][$id]['title'] = $title;
$ninja_forms_help_screen_tabs[$page][$tab][$id]['content'] = $display_function;
//Tab - Metaboxes Registration function
function ninja_forms_register_tab_metabox($args = array()){
global $ninja_forms_tabs_metaboxes;
'display_container' => true,
// Parse incomming $args into an array and merge it with $defaults
$args = wp_parse_args( $args, $defaults );
foreach($args as $key => $val){
$ninja_forms_tabs_metaboxes[$page][$tab][$slug][$key] = $val;
//Register Tab Metabox Options
function ninja_forms_register_tab_metabox_options( $args = array() ){
global $ninja_forms_tabs_metaboxes;
$new_settings = $args['settings'];
if( isset( $ninja_forms_tabs_metaboxes[$page][$tab][$slug]['settings'] ) ){
$settings = $ninja_forms_tabs_metaboxes[$page][$tab][$slug]['settings'];
if( is_array( $new_settings ) AND !empty( $new_settings ) ){
foreach( $new_settings as $s ){
if( is_array( $settings ) ){
array_push( $settings, $s );
$ninja_forms_tabs_metaboxes[$page][$tab][$slug]['settings'] = $settings;