PluginProbe
MultiSafepay plugin for WooCommerce / trunk
MultiSafepay plugin for WooCommerce vtrunk
6.11.1 6.12.0 6.13.0 6.2.0 6.2.1 6.3.0 6.3.1 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.6.0 6.6.1 6.6.2 6.7.0 6.7.1 6.7.2 6.7.3 6.8.0 6.8.1 6.8.2 6.8.3 6.9.0 All 84 releases
multisafepay / src / Utils / Activator.php

Activator.php in MultiSafepay plugin for WooCommerce trunk, at src/Utils/Activator.php

77 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace MultiSafepay\WooCommerce\Utils;
4
5 use MultiSafepay\WooCommerce\Exceptions\MissingDependencyException;
6
7 /**
8 * This class defines all code necessary to run during the plugin's activation.
9 *
10 * @see https://developer.wordpress.org/reference/functions/register_activation_hook/
11 */
12 class Activator {
13
14 /**
15 * Fired during plugin activation according if is multisite or not.
16 *
17 * @param null|bool $network_wide
18 * @return void
19 */
20 public function activate( ?bool $network_wide ): void {
21 if ( ! current_user_can( 'activate_plugins' ) ) {
22 die( esc_html__( 'It seems you don\'t have permission to activate plugins', 'multisafepay' ) );
23 }
24 if ( ( ! is_multisite() ) || ( is_multisite() && ! $network_wide ) ) {
25 $this->activate_plugin_single_site();
26 }
27 if ( $network_wide ) {
28 $this->activate_plugin_all_sites();
29 }
30 }
31
32 /**
33 * Check if dependencies are not active and return fatal error
34 * for a single site.
35 *
36 * @return void
37 */
38 private function activate_plugin_single_site(): void {
39 try {
40 $dependency_checker = new DependencyChecker();
41 $dependency_checker->check();
42 } catch ( MissingDependencyException $missing_dependency_exception ) {
43 $dependencies = implode( ', ', $missing_dependency_exception->get_missing_plugin_names() );
44 $message = sprintf( __( 'Missing dependencies: %s. Please install these extensions to use the MultiSafepay WooCommerce plugin', 'multisafepay' ), $dependencies ); // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
45 die( esc_html( $message ) );
46 }
47 }
48
49 /**
50 * Check if dependencies are not active and return fatal error
51 * for a network.
52 *
53 * @return void
54 */
55 private function activate_plugin_all_sites(): void {
56 $blog_ids = $this->get_blogs_ids();
57 foreach ( $blog_ids as $blog_id ) {
58 switch_to_blog( $blog_id );
59 $this->activate_plugin_single_site();
60 restore_current_blog();
61 }
62 }
63
64 /**
65 * Return all sites ids
66 *
67 * @return array
68 */
69 private function get_blogs_ids(): array {
70 $args = array(
71 'fields' => 'ids',
72 );
73 $blogs_ids = get_sites( $args );
74 return $blogs_ids;
75 }
76 }
77