Skip to content

Commit

Permalink
1.3.4 admin bar menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepm committed Dec 29, 2019
1 parent d4ffddc commit 040fdfd
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 17 deletions.
88 changes: 73 additions & 15 deletions class-wp-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class WP_Proxy {

/**
* WP_Proxy Construct
*
* @var wp_proxy
*/
public function __construct() {
$this->load_plugin_textdomain();
Expand All @@ -53,6 +51,8 @@ public function __construct() {
}
add_action( 'admin_menu', array( $this, 'options_page' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_init', array( $this, 'wp_proxy_enable_or_disable' ) );
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
add_filter( 'plugin_row_meta', array( $this, 'plugin_details_links' ), 10, 2 );
}
Expand Down Expand Up @@ -106,6 +106,7 @@ public function options_page() {
add_options_page( 'WP Proxy', esc_html__( 'WP Proxy', 'wp-proxy' ), 'manage_options', 'wp_proxy', array( $this, 'wp_proxy_option' ) );
if ( isset( $_POST['option_page'] ) && 'wp_proxy' === sanitize_text_field( wp_unslash( $_POST['option_page'] ) ) && isset( $_POST['_wpnonce'] ) ) {
if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wp_proxy-options' ) ) {
$wp_proxy_options = $this->options;
if ( isset( $_POST['proxy_host'] ) ) {
$wp_proxy_options['proxy_host'] = sanitize_text_field( wp_unslash( $_POST['proxy_host'] ) );
}
Expand Down Expand Up @@ -140,6 +141,24 @@ public function options_page() {
}
}

/**
* Enable or disable
*
* @since 1.3.4
*/
public function wp_proxy_enable_or_disable() {
// avoid invalid nonce.
if ( isset( $_GET['wp_proxy'] ) && check_admin_referer( 'wp-proxy-quick-set', 'wp-proxy-quick-set' ) ) {
$wp_proxy_options = $this->options;
if ( 'enable' === sanitize_text_field( wp_unslash( $_GET['wp_proxy'] ) ) ) {
$wp_proxy_options['enable'] = true;
} else {
$wp_proxy_options['enable'] = false;
}
update_option( 'wp_proxy_options', $wp_proxy_options );
}
}

/**
* In plugins page show some links
*
Expand Down Expand Up @@ -172,6 +191,45 @@ public function plugin_action_links( $links, $file ) {
return $links;
}

/**
* Admin bar menu
*
* @param mixed $wp_admin_bar admin_bar.
* @since 1.3.4
*/
public function admin_bar_menu( $wp_admin_bar ) {
if ( is_user_logged_in() && is_admin_bar_showing() && current_user_can( 'manage_options' ) ) {
$options = get_option( 'wp_proxy_options' );
$url = admin_url( 'options-general.php?page=wp_proxy' );
$wp_admin_bar->add_node(
array(
'id' => 'wp_proxy',
'title' => __( 'WP Proxy' ),
'href' => $url,
)
);
if ( $options['enable'] ) {
$wp_admin_bar->add_node(
array(
'id' => 'disable_wp_proxy',
'parent' => 'wp_proxy',
'title' => __( 'Disabled' ),
'href' => wp_nonce_url( add_query_arg( 'wp_proxy', 'disable' ), 'wp-proxy-quick-set', 'wp-proxy-quick-set' ),
)
);
} else {
$wp_admin_bar->add_node(
array(
'id' => 'enable_wp_proxy',
'parent' => 'wp_proxy',
'title' => __( 'Enabled' ),
'href' => wp_nonce_url( add_query_arg( 'wp_proxy', 'enable' ), 'wp-proxy-quick-set', 'wp-proxy-quick-set' ),
)
);
}
}
}

/**
* Check URL
*
Expand Down Expand Up @@ -216,28 +274,28 @@ public function register_settings() {
);
add_settings_field(
'proxy_host',
esc_html__( 'Proxy Host', 'wp-proxy' ),
__( 'Hostname' ),
array( $this, 'proxy_host_callback' ),
'wp_proxy',
'wp_proxy_config'
);
add_settings_field(
'proxy_port',
esc_html__( 'Proxy Port', 'wp-proxy' ),
__( 'Port' ),
array( $this, 'proxy_port_callback' ),
'wp_proxy',
'wp_proxy_config'
);
add_settings_field(
'Username',
esc_html__( 'Proxy Username', 'wp-proxy' ),
__( 'Username' ),
array( $this, 'proxy_username_callback' ),
'wp_proxy',
'wp_proxy_config'
);
add_settings_field(
'password',
esc_html__( 'Proxy Password', 'wp-proxy' ),
__( 'Password' ),
array( $this, 'proxy_password_callback' ),
'wp_proxy',
'wp_proxy_config'
Expand All @@ -251,7 +309,7 @@ public function register_settings() {
);
add_settings_field(
'enable',
esc_html__( 'Enable', 'wp-proxy' ),
__( 'Enabled' ),
array( $this, 'proxy_enable_callback' ),
'wp_proxy',
'wp_proxy_config'
Expand Down Expand Up @@ -289,7 +347,7 @@ public function wp_proxy_option() {
*/
public function proxy_host_callback() {
?>
<input id="proxy_host" name="proxy_host" type="text" placeholder="<?php esc_html_e( 'proxy host', 'wp-proxy' ); ?>" value="<?php echo esc_html( $this->options['proxy_host'] ); ?>" autocomplete="off">
<input id="proxy_host" name="proxy_host" type="text" placeholder="<?php esc_html_e( 'Hostname' ); ?>" value="<?php echo esc_html( $this->options['proxy_host'] ); ?>" autocomplete="off">
<?php
}

Expand All @@ -300,7 +358,7 @@ public function proxy_host_callback() {
*/
public function proxy_port_callback() {
?>
<input id="proxy_port" name="proxy_port" type="number" placeholder="<?php esc_html_e( 'proxy port', 'wp-proxy' ); ?>" value="<?php echo esc_html( $this->options['proxy_port'] ); ?>" autocomplete="off">
<input id="proxy_port" name="proxy_port" type="number" placeholder="<?php esc_html_e( 'Port' ); ?>" value="<?php echo esc_html( $this->options['proxy_port'] ); ?>" autocomplete="off">
<?php
}

Expand All @@ -311,7 +369,7 @@ public function proxy_port_callback() {
*/
public function proxy_username_callback() {
?>
<input id="username" name="username" type="text" placeholder="<?php esc_html_e( 'username', 'wp-proxy' ); ?>" value="<?php echo esc_html( $this->options['username'] ); ?>" autocomplete="off">
<input id="username" name="username" type="text" placeholder="<?php esc_html_e( 'Username' ); ?>" value="<?php echo esc_html( $this->options['username'] ); ?>" autocomplete="off">
<?php
}

Expand All @@ -322,7 +380,7 @@ public function proxy_username_callback() {
*/
public function proxy_password_callback() {
?>
<input id="password" name="password" type="password" placeholder="<?php esc_html_e( 'password', 'wp-proxy' ); ?>" value="<?php echo esc_html( $this->options['password'] ); ?>" autocomplete="off">
<input id="password" name="password" type="password" placeholder="<?php esc_html_e( 'Password' ); ?>" value="<?php echo esc_html( $this->options['password'] ); ?>" autocomplete="off">
<?php
}

Expand All @@ -346,11 +404,11 @@ public function proxy_enable_callback() {
?>
<select name="enable" id="enable">
<?php if ( $this->options['enable'] ) { ?>
<option value="yes" selected="selected"><?php esc_html_e( 'yes', 'wp-proxy' ); ?></option>
<option value="no"><?php esc_html_e( 'no', 'wp-proxy' ); ?></option>
<option value="yes" selected="selected"><?php esc_html_e( 'Yes' ); ?></option>
<option value="no"><?php esc_html_e( 'No' ); ?></option>
<?php } else { ?>
<option value="yes"><?php esc_html_e( 'yes', 'wp-proxy' ); ?></option>
<option value="no" selected="selected"><?php esc_html_e( 'no', 'wp-proxy' ); ?></option>
<option value="yes"><?php esc_html_e( 'Yes' ); ?></option>
<option value="no" selected="selected"><?php esc_html_e( 'No' ); ?></option>
<?php } ?>
</select>
<?php
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://xn--vkuk.org/blog/wp-proxy
Tags: proxy
Requires at least: 3.0.1
Tested up to: 5.3.2
Stable tag: 1.3.3
Stable tag: 1.3.4
Requires PHP: 5.2.4
License: GPLv2 or later

Expand All @@ -30,6 +30,12 @@ Always free, we don't provide http proxy, and code is open source, it's very sim
No thanks. This is just a simple plugin, I would be very happy if it useful to you.

== Changelog ==
= 1.3.4 =
* use some default text-domain
* admin bar menu

= 1.3.3 =
* plugins page show links

= 1.3.2 =
* fill readme
Expand Down
2 changes: 1 addition & 1 deletion wp-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Proxy
* Plugin URI: https://xn--vkuk.org/blog/wp-proxy
* Description: manage proxy for WordPress
* Version: 1.3.3
* Version: 1.3.4
* Author: sleepm
* Text Domain: wp-proxy
* Domain Path: /languages
Expand Down

0 comments on commit 040fdfd

Please sign in to comment.