Completed
Push — master ( 146458...b94c12 )
by Sudar
01:55
created

setting-helpers.php ➔ bd_text_callback()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 12
nop 1
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Helper functions for settings API.
4
 * Most of these functions are copied from Easy Digital Downloads
5
 *
6
 * @since 5.3
7
 * @author     Sudar
8
 * @package    BulkDelete\Settings
9
 */
10
11
12
/**
13
 * Header Callback
14
 *
15
 * Renders the header.
16
 *
17
 * @since  5.3
18
 * @param array   $args Arguments passed by the setting
19
 * @return void
20
 */
21
function bd_header_callback( $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
	echo '<hr/>';
23
}
24
25
/**
26
 * Text Callback
27
 *
28
 * Renders text fields.
29
 *
30
 * @since  5.3
31
 * @param array   $args Arguments passed by the setting
32
 * @return void
33
 */
34
function bd_text_callback( $args ) {
35
	$option_name = $args['option'];
36
	$bd_options = get_option( $option_name );
37
38
	if ( isset( $bd_options[ $args['id'] ] ) ) {
39
		$value = $bd_options[ $args['id'] ];
40
	} else {
41
		$value = isset( $args['std'] ) ? $args['std'] : '';
42
	}
43
44
	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
45
	$html = '<input type="text" class="' . $size . '-text" id="' . $option_name . '[' . $args['id'] . ']" name="' . $option_name . '[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '">';
46
	$html .= '<label for="' . $option_name . '[' . $args['id'] . ']"> '  . $args['desc'] . '</label>';
47
48
	echo $html;
49
}
50
51
/**
52
 * Rich Editor Callback
53
 *
54
 * Renders rich editor fields.
55
 *
56
 * @since 5.3
57
 * @param array   $args Arguments passed by the setting
58
 */
59
function bd_rich_editor_callback( $args ) {
60
	$option_name = $args['option'];
61
	$bd_options = get_option( $option_name );
62
63
	if ( isset( $bd_options[ $args['id'] ] ) ) {
64
		$value = $bd_options[ $args['id'] ];
65
	} else {
66
		$value = isset( $args['std'] ) ? $args['std'] : '';
67
	}
68
69
	ob_start();
70
	wp_editor( stripslashes( $value ), $option_name . '_' . $args['id'], array( 'textarea_name' => $option_name . '[' . $args['id'] . ']', 'media_buttons' => false ) );
71
	$html = ob_get_clean();
72
73
	$html .= '<br/><label for="' . $option_name . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
74
75
	echo $html;
76
}
77
?>
78