Skip to content

Commit

Permalink
Merge pull request #65 from kasparsd/fix/settings-link
Browse files Browse the repository at this point in the history
Bugfix: settings link
  • Loading branch information
kasparsd authored Apr 27, 2020
2 parents b4943bc + 4ff7821 commit 3141671
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"scripts": {
"grunt": "grunt",
"build": "composer release && grunt build",
"deploy": "grunt deploy",
"deploy-trunk": "grunt deploy-trunk",
"deploy": "composer release && grunt deploy",
"deploy-trunk": "composer release && grunt deploy-trunk",
"test": "composer test",
"lint": "composer lint && npm run lint-js",
"lint-js": "eslint *.js assets/js",
Expand Down
31 changes: 29 additions & 2 deletions src/WidgetContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ public function init() {
// Register admin settings menu
add_action( 'admin_menu', array( $this, 'widget_context_settings_menu' ) );

// Register admin settings
// Register admin settings.
add_action( 'admin_init', array( $this, 'widget_context_settings_init' ) );

// Add quick links to the plugin list.
add_action(
'plugin_action_links_' . $this->plugin->basename(),
array( $this, 'plugin_action_links' )
);
}


Expand Down Expand Up @@ -211,6 +217,27 @@ public function pro_nag_enabled() {
return (bool) apply_filters( 'widget_context_pro_nag', true );
}

/**
* Add a link to the plugin settings in the plugin list.
*
* @return array List of links.
*/
public function plugin_action_links( $links ) {
$links[] = sprintf(
'<a href="%s">%s</a>',
esc_url( $this->plugin_settings_admin_url() ),
esc_html__( 'Settings', 'widget-context' )
);

if ( $this->pro_nag_enabled() ) {
$links[] = sprintf(
'<a href="%s" target="_blank">PRO 🚀</a>',
esc_url( 'https://widgetcontext.com/pro' )
);
}

return $links;
}

function set_widget_contexts_frontend() {
// Hide/show widgets for is_active_sidebar() to work
Expand Down Expand Up @@ -680,7 +707,7 @@ function display_widget_context( $widget_id = null ) {
if ( current_user_can( 'edit_theme_options' ) ) {
$settings_link[] = sprintf(
'<a href="%s" title="%s" target="_blank">%s</a>',
admin_url( 'options-general.php?page=widget_context_settings' ),
esc_url( $this->plugin_settings_admin_url() ),
esc_attr__( 'Widget Context Settings', 'widget-context' ),
esc_html__( 'Settings', 'widget-context' )
);
Expand Down
14 changes: 14 additions & 0 deletions tests/php/WidgetContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ public function testLegacyInstance() {
);
}

public function testSettingsUrl() {
WP_Mock::userFunction(
'admin_url',
array(
'args' => array(
WP_Mock\Functions::type( 'string' ),
),
'times' => 1,
)
);

$this->plugin->plugin_settings_admin_url();
}

public function testRequestPathResolver() {
$this->assertEquals(
'path-to-a/url.html?true=2',
Expand Down

0 comments on commit 3141671

Please sign in to comment.