| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
/* |
| 6 |
Description: Extends the functionality of Profile Builder by adding the possibility to have custom css classes on fields |
| 7 |
*/ |
| 8 |
|
| 9 |
/* |
| 10 |
* Function that enqueues the necessary scripts |
| 11 |
* |
| 12 |
* @since v.1.0.0 |
| 13 |
*/ |
| 14 |
function wppb_ccc_scripts( $hook ) { |
| 15 |
if ( $hook == 'profile-builder_page_manage-fields' ) { |
| 16 |
wp_enqueue_script('wppb-custom-css-class-field', plugin_dir_url(__FILE__) . 'assets/js/main.js', array('jquery', 'wppb-manage-fields-live-change')); |
| 17 |
} |
| 18 |
} |
| 19 |
add_action( 'admin_enqueue_scripts', 'wppb_ccc_scripts' ); |
| 20 |
|
| 21 |
/* |
| 22 |
* Function that adds the numbers only checkbox on an input field. |
| 23 |
* |
| 24 |
* @since v.1.0.0 |
| 25 |
* |
| 26 |
* @param array $fields - The current field properties |
| 27 |
* |
| 28 |
* @return array - The field properties that now include the numbers only checkbox |
| 29 |
*/ |
| 30 |
function wppb_ccc_field( $fields ) { |
| 31 |
$class = array( |
| 32 |
'type' => 'text', |
| 33 |
'slug' => 'class-field', |
| 34 |
'title' => __( 'CSS Class', 'profile-builder' ), |
| 35 |
'description' => __( "Add a class to a field. Should not contain dots(.) and for multiple classes separate by space.", 'profile-builder' ) |
| 36 |
); |
| 37 |
array_push( $fields, $class ); |
| 38 |
return $fields; |
| 39 |
} |
| 40 |
add_filter( 'wppb_manage_fields', 'wppb_ccc_field' ); |
| 41 |
|
| 42 |
function wppb_ccc_class( $class, $field, $error_var ){ |
| 43 |
if( !empty( $field['class-field'] ) ){ |
| 44 |
$class .= ' '. esc_attr( $field['class-field'] ); |
| 45 |
} |
| 46 |
return $class; |
| 47 |
} |
| 48 |
add_filter( 'wppb_field_css_class', 'wppb_ccc_class', 10, 3 ); |