-
Notifications
You must be signed in to change notification settings - Fork 23
/
portfolio.php
301 lines (264 loc) · 8.56 KB
/
portfolio.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?php
/**
* Plugin Name: Custom Content Portfolio
* Plugin URI: https://themehybrid.com/plugins/custom-content-portfolio
* Description: Portfolio manager for WordPress. This plugin allows you to manage, edit, and create new portfolio items in an unlimited number of portfolios.
* Version: 2.1.0
* Author: Justin Tadlock
* Author URI: https://themehybrid.com
* Text Domain: custom-content-portfolio
* Domain Path: /lang
*
* The Custom Content Portfolio plugin was created to solve the problem of theme developers continuing
* to incorrectly add custom post types to handle portfolios within their themes. This plugin allows
* any theme developer to build a "portfolio" theme without having to code the functionality. This
* gives more time for design and makes users happy because their data isn't lost when they switch to
* a new theme. Oh, and, this plugin lets creative folk put together a portfolio of their work on
* their site.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume
* that you can use any other version of the GPL.
*
* 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.
*
* @package CustomContentPortfolio
* @version 2.1.0
* @author Justin Tadlock <justintadlock@gmail.com>
* @copyright Copyright (c) 2013-2017, Justin Tadlock
* @link https://themehybrid.com/plugins/custom-content-portfolio
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/**
* Singleton class that sets up and initializes the plugin.
*
* @since 1.0.0
* @access public
* @return void
*/
final class CCP_Plugin {
/**
* Directory path to the plugin folder.
*
* @since 1.0.0
* @access public
* @var string
*/
public $dir_path = '';
/**
* Directory URI to the plugin folder.
*
* @since 1.0.0
* @access public
* @var string
*/
public $dir_uri = '';
/**
* JavaScript directory URI.
*
* @since 1.0.0
* @access public
* @var string
*/
public $js_uri = '';
/**
* CSS directory URI.
*
* @since 1.0.0
* @access public
* @var string
*/
public $css_uri = '';
/**
* Returns the instance.
*
* @since 1.0.0
* @access public
* @return object
*/
public static function get_instance() {
static $instance = null;
if ( is_null( $instance ) ) {
$instance = new self;
$instance->setup();
$instance->includes();
$instance->setup_actions();
}
return $instance;
}
/**
* Constructor method.
*
* @since 1.0.0
* @access private
* @return void
*/
private function __construct() {}
/**
* Magic method to output a string if trying to use the object as a string.
*
* @since 1.0.0
* @access public
* @return void
*/
public function __toString() {
return 'custom-content-portfolio';
}
/**
* Magic method to keep the object from being cloned.
*
* @since 1.0.0
* @access public
* @return void
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Whoah, partner!', 'custom-content-portfolio' ), '1.0.0' );
}
/**
* Magic method to keep the object from being unserialized.
*
* @since 1.0.0
* @access public
* @return void
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Whoah, partner!', 'custom-content-portfolio' ), '1.0.0' );
}
/**
* Magic method to prevent a fatal error when calling a method that doesn't exist.
*
* @since 1.0.0
* @access public
* @return void
*/
public function __call( $method = '', $args = array() ) {
_doing_it_wrong( "Custom_Content_Portfolio::{$method}", __( 'Method does not exist.', 'custom-content-portfolio' ), '1.0.0' );
unset( $method, $args );
return null;
}
/**
* Initial plugin setup.
*
* @since 1.0.0
* @access private
* @return void
*/
private function setup() {
$this->dir_path = trailingslashit( plugin_dir_path( __FILE__ ) );
$this->dir_uri = trailingslashit( plugin_dir_url( __FILE__ ) );
$this->js_uri = trailingslashit( $this->dir_uri . 'js' );
$this->css_uri = trailingslashit( $this->dir_uri . 'css' );
}
/**
* Loads include and admin files for the plugin.
*
* @since 1.0.0
* @access private
* @return void
*/
private function includes() {
// Load functions files.
require_once( $this->dir_path . 'inc/functions-capabilities.php' );
require_once( $this->dir_path . 'inc/functions-filters.php' );
require_once( $this->dir_path . 'inc/functions-options.php' );
require_once( $this->dir_path . 'inc/functions-meta.php' );
require_once( $this->dir_path . 'inc/functions-rewrite.php' );
require_once( $this->dir_path . 'inc/functions-post-types.php' );
require_once( $this->dir_path . 'inc/functions-taxonomies.php' );
require_once( $this->dir_path . 'inc/functions-project.php' );
require_once( $this->dir_path . 'inc/functions-deprecated.php' );
// Load template files.
require_once( $this->dir_path . 'inc/template-project.php' );
require_once( $this->dir_path . 'inc/template-general.php' );
// Load admin files.
if ( is_admin() ) {
require_once( $this->dir_path . 'admin/butterbean/butterbean.php' );
require_once( $this->dir_path . 'admin/functions-admin.php' );
require_once( $this->dir_path . 'admin/class-manage-projects.php' );
require_once( $this->dir_path . 'admin/class-project-edit.php' );
require_once( $this->dir_path . 'admin/class-settings.php' );
}
}
/**
* Sets up initial actions.
*
* @since 1.0.0
* @access private
* @return void
*/
private function setup_actions() {
// Internationalize the text strings used.
add_action( 'plugins_loaded', array( $this, 'i18n' ), 2 );
// Register activation hook.
register_activation_hook( __FILE__, array( $this, 'activation' ) );
}
/**
* Loads the translation files.
*
* @since 1.0.0
* @access public
* @return void
*/
public function i18n() {
load_plugin_textdomain( 'custom-content-portfolio', false, trailingslashit( dirname( plugin_basename( __FILE__ ) ) ) . 'lang' );
}
/**
* Method that runs only when the plugin is activated.
*
* @since 1.0.0
* @access public
* @global $wpdb
* @return void
*/
public function activation() {
// Temp. code to make sure post types and taxonomies are correct.
global $wpdb;
$wpdb->query( "UPDATE {$wpdb->posts} SET post_type = 'portfolio_project' WHERE post_type = 'portfolio_item'" );
$wpdb->query( "UPDATE {$wpdb->postmeta} SET meta_key = 'url' WHERE meta_key = 'portfolio_item_url'" );
$wpdb->query( "UPDATE {$wpdb->term_taxonomy} SET taxonomy = 'portfolio_category' WHERE taxonomy = 'portfolio'" );
// Get the administrator role.
$role = get_role( 'administrator' );
// If the administrator role exists, add required capabilities for the plugin.
if ( ! is_null( $role ) ) {
// Remove old caps.
$role->remove_cap( 'manage_portfolio' );
$role->remove_cap( 'create_portfolio_items' );
$role->remove_cap( 'edit_portfolio_items' );
// Taxonomy caps.
$role->add_cap( 'manage_portfolio_categories' );
$role->add_cap( 'edit_portfolio_categories' );
$role->add_cap( 'delete_portfolio_categories' );
$role->add_cap( 'assign_portfolio_categories' );
$role->add_cap( 'manage_portfolio_tags' );
$role->add_cap( 'edit_portfolio_tags' );
$role->add_cap( 'delete_portfolio_tags' );
$role->add_cap( 'assign_portfolio_tags' );
// Post type caps.
$role->add_cap( 'create_portfolio_projects' );
$role->add_cap( 'edit_portfolio_projects' );
$role->add_cap( 'edit_others_portfolio_projects' );
$role->add_cap( 'publish_portfolio_projects' );
$role->add_cap( 'read_private_portfolio_projects' );
$role->add_cap( 'delete_portfolio_projects' );
$role->add_cap( 'delete_private_portfolio_projects' );
$role->add_cap( 'delete_published_portfolio_projects' );
$role->add_cap( 'delete_others_portfolio_projects' );
$role->add_cap( 'edit_private_portfolio_projects' );
$role->add_cap( 'edit_published_portfolio_projects' );
}
}
}
/**
* Gets the instance of the `CCP_Plugin` class. This function is useful for quickly grabbing data
* used throughout the plugin.
*
* @since 1.0.0
* @access public
* @return object
*/
function ccp_plugin() {
return CCP_Plugin::get_instance();
}
// Let's do this thang!
ccp_plugin();