Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 196 lines (168 sloc) 5.94 kb
2cf62146 »
2010-11-25 Importing the Members plugin files and folders.
1 <?php
2 /**
3 * Plugin Name: Members
4 * Plugin URI: http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin
5 * Description: A user, role, and content management plugin for controlling permissions and access. A plugin for making WordPress a more powerful <acronym title="Content Management System">CMS</acronym>.
88de6945 »
2010-11-28 Add the Members_Load class to initialize the plugin.
6 * Version: 0.2 Beta
2cf62146 »
2010-11-25 Importing the Members plugin files and folders.
7 * Author: Justin Tadlock
8 * Author URI: http://justintadlock.com
9 *
88de6945 »
2010-11-28 Add the Members_Load class to initialize the plugin.
10 * The members plugin was created because the WordPress community is lacking a solid permissions
11 * plugin that is both open source and works completely within the confines of the APIs in WordPress.
12 * But, the plugin is so much more than just a plugin to control permissions. It is meant to extend
13 * WordPress by making user, role, and content management as simple as using the system altogether.
2cf62146 »
2010-11-25 Importing the Members plugin files and folders.
14 *
88de6945 »
2010-11-28 Add the Members_Load class to initialize the plugin.
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License version 2, as published by the Free Software Foundation. You may NOT assume
17 * that you can use any other version of the GPL.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
20 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2cf62146 »
2010-11-25 Importing the Members plugin files and folders.
21 *
22 * @package Members
88de6945 »
2010-11-28 Add the Members_Load class to initialize the plugin.
23 * @version 0.2.0
24 * @author Justin Tadlock <justin@justintadlock.com>
25 * @copyright Copyright (c) 2009 - 2010, Justin Tadlock
26 * @link http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin
27 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2cf62146 »
2010-11-25 Importing the Members plugin files and folders.
28 */
29
30 /**
88de6945 »
2010-11-28 Add the Members_Load class to initialize the plugin.
31 * @since 0.2.0
2cf62146 »
2010-11-25 Importing the Members plugin files and folders.
32 */
88de6945 »
2010-11-28 Add the Members_Load class to initialize the plugin.
33 class Members_Load {
34
35 /**
36 * PHP4 constructor method.
37 *
38 * @since 0.2.0
39 */
40 function Members_Load() {
41 $this->__construct();
42 }
43
44 /**
45 * PHP5 constructor method.
46 *
47 * @since 0.2.0
48 */
49 function __construct() {
50 add_action( 'plugins_loaded', array( &$this, 'constants' ), 1 );
51 add_action( 'plugins_loaded', array( &$this, 'locale' ), 2 );
52 add_action( 'plugins_loaded', array( &$this, 'load' ), 3 );
53 add_action( 'plugins_loaded', array( &$this, 'admin' ), 4 );
54 }
55
56 /**
57 * Defines constants used by the plugin.
58 *
59 * @since 0.2.0
60 */
61 function constants() {
62
63 /* Set constant path to the members plugin directory. */
64 define( 'MEMBERS_DIR', plugin_dir_path( __FILE__ ) );
65
66 /* Set constant path to the members plugin URL. */
67 define( 'MEMBERS_URI', plugin_dir_url( __FILE__ ) );
68
69 /* Set constant path to the members components directory. */
70 define( 'MEMBERS_COMPONENTS', trailingslashit( MEMBERS_DIR ) . 'components' );
71 }
72
73 /**
74 * Loads the initial files needed by the plugin.
75 *
76 * @since 0.2.0
77 */
78 function load() {
79 if ( !is_admin() )
80 require_once( MEMBERS_DIR . 'functions.php' );
81
82 /* Load the components system, which is the file that has all the components-related functions. */
83 require_once( MEMBERS_DIR . 'components.php' );
84
85 /* Set up globals. */
86 add_action( 'after_setup_theme', 'members_core_globals_setup', 0 );
87 }
88
89 /**
90 * Loads the translation files.
91 *
92 * @since 0.2.0
93 */
94 function locale() {
95 /* Load the translation of the plugin. */
96 load_plugin_textdomain( 'members', false, 'members/languages' );
97 }
98
99 /**
100 * Loads the admin functions and files.
101 *
102 * @since 0.2.0
103 */
104 function admin() {
105
106 /* Load global functions for the WordPress admin. */
107 if ( is_admin() ) {
108 require_once( MEMBERS_DIR . 'functions-admin.php' );
109
110 /* Members components settings page. */
111 add_action( 'admin_menu', 'members_settings_page_init' );
112 add_action( 'admin_init', 'members_register_settings' );
113 }
114 }
2cf62146 »
2010-11-25 Importing the Members plugin files and folders.
115 }
116
88de6945 »
2010-11-28 Add the Members_Load class to initialize the plugin.
117 $members_load = new Members_Load();
118
2cf62146 »
2010-11-25 Importing the Members plugin files and folders.
119 /**
120 * Set up the $members global variable. Since we'll need to have several
121 * different variables, it just makes sense to put them all into one place.
122 * Other functions will hook onto this (e.g., $members-registered_components).
123 *
124 * @since 0.1
125 * @global $members object The global members object.
126 * @global $current_user object The currently logged-in user.
127 */
128 function members_core_globals_setup() {
129 global $members, $current_user;
130
131 /* Get the currently logged-in user. */
132 $current_user = wp_get_current_user();
133
134 /* Add the currently logged-in user to our global object. */
135 $members->current_user = $current_user;
136
137 /* Get all active components */
138 $members->active_components = get_option( 'members_settings' );
139 }
140
141 /**
142 * Creates the members settings/components page.
143 *
144 * @since 0.1
145 * @uses add_submenu_page() Creates a submenu for the Settings menu item.
146 */
147 function members_settings_page_init() {
148 global $members;
149
88de6945 »
2010-11-28 Add the Members_Load class to initialize the plugin.
150 $members->settings_page = add_submenu_page( 'options-general.php', __('Members Components', 'members'), __('Members Components', 'members'), 'manage_options', 'members-components', 'members_settings_page' );
2cf62146 »
2010-11-25 Importing the Members plugin files and folders.
151 }
152
153 /**
154 * Registers the plugin settings, which will become an array of activated components.
155 *
156 * @since 0.1
157 * @uses register_setting() Function for registering a setting in WordPress.
158 */
159 function members_register_settings() {
160 register_setting( 'members_plugin_settings', 'members_settings', 'members_settings_validate' );
161 }
162
163 /**
164 * Loads the admin screen page for selecting components for use with the plugin.
165 *
166 * @since 0.1
167 */
168 function members_settings_page() {
169 require_once( MEMBERS_DIR . 'settings.php' );
170 }
171
172 /**
173 * Validates the members settings. Since the settings is just a list of components,
174 * all we need to do here is loop through the array and check for true/false.
175 *
176 * @since 0.1
177 * @param $input array Values sent by the settings page.
178 * @return $input array Validated values to return.
179 */
180 function members_settings_validate( $input ) {
181 if ( !is_array( $input ) )
182 return $input;
183
184 foreach ( $input as $key => $value ) {
185
186 /* Disable old edit_roles and new_roles components. */
187 if ( 'edit_roles' == $input[$key] || 'new_roles' == $input[$key] )
188 $input[$key] = false;
189 else
190 $input[$key] = ( $input[$key] == 1 ? 1 : 0 );
191 }
192
193 return $input;
194 }
195
196 ?>
Something went wrong with that request. Please try again.