UserExperience.php
3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Admin User Experience controller.
*
* @package ContentControl\Admin
* @copyright (c) 2023 Code Atlantic LLC
*/
namespace ContentControl\Controllers\Admin;
use ContentControl\Base\Controller;
/**
* UserExperience controller class.
*/
class UserExperience extends Controller {
/**
* Initialize widget editor UX.
*
* @return void
*/
public function init() {
add_filter( 'plugin_action_links', [ $this, 'plugin_action_links' ], 10, 2 );
add_action( "after_plugin_row_{$this->container->get('basename')}", [
$this,
'after_plugin_row',
], 10, 2 );
}
/**
* Render plugin action links.
*
* @param array<string,string> $links Existing links.
* @param string $file Plugin file path.
*
* @return mixed
*/
public function plugin_action_links( $links, $file ) {
$basename = $this->container->get( 'basename' );
if ( $file === $basename ) {
$plugin_action_links = apply_filters(
'content_control/plugin_action_links',
[
'upgrade' => '<a target="_blank" href="https://contentcontrolplugin.com/pricing/?utm_campaign=upgrade-to-pro&utm_source=plugins-page&utm_medium=plugin-ui&utm_content=action-links-upgrade-text">' . __( 'Upgrade to Pro', 'content-control' ) . '</a>',
'settings' => '<a href="' . admin_url( 'options-general.php?page=content-control-settings' ) . '">' . __( 'Settings', 'content-control' ) . '</a>',
]
);
if ( $this->container->is_license_active() || $this->container->is_pro_active() ) {
unset( $plugin_action_links['upgrade'] );
}
if ( substr( get_locale(), 0, 2 ) === 'en' ) {
$plugin_action_links = array_merge( [ 'translate' => '<a href="' . sprintf( 'https://translate.wordpress.org/locale/%s/default/wp-plugins/content-control/', substr( get_locale(), 0, 2 ) ) . '" target="_blank">' . __( 'Translate', 'content-control' ) . '</a>' ], $plugin_action_links );
}
foreach ( $plugin_action_links as $link ) {
array_unshift( $links, $link );
}
}
return $links;
}
/**
* Add a row to the plugin list table.
*
* @param string $file Plugin file path.
* @param array<string,string|int> $plugin_data Plugin data.
*
* @return void
*/
public function after_plugin_row( $file, $plugin_data ) {
$plugin_slug = $this->container->get( 'slug' );
if ( $plugin_slug !== $plugin_data['slug'] ) {
return;
}
$plugin_url = $this->container->get( 'url' );
?>
<!-- <tr class="plugin-update-tr active">
<td colspan="3" class="plugin-update colspanchange">
<div class="update-message notice inline notice-warning notice-alt">
<p>
<?php
printf(
/* translators: %1$s: Plugin name, %2$s: Plugin URL */
esc_html__( 'You are using the %1$s plugin. Please visit the %2$s to learn how to use it.', 'content-control' ),
'<strong>' . esc_html__( 'Content Control', 'content-control' ) . '</strong>',
'<a href="' . esc_url( $plugin_url ) . '" target="_blank">' . esc_html__( 'plugin website', 'content-control' ) . '</a>'
);
?>
</p>
</div>
</td>
</tr> -->
<?php
}
}