Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ad-code-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace Automattic\AdCodeManager;

use Ad_Code_Manager;
use Automattic\AdCodeManager\UI\Plugin_Actions;

const AD_CODE_MANAGER_VERSION = '0.5';
const AD_CODE_MANAGER_FILE = __FILE__;
Expand All @@ -36,11 +37,20 @@
require_once __DIR__ . '/src/class-acm-widget.php';
require_once __DIR__ . '/src/markdown.php';
require_once __DIR__ . '/src/class-ad-code-manager.php';
require_once __DIR__ . '/src/UI/class-plugin-actions.php';

add_action(
'plugins_loaded',
function () {
$GLOBALS['ad_code_manager'] = new Ad_Code_Manager();
$GLOBALS['ad_code_manager']->run();
}
}
);

add_action(
'admin_init',
function () {
$plugin_actions = new Plugin_Actions();
$plugin_actions->run();
}
);
48 changes: 48 additions & 0 deletions src/UI/class-plugin-actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Ad Code Manager plugins actions class
*
* @package Automattic\AdCodeManager
* @since 0.6.0
*/

declare(strict_types=1);

namespace Automattic\AdCodeManager\UI;

use const Automattic\AdCodeManager\AD_CODE_MANAGER_FILE;

/**
* User Interface changes for the plugins actions.
*
* @since 0.6.0
*/
final class Plugin_Actions {

/**
* Register action and filter hook callbacks.
*
* @return void
*/
public function run(): void {
add_filter( 'plugin_action_links_' . plugin_basename( AD_CODE_MANAGER_FILE ), array( $this, 'add_plugin_meta_links' ) );
}

/**
* Adds a 'Settings' action link to the Plugins screen in WP admin.
*
* @param array $actions An array of plugin action links. By default, this can include 'activate',
* 'deactivate', and 'delete'. With Multisite active this can also include
* 'network_active' and 'network_only' items.
* @return array
*/
public function add_plugin_meta_links( array $actions ): array {
$actions['settings'] = sprintf(
'<a href="%s">%s</a>',
esc_url( get_admin_url( null, 'options-general.php?page=ad-code-manager' ) ),
esc_html__( 'Settings', 'ad-code-manager' )
);

return $actions;
}
}
47 changes: 47 additions & 0 deletions tests/Integration/UI/PluginActionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* UI Tests for the plugin actions
*
* @package Automattic\AdCodeManager\Tests\UI
*/

declare(strict_types=1);

namespace Automattic\AdCodeManager\Tests\Integration\UI;

use Automattic\AdCodeManager\Tests\Integration\TestCase;
use Automattic\AdCodeManager\UI\Plugin_Actions;

use const Automattic\AdCodeManager\AD_CODE_MANAGER_FILE;

/**
* UI Tests for the plugin screen.
*/
final class PluginActionsTest extends TestCase {
/**
* Check that plugins screen will add a hook to change the plugin action links.
*
* @covers \Automattic\AdCodeManager\UI\Plugin_Actions::run
* @group ui
*/
public function test_plugins_screen_has_filter_to_add_a_settings_action_link(): void {
$plugins_screen = new Plugin_Actions();
$plugins_screen->run();

self::assertNotFalse( has_filter( 'plugin_action_links_' . plugin_basename( AD_CODE_MANAGER_FILE ), array( $plugins_screen, 'add_plugin_meta_links' ) ) );
}

/**
* Check that plugins screen will add a hook to change the plugin action links.
*
* @covers Automattic\AdCodeManager\UI\Plugin_Actions::run
* @covers Automattic\AdCodeManager\UI\Plugin_Actions::add_plugin_meta_links
* @group ui
*/
public function test_plugins_screen_adds_a_settings_action_link(): void {
$actions = array();
$actions = ( new Plugin_Actions() )->add_plugin_meta_links( $actions );

self::assertCount( 1, $actions );
}
}