Passed
Push — hotfix/fix-counts ( 4b43d1...cc9e05 )
by Paul
03:52
created

Customization::isReviewEditor()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Controllers\EditorController;
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
            return;
44
        }
45
        wp_deregister_script('autosave');
46
    }
47
48
    /**
49
     * @return void
50
     */
51
    public function removeMetaBoxes()
52
    {
53
        remove_meta_box('slugdiv', Application::POST_TYPE, 'advanced');
54
    }
55
56
    /**
57
     * @return void
58
     */
59 1
    public function removePostTypeSupport()
60
    {
61 1
        if (!$this->isReviewEditor() || $this->isReviewEditable()) {
62 1
            return;
63
        }
64
        remove_post_type_support(Application::POST_TYPE, 'title');
65
        remove_post_type_support(Application::POST_TYPE, 'editor');
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    protected function isReviewEditable()
72
    {
73
        $postId = intval(filter_input(INPUT_GET, 'post'));
74
        return $postId > 0
75
            && 'local' == get_post_meta($postId, 'review_type', true)
76
            && $this->isReviewEditor();
77
    }
78
79
    /**
80
     * @return bool
81
     */
82 1
    protected function isReviewEditor()
83
    {
84 1
        $screen = glsr_current_screen();
85 1
        return 'post' == $screen->base
86 1
            && Application::POST_TYPE == $screen->id
87 1
            && Application::POST_TYPE == $screen->post_type;
88
    }
89
}
90