-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpbasis.php
executable file
·131 lines (100 loc) · 4.25 KB
/
wpbasis.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/*
Plugin Name: WP Basis
Plugin URI: https://github.com/wpmark/wpbasis
Description: WP Basis provides the basis of a WordPress site by giving you access to the types of functions you end up writing for all sites. It also gives modifications to the WordPress dashboard which make it easier to work with for your clients.
Author: Mark Wilkinson
Author URI: http://markwilkinson.me
Version: 1.6.4
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/* exist if directly accessed */
if( ! defined( 'ABSPATH' ) ) exit;
/* define variable for path to this plugin file. */
define( 'WPBASIS_LOCATION', dirname( __FILE__ ) );
define( 'WPBASIS_LOCATION_URL', plugins_url( '', __FILE__ ) );
/**
* include the necessary functions file for the plugin
*/
require_once dirname( __FILE__ ) . '/functions/template-functions.php';
require_once dirname( __FILE__ ) . '/functions/counters.php';
require_once dirname( __FILE__ ) . '/deprecated/deprecated.php';
/**
* include the admin functions
*/
require_once dirname( __FILE__ ) . '/functions/admin/admin-profile.php';
require_once dirname( __FILE__ ) . '/functions/admin/admin-menus.php';
require_once dirname( __FILE__ ) . '/functions/admin/admin-menus-content.php';
require_once dirname( __FILE__ ) . '/functions/admin/admin.php';
require_once dirname( __FILE__ ) . '/functions/admin/admin-bar.php';
require_once dirname( __FILE__ ) . '/functions/admin/admin-display.php';
/**
* include the plugin defaults
*/
require_once dirname( __FILE__ ) . '/functions/defaults/default-tabs.php';
require_once dirname( __FILE__ ) . '/functions/defaults/default-settings.php';
require_once dirname( __FILE__ ) . '/functions/defaults/default-capabilities.php';
/**
* deal with legacy code here
* load post type descriptions - filterable
* add the site options - filterable
*/
if( apply_filters( 'wpbasis_use_post_type_descriptions', false ) == true ) {
require_once dirname( __FILE__ ) . '/deprecated/post-type-descriptions.php';
}
if( apply_filters( 'wpbasis_show_site_options', false ) == true ) {
require_once dirname( __FILE__ ) . '/deprecated/site-options.php';
}
/**
* Function wpbasis_on_activation()
* On plugin activation makes current user a wpbasis user and
* sets an option to redirect the user to another page.
*/
function wpbasis_on_activation() {
/* get the current users, user ID */
$wpbasis_user_id = get_current_user_id();
/* make the user a wpbasis super user */
update_usermeta( $wpbasis_user_id, 'wpbasis_user', 1 );
/* set option to initialise the redirect */
add_option( 'wpbasis_activation_redirect', true );
}
register_activation_hook( __FILE__, 'wpbasis_on_activation' );
/**
* Function wp_basis_activation_redirect()
* Redirects user to the settings page for wp basis on plugin
* activation.
*/
function wp_basis_activation_redirect() {
/* check whether we should redirect the user or not based on the option set on activation */
if( true == get_option( 'wpbasis_activation_redirect' ) ) {
/* delete the redirect option */
delete_option( 'wpbasis_activation_redirect' );
/* redirect the user to the wp basis settings page */
wp_redirect( admin_url( 'admin.php?page=wpbasis_settings' ) );
exit;
}
}
add_action( 'admin_init', 'wp_basis_activation_redirect' );
/**
* Function wpbasis_enqueue_scripts()
* Adds plugins scripts and styles
*/
function wpbasis_enqueue_scripts() {
/* load the global variable to see which admin page we are on */
global $pagenow;
/* check whether the current admin page is wpbasis dashboard page */
if( $pagenow == 'admin.php' ) {
/* site js scripts */
wp_enqueue_script( 'wpbasis_js', plugins_url( 'assets/js/wpbasis-min.js', __FILE__ ), 'jquery' );
/* register the stylesheet */
wp_enqueue_style( 'wpbasis_admin_css', plugins_url( 'assets/css/wpbasis.css', __FILE__ ) );
}
}
add_action( 'admin_enqueue_scripts', 'wpbasis_enqueue_scripts' );