Passed
Push — master ( f510e9...9822a2 )
by Paul
10:29
created

TranslationHooks::translateAdminPostPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Hooks;
4
5
use GeminiLabs\SiteReviews\Controllers\TranslationController;
6
use GeminiLabs\SiteReviews\Modules\Translation;
7
8
class TranslationHooks extends AbstractHooks
9
{
10
    /**
11
     * @return void
12
     */
13
    public function translateAdminEditPage()
14
    {
15
        if (glsr()->post_type === glsr_current_screen()->post_type) {
16
            $this->hook(TranslationController::class, [
17
                ['filterBulkUpdateMessages', 'bulk_post_updated_messages', 10, 2],
18
                ['filterPostStates', 'display_post_states', 10, 2],
19
                ['filterPostStatusLabels', 'gettext_default', 10, 2],
20
                ['filterPostStatusText', 'ngettext_default', 10, 4],
21
            ]);
22
        }
23
    }
24
25
    /**
26
     * @return void
27
     */
28
    public function translateAdminPostPage()
29
    {
30
        if (glsr()->post_type === glsr_current_screen()->post_type) {
31
            $this->hook(TranslationController::class, [
32
                ['filterPostStatusLabels', 'gettext_default', 10, 2],
33
                ['translatePostStatusLabels', 'admin_print_scripts-post.php'],
34
            ]);
35
        }
36
    }
37
38
    /**
39
     * @return void
40
     */
41
    public function translatePlugin()
42
    {
43
        if (empty(glsr(Translation::class)->translations())) {
44
            $this->hook(TranslationController::class, [
45
                ['filterGettext', "gettext_{$this->id}", 10, 2],
46
                ['filterGettextWithContext', "gettext_with_context_{$this->id}", 10, 3],
47
                ['filterNgettext', "ngettext_{$this->id}", 10, 4],
48
                ['filterNgettextWithContext', "ngettext_with_context_{$this->id}", 10, 5],
49
            ]);
50
        }
51
    }
52
53
    /**
54
     * @return void
55
     */
56
    public function run()
57
    {
58
        add_action('load-edit.php', [$this, 'translateAdminEditPage']);
59
        add_action('load-post.php', [$this, 'translateAdminPostPage']);
60
        add_action('plugins_loaded', [$this, 'translatePlugin']);
61
    }
62
}
63