'none', 'auth_token' => '', 'show_token_to_users' => '0', 'cookie_lifetime' => '0', 'disable_xmlrpc' => '1' ); /** * current options * * @var array */ public $options = array(); /** * the settings page * * @var string */ public $page = 'reading'; /** * section identifier * * @var string */ public $section = 'authenticator_reading'; /** * constructor */ public function __construct() { $this->load_options(); register_setting( $this->page, Authenticator::KEY, array( $this, 'validate' ) ); add_settings_section( $this->section, __( 'Authenticator Options', Authenticator::TEXTDOMAIN ), array( $this, 'description' ), $this->page ); add_settings_field( 'feed_authentication', __( 'What type of feed authentication you prefer?', Authenticator::TEXTDOMAIN ), array( $this, 'auth_checkbox' ), $this->page, $this->section, array( 'id' => 'feed_authentication', 'name' => Authenticator::KEY . '[feed_authentication]', ) ); add_settings_field( 'show_token_to_users', __( 'Show auth token on the users profile settings page?', Authenticator::TEXTDOMAIN ), array( $this, 'checkbox' ), $this->page, $this->section, array( 'id' => 'show_token_to_users', 'name' => Authenticator::KEY . '[show_token_to_users]', 'label_for' => 'show_token_to_users' ) ); add_settings_field( 'cookie_lifetime', __( 'Cookie lifetime in days', Authenticator::TEXTDOMAIN ), array( $this, 'textinput' ), $this->page, $this->section, array( 'id' => 'cookie_lifetime', 'name' => Authenticator::KEY . '[cookie_lifetime]', 'label_for' => 'cookie_lifetime', 'notice' => __( 'User will be logged in for this time', Authenticator::TEXTDOMAIN ) ) ); add_settings_field( 'disable_xmlrpc', __( 'Disable XML-RPC Interface?', Authenticator::TEXTDOMAIN ), array( $this, 'checkbox' ), $this->page, $this->section, array( 'id' => 'disable_xmlrpc', 'name' => Authenticator::KEY . '[disable_xmlrpc]', 'label_for' => 'disable_xmlrpc', 'notice' => __( 'This setting will disable the interface even for logged in users.', Authenticator::TEXTDOMAIN ) ) ); new Authenticator_Settings_UI(); new Authenticator_User_Profile(); } /** * prints the form field * * @param array $attr * * @return void */ public function auth_checkbox( $attr ) { $id = $attr[ 'id' ]; $name = $attr[ 'name' ]; $current = $this->options[ $id ]; ?>
/>
/>
/>
options[ 'feed_authentication' ] ) : ?>
disabled="disabled"
value="get_auth_token(); ?>"
/>
options[ 'feed_authentication' ] ) : ?>
' . $example_url . '' ); ?>
options[ $id ]; ?> /> options[ $id ] ? '' : $this->options[ $id ]; ?>options[ 'auth_token' ] ) || isset( $_POST[ 'authenticator_regenerate_token' ] ) ) { $this->generate_auth_token(); } break; default : $request[ 'feed_authentication' ] = 'none'; break; } if ( ! isset( $request[ 'show_token_to_users' ] ) ) { $request[ 'show_token_to_users' ] = '0'; } else { $request[ 'show_token_to_users' ] = '1'; } $request[ 'auth_token' ] = $this->get_auth_token(); $request[ 'cookie_lifetime' ] = ( int ) $request[ 'cookie_lifetime' ]; if ( empty( $request[ 'disable_xmlrpc' ] ) ) { $request[ 'disable_xmlrpc' ] = '0'; } else { $request[ 'disable_xmlrpc' ] = '1'; } return $request; } /** * get the auth token * * @return string */ public function get_auth_token() { if ( ! isset( $this->options[ 'auth_token' ] ) ) { $this->options[ 'auth_token' ] = self::$default_options[ 'auth_token' ]; $this->update_options(); } return $this->options[ 'auth_token' ]; } /** * generate an auth token * * @return string */ protected function generate_auth_token() { if ( ! is_user_logged_in() ) { return NULL; } $user = wp_get_current_user(); $this->options[ 'auth_token' ] = md5( $user->data->user_pass . uniqid() ); return $this->options[ 'auth_token' ]; } /** * prints the sections description, if it were needed * * @return void */ public function description() { return; } /** * load options and set defaults if necessary * * @return void */ public function load_options() { $options = get_option( Authenticator::KEY, '' ); if ( ! is_array( $options ) ) { $this->options = self::$default_options; $this->update_options(); } else { $this->options = $options; #check options for updates on default options $update = FALSE; foreach ( self::$default_options as $k => $v ) { if ( ! isset( $this->options[ $k ] ) ) { $this->options[ $k ] = $v; $update = TRUE; } } if ( $update ) { $this->update_options(); } } } /** * update options manually * * @return void */ protected function update_options() { update_option( Authenticator::KEY, $this->options ); } }