'; echo '' . esc_html( $value['lable'] ) . ''; echo ''; echo ''; } /** * Generates a form field for the plugin settings page * * This method creates a form field, such as a text input or textarea, for use in the plugin's settings page. * * @since 1.0.2 */ public function awa_form_field() { $options = array( array( 'name' => 'awa-ip-field', 'desc' => 'Enter Allow ip', 'id' => 'allowip', 'type' => 'textarea', 'lable' => 'Enter Allow Ip', ), ); foreach ( $options as $value ) { switch ( $value['name'] ) { case 'awa-ip-field': $this->awa_create_ip_field( $value ); break; } } } /** * Displays the plugin settings page. * * This method outputs the HTML for the plugin's settings page, allowing users to configure plugin options. * * @since 1.0.2 */ public function awa_plugin_settings_page() { echo '
'; echo '

Wp-admin Access Allow Setting

'; echo '
'; settings_fields( 'awa-plugin-settings-group' ); do_settings_sections( 'awa-plugin-settings-group' ); echo ' '; $this->awa_form_field(); echo '
'; echo 'Note: You have enter comma separated ip for this format.
Multiple Ip: 195.167.10.17,182.128.10.159,505.256.63' . '
Single Ip: 195.167.10.17
'; submit_button(); echo '
'; echo '
'; } /** * Blocks access to admin users unless from certain IPs. Regular users may be from anywhere. * * @param string $user The username. * @param string $name The name of the user. * @param string $pass The password of the user. */ public function awa_ip( $user, $name, $pass ) { $disableip = get_option( 'awa-ip-field' ); // Ensure $_SERVER data is unslashed and sanitized before use. $req_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; $remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; $allow_ips = explode( ',', $disableip ); if ( '' != $disableip ) { if ( ! in_array( $remote_addr, $allow_ips ) && preg_match( '#wp-admin#', $req_uri ) && preg_match( '#wp-login#', $req_uri ) ) { echo esc_html( 'Access Forbidden' ) . ': ' . esc_html( __( 'ERROR: Access Forbidden.' ) ); die; } } } } $restrict_settings_page = new Allow_WP_Admin_Access_Setup_Action();