Passed
Push — feature/rebusify ( 0fe5b2...103190 )
by Paul
08:37 queued 03:55
created

WelcomeController::renderPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 15
ccs 0
cts 9
cp 0
crap 2
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Controllers;
4
5
use GeminiLabs\SiteReviews\Application;
6
use GeminiLabs\SiteReviews\Modules\Html\Builder;
7
use GeminiLabs\SiteReviews\Modules\Html\Template;
8
9
class WelcomeController extends Controller
10
{
11
    /**
12
     * @return array
13
     * @filter plugin_action_links_site-reviews/site-reviews.php
14
     */
15
    public function filterActionLinks(array $links)
16
    {
17
        $links['welcome'] = glsr(Builder::class)->a(__('About', 'site-reviews'), [
18
            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'),
19
        ]);
20
        return $links;
21
    }
22
23
    /**
24
     * @return string
25
     * @filter admin_title
26
     */
27
    public function filterAdminTitle($title)
28
    {
29
        return Application::POST_TYPE.'_page_welcome' == glsr_current_screen()->id
30
            ? sprintf(__('Welcome to %s &#8212; WordPress', 'site-reviews'), glsr()->name)
31
            : $title;
32
    }
33
34
    /**
35
     * @param string $text
36
     * @return string
37
     * @filter admin_footer_text
38
     */
39
    public function filterFooterText($text)
40
    {
41
        if (Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id) {
42
            return $text;
43
        }
44
        $url = 'https://wordpress.org/support/view/plugin-reviews/site-reviews?filter=5#new-post';
45
        return wp_kses_post(sprintf(
46
            __( 'Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews'),
47
            '<strong>'.glsr()->name.'</strong> <a href="'.$url.'" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>',
48
            '<a href="'.$url.'" target="_blank">wordpress.org</a>'
49
        ));
50
    }
51
52
    /**
53
     * @param string $plugin
54
     * @param bool $isNetworkActivation
55
     * @return void
56
     * @action activated_plugin
57
     */
58
    public function redirectOnActivation($plugin, $isNetworkActivation)
59
    {
60
        if (!$isNetworkActivation
61
            && 'cli' !== php_sapi_name() 
62
            && $plugin === plugin_basename(glsr()->file)) {
63
            wp_safe_redirect(admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'));
64
            exit;
1 ignored issue
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
65
        }
66
    }
67
68
    /**
69
     * @return void
70
     * @action admin_menu
71
     */
72
    public function registerPage()
73
    {
74
        add_submenu_page('edit.php?post_type='.Application::POST_TYPE,
75
            sprintf(__('Welcome to %s', 'site-reviews'), glsr()->name),
76
            glsr()->name,
77
            glsr()->getPermission('welcome'),
78
            'welcome',
79
            [$this, 'renderPage']
80
        );
81
        remove_submenu_page('edit.php?post_type='.Application::POST_TYPE, 'welcome');
82
    }
83
84
    /**
85
     * @return void
86
     * @see $this->registerPage()
87
     * @callback add_submenu_page
88
     */
89
    public function renderPage()
90
    {
91
        $tabs = apply_filters('site-reviews/addon/welcome/tabs', [
92
            'getting-started' => __('Getting Started', 'site-reviews'),
93
            'whatsnew' => __('What\'s New', 'site-reviews'),
94
            'support' => __('Support', 'site-reviews'),
95
        ]);
96
97
        glsr()->render('pages/welcome/index', [
98
            'data' => [
99
                'context' => [
100
                ],
101
            ],
102
            'tabs' => $tabs,
103
            'template' => glsr(Template::class),
104
        ]);
105
    }
106
}
107