PluginProbe
Edit Flow / 0.8
Edit Flow v0.8
0.11.1 0.11.0 0.7.2 0.7.3 0.7.4 0.7.5 0.7.6 0.8 0.8.1 0.8.2 0.9 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 trunk 0.1.5 0.10.0 0.10.1 0.10.2 All 44 releases
edit-flow / modules / settings / settings.php

settings.php in Edit Flow 0.8, at modules/settings/settings.php

384 lines 14.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( !class_exists('EF_Settings') ) {
4
5 class EF_Settings extends EF_Module {
6
7 var $module;
8
9 /**
10 * Register the module with Edit Flow but don't do anything else
11 */
12 function __construct() {
13 global $edit_flow;
14
15 // Register the module with Edit Flow
16 $this->module_url = $this->get_module_url( __FILE__ );
17 $args = array(
18 'title' => __( 'Edit Flow', 'edit-flow' ),
19 'short_description' => __( 'Edit Flow redefines your WordPress publishing workflow.', 'edit-flow' ),
20 'extended_description' => __( 'Enable any of the features below to take control of your workflow. Custom statuses, email notifications, editorial comments, and more help you and your team save time so everyone can focus on what matters most: the content.', 'edit-flow' ),
21 'module_url' => $this->module_url,
22 'img_url' => $this->module_url . 'lib/eflogo_s128.png',
23 'slug' => 'settings',
24 'settings_slug' => 'ef-settings',
25 'default_options' => array(
26 'enabled' => 'on',
27 ),
28 'configure_page_cb' => 'print_default_settings',
29 'autoload' => true,
30 );
31 $this->module = EditFlow()->register_module( 'settings', $args );
32 }
33
34 /**
35 * Initialize the rest of the stuff in the class if the module is active
36 */
37 function init() {
38
39 add_action( 'admin_init', array( $this, 'helper_settings_validate_and_save' ), 100 );
40
41 add_action( 'admin_print_styles', array( $this, 'action_admin_print_styles' ) );
42 add_action( 'admin_print_scripts', array( $this, 'action_admin_print_scripts' ) );
43 add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ) );
44 add_action( 'admin_menu', array( $this, 'action_admin_menu' ) );
45
46 add_action( 'wp_ajax_change_edit_flow_module_state', array( $this, 'ajax_change_edit_flow_module_state' ) );
47
48 }
49
50 /**
51 * Add necessary things to the admin menu
52 */
53 function action_admin_menu() {
54 global $edit_flow;
55
56 // Select Edit Flow icon
57 if ( defined( 'MP6' ) ) :
58 $ef_logo = 'lib/eflogo_s32b.png';
59 else :
60 $ef_logo = 'lib/eflogo_s32.png';
61 endif;
62
63 add_menu_page( $this->module->title, $this->module->title, 'manage_options', $this->module->settings_slug, array( $this, 'settings_page_controller' ), $this->module->module_url . $ef_logo ) ;
64
65 foreach ( $edit_flow->modules as $mod_name => $mod_data ) {
66 if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on'
67 && $mod_data->configure_page_cb && $mod_name != $this->module->name )
68 add_submenu_page( $this->module->settings_slug, $mod_data->title, $mod_data->title, 'manage_options', $mod_data->settings_slug, array( $this, 'settings_page_controller' ) ) ;
69 }
70 }
71
72 function action_admin_enqueue_scripts() {
73
74 if ( $this->is_whitelisted_settings_view() )
75 wp_enqueue_script( 'edit-flow-settings-js', $this->module_url . 'lib/settings.js', array( 'jquery' ), EDIT_FLOW_VERSION, true );
76
77 }
78
79 /**
80 * Add settings styles to the settings page
81 */
82 function action_admin_print_styles() {
83
84 if ( $this->is_whitelisted_settings_view() )
85 wp_enqueue_style( 'edit_flow-settings-css', $this->module_url . 'lib/settings.css', false, EDIT_FLOW_VERSION );
86
87
88 }
89
90 /**
91 * Extra data we need on the page for transitions, etc.
92 *
93 * @since 0.7
94 */
95 function action_admin_print_scripts() {
96 ?>
97 <script type="text/javascript">
98 var ef_admin_url = '<?php echo get_admin_url(); ?>';
99 </script>
100 <?php
101 }
102
103 function ajax_change_edit_flow_module_state() {
104 global $edit_flow;
105
106 if ( !wp_verify_nonce( $_POST['change_module_nonce'], 'change-edit-flow-module-nonce' ) || !current_user_can( 'manage_options') )
107 wp_die( __( 'Cheatin&#8217; uh?' ) );
108
109 if ( !isset( $_POST['module_action'], $_POST['slug'] ) )
110 die('-1');
111
112 $module_action = sanitize_key( $_POST['module_action'] );
113 $slug = sanitize_key( $_POST['slug'] );
114
115 $module = $edit_flow->get_module_by( 'slug', $slug );
116
117 if ( !$module )
118 die('-1');
119
120 if ( $module_action == 'enable' )
121 $return = $edit_flow->update_module_option( $module->name, 'enabled', 'on' );
122 else if ( $module_action == 'disable' )
123 $return = $edit_flow->update_module_option( $module->name, 'enabled', 'off' );
124
125 if ( $return )
126 die('1');
127 else
128 die('-1');
129 }
130
131 /**
132 * Handles all settings and configuration page requests. Required element for Edit Flow
133 */
134 function settings_page_controller() {
135 global $edit_flow;
136
137 $requested_module = $edit_flow->get_module_by( 'settings_slug', $_GET['page'] );
138 if ( !$requested_module )
139 wp_die( __( 'Not a registered Edit Flow module', 'edit-flow' ) );
140 $configure_callback = $requested_module->configure_page_cb;
141 $requested_module_name = $requested_module->name;
142
143 // Don't show the settings page for the module if the module isn't activated
144 if ( !$this->module_enabled( $requested_module_name ) ) {
145 echo '<div class="message error"><p>' . sprintf( __( 'Module not enabled. Please enable it from the <a href="%1$s">Edit Flow settings page</a>.', 'edit-flow' ), EDIT_FLOW_SETTINGS_PAGE ) . '</p></div>';
146 return;
147 }
148
149 $this->print_default_header( $requested_module );
150 $edit_flow->$requested_module_name->$configure_callback();
151 $this->print_default_footer( $requested_module );
152
153 }
154
155 /**
156 *
157 */
158 function print_default_header( $current_module ) {
159
160 // If there's been a message, let's display it
161 if ( isset( $_GET['message'] ) )
162 $message = $_GET['message'];
163 else if ( isset( $_REQUEST['message'] ) )
164 $message = $_REQUEST['message'];
165 else if ( isset( $_POST['message'] ) )
166 $message = $_POST['message'];
167 else
168 $message = false;
169 if ( $message && isset( $current_module->messages[$message] ) )
170 $display_text = '<span class="edit-flow-updated-message edit-flow-message">' . esc_html( $current_module->messages[$message] ) . '</span>';
171
172 // If there's been an error, let's display it
173 if ( isset( $_GET['error'] ) )
174 $error = $_GET['error'];
175 else if ( isset( $_REQUEST['error'] ) )
176 $error = $_REQUEST['error'];
177 else if ( isset( $_POST['error'] ) )
178 $error = $_POST['error'];
179 else
180 $error = false;
181 if ( $error && isset( $current_module->messages[$error] ) )
182 $display_text = '<span class="edit-flow-error-message edit-flow-message">' . esc_html( $current_module->messages[$error] ) . '</span>';
183
184 if ( $current_module->img_url )
185 $page_icon = '<img src="' . esc_url( $current_module->img_url ) . '" class="module-icon icon32" />';
186 else
187 $page_icon = '<div class="icon32" id="icon-options-general"><br/></div>';
188 ?>
189 <div class="wrap edit-flow-admin">
190 <?php if ( $current_module->name != 'settings' ): ?>
191 <?php echo $page_icon; ?>
192 <h2><a href="<?php echo EDIT_FLOW_SETTINGS_PAGE; ?>"><?php _e('Edit Flow', 'edit-flow') ?></a>:&nbsp;<?php echo $current_module->title; ?><?php if ( isset( $display_text ) ) { echo $display_text; } ?></h2>
193 <?php else: ?>
194 <?php echo $page_icon; ?>
195 <h2><?php _e('Edit Flow', 'edit-flow') ?><?php if ( isset( $display_text ) ) { echo $display_text; } ?></h2>
196 <?php endif; ?>
197
198 <div class="explanation">
199 <?php if ( $current_module->short_description ): ?>
200 <h3><?php echo $current_module->short_description; ?></h3>
201 <?php endif; ?>
202 <?php if ( $current_module->extended_description ): ?>
203 <p><?php echo $current_module->extended_description; ?></p>
204 <?php endif; ?>
205 </div>
206 <?php
207 }
208
209 /**
210 * Adds Settings page for Edit Flow.
211 */
212 function print_default_settings() {
213
214 ?>
215 <div class="edit-flow-modules">
216 <?php $this->print_modules(); ?>
217 </div>
218 <?php
219 }
220
221 function print_default_footer( $current_module ) {
222 ?>
223 <?php if ( $current_module->slug == 'settings' ): ?>
224 <div class="credits">
225 <p><a href="http://editflow.org/">Edit Flow</a> is produced by <a href="http://danielbachhuber.com/">Daniel Bachhuber</a>, <a href="http://digitalize.ca/">Mo Jangda</a>, and <a href="http://www.scottbressler.com/blog/">Scott Bressler</a>, with special help from <a href="http://andrewspittle.net">Andrew Spittle</a> and <a href="http://andrewwitherspoon.com/">Andrew Witherspoon</a>.
226 <br />You're using Edit Flow v<?php echo EDIT_FLOW_VERSION; ?>.
227 <br />Icons courtesy of the <a href="http://thenounproject.com/">Noun Project</a>.
228 <br /><a href="http://wordpress.org/tags/edit-flow?forum_id=10">Please give us your feedback, ideas, bug reports and comments</a> in the WordPress.org forums.
229 </div>
230 </div>
231 <?php endif; ?>
232 <?php
233 }
234
235 function print_modules() {
236 global $edit_flow;
237
238 if ( !count( $edit_flow->modules ) ) {
239 echo '<div class="message error">' . __( 'There are no Edit Flow modules registered', 'edit-flow' ) . '</div>';
240 } else {
241
242 foreach ( $edit_flow->modules as $mod_name => $mod_data ) {
243 if ( $mod_data->autoload )
244 continue;
245
246 $classes = array(
247 'edit-flow-module',
248 );
249 if ( $mod_data->options->enabled == 'on' )
250 $classes[] = 'module-enabled';
251 elseif ( $mod_data->options->enabled == 'off' )
252 $classes[] = 'module-disabled';
253 if ( $mod_data->configure_page_cb )
254 $classes[] = 'has-configure-link';
255 echo '<div class="' . implode( ' ', $classes ) . '" id="' . $mod_data->slug . '">';
256 if ( $mod_data->img_url )
257 echo '<img src="' . esc_url( $mod_data->img_url ) . '" height="24px" width="24px" class="float-right module-icon" />';
258 echo '<form method="get" action="' . get_admin_url( null, 'options.php' ) . '">';
259 echo '<h4>' . esc_html( $mod_data->title ) . '</h4>';
260 if ( 'on' == $mod_data->options->enabled )
261 echo '<p>' . wp_kses($mod_data->short_description, 'a') . '</p>';
262 else
263 echo '<p>' . strip_tags( $mod_data->short_description ) . '</p>';
264 echo '<p class="edit-flow-module-actions">';
265 if ( $mod_data->configure_page_cb ) {
266 $configure_url = add_query_arg( 'page', $mod_data->settings_slug, get_admin_url( null, 'admin.php' ) );
267 echo '<a href="' . $configure_url . '" class="configure-edit-flow-module button button-primary';
268 if ( $mod_data->options->enabled == 'off' ) echo ' hidden" style="display:none;';
269 echo '">' . $mod_data->configure_link_text . '</a>';
270 }
271 echo '<input type="submit" class="button-primary button enable-disable-edit-flow-module"';
272 if ( $mod_data->options->enabled == 'on' ) echo ' style="display:none;"';
273 echo ' value="' . __( 'Enable', 'edit-flow' ) . '" />';
274 echo '<input type="submit" class="button-secondary button-remove button enable-disable-edit-flow-module"';
275 if ( $mod_data->options->enabled == 'off' ) echo ' style="display:none;"';
276 echo ' value="' . __( 'Disable', 'edit-flow' ) . '" />';
277 echo '</p>';
278 wp_nonce_field( 'change-edit-flow-module-nonce', 'change-module-nonce', false );
279 echo '</form>';
280 echo '</div>';
281 }
282
283 }
284
285 }
286
287 /**
288 * Given a form field and a description, prints either the error associated with the field or the description.
289 *
290 * @since 0.7
291 *
292 * @param string $field The form field for which to check for an error
293 * @param string $description Unlocalized string to display if there was no error with the given field
294 */
295 function helper_print_error_or_description( $field, $description ) {
296 if ( isset( $_REQUEST['form-errors'][$field] ) ): ?>
297 <div class="form-error">
298 <p><?php echo esc_html( $_REQUEST['form-errors'][$field] ); ?></p>
299 </div>
300 <?php else: ?>
301 <p class="description"><?php echo esc_html( $description ); ?></p>
302 <?php endif;
303 }
304
305 /**
306 * Generate an option field to turn post type support on/off for a given module
307 *
308 * @param object $module Edit Flow module we're generating the option field for
309 * @param {missing}
310 *
311 * @since 0.7
312 */
313 function helper_option_custom_post_type( $module, $args = array() ) {
314
315 $all_post_types = array(
316 'post' => __( 'Posts' ),
317 'page' => __( 'Pages' ),
318 );
319 $custom_post_types = $this->get_supported_post_types_for_module();
320 if ( count( $custom_post_types ) ) {
321 foreach( $custom_post_types as $custom_post_type => $args ) {
322 $all_post_types[$custom_post_type] = $args->label;
323 }
324 }
325
326 foreach( $all_post_types as $post_type => $title ) {
327 echo '<label for="' . esc_attr( $post_type ) . '">';
328 echo '<input id="' . esc_attr( $post_type ) . '" name="'
329 . $module->options_group_name . '[post_types][' . esc_attr( $post_type ) . ']"';
330 if ( isset( $module->options->post_types[$post_type] ) )
331 checked( $module->options->post_types[$post_type], 'on' );
332 // Defining post_type_supports in the functions.php file or similar should disable the checkbox
333 disabled( post_type_supports( $post_type, $module->post_type_support ), true );
334 echo ' type="checkbox" />&nbsp;&nbsp;&nbsp;' . esc_html( $title ) . '</label>';
335 // Leave a note to the admin as a reminder that add_post_type_support has been used somewhere in their code
336 if ( post_type_supports( $post_type, $module->post_type_support ) )
337 echo '&nbsp&nbsp;&nbsp;<span class="description">' . sprintf( __( 'Disabled because add_post_type_support( \'%1$s\', \'%2$s\' ) is included in a loaded file.', 'edit-flow' ), $post_type, $module->post_type_support ) . '</span>';
338 echo '<br />';
339 }
340
341 }
342
343 /**
344 * Validation and sanitization on the settings field
345 * This method is called automatically/ doesn't need to be registered anywhere
346 *
347 * @since 0.7
348 */
349 function helper_settings_validate_and_save() {
350
351 if ( !isset( $_POST['action'], $_POST['_wpnonce'], $_POST['option_page'], $_POST['_wp_http_referer'], $_POST['edit_flow_module_name'], $_POST['submit'] ) || !is_admin() )
352 return false;
353
354 global $edit_flow;
355 $module_name = sanitize_key( $_POST['edit_flow_module_name'] );
356
357 if ( $_POST['action'] != 'update'
358 || $_POST['option_page'] != $edit_flow->$module_name->module->options_group_name )
359 return false;
360
361 if ( !current_user_can( 'manage_options' ) || !wp_verify_nonce( $_POST['_wpnonce'], $edit_flow->$module_name->module->options_group_name . '-options' ) )
362 wp_die( __( 'Cheatin&#8217; uh?' ) );
363
364 $new_options = ( isset( $_POST[$edit_flow->$module_name->module->options_group_name] ) ) ? $_POST[$edit_flow->$module_name->module->options_group_name] : array();
365
366 // Only call the validation callback if it exists?
367 if ( method_exists( $edit_flow->$module_name, 'settings_validate' ) )
368 $new_options = $edit_flow->$module_name->settings_validate( $new_options );
369
370 // Cast our object and save the data.
371 $new_options = (object)array_merge( (array)$edit_flow->$module_name->module->options, $new_options );
372 $edit_flow->update_all_module_options( $edit_flow->$module_name->module->name, $new_options );
373
374 // Redirect back to the settings page that was submitted without any previous messages
375 $goback = add_query_arg( 'message', 'settings-updated', remove_query_arg( array( 'message'), wp_get_referer() ) );
376 wp_safe_redirect( $goback );
377 exit;
378
379 }
380
381 }
382
383 }
384