-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcustom-post-type.php
executable file
·116 lines (93 loc) · 3.8 KB
/
custom-post-type.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
<?php
/*
Plugin Name: CPT Portfolio
Plugin URI: http://www.sitebase.be
Description: This is a custom post type example created with the WordPress Framework by Sitebase
Author: Sitebase
Version: 1.0
Requires at least: 2.8
Author URI: http://www.sitebase.be
*/
// Include library
if(!class_exists('WpFramework_Base_0_6')) include "library/wp-framework/Base.php";
if(!class_exists('WpFramework_Vo_Form')) include_once "library/wp-framework/Vo/Form.php";
class CptExample extends WpFramework_Base_0_6 {
const NAME = 'CPT Example';
const NAME_SLUG = 'cpt-example';
/**
* Array of form validators for corresponding fields
*
* @var array
*/
private $_form_validators = null;
/**
* Form fields an default values
*
* @var array
*/
private $_form_fields_default = array(
'website_url' => '',
'year' => ''
);
/**
* Constructor
*
* @return void
*/
public function __construct(){
// Call parent constructor
parent::__construct();
// Validate input
if(!class_exists('WpFramework_Validators_Abstract')) include_once $this->plugin_path . '/library/wp-framework/Validators/Abstract.php';
if(!class_exists('WpFramework_Validators_NotEmpty')) include_once $this->plugin_path . '/library/wp-framework/Validators/NotEmpty.php';
if(!class_exists('WpFramework_Validators_Url')) include_once $this->plugin_path . '/library/wp-framework/Validators/Url.php';
if(!class_exists('WpFramework_Validators_Integer')) include_once $this->plugin_path . '/library/wp-framework/Validators/Integer.php';
$this->_form_validators['website_url'][] = new WpFramework_Validators_NotEmpty(__('This field is required'));
$this->_form_validators['website_url'][] = new WpFramework_Validators_Url(__('This isn\'t a valid URL'));
$this->_form_validators['year'][] = new WpFramework_Validators_Integer(__('This input must be a numeric value'));
}
/**********************************************************
* PRIVATE METHODS
**********************************************************/
/**********************************************************
* PUBLIC METHODS
**********************************************************/
public function action_init() {
$portfolio_args = array(
'label' => __('Portfolio'),
'singular_label' => __('Portfolio'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail')
);
register_post_type('portfolio',$portfolio_args);
}
public function action_admin_init() {
add_meta_box("details", "Options", array($this, "options"), "portfolio", "normal", "low");
}
public function action_save_post($postpage_id) {
$this->save_post_meta($postpage_id, array_keys($this->_form_fields_default), $_POST);
}
function options(){
global $post;
$data = $this->get_post_meta($post->ID, array_keys($this->_form_fields_default));
if(!is_array($data)) $data = array();
// If not isset the form is not submitted
$validation_results = $this->validate_fields(array_merge($this->_form_fields_default, $data), $this->_form_validators);
$data['wpform'] = new WpFramework_Vo_Form(array_merge($this->_form_fields_default, $data), $validation_results);
$this->load_view($this->plugin_path . "/views/cpt-options.php", $data);
}
/**
* Load stylesheet
*
* @return void
*/
public function action_admin_print_styles() {
//$this->enqueue_style('cpt-portfolio-style', $this->plugin_url . '/assets/cpt.css', null, '1.0');
$this->enqueue_style('wpframeworktest-style', $this->plugin_url . '/assets/css/wpf.css', null, '1.0');
}
}
$_GLOBALS['cpt-example'] = new CptExample();