diff --git a/src/Enhancements/Meta.php b/src/Enhancements/Meta.php index f0c578f..198d1e7 100644 --- a/src/Enhancements/Meta.php +++ b/src/Enhancements/Meta.php @@ -30,17 +30,12 @@ class Meta { * * @since 1.0.0 * - * @param string $plugin_basename The plugin basename. - * * @return void */ - public function setup( $plugin_basename ) { - - // Set the plugin basename. - $this->plugin_basename = $plugin_basename; + public function setup() { add_filter( 'plugin_row_meta', array( $this, 'meta_links' ), 10, 2 ); - add_filter( "plugin_action_links_{$this->plugin_basename}", array( $this, 'action_links' ) ); + add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 ); } /** @@ -56,7 +51,7 @@ public function setup( $plugin_basename ) { public function meta_links( $links, $file ) { // Return early if not on the plugin page. - if ( $this->plugin_basename !== $file ) { + if ( ! $this->is_this_plugin( $file ) ) { return $links; } @@ -94,6 +89,11 @@ public function meta_links( $links, $file ) { */ public function action_links( $links ) { + // Leave early if the filter is not for this plugin. + if ( ! $this->is_this_plugin( $file ) ) { + return $links; + } + $plugin_links = array(); $plugin_links[] = sprintf( /* translators: 1: Open anchor tag, 2: Close anchor tag. */ esc_html_x( '%1$sGet PRO%2$s', 'plugin link', 'woo-store-vacation' ), @@ -114,4 +114,18 @@ public function action_links( $links ) { return array_merge( $plugin_links, $links ); } + + /** + * Check if the current plugin is the one we are looking for. + * + * @since 1.0.0 + * + * @param string $file Path to the plugin file relative to the plugins' directory. + * + * @return bool + */ + private function is_this_plugin( $file ) { + + return woo_store_vacation()->service( 'file' )->plugin_basename() === $file; + } }