PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / trunk
WCPOS – Point of Sale (POS) plugin for WooCommerce vtrunk
1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 1.9.13 1.9.12 1.9.11 1.9.10 All 159 releases
woocommerce-pos / includes / Admin / Plugins.php

Plugins.php in WCPOS – Point of Sale (POS) plugin for WooCommerce trunk, at includes/Admin/Plugins.php

118 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP Plugin Updates.
4 *
5 * @author Paul Kilmurray <paul@kilbot.com>
6 *
7 * @see http://wcpos.com
8 * @package WCPOS\WooCommercePOS
9 */
10
11 namespace WCPOS\WooCommercePOS\Admin;
12
13 use WCPOS\WooCommercePOS\Services\Analytics;
14 use const WCPOS\WooCommercePOS\PLUGIN_FILE;
15 use const WCPOS\WooCommercePOS\VERSION;
16
17 /**
18 * Plugins class.
19 */
20 class Plugins {
21 /**
22 * Constructor.
23 */
24 public function __construct() {
25 add_filter( 'plugin_action_links_' . PLUGIN_FILE, array( $this, 'plugin_action_links' ) );
26 add_action( 'in_plugin_update_message-' . PLUGIN_FILE, array( $this, 'plugin_update_message' ), 10, 2 );
27 }
28
29 /**
30 * Filters the list of action links displayed for a specific plugin in the Plugins list table.
31 *
32 * @param string[] $actions An array of plugin action links.
33 */
34 public function plugin_action_links( array $actions ): array {
35 $settings = array(
36 'settings' => '<a href="' . admin_url( 'admin.php?page=woocommerce-pos-settings' ) . '">' .
37 // translators: Plugin row action link that opens WCPOS settings.
38 __( 'Settings', 'woocommerce-pos' ) . '</a>',
39 );
40
41 // Add "Upgrade to Pro" link if Pro is not installed.
42 if ( ! defined( 'WCPOS\WooCommercePOSPro\VERSION' ) ) {
43 Analytics::instance()->capture_once(
44 'upgrade_cta_viewed',
45 array(
46 'placement' => 'plugin_row_action',
47 ),
48 'plugin_row_action',
49 Analytics::AMBIENT_IMPRESSION_TTL
50 );
51
52 $actions['upgrade'] = '<a href="https://wcpos.com/pro" target="_blank" rel="noopener noreferrer" data-wcpos-upgrade-placement="plugin_row_action" style="color: #d63638; font-weight: 600;">' .
53 /* translators: Plugin admin screen label or notice for WCPOS. */
54 __( 'Upgrade to Pro', 'woocommerce-pos' ) . '</a>';
55 }
56
57 return $settings + $actions;
58 }
59
60 /**
61 * Fires at the end of the update message container in each row of the plugins list table.
62 * Thanks to: http://andidittrich.de/2015/05/howto-upgrade-notice-for-wordpress-plugins.html.
63 *
64 * @param array $plugin_data An array of plugin metadata.
65 * @param object $r An object of metadata about the available plugin update.
66 *
67 * @since 2.8.0
68 */
69 public function plugin_update_message( $plugin_data, $r ): void {
70 // Check if updating to v1.8.x from an earlier version.
71 $new_version = isset( $r->new_version ) ? $r->new_version : '';
72 $current_version = VERSION;
73
74 // Show major update notice when upgrading to 1.8.x from earlier versions.
75 // @phpstan-ignore-next-line.
76 if ( version_compare( $new_version, '1.8.0', '>=' ) && version_compare( $current_version, '1.8.0', '<' ) ) {
77 $this->show_major_update_notice();
78 }
79
80 // Show any additional upgrade notice from readme.txt.
81 if ( isset( $r->upgrade_notice ) && \strlen( trim( $r->upgrade_notice ) ) > 0 ) {
82 echo '<p style="background-color: #d54e21; padding: 10px; color: #f9f9f9; margin-top: 10px"><strong>' .
83 // translators: Prefix for an important plugin update notice in the WordPress plugins screen.
84 esc_html__( 'Important:', 'woocommerce-pos' ) . '</strong> ';
85 echo esc_html( $r->upgrade_notice ), '</p>';
86 }
87 }
88
89 /**
90 * Display a major update notice for v1.8.
91 */
92 private function show_major_update_notice(): void {
93 ?>
94 <hr style="margin: 15px 0; border: 0; border-top: 1px solid #ffb900;">
95 <div style="background: linear-gradient(135deg, #fff3cd 0%, #ffeeba 100%); border: 1px solid #ffb900; border-radius: 4px; padding: 12px 15px; margin-top: 10px;">
96 <p style="margin: 0 0 10px 0; font-weight: 600; color: #856404; font-size: 14px;">
97 <span class="dashicons dashicons-warning" style="color: #ffb900; margin-right: 5px;"></span>
98 <?php /* translators: Plugin admin screen label or notice for WCPOS. */ esc_html_e( 'Major Update', 'woocommerce-pos' ); ?>
99 </p>
100 <p style="margin: 0 0 10px 0; color: #856404;">
101 <?php esc_html_e( 'Update when you have time to test the POS. You can rollback to the previous version if needed.', 'woocommerce-pos' ); ?>
102 </p>
103 <p style="margin: 0; padding: 10px; background-color: rgba(255,255,255,0.5); border-radius: 3px; color: #0073aa;">
104 <span class="dashicons dashicons-star-filled" style="color: #ffb900; margin-right: 5px;"></span>
105 <strong><?php /* translators: Plugin admin screen label or notice for WCPOS. */ esc_html_e( 'Pro Users:', 'woocommerce-pos' ); ?></strong>
106 <?php
107 printf(
108 /* translators: %s: URL to My Account page */
109 esc_html__( 'WCPOS Pro is now a standalone plugin. Download the latest version from %s', 'woocommerce-pos' ),
110 '<a href="https://wcpos.com/my-account" target="_blank" rel="noopener noreferrer" style="color: #0073aa; text-decoration: underline;">wcpos.com/my-account</a>'
111 );
112 ?>
113 </p>
114 </div>
115 <?php
116 }
117 }
118