Completed
Pull Request — master (#111)
by Luca
02:07
created

Service   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 48
rs 10
c 1
b 0
f 0
wmc 4
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 9 2
B hook() 0 25 2
1
<?php
2
3
namespace lloc\Msls\ContentImport;
4
5
use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
6
use lloc\Msls\MslsOptions;
7
use lloc\Msls\MslsRegistryInstance;
8
9
/**
10
 * Class Service
11
 *
12
 * A service provider for the content import functionality.
13
 *
14
 * @package lloc\Msls\ContentImport
15
 */
16
class Service extends MslsRegistryInstance {
17
18
	/**
19
	 * Hooks the classes that provide the content import functionality if the content import option is active.
20
	 *
21
	 * @return bool Whether the content import functionality support classes where hooked or not.
22
	 */
23
	public function register() {
24
		if ( ! MslsOptions::instance()->activate_content_import ) {
25
			return false;
26
		}
27
28
		$this->hook();
29
30
		return true;
31
	}
32
33
	/**
34
	 * Hooks the filters and actions for this service provider.
35
	 *
36
	 * Differently from the `register` method this method will not check for options to hook.
37
	 */
38
	public function hook() {
39
		add_action( 'load-post.php', function () {
40
			return ContentImporter::instance()->handle_import();
41
		} );
42
		add_action( 'load-post.php', function () {
43
			add_action( 'admin_notices', function () {
44
				AdminNoticeLogger::instance()->show_last_log();
45
			} );
46
		} );
47
		add_action( 'load-post-new.php', function () {
48
			return ContentImporter::instance()->handle_import();
49
		} );
50
		add_filter( 'wp_insert_post_empty_content', function ( $empty ) {
51
			return ContentImporter::instance()->filter_empty( $empty );
52
		} );
53
		add_filter( 'wp_get_attachment_url', function ( $url, $post_id ) {
54
			return AttachmentPathFinder::instance()->filter_attachment_url( $url, $post_id );
55
		}, 99, 2 );
56
		add_filter( 'wp_calculate_image_srcset', function ( $sources, $sizeArray, $imageSrc, $imageMeta, $attachmentId ) {
57
			return AttachmentPathFinder::instance()->filter_srcset( $sources, $sizeArray, $imageSrc, $imageMeta, $attachmentId );
58
		}, 99, 5 );
59
60
		if ( is_admin() ) {
61
		}
62
	}
63
}