-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdashboard.php
executable file
·66 lines (49 loc) · 2.2 KB
/
dashboard.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
<?php
/*
Plugin Name: Dashboard Widget Example
Plugin URI: http://www.sitebase.be
Description: This is an example dashboard widget 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 DashboardExample extends WpFramework_Base_0_6 {
const NAME = 'Dashboard Example';
const NAME_SLUG = 'dashboard-example';
/**
* Array of form validators for corresponding fields
*
* @var array
*/
private $_form_validators = null;
public function action_wp_dashboard_setup() {
// 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';
$this->_form_validators['text'][] = new WpFramework_Validators_NotEmpty(__('This field is required'));
wp_add_dashboard_widget( self::NAME_SLUG, __( self::NAME, $this->plugin_name ), array(&$this, "display"), array(&$this, "setup") );
}
public function display() {
$data = $this->get_option(self::NAME_SLUG);
echo 'Your text is: ' . $data['text'];
}
public function setup() {
$data = $this->get_option(self::NAME_SLUG);
// Do form validation
if(!isset($_POST)) $_POST = array();
if(!is_array($data)) $data = array();
$validation_results = $this->validate_fields(array_merge($data, $_POST), $this->_form_validators);
$data['wpform'] = new WpFramework_Vo_Form(array_merge(array_merge($data, $_POST)), $validation_results);
// Save data if posted
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_POST['widget_id'] ) && self::NAME_SLUG == $_POST['widget_id'] ) {
$this->save_option(self::NAME_SLUG, $data['wpform']->getFields());
}
// Load view
$this->load_view($this->plugin_path . "/views/dashboard-options.php", $data);
}
}
$_GLOBALS['dashboard-example'] = new DashboardExample();