| 1 |
<?php |
| 2 |
/** |
| 3 |
* The plugin meta class. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
* |
| 7 |
* @package woo-additional-terms |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Woo_Additional_Terms\Enhancements; |
| 11 |
|
| 12 |
use Woo_Additional_Terms\Helper; |
| 13 |
|
| 14 |
/** |
| 15 |
* The plugin meta class. |
| 16 |
*/ |
| 17 |
class Meta { |
| 18 |
|
| 19 |
/** |
| 20 |
* Setup hooks and filters. |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function setup() { |
| 27 |
|
| 28 |
add_filter( 'plugin_row_meta', array( $this, 'meta_links' ), 10, 2 ); |
| 29 |
add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Add additional helpful links to the plugin’s metadata. |
| 34 |
* |
| 35 |
* @since 1.0.0 |
| 36 |
* |
| 37 |
* @param array $links An array of the plugin’s metadata. |
| 38 |
* @param string $file Path to the plugin file relative to the plugins' directory. |
| 39 |
* |
| 40 |
* @return array |
| 41 |
*/ |
| 42 |
public function meta_links( $links, $file ) { |
| 43 |
|
| 44 |
// Return early if not on the plugin page. |
| 45 |
if ( ! $this->is_this_plugin( $file ) ) { |
| 46 |
return $links; |
| 47 |
} |
| 48 |
|
| 49 |
$plugin_links = array( |
| 50 |
sprintf( /* translators: 1: Open anchor tag, 2: Close anchor tag. */ |
| 51 |
esc_html_x( '%1$sDocs%2$s', 'plugin link', 'woo-additional-terms' ), |
| 52 |
sprintf( |
| 53 |
'<a href="%s" target="_blank" rel="noopener noreferrer nofollow">', |
| 54 |
esc_url( Helper\Links::docs_uri() ) |
| 55 |
), |
| 56 |
'</a>' |
| 57 |
), |
| 58 |
sprintf( /* translators: 1: Open anchor tag, 2: Close anchor tag. */ |
| 59 |
esc_html_x( '%1$sCommunity support%2$s', 'plugin link', 'woo-additional-terms' ), |
| 60 |
sprintf( |
| 61 |
'<a href="https://wordpress.org/support/plugin/%s" target="_blank" rel="noopener noreferrer nofollow">', |
| 62 |
esc_attr( woo_additional_terms()->get_slug() ) |
| 63 |
), |
| 64 |
'</a>' |
| 65 |
), |
| 66 |
); |
| 67 |
|
| 68 |
return array_merge( $links, $plugin_links ); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Display additional links in the plugin table page. |
| 73 |
* Filters the list of action links displayed for a specific plugin in the Plugins list table. |
| 74 |
* |
| 75 |
* @since 1.0.0 |
| 76 |
* |
| 77 |
* @param array $links Plugin table/item action links. |
| 78 |
* @param string $file Path to the plugin file relative to the plugins' directory. |
| 79 |
* |
| 80 |
* @return array |
| 81 |
*/ |
| 82 |
public function action_links( $links, $file ) { |
| 83 |
|
| 84 |
// Leave early if the filter is not for this plugin. |
| 85 |
if ( ! $this->is_this_plugin( $file ) ) { |
| 86 |
return $links; |
| 87 |
} |
| 88 |
|
| 89 |
$plugin_links = array(); |
| 90 |
$plugin_links[] = sprintf( /* translators: 1: Open anchor tag, 2: Close anchor tag. */ |
| 91 |
esc_html_x( '%1$sUpgrade to Pro%2$s', 'plugin link', 'woo-additional-terms' ), |
| 92 |
sprintf( |
| 93 |
'<a href="%s" target="_blank" rel="noopener noreferrer nofollow" style="color:green;font-weight:bold;">✅ ', |
| 94 |
esc_url( Helper\Links::pro_uri() ) |
| 95 |
), |
| 96 |
'</a>' |
| 97 |
); |
| 98 |
|
| 99 |
if ( current_user_can( 'manage_woocommerce' ) ) { |
| 100 |
$plugin_links[] = sprintf( /* translators: 1: Open anchor tag, 2: Close anchor tag. */ |
| 101 |
esc_html_x( '%1$sSettings%2$s', 'plugin settings page', 'woo-additional-terms' ), |
| 102 |
sprintf( |
| 103 |
'<a href="%s">', |
| 104 |
esc_url( Helper\Settings::page_uri() ) |
| 105 |
), |
| 106 |
'</a>' |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
return array_merge( $plugin_links, $links ); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Check if the current plugin is the one we are looking for. |
| 115 |
* |
| 116 |
* @since 1.0.0 |
| 117 |
* |
| 118 |
* @param string $file Path to the plugin file relative to the plugins' directory. |
| 119 |
* |
| 120 |
* @return bool |
| 121 |
*/ |
| 122 |
private function is_this_plugin( $file ) { |
| 123 |
|
| 124 |
return woo_additional_terms()->service( 'file' )->plugin_basename() === $file; |
| 125 |
} |
| 126 |
} |
| 127 |
|