Skip to content

Commit

Permalink
Merge branch 'rc-1.4.0' into feature/settings-link
Browse files Browse the repository at this point in the history
  • Loading branch information
petenelson committed Jan 11, 2017
2 parents 5f35639 + 00d81bd commit 5aee66b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 21 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
**Donate link:** https://petenelson.io/
**Requires at least:** 4.4
**Tested up to:** 4.7
**Stable tag:** 1.3.0
**Stable tag:** 1.4.0
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -49,6 +49,9 @@ Have any questions? We can answer them here?

## Changelog ##

### 1.4.0 January 9th, 2017 ###
* Updated Settings UI for better clarity.

### 1.3.0 December 12th, 2016 ###
* Added option to require authentication for core endpoints.

Expand Down
56 changes: 55 additions & 1 deletion includes/settings/class-rest-api-toolbox-settings-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,66 @@ static public function settings_yes_no( $args ) {
}


static public function settings_checkbox( $args ) {

$args = wp_parse_args( $args,
array(
'name' => '',
'key' => '',
'after' => '',
)
);

$name = $args['name'];
$key = $args['key'];
$after = $args['after'];

$option = get_option( $key );
$value = isset( $option[ $name ] ) ? $option[ $name ] : '';

if ( empty( $value ) ) {
$value = '0';
}

echo '<div>';

// Checkbox
printf( '<label for="%1$s"><input id="%1$s" name="%2$s" type="checkbox" value="1" %3$s /></label> ',
esc_attr( "{$name}_1" ),
esc_attr( "{$key}[{$name}]" ),
checked( '1', $value, false )
);

echo '</div>';

self::output_after( $after );
}

/**
* Outputs trailing text after a settings input field.
*
* @param string $after The trailing text.
* @return void
*/
static public function output_after( $after ) {
if ( ! empty( $after ) ) {
echo '<div>' . wp_kses_post( $after ) . '</div>';
echo '<p class="description">' . wp_kses_post( $after ) . '</p>';
}
}

/**
* Outputs a section header.
*
* @param string $title The section header.
* @return void
*/
static public function header( $title ) {
?>
<h2><?php echo esc_html( $title ); ?></h2>
<hr/>
<?php
}


}

Expand Down
54 changes: 40 additions & 14 deletions includes/settings/class-rest-api-toolbox-settings-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ static public function register_core_settings() {

register_setting( $key, $key, array( __CLASS__, 'sanitize_core_settings') );

$section = 'core';
$section_remove = 'core-remove';
$section_auth = 'core-authentication';

add_settings_section( $section, '', null, $key );
add_settings_section( $section_remove, '', array( __CLASS__, 'section_header_remove' ), $key );
add_settings_section( $section_auth, '', array( __CLASS__, 'section_header_require_authentication' ), $key );

add_settings_field( 'remove-all-core-routes', __( 'Remove All WordPress Core Endpoints', 'rest-api-toolbox' ), array( __CLASS__, 'settings_yes_no' ), $key, $section,
array( 'key' => $key, 'name' => 'remove-all-core-routes', 'after' => '' ) );
add_settings_field( 'remove-all-core-routes', __( 'All WordPress Core Endpoints', 'rest-api-toolbox' ),
array( __CLASS__, 'settings_checkbox' ),
$key,
$section_remove,
array( 'key' => $key, 'name' => 'remove-all-core-routes', 'after' => '' )
);

$namespace = REST_API_Toolbox_Common::core_namespace();
$endpoints = REST_API_Toolbox_Common::core_endpoints();
Expand All @@ -37,31 +43,51 @@ static public function register_core_settings() {

// Add yes/no options to remove the endpoint.
$name = 'remove-endpoint|/' . $namespace . '/' . $endpoint;
add_settings_field( $name, sprintf( __( 'Remove Endpoint: %s', 'rest-api-toolbox' ), $endpoint),
array( __CLASS__, 'settings_yes_no' ),
add_settings_field( $name, sprintf( __( '%s', 'rest-api-toolbox' ), $endpoint),
array( __CLASS__, 'settings_checkbox' ),
$key,
$section,
$section_remove,
array( 'key' => $key, 'name' => $name, 'after' => '' )
);

// Add yes/no options to require authentication.
$name = 'require-authentication|/' . $namespace . '/' . $endpoint;
add_settings_field( $name, sprintf( __( 'Require Authentication: %s', 'rest-api-toolbox' ), $endpoint),
array( __CLASS__, 'settings_yes_no' ),
add_settings_field( $name, sprintf( __( '%s', 'rest-api-toolbox' ), $endpoint),
array( __CLASS__, 'settings_checkbox' ),
$key,
$section,
$section_auth,
array( 'key' => $key, 'name' => $name, 'after' => '' )
);
}

}

static public function sanitize_core_settings( $settings ) {

return $settings;
/**
* Outputs the Remove Endpoints header.
*
* @return void
*/
static public function section_header_remove() {
self::header( __( 'Remove Endpoints', 'rest-api-toolbox' ) );
}

/**
* Outputs the Require Authentication header.
*
* @return void
*/
static public function section_header_require_authentication() {
self::header( __( 'Require Authentication', 'rest-api-toolbox' ) );
}

/**
* Performs any necessary sanitation on core settings.
*
* @param array $settings Core settings
* @return array
*/
static public function sanitize_core_settings( $settings ) {
return $settings;
}
}

}
4 changes: 2 additions & 2 deletions includes/settings/class-rest-api-toolbox-settings-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ static public function register_general_settings() {

add_settings_section( $section, '', null, $key );

add_settings_field( 'disable-rest-api', __( 'Disable REST API', 'rest-api-toolbox' ), array( __CLASS__, 'settings_yes_no' ), $key, $section,
add_settings_field( 'disable-rest-api', __( 'Disable REST API', 'rest-api-toolbox' ), array( __CLASS__, 'settings_checkbox' ), $key, $section,
array( 'key' => $key, 'name' => 'disable-rest-api', 'after' => '' ) );

add_settings_field( 'disable-jsonp', __( 'Disable JSONP Support', 'rest-api-toolbox' ), array( __CLASS__, 'settings_yes_no' ), $key, $section,
add_settings_field( 'disable-jsonp', __( 'Disable JSONP Support', 'rest-api-toolbox' ), array( __CLASS__, 'settings_checkbox' ), $key, $section,
array( 'key' => $key, 'name' => 'disable-jsonp', 'after' => '' ) );

add_settings_field( 'rest-api-prefix', __( 'REST API Prefix', 'rest-api-toolbox' ), array( __CLASS__, 'settings_input' ), $key, $section,
Expand Down
2 changes: 1 addition & 1 deletion includes/settings/class-rest-api-toolbox-settings-ssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static public function register_ssl_settings( $title ) {

add_settings_section( $section, '', null, $key );

add_settings_field( 'require-ssl', __( 'Require SSL', 'rest-api-toolbox' ), array( __CLASS__, 'settings_yes_no' ), $key, $section,
add_settings_field( 'require-ssl', __( 'Require SSL', 'rest-api-toolbox' ), array( __CLASS__, 'settings_checkbox' ), $key, $section,
array( 'key' => $key, 'name' => 'require-ssl', 'after' => '' ) );

}
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: rest api, rest, wp rest api
Donate link: https://petenelson.io/
Requires at least: 4.4
Tested up to: 4.7
Stable tag: 1.3.0
Stable tag: 1.4.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -41,6 +41,9 @@ Have any questions? We can answer them here?

== Changelog ==

= 1.4.0 January 9th, 2017 =
* Updated Settings UI for better clarity.

= 1.3.0 December 12th, 2016 =
* Added option to require authentication for core endpoints.

Expand Down
2 changes: 1 addition & 1 deletion rest-api-toolbox.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: REST API Toolbox
* Version: 1.3.0
* Version: 1.4.0
* Description: Allows easy tweaks of several REST API settings
* Author: Pete Nelson
* Author URI: https://github.com/petenelson/wp-rest-api-toolbox
Expand Down

0 comments on commit 5aee66b

Please sign in to comment.