Passed
Push — master ( 36836d...ee0da0 )
by Paul
04:21
created

Customization::removeMetaBoxes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Editor;
4
5
use GeminiLabs\SiteReviews\Application;
6
7
class Customization
8
{
9
	/**
10
	 * @return array
11
	 */
12
	public function filterEditorSettings( array $settings )
13
	{
14
		if( $this->isReviewEditable() ) {
15
			$settings = [
16
				'media_buttons' => false,
17
				'quicktags' => false,
18
				'textarea_rows' => 12,
19
				'tinymce' => false,
20
			];
21
		}
22
		return $settings;
23
	}
24
25
	/**
26
	 * @param string $html
27
	 * @return string
28
	 */
29
	public function filterEditorTextarea( $html )
30
	{
31
		if( $this->isReviewEditable() ) {
32
			$html = str_replace( '<textarea', '<div id="ed_toolbar"></div><textarea', $html );
33
		}
34
		return $html;
35
	}
36
37
	/**
38
	 * @return void
39
	 */
40
	public function removeAutosave()
41
	{
42
		if( $this->isReviewEditor() && !$this->isReviewEditable() ) {
43
			wp_deregister_script( 'autosave' );
44
		}
45
	}
46
47
	/**
48
	 * @return void
49
	 */
50
	public function removeMetaBoxes()
51
	{
52
		remove_meta_box( 'slugdiv', Application::POST_TYPE, 'advanced' );
53
	}
54
55
	/**
56
	 * @return bool
57
	 */
58
	protected function isReviewEditable()
59
	{
60
		$postId = intval( filter_input( INPUT_GET, 'post' ));
61
		return $postId > 0
62
			&& get_post_meta( $postId, 'review_type', true ) == 'local'
63
			&& $this->isReviewEditor();
64
	}
65
66
	/**
67
	 * @return bool
68
	 */
69
	protected function isReviewEditor()
70
	{
71
		return glsr_current_screen()->base == 'post'
72
			&& glsr_current_screen()->id == Application::POST_TYPE
73
			&& glsr_current_screen()->post_type == Application::POST_TYPE;
74
	}
75
}
76