PluginProbe
UpStream: a Project Management Plugin for WordPress / 2.1.0
UpStream: a Project Management Plugin for WordPress v2.1.0
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / admin / options / class-upstream-options-projects.php

class-upstream-options-projects.php in UpStream: a Project Management Plugin for WordPress 2.1.0, at includes/admin/options/class-upstream-options-projects.php

253 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UpStream_Options_Projects
4 *
5 * @package UpStream
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 if ( ! class_exists( 'UpStream_Options_Projects' ) ) :
14
15 /**
16 * CMB2 Theme Options
17 *
18 * @version 0.1.0
19 */
20 class UpStream_Options_Projects {
21
22
23 /**
24 * Array of metaboxes/fields
25 *
26 * @var array
27 */
28 public $id = 'upstream_projects';
29
30 /**
31 * Page title
32 *
33 * @var string
34 */
35 protected $title = '';
36
37 /**
38 * Menu Title
39 *
40 * @var string
41 */
42 protected $menu_title = '';
43
44 /**
45 * Menu Title
46 *
47 * @var string
48 */
49 protected $description = '';
50
51 /**
52 * Holds an instance of the object
53 *
54 * @var Myprefix_Admin
55 **/
56 public static $instance = null;
57
58 /**
59 * Constructor
60 *
61 * @since 0.1.0
62 */
63 public function __construct() {
64 // Set our title.
65 $this->title = upstream_project_label_plural();
66 $this->menu_title = $this->title;
67 // $this->description = sprintf( __( '%s Description', 'upstream' ), upstream_project_label() );
68 }
69
70 /**
71 * Returns the running object
72 *
73 * @return Myprefix_Admin
74 **/
75 public static function get_instance() {
76 if ( is_null( self::$instance ) ) {
77 self::$instance = new self();
78 }
79
80 return self::$instance;
81 }
82
83
84 /**
85 * Add the options metabox to the array of metaboxes
86 *
87 * @since 0.1.0
88 */
89 public function options() {
90 $options = apply_filters(
91 $this->id . '_option_fields',
92 array(
93 'id' => $this->id,
94 'title' => $this->title,
95 'menu_title' => $this->menu_title,
96 'desc' => $this->description,
97 'show_on' => array(
98 'key' => 'options-page',
99 'value' => array( $this->id ),
100 ),
101 'show_names' => true,
102 'fields' => array(
103 array(
104 'name' => __( 'Statuses', 'upstream' ),
105 'id' => 'status_title',
106 'type' => 'title',
107 'desc' => sprintf(
108 // translators: %1$s: upstream_project_label.
109 // translators: %2$s: upstream_project_label.
110 // translators: %3$s: upstream_project_label.
111 __(
112 'The statuses and colors that can be used for the main status of the %1$s.<br>These will become available in the %2$s Status dropdown within the %3$s',
113 'upstream'
114 ),
115 upstream_project_label(),
116 upstream_project_label(),
117 upstream_project_label()
118 ),
119 ),
120 array(
121 'id' => 'statuses',
122 'type' => 'group',
123 'name' => '',
124 'description' => '',
125 'options' => array(
126 'group_title' => __( 'Status {#}', 'upstream' ),
127 'add_button' => __( 'Add Status', 'upstream' ),
128 'remove_button' => __( 'Remove Entry', 'upstream' ),
129 'sortable' => true, // beta.
130 ),
131 'sanitization_cb' => array( 'UpStream_Admin', 'on_before_save' ),
132 'fields' => array(
133 array(
134 'name' => __( 'Hidden', 'upstream' ),
135 'id' => 'id',
136 'type' => 'hidden',
137 ),
138 array(
139 'name' => __( 'Status Color', 'upstream' ),
140 'id' => 'color',
141 'type' => 'colorpicker',
142 'attributes' => array(
143 'data-colorpicker' => json_encode(
144 array(
145 // Iris Options set here as values in the 'data-colorpicker' array.
146 'palettes' => upstream_colorpicker_default_colors(),
147 'width' => 300,
148 )
149 ),
150 ),
151 ),
152 array(
153 'name' => __( 'Status Name', 'upstream' ),
154 'id' => 'name',
155 'type' => 'text',
156 ),
157 array(
158 'name' => __( 'Type of Status', 'upstream' ),
159 'id' => 'type',
160 'type' => 'radio',
161 'default' => 'open',
162 'desc' => __(
163 "A Status Name such as 'In Progress' or 'Overdue' would be considered Open.",
164 'upstream'
165 ) . '<br>' . __(
166 "A Status Name such as 'Complete' or 'Cancelled' would be considered Closed.",
167 'upstream'
168 ),
169 'options' => array(
170 'open' => __( 'Open', 'upstream' ),
171 'closed' => __( 'Closed', 'upstream' ),
172 ),
173 ),
174 ),
175 ),
176
177 array(
178 'name' => __( 'Other Settings', 'upstream' ),
179 'id' => 'project_other_settings',
180 'type' => 'title',
181 'desc' => __( 'Additional settings for projects in UpStream.', 'upstream' ),
182 ),
183 array(
184 'name' => __( 'Number of Projects Per Page on Frontend', 'upstream' ),
185 'id' => 'project_number_per_page',
186 'type' => 'text',
187 'desc' => __( 'The number of projects per page to display on front end.', 'upstream' ),
188 'default' => 1000,
189 ),
190 ),
191 )
192 );
193
194 return $options;
195 }
196
197 /**
198 * Create ids for all existent project statuses.
199 *
200 * @since 1.17.0
201 * @static
202 */
203 public static function create_projects_statuses_ids() {
204 $continue = ! (bool) get_option( 'upstream:created_projects_args_ids' );
205 if ( ! $continue ) {
206 return;
207 }
208
209 $options = get_option( 'upstream_projects' );
210 if ( isset( $options['statuses'] ) ) {
211 $options['statuses'] = UpStream_Admin::create_missing_ids_in_set( $options['statuses'] );
212
213 update_option( 'upstream_projects', $options );
214
215 $statuses = array();
216 foreach ( $options['statuses'] as $row ) {
217 $statuses[ $row['name'] ] = $row['id'];
218 }
219
220 // Update existent Milestone data across all Projects.
221 global $wpdb;
222
223 $metas = $wpdb->get_results(
224 sprintf(
225 'SELECT `post_id`, `meta_value`
226 FROM `%s`
227 WHERE `meta_key` = "_upstream_project_status"',
228 $wpdb->prefix . 'postmeta'
229 )
230 );
231
232 if ( count( $metas ) > 0 ) {
233 foreach ( $metas as $meta ) {
234 if ( empty( $meta->meta_value )
235 || ! isset( $statuses[ $meta->meta_value ] )
236 ) {
237 continue;
238 }
239
240 $meta->meta_value = $statuses[ $meta->meta_value ];
241
242 update_post_meta( $meta->post_id, '_upstream_project_status', $meta->meta_value );
243 }
244 }
245
246 update_option( 'upstream:created_projects_args_ids', 1 );
247 }
248 }
249 }
250
251
252 endif;
253