PluginProbe
Edit Flow / 0.7.6
Edit Flow v0.7.6
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.7.6, at modules/settings/settings.php

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