-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathService.php
More file actions
94 lines (86 loc) · 1.92 KB
/
Service.php
File metadata and controls
94 lines (86 loc) · 1.92 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
<?php
namespace lloc\Msls\ContentImport;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
use lloc\Msls\MslsRegistryInstance;
/**
* Class Service
*
* A service provider for the content import functionality.
*
* @package lloc\Msls\ContentImport
*/
class Service extends MslsRegistryInstance {
/**
* Hooks the classes that provide the content import functionality if the content import option is active.
*
* @return bool Whether the content import functionality support classes where hooked or not.
*/
public function register(): bool {
if ( ! msls_options()->activate_content_import ) {
return false;
}
$this->hook();
return true;
}
/**
* Hooks the filters and actions for this service provider.
*
* Differently from the `register` method this method will not check for options to hook.
*/
public function hook(): void {
add_action(
'load-post.php',
function () {
ContentImporter::instance()->handle_import();
}
);
add_action(
'load-post.php',
function () {
add_action(
'admin_notices',
function () {
AdminNoticeLogger::instance()->show_last_log();
}
);
}
);
add_action(
'load-post-new.php',
function () {
ContentImporter::instance()->handle_import();
}
);
add_filter(
'wp_insert_post_empty_content',
function ( $bare ) {
return ContentImporter::instance()->filter_empty( $bare );
}
);
add_filter(
'wp_get_attachment_url',
function ( $url, $post_id ) {
return AttachmentPathFinder::instance()->filter_attachment_url( $url, $post_id );
},
99,
2
);
add_filter(
'wp_calculate_image_srcset',
function ( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
return AttachmentPathFinder::instance()->filter_srcset(
$sources,
$size_array,
$image_src,
$image_meta,
$attachment_id
);
},
99,
5
);
}
}