BD_Settings_Page   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 118
ccs 0
cts 43
cp 0
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sanitize_settings() 0 2 1
A get_addon_settings() 0 4 1
A display_settings_page() 0 33 1
A add_menu() 0 23 2
1
<?php
2
/**
3
 * Utility class for Settings page.
4
 *
5
 * @since      5.3
6
 *
7
 * @author     Sudar
8
 *
9
 * @package    BulkDelete\Admin\Settings
10
 */
11
defined( 'ABSPATH' ) || exit; // Exit if accessed directly
12
13
class BD_Settings_Page {
14
	/**
15
	 * Slug for settings page.
16
	 *
17
	 * @since 5.3
18
	 */
19
	const SETTINGS_PAGE_SLUG = 'bd-settings';
20
21
	/**
22
	 * Slugs for addon settings.
23
	 *
24
	 * @since 5.3
25
	 */
26
	const ADDON_SETTING_OPTION_GROUP = 'bd_addon_settings';
27
	const ADDON_SETTING_OPTION_NAME  = 'bd_addon_settings';
28
29
	/**
30
	 * Add settings menu if needed.
31
	 *
32
	 * @static
33
	 *
34
	 * @since  5.3
35
	 */
36
	public static function add_menu() {
37
		$settings_page_needed = apply_filters( 'bd_settings_page_needed', false );
38
		if ( ! $settings_page_needed ) {
39
			return;
40
		}
41
42
		$bd = BULK_DELETE();
43
44
		// add page
45
		$bd->settings_page = add_submenu_page(
46
			Bulk_Delete::POSTS_PAGE_SLUG,
47
			__( 'Bulk Delete Settings', 'bulk-delete' ),
48
			__( 'Settings', 'bulk-delete' ),
49
			'delete_posts',
50
			self::SETTINGS_PAGE_SLUG,
51
			array( __CLASS__, 'display_settings_page' )
52
		);
53
54
		// register settings
55
		register_setting(
56
			self::ADDON_SETTING_OPTION_GROUP,       // Option group
57
			self::ADDON_SETTING_OPTION_NAME,        // Option name
58
			array( __CLASS__, 'sanitize_settings' ) // Sanitize callback
59
		);
60
	}
61
62
	/**
63
	 * Sanitize Settings.
64
	 *
65
	 * @static
66
	 *
67
	 * @since 5.3
68
	 *
69
	 * @param array $input (optional) Input array
70
	 *
71
	 * @return array Sanitized input
72
	 */
73
	public static function sanitize_settings( $input = array() ) {
74
		return apply_filters( 'bd_sanitize_settings_page_fields', $input );
75
	}
76
77
	/**
78
	 * Return Addon settings.
79
	 *
80
	 * @since 5.3
81
	 * @static
82
	 *
83
	 * @return array Addon settings
84
	 */
85
	public static function get_addon_settings() {
86
		$options = get_option( self::ADDON_SETTING_OPTION_NAME, array() );
87
88
		return apply_filters( 'bd_addon_settings', $options );
89
	}
90
91
	/**
92
	 * Show the settings page.
93
	 *
94
	 * @static
95
	 *
96
	 * @since 5.3
97
	 */
98
	public static function display_settings_page() {
99
?>
100
    <div class="wrap">
101
        <h2><?php _e( 'Bulk Delete Settings', 'bulk-delete' );?></h2>
102
        <?php settings_errors(); ?>
103
104
        <div id = "poststuff">
105
            <div id="post-body" class="metabox-holder columns-2">
106
107
                <div id="postbox-container-2" class="postbox-container">
108
                    <form method = "post" action="options.php">
109
                        <table class="form-table">
110
<?php
111
		settings_fields( self::ADDON_SETTING_OPTION_GROUP );
112
		do_settings_sections( self::SETTINGS_PAGE_SLUG );
113
?>
114
                        </table>
115
                        <?php submit_button(); ?>
116
                    </form>
117
                </div> <!-- #postbox-container-2 -->
118
119
            </div> <!-- #post-body -->
120
        </div><!-- #poststuff -->
121
    </div><!-- .wrap -->
122
<?php
123
		/**
124
		 * Runs just before displaying the footer text in the "Bulk Delete Settings" admin page.
125
		 *
126
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Settings" admin page.
127
		 *
128
		 * @since 5.3
129
		 */
130
		do_action( 'bd_admin_footer_settings_page' );
131
	}
132
}
133