Skip to content

Commit

Permalink
Merge pull request petenelson#36 from petenelson/feature/settings-link
Browse files Browse the repository at this point in the history
Feature/settings link
  • Loading branch information
petenelson committed Jan 12, 2017
2 parents 00d81bd + 63ea668 commit 754c0f0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Have any questions? We can answer them here?

## Changelog ##

### 1.4.0 January 9th, 2017 ###
### 1.4.0 January 11th, 2017 ###
* Added link to settings page from the plugins list page.
* Updated Settings UI for better clarity.

### 1.3.0 December 12th, 2016 ###
Expand Down
54 changes: 54 additions & 0 deletions includes/class-rest-api-toolbox-admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

if ( ! defined( 'ABSPATH' ) ) die( 'restricted access' );

if ( ! class_exists( 'REST_API_Toolbox_Admin' ) ) {

class REST_API_Toolbox_Admin extends REST_API_Toolbox_Base {

/**
* Wires up WordPress hooks and filters
*
* @return void
*/
static public function plugins_loaded() {

add_filter( 'plugin_action_links_' . REST_API_TOOLBOX_BASENAME, array( __CLASS__, 'plugin_action_links' ), 10, 4 );
}

/**
* Adds additional links to the row on the plugins page.
*
* @param array $actions An array of plugin action links.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param array $plugin_data An array of plugin data.
* @param string $context The plugin context. Defaults are 'All', 'Active',
* 'Inactive', 'Recently Activated', 'Upgrade',
* 'Must-Use', 'Drop-ins', 'Search'.
*/
static public function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) {

if ( is_plugin_active( $plugin_file ) && current_user_can( 'manage_options' ) ) {

// Build the URL for the settings page.
$url = add_query_arg(
'page',
rawurlencode( REST_API_Toolbox_Settings_Base::$settings_page ),
admin_url( 'admin.php' )
);

// Add the anchor tag to the list of plugin links.
$new_actions = array(
'settings' => sprintf( '<a href="%1$s">%2$s</a>',
esc_url( $url ),
esc_html__( 'Settings' )
)
);

$actions = array_merge( $new_actions, $actions );
}

return $actions;
}
}
}
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Have any questions? We can answer them here?

== Changelog ==

= 1.4.0 January 9th, 2017 =
= 1.4.0 January 11th, 2017 =
* Added link to settings page from the plugins list page.
* Updated Settings UI for better clarity.

= 1.3.0 December 12th, 2016 =
Expand Down
10 changes: 10 additions & 0 deletions rest-api-toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ static function define_constants() {
if ( ! defined( 'REST_API_TOOLBOX_ROOT' ) ) {
define( 'REST_API_TOOLBOX_ROOT', trailingslashit( dirname( __FILE__ ) ) );
}

if ( ! defined( 'REST_API_TOOLBOX_FILE' ) ) {
define( 'REST_API_TOOLBOX_FILE', __FILE__ );
}

if ( ! defined( 'REST_API_TOOLBOX_BASENAME' ) ) {
define( 'REST_API_TOOLBOX_BASENAME', plugin_basename( REST_API_TOOLBOX_FILE ) );
}
}

static function get_required_files() {
Expand All @@ -26,6 +34,7 @@ static function get_required_files() {
'class-rest-api-toolbox-common',
'class-rest-api-toolbox-prefix',
'class-rest-api-toolbox-i18n',
'class-rest-api-toolbox-admin',
'settings/class-rest-api-toolbox-settings-base',
'settings/class-rest-api-toolbox-settings',
'settings/class-rest-api-toolbox-settings-general',
Expand All @@ -47,6 +56,7 @@ static function get_class_names() {
'REST_API_Toolbox_Common',
'REST_API_Toolbox_Prefix',
'REST_API_Toolbox_i18n',
'REST_API_Toolbox_Admin',
'REST_API_Toolbox_Settings_Base',
'REST_API_Toolbox_Settings',
'REST_API_Toolbox_Settings_General',
Expand Down

0 comments on commit 754c0f0

Please sign in to comment.