PluginProbe
Edit Flow / 0.8.2
Edit Flow v0.8.2
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.2, at modules/settings/settings.php

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