PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / Hooks / PluginHooks.php

PluginHooks.php in Packeta 2.0.9, at src/Packetery/Module/Hooks/PluginHooks.php

174 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 namespace Packetery\Module\Hooks;
4
5 use Automattic\WooCommerce\Utilities\FeaturesUtil;
6 use Packetery\Module\Framework\WcAdapter;
7 use Packetery\Module\Framework\WpAdapter;
8 use Packetery\Module\ModuleHelper;
9 use Packetery\Module\Options;
10 use Packetery\Module\Options\FlagManager\FeatureFlagNotice;
11 use Packetery\Module\Options\FlagManager\FeatureFlagProvider;
12 use Packetery\Module\Order;
13 use Packetery\Module\Plugin;
14 use Packetery\Nette\Http\Request;
15
16 class PluginHooks {
17
18 /**
19 * @var Request
20 */
21 private $request;
22
23 /**
24 * @var FeatureFlagProvider
25 */
26 private $featureFlagProvider;
27
28 /**
29 * @var Order\PacketSubmitter
30 */
31 private $packetSubmitter;
32
33 /**
34 * @var Order\PacketCanceller
35 */
36 private $packetCanceller;
37
38 /**
39 * @var Order\PacketClaimSubmitter
40 */
41 private $packetClaimSubmitter;
42
43 /**
44 * @var ModuleHelper
45 */
46 private $moduleHelper;
47
48 /**
49 * @var WpAdapter
50 */
51 private $wpAdapter;
52
53 /**
54 * @var WcAdapter
55 */
56 private $wcAdapter;
57
58 public function __construct(
59 Request $request,
60 FeatureFlagProvider $featureFlagProvider,
61 Order\PacketSubmitter $packetSubmitter,
62 Order\PacketCanceller $packetCanceller,
63 Order\PacketClaimSubmitter $packetClaimSubmitter,
64 ModuleHelper $moduleHelper,
65 WpAdapter $wpAdapter,
66 WcAdapter $wcAdapter
67 ) {
68
69 $this->request = $request;
70 $this->featureFlagProvider = $featureFlagProvider;
71 $this->packetSubmitter = $packetSubmitter;
72 $this->packetCanceller = $packetCanceller;
73 $this->packetClaimSubmitter = $packetClaimSubmitter;
74 $this->moduleHelper = $moduleHelper;
75 $this->wpAdapter = $wpAdapter;
76 $this->wcAdapter = $wcAdapter;
77 }
78
79 /**
80 * Declares plugin compability with features.
81 *
82 * @return void
83 */
84 public function declareWooCommerceCompability(): void {
85 if ( class_exists( FeaturesUtil::class ) === false ) {
86 return;
87 }
88
89 // High-Performance Order Storage.
90 $this->wcAdapter->featuresUtilDeclareCompatibility( 'custom_order_tables', ModuleHelper::getPluginMainFilePath() );
91 }
92
93 /**
94 * Loads plugin translation file by user locale.
95 */
96 public function loadTranslation(): void {
97 $domain = Plugin::DOMAIN;
98 $this->wpAdapter->unloadTextDomain( $domain, true );
99 $locale = $this->moduleHelper->getLocale();
100 $moFile = WP_LANG_DIR . "/plugins/$domain-$locale.mo";
101
102 if ( file_exists( $moFile ) ) {
103 $this->wpAdapter->loadPluginTextDomain( $domain );
104 } else {
105 $this->wpAdapter->loadDefaultTextDomain();
106 }
107 }
108
109 /**
110 * Adds action links visible at the plugin screen.
111 *
112 * @link https://developer.wordpress.org/reference/hooks/plugin_action_links_plugin_file/
113 *
114 * @param array $links Plugin Action links.
115 *
116 * @return array
117 */
118 public function addPluginActionLinks( array $links ): array {
119 $settingsLink = '<a href="' . $this->wpAdapter->escUrl( $this->wpAdapter->adminUrl( 'admin.php?page=' . Options\Page::SLUG ) ) . '" aria-label="' .
120 $this->wpAdapter->escAttr( $this->wpAdapter->__( 'View the plugin documentation', 'packeta' ) ) . '">' .
121 $this->wpAdapter->escHtml( $this->wpAdapter->__( 'Settings', 'packeta' ) ) . '</a>';
122
123 array_unshift( $links, $settingsLink );
124
125 return $links;
126 }
127
128 /**
129 * Adds links to the plugin list screen.
130 *
131 * @link https://developer.wordpress.org/reference/hooks/plugin_row_meta/
132 *
133 * @param array $links Plugin Row Meta.
134 * @param string $pluginFileName Plugin Base file.
135 *
136 * @return array
137 */
138 public function addPluginRowMeta( array $links, string $pluginFileName ): array {
139 if ( strpos( $pluginFileName, basename( ModuleHelper::getPluginMainFilePath() ) ) === false ) {
140 return $links;
141 }
142 $links[] = '<a href="' . $this->wpAdapter->escUrl( 'https://github.com/Zasilkovna/WooCommerce/wiki' ) . '" aria-label="' .
143 $this->wpAdapter->escAttr( $this->wpAdapter->__( 'View Packeta documentation', 'packeta' ) ) . '">' .
144 $this->wpAdapter->escHtml( $this->wpAdapter->__( 'Documentation', 'packeta' ) ) . '</a>';
145
146 return $links;
147 }
148
149 /**
150 * Check for action parameter and process wanted action.
151 *
152 * @return void
153 */
154 public function handleActions(): void {
155 $action = $this->request->getQuery( Plugin::PARAM_PACKETERY_ACTION );
156
157 if ( $action === Order\PacketActionsCommonLogic::ACTION_SUBMIT_PACKET ) {
158 $this->packetSubmitter->processAction();
159 }
160
161 if ( $action === Order\PacketActionsCommonLogic::ACTION_SUBMIT_PACKET_CLAIM ) {
162 $this->packetClaimSubmitter->processAction();
163 }
164
165 if ( $action === Order\PacketActionsCommonLogic::ACTION_CANCEL_PACKET ) {
166 $this->packetCanceller->processAction();
167 }
168
169 if ( $action === FeatureFlagNotice::ACTION_HIDE_SPLIT_MESSAGE ) {
170 $this->featureFlagProvider->dismissSplitActivationNotice();
171 }
172 }
173 }
174