diff --git a/ad-code-manager.php b/ad-code-manager.php index 895e66c..484157c 100644 --- a/ad-code-manager.php +++ b/ad-code-manager.php @@ -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__; @@ -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(); + } ); diff --git a/src/UI/class-plugin-actions.php b/src/UI/class-plugin-actions.php new file mode 100644 index 0000000..7741aff --- /dev/null +++ b/src/UI/class-plugin-actions.php @@ -0,0 +1,48 @@ +%s', + esc_url( get_admin_url( null, 'options-general.php?page=ad-code-manager' ) ), + esc_html__( 'Settings', 'ad-code-manager' ) + ); + + return $actions; + } +} diff --git a/tests/Integration/UI/PluginActionsTest.php b/tests/Integration/UI/PluginActionsTest.php new file mode 100644 index 0000000..728a381 --- /dev/null +++ b/tests/Integration/UI/PluginActionsTest.php @@ -0,0 +1,47 @@ +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 ); + } +}