Completed
Branch dev (aae49a)
by
unknown
19:32
created

AdminPageFrameworkLoader_NetworkAdmin::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 11
rs 9.4286
ccs 0
cts 8
cp 0
cc 1
eloc 5
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * One of the abstract class of the plugin admin page class.
4
 * 
5
 * @package      Admin Page Framework Loader
6
 * @copyright    Copyright (c) 2014-2015, Michael Uno
7
 * @author       Michael Uno
8
 * @authorurl    http://michaeluno.jp
9
 * @since        3.5.0
10
 */
11
12
class AdminPageFrameworkLoader_NetworkAdmin extends AdminPageFramework_NetworkAdmin {
2 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
13
    
14
    /**
15
     * User constructor.
16
     * 
17
     * @since       3.5.0
18
     */
19
    public function start() {
0 ignored issues
show
Coding Style introduced by
start uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
20
  
21
        if ( ! $this->oProp->bIsAdmin ) {
22
            return;
23
        }
24
        if ( ! is_network_admin() ) {
25
            return;
26
        }
27
          
28
        // Enable / disable the demo pages
29
        if ( isset( $_GET['enable_apfl_demo_pages'] ) ) {
30
            
31
            // Update the options and reload the page
32
            $_oOption = AdminPageFrameworkLoader_Option::getInstance( AdminPageFrameworkLoader_Registry::$aOptionKeys['main'] );
33
            $_oOption->update( 'enable_demo', $_GET['enable_apfl_demo_pages'] );
34
            
35
            $this->setSettingNotice( 
36
                __( 'Enabled demo!', 'admin-page-framework-loader' ),
37
                'updated' 
38
            );
39
            $this->oUtil->goToLocalURL( 
40
                remove_query_arg( 'enable_apfl_demo_pages' ),
41
                array( 'AdminPageFrameworkLoader_Utility', 'replyToShowRedirectError' )
42
            );
43
44
        }
45
             
46
    }
47
  
48
    /**
49
     * Sets up admin pages.
50
     * 
51
     * @since       3.5.0
52
     */
53
    public function setUp() {
54
        
55
        // Action Links (plugin.php)
56
        $this->addLinkToPluginTitle(
57
            $this->_getDemoSwitcherLink( $this->oProp->aOptions )
58
        );
59
        $this->addLinkToPluginDescription(
60
            "<a href='https://wordpress.org/support/plugin/admin-page-framework' target='_blank'>" . __( 'Support', 'admin-page-framework-loader' ) . "</a>"
61
        );
62
        
63
    }
64
          
65
        /**
66
         * Returns the switch link of the demo pages.
67
         */
68
        private function _getDemoSwitcherLink( $mOptions=array() ) {
1 ignored issue
show
Coding Style introduced by
Method name "_getDemoSwitcherLink" should not be prefixed with an underscore to indicate visibility
Loading history...
69
            
70
            $_bEnabled  = isset( $mOptions['enable_demo'] ) && $mOptions['enable_demo'];
71
            $_sLink    = esc_url( 
72
                add_query_arg( 
73
                    array( 
74
                        'enable_apfl_demo_pages' => $_bEnabled ? 0 : 1,
75
                    )
76
                )
77
            );        
78
            return $_bEnabled
79
                ? "<a href='{$_sLink}'>" . __( 'Disable Demo', 'admin-page-framework-loader' ) . "</a>"
80
                : "<a href='{$_sLink}'><strong style='font-size: 1em;'>" . __( 'Enable Demo', 'admin-page-framework-loader' ) . "</strong></a>";
81
            
82
        }            
83
84
}
1 ignored issue
show
Coding Style introduced by
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...