Passed
Pull Request — master (#7)
by Joseph
02:29
created

AdminSettings::sectionCallback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 9.4285
1
<?php
2
/**
3
 * This file is part of the Subway WordPress Plugin Package.
4
 *
5
 * (c) Joseph Gabito <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 * 
10
 * PHP Version 5.4
11
 * 
12
 * @category Subway\Admin\Settings
13
 * @package  Subway
14
 * @author   Joseph G. <[email protected]>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @version  GIT:github.com/codehaiku/subway
17
 * @link     github.com/codehaiku/subway The Plugin Repository
18
 */
19
20
namespace Subway;
21
22
if (! defined('ABSPATH') ) {
23
    return;
24
}
25
26
/**
27
 * Registers all the admin settings inside Settings > Subway
28
 *
29
 * @category Subway\Admin\Settings
30
 * @package  Subway
31
 * @author   Joseph G. <[email protected]>
32
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
33
 * @link     github.com/codehaiku/subway The Plugin Repository
34
 * @since    1.0  
35
 */
36
final class AdminSettings
37
{
38
39
    /**
40
     * Our class constructor
41
     */
42
    public function __construct() 
43
    {
44
        
45
        add_action('admin_menu', array( $this, 'adminMenu' ));
46
47
        add_action('admin_init', array( $this, 'registerSettings' ));
48
49
    }
50
51
    /**
52
     * Display 'Subway' link under 'Settings'
53
     *
54
     * @return void
55
     */
56
    public function adminMenu() 
57
    {
58
59
        add_options_page(
60
            'Subway Settings', 'Subway', 'manage_options', 
61
            'subway', array( $this, 'optionsPage' )
62
        );
63
64
        return;
65
    }
66
67
    /**
68
     * Registers all settings related to Subway.
69
     *
70
     * @return void
71
     */
72
    public function registerSettings() 
73
    {
74
75
        // Register our settings section.
76
        add_settings_section(
77
            'subway-page-visibility-section', __('Pages Visibility', 'subway'), 
78
            array( $this, 'sectionCallback' ), 'subway-settings-section' 
79
        );
80
81
        // Register Redirect Options pages.
82
        add_settings_section(
83
            'subway-redirect-section', __('Redirect Options', 'subway'), 
84
            array( $this, 'redirectCallback' ), 'subway-settings-section' 
85
        );
86
87
        // Register the fields.
88
        $fields = array(
89
            array(
90
                'id' => 'subway_is_public',
91
                'label' => __('Public Website', 'subway'),
92
                'callback' => 'subway_is_public_form',
93
                'section' => 'subway-settings-section',
94
                'group' => 'subway-page-visibility-section',
95
            ),
96
    
97
            array(
98
                'id' => 'subway_login_page',
99
                'label' => __('Private Login Page', 'subway'),
100
                'callback' => 'subway_login_page_form',
101
                'section' => 'subway-settings-section',
102
                'group' => 'subway-page-visibility-section',
103
            ),
104
            array(
105
                'id' => 'subway_public_post',
106
                'label' => __('Public Posts IDs', 'subway'),
107
                'callback' => 'subway_public_post',
108
                'section' => 'subway-settings-section',
109
                'group' => 'subway-page-visibility-section',
110
            ),
111
    
112
            array(
113
                'id' => 'subway_redirect_type',
114
                'label' => __('Redirect Type', 'subway'),
115
                'callback' => 'subway_redirect_option_form',
116
                'section' => 'subway-settings-section',
117
                'group' => 'subway-redirect-section',
118
            ),
119
            array(
120
                'id' => 'subway_redirect_wp_admin',
121
                'label' => __('Bypassing <em>wp-login.php</em>', 'subway'),
122
                'callback' => 'subway_lock_wp_admin',
123
                'section' => 'subway-settings-section',
124
                'group' => 'subway-redirect-section',
125
            ),
126
        );
127
128
        foreach ( $fields as $field ) {
129
130
            add_settings_field(
131
                $field['id'], $field['label'], 
132
                $field['callback'], $field['section'], 
133
                $field['group']
134
            );
135
136
            register_setting('subway-settings-group', $field['id']);
137
138
            $file = str_replace('_', '-', $field['callback']);
139
140
            include_once trailingslashit(SUBWAY_DIR_PATH) . 
141
            'settings-fields/field-' . sanitize_title($file) . '.php';
142
143
        }
144
145
        // Register Redirect Page ID Settings.
146
        register_setting('subway-settings-group', 'subway_redirect_page_id');
147
148
        // Register Redirect Custom URL Settings.
149
        register_setting('subway-settings-group', 'subway_redirect_custom_url');
150
151
        return;
152
    }
153
154
    /**
155
     * Callback function for the first Section.
156
     *
157
     * @return void
158
     */
159
    public function sectionCallback() 
160
    {
161
        echo esc_html_e(
162
            'All settings related to the 
163
        	visibility of your site and pages.', 'subway'
164
        );
165
        return;
166
    }
167
168
    /**
169
     * Callback function for the second Section.
170
     *
171
     * @return void
172
     */
173
    public function redirectCallback() 
174
    {
175
        return;
176
    }
177
178
    /**
179
     * Renders the 'wrapper' for our options pages.
180
     *
181
     * @return void
182
     */
183
    public function optionsPage() 
184
    {
185
        ?>
186
187
        <div class="wrap">
188
            <h2>
189
                <?php esc_html_e('Subway Settings', 'subway'); ?>
190
             </h2>
191
             <form id="subway-settings-form" action="options.php" method="POST">
192
                <?php settings_fields('subway-settings-group'); ?>
193
                <?php do_settings_sections('subway-settings-section'); ?>
194
                <?php submit_button(); ?>
195
             </form>
196
        </div>
197
        
198
        <?php
199
    }
200
201
}
202
203
$subwaySettings = new AdminSettings();
204