Completed
Branch master (69b4cd)
by Michael
05:07
created

admin-page-framework-loader.php ➔ AdminPageFrameworkLoader_Warning()   B

Complexity

Conditions 6
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 13
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 20
rs 8.8571
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 17 and the first side effect is on line 222.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/** 
3
 *  Plugin Name:    Admin Page Framework - Loader
4
 *  Plugin URI:     http://admin-page-framework.michaeluno.jp/
5
 *  Description:    Loads Admin Page Framework which facilitates WordPress plugin and theme development.
6
 *  Author:         Michael Uno
7
 *  Author URI:     http://en.michaeluno.jp/
8
 *  Requirements:   PHP 5.2.4 or above, WordPress 3.3 or above.
9
 *  Version:        3.7.15
10
 */
11
12
/**
13
 * The base registry information.
14
 * 
15
 * @since       3.5.0
16
 */
17
class AdminPageFrameworkLoader_Registry_Base {
18
19
    const VERSION        = '3.7.15';    // <--- DON'T FORGET TO CHANGE THIS AS WELL!!
20
    const NAME           = 'Admin Page Framework - Loader'; // the name is not 'Admin Page Framework' because warning messages gets confusing.
21
    const SHORTNAME      = 'Admin Page Framework';  // used for a menu title etc.
22
    const DESCRIPTION    = 'Loads Admin Page Framework which facilitates WordPress plugin and theme development.';
23
    const URI            = 'http://admin-page-framework.michaeluno.jp/';
24
    const AUTHOR         = 'miunosoft (Michael Uno)';
25
    const AUTHOR_URI     = 'http://en.michaeluno.jp/';
26
    const COPYRIGHT      = 'Copyright (c) 2015-2016, Michael Uno';
27
    const LICENSE        = 'GPL v2 or later';
28
    const CONTRIBUTORS   = '';
29
30
}
31
/**
32
 * Provides the plugin information.
33
 * 
34
 * The plugin will refer to these information.
35
 * 
36
 * @since       3.5.0 
37
 */
38
final class AdminPageFrameworkLoader_Registry extends AdminPageFrameworkLoader_Registry_Base {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
39
40
    /**
41
     * The plugin option key used for the options table.
42
     */
43
    static public $aOptionKeys = array(
44
        'main'    => 'admin_page_framework_loader',
45
        'demo'    => array(
46
            'main'          => 'APF_Demo',
47
            'taxonomy'      => 'APF_TaxonomyField',
48
            'basic_usage'   => 'APF_BasicUsage',
49
        )
50
    );
51
52
    /**
53
     * The transient prefix. 
54
     * 
55
     * @remark      This is also accessed from `uninstall.php` so do not remove.
56
     * @remark      Do not exceed 8 characters as a transient name allows 45 characters or less ( 40 for site transients ) so that md5 (32 characters) can be added.
57
     */
58
    const TRANSIENT_PREFIX         = 'APFL_';
59
60
    /**
61
     * The hook slug used for the prefix of action and filter hook names.
62
     * 
63
     * @remark      The ending underscore is not necessary.
64
     */
65
    const HOOK_SLUG                = 'admin_page_framework_loader';
66
67
    /**
68
     * The text domain slug and its path.
69
     * 
70
     * These will be accessed from the bootstrap script.
71
     */
72
    const TEXT_DOMAIN              = 'admin-page-framework-loader';
73
    const TEXT_DOMAIN_PATH         = '/language';
74
75
    // These properties will be defined in the setUp() method.
76
    static public $sFilePath = '';
77
    static public $sDirPath  = '';
78
79
    /**
80
     * Requirements.
81
     */    
82
    static public $aRequirements = array(
83
        'php' => array(
84
            'version'   => '5.2.4',
85
            'error'     => 'The plugin requires the PHP version %1$s or higher.',
86
        ),
87
        'wordpress'         => array(
88
            'version'   => '3.4',
89
            'error'     => 'The plugin requires the WordPress version %1$s or higher.',
90
        ),
91
        'mysql'             => array(
92
            'version'   => '5.0',
93
            'error'     => 'The plugin requires the MySQL version %1$s or higher.',
94
        ),
95
        'functions'         => '', // disabled
96
        // array(
97
            // e.g. 'mblang' => 'The plugin requires the mbstring extension.',
98
        // ),
99
        'classes'           => '', // disabled
100
        // array(
101
            // e.g. 'DOMDocument' => 'The plugin requires the DOMXML extension.',
102
        // ),
103
        'constants'         => '', // disabled
104
        // array(
105
            // e.g. 'THEADDONFILE' => 'The plugin requires the ... addon to be installed.',
106
            // e.g. 'APSPATH' => 'The script cannot be loaded directly.',
107
        // ),
108
        'files'             => '', // disabled
109
        // array(
110
            // e.g. 'home/my_user_name/my_dir/scripts/my_scripts.php' => 'The required script could not be found.',
111
        // ),
112
    );
113
114
    /**
115
     * Used admin pages.
116
     */
117
    static public $aAdminPages = array(
118
        // key => 'page slug'
119
        'about'     => 'apfl_about',        // the welcome page
120
        'addon'     => 'apfl_addons',
121
        'tool'      => 'apfl_tools',
122
        'help'      => 'apfl_contact',
123
    );
124
125
    /**
126
     * Used post types.
127
     */
128
    static public $aPostTypes = array(
129
        'demo'      => 'apf_posts',
130
    );
131
132
    /**
133
     * Used taxonomies.
134
     */
135
    static public $aTaxonomies = array(
136
    );
137
138
    /**
139
     * Sets up static properties.
140
     * @return      void
141
     */
142
    static public function setUp( $sPluginFilePath ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
143
        self::$sFilePath = $sPluginFilePath;
144
        self::$sDirPath  = dirname( self::$sFilePath );
145
    }    
146
147
    /**
148
     * Returns the URL with the given relative path to the plugin path.
149
     * 
150
     * <h3>Example</h3>
151
     * <code>
152
     * AdminPageFrameworkLoader_Registry::getPluginURL( 'asset/css/meta_box.css' );
153
     * </code>
154
     * @since       3.5.0
155
     * @return      string
156
     */
157
    public static function getPluginURL( $sRelativePath='' ) {
158
        if ( isset( self::$_sPluginURLCache ) ) {
159
            return self::$_sPluginURLCache . $sRelativePath;
160
        }
161
        self::$_sPluginURLCache = trailingslashit( plugins_url( '', self::$sFilePath ) );
162
        return self::$_sPluginURLCache . $sRelativePath;
163
    }
164
        /**
165
         * @since       3.7.9
166
         */
167
        static private $_sPluginURLCache;
168
169
    /**
170
     * Returns the information of this class.
171
     * 
172
     * @since       3.5.0
173
     * @return      array
174
     */
175
    static public function getInfo() {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
176
        $_oReflection = new ReflectionClass( __CLASS__ );
177
        return $_oReflection->getConstants()
178
            + $_oReflection->getStaticProperties()
179
        ;
180
    }
181
182
    /**
183
     * Stores admin notices.
184
     * @since       3.5.0
185
     */
186
    static public $_aAdminNotices = array();
187
    /**
188
     * Sets an admin notice.
189
     * @since       3.5.0
190
     * @return      void
191
     */ 
192
    static public function setAdminNotice( $sMessage, $sClassAttribute='error' ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
193
        if ( ! is_admin() ) {  
194
            return; 
195
        }
196
        self::$_aAdminNotices[] = array(
197
            'message'           => $sMessage,
198
            'class_attribute'   => trim( $sClassAttribute ) . ' notice is-dismissible',
199
        );
200
        add_action( 'admin_notices', array( __CLASS__, '_replyToSetAdminNotice' ) );
201
    }
202
        /**
203
         * Displays the set admin notices.
204
         * @since       3.5.0
205
         * @return      void
206
         */
207
        static public function _replyToSetAdminNotice() {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
208
            foreach( self::$_aAdminNotices as $_aAdminNotice ) {
209
                echo "<div class='" . esc_attr( $_aAdminNotice['class_attribute'] ) . " notice is-dismissible'>"
210
                        ."<p>"
211
                            . sprintf(
212
                                '<strong>%1$s</strong>: ' . $_aAdminNotice['message'],
213
                                self::NAME . ' ' . self::VERSION
214
                            )
215
                        . "</p>"
216
                    . "</div>";
217
            }
218
        }
219
220
}
221
// Registry set-up.
222
AdminPageFrameworkLoader_Registry::setUp( __FILE__ );
223
224
// Initial checks. - Do no load if accessed directly, not exiting because the 'uninstall.php' and inclusion list generator will load this file.
225
if ( ! defined( 'ABSPATH' ) ) {
226
    return;
227
}
228
if ( defined( 'DOING_UNINSTALL' ) ) {
229
    return;
230
}
231
232
// Set warnings.
233
function AdminPageFrameworkLoader_Warning() {
234
235
    $_bFrameworkLoaded = class_exists( 'AdminPageFramework_Registry', false );
236
    if (
237
        ! $_bFrameworkLoaded
238
        || ! defined( 'AdminPageFramework_Registry::VERSION' ) // backward compatibility
239
        || version_compare( AdminPageFramework_Registry::VERSION, AdminPageFrameworkLoader_Registry::VERSION, '<' )
240
    ) {
241
        AdminPageFrameworkLoader_Registry::setAdminNotice(
242
            sprintf(
243
                'The framework has been already loaded and its version is lesser than yours. Your framework will not be loaded to avoid unexpected results. Loaded Version - %1$s. Your Version - %2$s.',
244
                $_bFrameworkLoaded && defined( 'AdminPageFramework_Registry::VERSION' )
245
                    ? AdminPageFramework_Registry::VERSION
246
                    : 'unknown',
247
                AdminPageFrameworkLoader_Registry::VERSION
248
            )
249
        );
250
    }
251
252
}
253
add_action( 'admin_init', 'AdminPageFrameworkLoader_Warning' );
254
255
// Include the library file - the development version will be available if you cloned the GitHub repository.
256
$_sDevelopmentVersionPath = AdminPageFrameworkLoader_Registry::$sDirPath . '/development/admin-page-framework.php';
257
$_bDebugMode              = defined( 'WP_DEBUG' ) && WP_DEBUG;
258
$_bLoadDevelopmentVersion = $_bDebugMode && file_exists( $_sDevelopmentVersionPath );
259
include(
260
    $_bLoadDevelopmentVersion
261
        ? $_sDevelopmentVersionPath
262
        : AdminPageFrameworkLoader_Registry::$sDirPath . '/library/apf/admin-page-framework.php'
263
);
264
265
// Include the framework loader plugin components.
266
include( AdminPageFramework_Registry::$aClassFiles[ 'AdminPageFramework_PluginBootstrap' ] );
267
include( AdminPageFrameworkLoader_Registry::$sDirPath . '/include/class/AdminPageFrameworkLoader_Bootstrap.php' );
268
new AdminPageFrameworkLoader_Bootstrap(
269
    AdminPageFrameworkLoader_Registry::$sFilePath,
270
    AdminPageFrameworkLoader_Registry::HOOK_SLUG    // hook prefix
271
);
272
273
/*
274
 * If you find this framework useful, include it in your project!
275
 * And please leave a nice comment in the review page, http://wordpress.org/support/view/plugin-reviews/admin-page-framework
276
 * 
277
 * If you have a suggestion, the GitHub repository is open to anybody so post an issue there.
278
 * https://github.com/michaeluno/admin-page-framework/issues
279
 * 
280
 * Happy coding!
281
 */
282