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

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