| 1 |
<?php |
| 2 |
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
if( ! class_exists('MWTSA_Admin_Settings') ) { |
| 5 |
|
| 6 |
class MWTSA_Admin_Settings { |
| 7 |
|
| 8 |
public $option_name = 'mwtsa_settings'; |
| 9 |
public $existing_options; |
| 10 |
|
| 11 |
public function __construct() { |
| 12 |
$this->option_name = MWTSA_Options::$option_name; |
| 13 |
$this->existing_options = MWTSA_Options::get_options(); |
| 14 |
|
| 15 |
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); |
| 16 |
add_action( 'admin_init', array( $this, 'mwtsa_settings_init' ) ); |
| 17 |
} |
| 18 |
|
| 19 |
public function add_admin_menu( ) { |
| 20 |
|
| 21 |
add_options_page( 'MWT: Search Analytics', 'MWT: Search Analytics', 'manage_options', 'mwt-search-analytics', array( &$this, 'options_page' ) ); |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
public function mwtsa_settings_init() { |
| 26 |
|
| 27 |
register_setting( 'general_options', $this->option_name ); |
| 28 |
|
| 29 |
add_settings_section( |
| 30 |
'mwtsa_general_options_section', |
| 31 |
__( 'General Settings', 'mwt-search-analytics' ), |
| 32 |
array( &$this, 'settings_section_callback' ), |
| 33 |
'general_options' |
| 34 |
); |
| 35 |
|
| 36 |
add_settings_field( |
| 37 |
'mwtsa_exclude_search_for_role', |
| 38 |
__( 'Ignore search queries for user roles', 'mwt-search-analytics' ), |
| 39 |
array( &$this, 'field_exclude_search_for_role_render' ), |
| 40 |
'general_options', |
| 41 |
'mwtsa_general_options_section' |
| 42 |
); |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
public function field_exclude_search_for_role_render() { |
| 47 |
$roles = get_editable_roles(); |
| 48 |
|
| 49 |
if ( ! empty( $roles ) ): |
| 50 |
foreach ( $roles as $role_key => $role ) : |
| 51 |
?> |
| 52 |
<label><input type='checkbox' name='mwtsa_settings[mwtsa_exclude_search_for_role][]' value='<?php echo $role_key ?>' <?php checked( in_array( $role_key, $this->existing_options['mwtsa_exclude_search_for_role'] ), 1 ) ?> /> <?php echo $role['name'] ?></label><br /> |
| 53 |
<?php |
| 54 |
endforeach; |
| 55 |
endif; |
| 56 |
} |
| 57 |
|
| 58 |
public function settings_section_callback( ) { |
| 59 |
|
| 60 |
echo ''; |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
public function options_page( ) { |
| 65 |
|
| 66 |
?> |
| 67 |
<form action='options.php' method='post'> |
| 68 |
|
| 69 |
<?php |
| 70 |
settings_fields( 'general_options' ); |
| 71 |
do_settings_sections( 'general_options' ); |
| 72 |
submit_button(); |
| 73 |
?> |
| 74 |
|
| 75 |
</form> |
| 76 |
<?php |
| 77 |
|
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
return new MWTSA_Admin_Settings(); |