1
|
|
|
<?php # -*- coding: utf-8 -*- |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace MultisiteGlobalMedia; |
5
|
|
|
|
6
|
|
|
use MultisiteGlobalMedia\Rest\Rest; |
7
|
|
|
use MultisiteGlobalMedia\WooCommerce; |
8
|
|
|
|
9
|
|
|
class Plugin |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string $rootFile |
14
|
|
|
*/ |
15
|
|
|
private $rootFile; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Plugin constructor. |
19
|
|
|
* |
20
|
|
|
* @param $file |
21
|
|
|
*/ |
22
|
|
|
public function __construct(string $file) |
23
|
|
|
{ |
24
|
|
|
$this->rootFile = $file; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Integration the WordPress environment. |
29
|
|
|
*/ |
30
|
|
|
public function onLoad() |
31
|
|
|
{ |
32
|
|
|
$pluginProperties = new PluginProperties($this->rootFile); |
33
|
|
|
$site = new Site(); |
34
|
|
|
$singleSwitcher = new SingleSwitcher(); |
35
|
|
|
|
36
|
|
|
$assets = new Assets($pluginProperties); |
37
|
|
|
$attachment = new Attachment($site, $singleSwitcher); |
38
|
|
|
$thumbnail = new Thumbnail($site, $singleSwitcher); |
39
|
|
|
$rest = new Rest($site); |
40
|
|
|
|
41
|
|
|
add_action('admin_enqueue_scripts', [$assets, 'enqueueScripts']); |
42
|
|
|
add_action('admin_enqueue_scripts', [$assets, 'enqueueStyles']); |
43
|
|
|
add_action('wp_ajax_query-attachments', [$attachment, 'ajaxQueryAttachments'], 0); |
44
|
|
|
add_action('wp_ajax_get-attachment', [$attachment, 'ajaxGetAttachment'], 0); |
45
|
|
|
add_action('wp_ajax_send-attachment-to-editor', [$attachment, 'ajaxSendAttachmentToEditor'], 0); |
46
|
|
|
add_filter('wp_get_attachment_image_src', [$attachment, 'attachmentImageSrc'], 99, 4); |
47
|
|
|
add_filter('media_view_strings', [$attachment, 'mediaStrings']); |
48
|
|
|
|
49
|
|
|
remove_filter('the_content', 'wp_make_content_images_responsive'); |
50
|
|
|
add_filter('the_content', [$attachment, 'makeContentImagesResponsive']); |
51
|
|
|
|
52
|
|
|
add_action('save_post', [$thumbnail, 'saveThumbnailMeta'], 99); |
53
|
|
|
add_action('wp_ajax_get-post-thumbnail-html', [$thumbnail, 'ajaxGetPostThumbnailHtml'], 99); |
54
|
|
|
add_filter('admin_post_thumbnail_html', [$thumbnail, 'adminPostThumbnailHtml'], 99, 3); |
55
|
|
|
add_filter('post_thumbnail_html', [$thumbnail, 'postThumbnailHtml'], 99, 5); |
56
|
|
|
|
57
|
|
|
add_filter('register_post_type_args', [$rest, 'registerPostTypeArgs'], 10, 2); |
58
|
|
|
add_filter('rest_request_after_callbacks', [$rest, 'restRequestAfterCallbacks'], 10, 3); |
59
|
|
|
|
60
|
|
|
if (\function_exists('wc')) { |
61
|
|
|
$this->wcBootstrap($site, $singleSwitcher); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Integration for WooCommerce and his gallery support. |
67
|
|
|
* |
68
|
|
|
* @param Site $site |
69
|
|
|
* @param SingleSwitcher $siteSwitcher |
70
|
|
|
*/ |
71
|
|
|
public function wcBootstrap(Site $site, SingleSwitcher $siteSwitcher) |
72
|
|
|
{ |
73
|
|
|
$wooCommerceGallery = new WooCommerce\Gallery($site, $siteSwitcher); |
74
|
|
|
|
75
|
|
|
add_action('woocommerce_new_product', [$wooCommerceGallery, 'saveGalleryIds']); |
76
|
|
|
add_action('woocommerce_update_product', [$wooCommerceGallery, 'saveGalleryIds']); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|