Plugin Directory

Changeset 2219135


Ignore:
Timestamp:
12/29/2019 05:14:25 AM (6 years ago)
Author:
sdffamt
Message:

admin bar menu

Location:
wp-proxy/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-proxy/trunk/class-wp-proxy.php

    r2218302 r2219135  
    3030    /**
    3131     * WP_Proxy Construct
    32      *
    33      * @var wp_proxy
    3432     */
    3533    public function __construct() {
     
    5452        add_action( 'admin_menu', array( $this, 'options_page' ) );
    5553        add_action( 'admin_init', array( $this, 'register_settings' ) );
     54        add_action( 'admin_init', array( $this, 'wp_proxy_enable_or_disable' ) );
     55        add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
    5656        add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
    5757        add_filter( 'plugin_row_meta', array( $this, 'plugin_details_links' ), 10, 2 );
     
    107107        if ( isset( $_POST['option_page'] ) && 'wp_proxy' === sanitize_text_field( wp_unslash( $_POST['option_page'] ) ) && isset( $_POST['_wpnonce'] ) ) {
    108108            if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wp_proxy-options' ) ) {
     109                $wp_proxy_options = $this->options;
    109110                if ( isset( $_POST['proxy_host'] ) ) {
    110111                    $wp_proxy_options['proxy_host'] = sanitize_text_field( wp_unslash( $_POST['proxy_host'] ) );
     
    142143
    143144    /**
     145     * Enable or disable
     146     *
     147     * @since 1.3.4
     148     */
     149    public function wp_proxy_enable_or_disable() {
     150        // avoid invalid nonce.
     151        if ( isset( $_GET['wp_proxy'] ) && check_admin_referer( 'wp-proxy-quick-set', 'wp-proxy-quick-set' ) ) {
     152            $wp_proxy_options = $this->options;
     153            if ( 'enable' === sanitize_text_field( wp_unslash( $_GET['wp_proxy'] ) ) ) {
     154                $wp_proxy_options['enable'] = true;
     155            } else {
     156                $wp_proxy_options['enable'] = false;
     157            }
     158            update_option( 'wp_proxy_options', $wp_proxy_options );
     159        }
     160    }
     161
     162    /**
    144163     * In plugins page show some links
    145164     *
     
    171190        }
    172191        return $links;
     192    }
     193
     194    /**
     195     * Admin bar menu
     196     *
     197     * @param   mixed $wp_admin_bar admin_bar.
     198     * @since 1.3.4
     199     */
     200    public function admin_bar_menu( $wp_admin_bar ) {
     201        if ( is_user_logged_in() && is_admin_bar_showing() && current_user_can( 'manage_options' ) ) {
     202            $options = get_option( 'wp_proxy_options' );
     203            $url     = admin_url( 'options-general.php?page=wp_proxy' );
     204            $wp_admin_bar->add_node(
     205                array(
     206                    'id'    => 'wp_proxy',
     207                    'title' => __( 'WP Proxy' ),
     208                    'href'  => $url,
     209                )
     210            );
     211            if ( $options['enable'] ) {
     212                $wp_admin_bar->add_node(
     213                    array(
     214                        'id'     => 'disable_wp_proxy',
     215                        'parent' => 'wp_proxy',
     216                        'title'  => __( 'Disabled' ),
     217                        'href'   => wp_nonce_url( add_query_arg( 'wp_proxy', 'disable' ), 'wp-proxy-quick-set', 'wp-proxy-quick-set' ),
     218                    )
     219                );
     220            } else {
     221                $wp_admin_bar->add_node(
     222                    array(
     223                        'id'     => 'enable_wp_proxy',
     224                        'parent' => 'wp_proxy',
     225                        'title'  => __( 'Enabled' ),
     226                        'href'   => wp_nonce_url( add_query_arg( 'wp_proxy', 'enable' ), 'wp-proxy-quick-set', 'wp-proxy-quick-set' ),
     227                    )
     228                );
     229            }
     230        }
    173231    }
    174232
     
    217275        add_settings_field(
    218276            'proxy_host',
    219             esc_html__( 'Proxy Host', 'wp-proxy' ),
     277            __( 'Hostname' ),
    220278            array( $this, 'proxy_host_callback' ),
    221279            'wp_proxy',
     
    224282        add_settings_field(
    225283            'proxy_port',
    226             esc_html__( 'Proxy Port', 'wp-proxy' ),
     284            __( 'Port' ),
    227285            array( $this, 'proxy_port_callback' ),
    228286            'wp_proxy',
     
    231289        add_settings_field(
    232290            'Username',
    233             esc_html__( 'Proxy Username', 'wp-proxy' ),
     291            __( 'Username' ),
    234292            array( $this, 'proxy_username_callback' ),
    235293            'wp_proxy',
     
    238296        add_settings_field(
    239297            'password',
    240             esc_html__( 'Proxy Password', 'wp-proxy' ),
     298            __( 'Password' ),
    241299            array( $this, 'proxy_password_callback' ),
    242300            'wp_proxy',
     
    252310        add_settings_field(
    253311            'enable',
    254             esc_html__( 'Enable', 'wp-proxy' ),
     312            __( 'Enabled' ),
    255313            array( $this, 'proxy_enable_callback' ),
    256314            'wp_proxy',
     
    290348    public function proxy_host_callback() {
    291349        ?>
    292             <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">
     350            <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">
    293351        <?php
    294352    }
     
    301359    public function proxy_port_callback() {
    302360        ?>
    303             <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">
     361            <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">
    304362        <?php
    305363    }
     
    312370    public function proxy_username_callback() {
    313371        ?>
    314             <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">
     372            <input id="username" name="username" type="text" placeholder="<?php esc_html_e( 'Username' ); ?>" value="<?php echo esc_html( $this->options['username'] ); ?>" autocomplete="off">
    315373        <?php
    316374    }
     
    323381    public function proxy_password_callback() {
    324382        ?>
    325             <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">
     383            <input id="password" name="password" type="password" placeholder="<?php esc_html_e( 'Password' ); ?>" value="<?php echo esc_html( $this->options['password'] ); ?>" autocomplete="off">
    326384        <?php
    327385    }
     
    347405            <select name="enable" id="enable">
    348406            <?php if ( $this->options['enable'] ) { ?>
    349                 <option value="yes" selected="selected"><?php esc_html_e( 'yes', 'wp-proxy' ); ?></option>
    350                 <option value="no"><?php esc_html_e( 'no', 'wp-proxy' ); ?></option>
     407                <option value="yes" selected="selected"><?php esc_html_e( 'Yes' ); ?></option>
     408                <option value="no"><?php esc_html_e( 'No' ); ?></option>
    351409            <?php } else { ?>
    352                 <option value="yes"><?php esc_html_e( 'yes', 'wp-proxy' ); ?></option>
    353                 <option value="no" selected="selected"><?php esc_html_e( 'no', 'wp-proxy' ); ?></option>
     410                <option value="yes"><?php esc_html_e( 'Yes' ); ?></option>
     411                <option value="no" selected="selected"><?php esc_html_e( 'No' ); ?></option>
    354412            <?php } ?>
    355413            </select>
  • wp-proxy/trunk/readme.txt

    r2218302 r2219135  
    55Requires at least: 3.0.1
    66Tested up to: 5.3.2
    7 Stable tag: 1.3.3
     7Stable tag: 1.3.4
    88Requires PHP: 5.2.4
    99License: GPLv2 or later
     
    3131
    3232== Changelog  ==
     33= 1.3.4 =
     34* use some default text-domain
     35* admin bar menu
     36
     37= 1.3.3 =
     38* plugins page show links
    3339
    3440= 1.3.2 =
  • wp-proxy/trunk/wp-proxy.php

    r2218302 r2219135  
    44 * Plugin URI: https://xn--vkuk.org/blog/wp-proxy
    55 * Description: manage proxy for WordPress
    6  * Version: 1.3.3
     6 * Version: 1.3.4
    77 * Author: sleepm
    88 * Text Domain: wp-proxy
Note: See TracChangeset for help on using the changeset viewer.