plugin_name = $plugin_name; $this->version = $version; } /** * This function introduces the theme options into the 'Appearance' menu and into a top-level * 'HMP' menu. */ public function setup_plugin_options_menu() { //Add the menu to the Plugins set of menu items add_options_page( 'Admin block', // The title to be displayed in the browser window for this page. 'Admin block',// The text to be displayed for this menu item 'manage_options',// Which type of users can see this menu item 'abbi_options',// The unique ID - that is, the slug - for this menu item array( $this, 'render_settings_page_content'),// The name of the function to call when rendering this menu's page 'dashicons-lock' ); } /** * Provides default values for the Display Options. * * @return array */ public function default_advanced_options() { $defaults = array( 'hide_wplogins' => '127.0.0.1', 'enable_devmode' => '', 'show_footer' => '', ); return $defaults; } /** * Provide default values for the Social Options. * * @return array */ public function default_abbi_help() { $defaults = array( ); return $defaults; } /** * Provides default values for the Input Options. * * @return array */ public function default_input_options() { $defaults = array( 'input_example' => 'default input example', 'textarea_example' => '', 'checkbox_example' => '', 'radio_example' => '2', 'time_options' => 'default' ); return $defaults; } /** * Renders a simple page to display for the theme menu defined above. */ public function render_settings_page_content( $active_tab = '' ) { ?>

' . __( 'Enter which IPs wish to display wp-admin.', 'admin-allow-by-ip' ) . '

'; } // end general_options_callback /** * Initializes the theme's display options page by registering the Sections, * Fields, and Settings. * * This function is registered with the 'admin_init' hook. */ public function initialize_advanced_options() { // If the theme options don't exist, create them. if( false == get_option( 'abbi_options_advanced_options' ) ) { $default_array = $this->default_advanced_options(); add_option( 'abbi_options_advanced_options', $default_array ); } add_settings_section( 'general_settings_section', // ID used to identify this section and with which to register options __( 'Development mode', 'admin-allow-by-ip' ), // Title to be displayed on the administration page array( $this, 'general_options_callback'),// Callback used to render the description of the section 'abbi_options_advanced_options' // Page on which to add this section of options ); add_settings_field( 'enable_devmode', __( 'Enable Development', 'admin-allow-by-ip' ), array( $this, 'toggle_block_callback'), 'abbi_options_advanced_options', 'general_settings_section', array( __( 'Enable developing mode for below IP(s).', 'admin-allow-by-ip' ), ) ); // Next, we'll introduce the fields for toggling the visibility of content elements. add_settings_field( 'hide_wplogins',// ID used to identify the field throughout the theme __( 'Hide wp logins', 'admin-allow-by-ip' ),// The label to the left of the option interface element array( $this, 'toggle_ips_callback'),// The name of the function responsible for rendering the option interface 'abbi_options_advanced_options',// The page on which this option will be displayed 'general_settings_section',// The name of the section to which this field belongs array( // The array of arguments to pass to the callback. In this case, just a description. __( 'ex - 192.168.1.2,192.168.1.3', 'admin-allow-by-ip' ), ) ); // Finally, we register the fields with WordPress register_setting( 'abbi_options_advanced_options', 'abbi_options_advanced_options', array( $this, 'validate_input_examples') ); } // end wppb-demo_initialize_theme_options public function initialize_help_options(){ add_settings_section( 'general_settings_section', // ID used to identify this section and with which to register options __( 'Development mode', 'admin-allow-by-ip' ), // Title to be displayed on the administration page array( $this, 'general_options_callback'),// Callback used to render the description of the section 'abbi_options_help_options' // Page on which to add this section of options ); // add_settings_field( // 'enable_devmode', // __( 'Enable Development', 'admin-allow-by-ip' ), // array( $this, 'toggle_block_callback'), // 'abbi_options_help_options', // 'general_settings_section', // array( // __( 'Enable developing mode for below IP(s).', 'admin-allow-by-ip' ), // ) // ); } public function toggle_block_callback($args) { $options = get_option('abbi_options_advanced_options'); $devmode = "enable_devmode"; // var_dump($options['enable_devmode']); $checked = checked(1, isset( $options['enable_devmode'] ) ? $options['enable_devmode'] : 0, false ); $html = ''; // $html .= ''; $html .= ""; $allowed_html = array( 'input' => array( 'type' => array(), 'id' => array(), 'name' => array(), 'value' => array(), 'checked' => array() ), ); echo wp_kses($html,$allowed_html ); // echo htmlspecialchars_decode(htmlspecialchars($html )); } /** * This function renders the interface elements for toggling the visibility of the header element. * * It accepts an array or arguments and expects the first element in the array to be the description * to be displayed next to the checkbox. */ public function toggle_ips_callback($args) { // First, we read the options collection $options = get_option('abbi_options_advanced_options'); // Next, we update the name attribute to access this element's ID in the context of the display options array // We also access the hide_wplogins element of the options collection in the call to the checked() helper function // $html = ''; $html = ''; // Here, we'll take the first argument of the array and add it to a label next to the checkbox // $html .= ''; $html .= ""; $allowed_html = array( 'input' => array( 'type' => array(), 'id' => array(), 'name' => array(), 'value' => array() ), ); echo wp_kses($html,$allowed_html ); } // end toggle_ips_callback /** * Sanitization callback for the social options. Since each of the social options are text inputs, * this function loops through the incoming option and strips all tags and slashes from the value * before serializing it. * * @params $input The unsanitized collection of options. * * @returns The collection of sanitized values. */ public function sanitize_abbi_help( $input ) { // Define the array for the updated options $output = array(); // Loop through each of the options sanitizing the data foreach( $input as $key => $val ) { if( isset ( $input[$key] ) ) { $output[$key] = esc_url_raw( strip_tags( stripslashes( $input[$key] ) ) ); } // end if } // end foreach // Return the new collection return apply_filters( 'sanitize_abbi_help', $output, $input ); } // end sanitize_abbi_help public function validate_input_examples( $input ) { // Create our array for storing the validated options $output = array(); // Loop through each of the incoming options foreach( $input as $key => $value ) { // Check to see if the current option has a value. If so, process it. if( isset( $input[$key] ) ) { // Strip all HTML and PHP tags and properly handle quoted strings $output[$key] = strip_tags( stripslashes( $input[ $key ] ) ); } // end if } // end foreach // Return the array processing any additional functions filtered by this action return apply_filters( 'validate_input_examples', $output, $input ); } // end validate_input_examples function _restrict_wp_login(){ global $pagenow; $getipset = get_option('abbi_options_advanced_options')['hide_wplogins']; $removelastcomma = str_replace(' ', '', rtrim($getipset, ',')); $iplists = explode(",", $removelastcomma); $removeempty = array_filter($iplists); foreach ($removeempty as $singleip) { if (!empty($_SERVER['HTTP_CLIENT_IP'])) $ip = $_SERVER['HTTP_CLIENT_IP']; elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; else $ip = $_SERVER['REMOTE_ADDR']; if ($singleip != $ip) { if ( is_user_logged_in() || strpos($singleip, $ip ) !== false ) return; if( 'wp-login.php' == $pagenow && $_GET['action'] != "logout") { wp_redirect( home_url() ); exit(); } } } } }