';
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 '
';
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() {
if (is_admin() || (!empty($_SERVER['REQUEST_URI']) && strpos(sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'])), 'wp-login.php') !== false)) {
$disableip = get_option( 'awa-ip-field' );
// Ensure $_SERVER data is unslashed and sanitized before use.
$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 ) ) {
if (is_admin() ){
echo esc_html__( 'Access Forbidden' , 'allow-wp-admin-access') . ': ' . esc_html( __( 'ERROR: Access Forbidden.' , 'allow-wp-admin-access') );
die;
}
}
}
}
}
public function check_ip( WP_User $user ) {
$disableip = get_option( 'awa-ip-field' );
// Ensure $_SERVER data is unslashed and sanitized before use.
$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 ) ) {
$message = esc_html__( 'The request is came from unknown source.', 'allow-wp-admin-access');
return new WP_Error( 'unknown_source', $message );
}
}
return $user;
}
}
$restrict_settings_page = new Allow_WP_Admin_Access_Setup_Action();