diff --git a/src/UI/class-plugins-actions.php b/src/UI/class-plugins-actions.php new file mode 100644 index 000000000..183b002a1 --- /dev/null +++ b/src/UI/class-plugins-actions.php @@ -0,0 +1,45 @@ +%s', + esc_url( Parsely::get_settings_url() ), + esc_html__( 'Settings', 'wp-parsely' ) + ); + + $actions['settings'] = $settings_link; + + return $actions; + } +} diff --git a/src/class-parsely.php b/src/class-parsely.php index 8cb5a8446..c86a26b50 100644 --- a/src/class-parsely.php +++ b/src/class-parsely.php @@ -111,11 +111,6 @@ public function run() { // display warning when plugin hasn't been configured. add_action( 'admin_footer', array( $this, 'display_admin_warning' ) ); - add_filter( - 'plugin_action_links_' . PARSELY_PLUGIN_BASENAME, - array( $this, 'add_plugin_meta_links' ) - ); - // phpcs:ignore WordPress.WP.CronInterval.CronSchedulesInterval add_filter( 'cron_schedules', array( $this, 'wpparsely_add_cron_interval' ) ); @@ -777,18 +772,6 @@ public function print_optional_settings() { // need to now. } - /** - * Adds a 'Settings' link to the Plugins screen in WP admin - * - * @category Function - * @package Parsely - * @param array $links The links to add. - */ - public function add_plugin_meta_links( $links ) { - array_unshift( $links, '' . __( 'Settings', 'wp-parsely' ) . '' ); - return $links; - } - /** * Display the admin warning if needed * @@ -803,7 +786,7 @@ public function display_admin_warning() { $message = sprintf( /* translators: %s: Plugin settings page URL */ __( 'The Parse.ly plugin is not active. You need to provide your Parse.ly Dash Site ID before things get cooking.', 'wp-parsely' ), - esc_url( $this->get_settings_url() ) + esc_url( self::get_settings_url() ) ); ?>

@@ -1972,7 +1955,7 @@ public function get_clean_parsely_page_value( $val ) { /** * Get the URL of the plugin settings page */ - private function get_settings_url() { + public static function get_settings_url() { return admin_url( 'options-general.php?page=' . self::MENU_SLUG ); } diff --git a/tests/UI/PluginsActionsTest.php b/tests/UI/PluginsActionsTest.php new file mode 100644 index 000000000..3736db855 --- /dev/null +++ b/tests/UI/PluginsActionsTest.php @@ -0,0 +1,45 @@ +run(); + + self::assertNotFalse( has_filter( 'plugin_action_links_' . PARSELY_PLUGIN_BASENAME, array( $plugins_screen, 'add_plugin_meta_links' ) ) ); + } + + /** + * Check that plugins screen will add a hook to change the plugin action links. + * + * @covers \Parsely\UI\Plugins_Actions::run + * @covers \Parsely\UI\Plugins_Actions::add_plugin_meta_links + * @uses \Parsely::get_settings_url + * @group ui + */ + public function test_plugins_screen_adds_a_settings_action_link() { + $actions = array(); + $plugins_screen = new Plugins_Actions(); + $actions = $plugins_screen->add_plugin_meta_links( $actions ); + + self::assertCount( 1, $actions ); + } +} diff --git a/wp-parsely.php b/wp-parsely.php index c2f1631b4..89ab952f9 100644 --- a/wp-parsely.php +++ b/wp-parsely.php @@ -52,6 +52,16 @@ $GLOBALS['parsely'] = new Parsely(); $GLOBALS['parsely']->run(); +// Until auto-loading happens, we need to include this file for tests as well. +require PARSELY_PLUGIN_DIR . 'src/UI/class-plugins-actions.php'; +add_action( + 'admin_init', + function() { + $GLOBALS['parsely_ui_plugins_actions'] = new Parsely\UI\Plugins_Actions(); + $GLOBALS['parsely_ui_plugins_actions']->run(); + } +); + require PARSELY_PLUGIN_DIR . 'src/class-parsely-recommended-widget.php'; add_action( 'widgets_init', 'parsely_recommended_widget_register' );