WordPress.org

Plugin Directory

Changeset 266766 for edit-flow


Ignore:
Timestamp:
07/24/10 13:15:34 (7 years ago)
Author:
sbressler
Message:

Added ability to turn off calendar site-weide, and created ef_view_calendar and ef_edit_calendar capabilities and assigned to default roles.

Location:
edit-flow/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • edit-flow/trunk/edit_flow.php

    r262845 r266766  
    55Description: Remixing the WordPress admin for better editorial workflow options. 
    66Author: Daniel Bachhuber, Scott Bressler, Mohammad Jangda, Andrew Spittle, et al. 
    7 Version: 0.5 
     7Version: 0.5.1 
    88Author URI: http://www.editflow.org/ 
    99 
     
    3939 
    4040// Define contants 
    41 define( 'EDIT_FLOW_VERSION' , '0.3.3'); 
     41define( 'EDIT_FLOW_VERSION' , '0.5.1'); 
    4242define( 'EDIT_FLOW_FILE_PATH' , dirname(__FILE__).'/'.basename(__FILE__) ); 
    4343define( 'EDIT_FLOW_URL' , plugins_url(plugin_basename(dirname(__FILE__)).'/') ); 
    4444define( 'EDIT_FLOW_MAIN_PAGE' , 'admin.php?page=edit-flow/edit_flow' ); 
    45 define( 'EDIT_FLOW_SETTINGS_PAGE' , 'options-general.php?page=edit_flow' ); 
     45define( 'EDIT_FLOW_SETTINGS_PAGE' , 'admin.php?page=edit-flow/settings' ); 
    4646define( 'EDIT_FLOW_CUSTOM_STATUS_PAGE' , 'admin.php?page=edit-flow/custom_status' ); 
    4747define( 'EDIT_FLOW_PREFIX' , 'ef_' ); 
     
    6868                    'custom_status_filter' => 'draft', 
    6969                    'custom_category_filter' => 'all', 
    70                     'custom_author_filter' => 'all' 
     70                    'custom_author_filter' => 'all', 
     71                    'calendar_enabled' => 1 
    7172                ); 
    7273     
     
    145146                 
    146147        // Upgrade if need be 
    147         $ef_prev_version = floatval($this->get_plugin_option('version')); 
     148        $ef_prev_version = ef_version_number_float($this->get_plugin_option('version')); 
    148149        if($ef_prev_version < EDIT_FLOW_VERSION) edit_flow_upgrade($ef_prev_version); 
    149150 
     
    288289         
    289290        // Add sub-menu page for Calendar 
    290         add_submenu_page('index.php', __('Edit Flow Calendar', 'edit-flow'), __('Edit Flow Calendar', 'edit-flow'), 'edit_posts', $this->get_page('calendar'), array(&$this,'calendar')); 
     291        if ( $this->calendar_viewable() ) 
     292            add_submenu_page('index.php', __('Edit Flow Calendar', 'edit-flow'), __('Edit Flow Calendar', 'edit-flow'), 'edit_posts', $this->get_page('calendar'), array(&$this,'calendar')); 
    291293         
    292294    } // END: add_menu_items()  
     
    386388                         
    387389                        <tr valign="top"> 
     390                            <th scope="row"><strong><?php _e('Calendar', 'edit-flow') ?></strong></th> 
     391                            <td> 
     392                                <p> 
     393                                    <label for="calendar_enabled"> 
     394                                        <input type="checkbox" name="<?php  echo $this->get_plugin_option_fullname('calendar_enabled') ?>" value="1" <?php checked($this->get_plugin_option('calendar_enabled')); ?> id="calendar_enabled" /> 
     395                                        <?php _e('Enable Edit Flow Calendar', 'edit-flow') ?> 
     396                                    </label> <br /> 
     397                                    <span class="description"><?php _e('This enables the Edit Flow Calendar to view editorial content at a glance.', 'edit-flow') ?></span> 
     398                                </p> 
     399                                <?php 
     400                                /* Options for modifying the roles with calendar viewing privileges, though the logic to actually modify those roles was never written. Just didn't want to delete this yet. 
     401                                <p> 
     402                                    <strong>Roles that can view calendar</strong><br /> 
     403                                    <?php foreach($wp_roles->get_names() as $role => $role_name) : 
     404                                        if ( $wp_roles->is_role( $role ) ) : 
     405                                            $target_role =& get_role( $role ); 
     406                                            $role_has_cap = $target_role->has_cap( 'view_calendar' ); 
     407                                            ?> 
     408                                            <label for="calendar_view_<?php echo $role; ?>"> 
     409                                                <input type="checkbox" id="calendar_view_<?php echo $role; ?>" value="<?php echo $role; ?>" <?php echo ($role_has_cap ? 'checked="yes"' : '');?> style="margin-bottom: 5px;" /> 
     410                                                <?php _e($role_name, 'edit-flow') ?> 
     411                                            </label> 
     412                                            <br /> 
     413                                        <?php endif; ?> 
     414                                    <?php endforeach; ?> 
     415                                    <span class="description"><?php _e('Select which roles above may view the Edit Flow Calendar.', 'edit-flow') ?></span> 
     416                                </p> 
     417                                */ 
     418                                ?> 
     419                            </td> 
     420                        </tr> 
     421                         
     422                        <tr valign="top"> 
    388423                            <th scope="row"><strong><?php _e('Dashboard', 'edit-flow') ?></strong></th> 
    389424                            <td> 
     
    485520    } // END: toplevel_menu() 
    486521 
    487  
    488522    function calendar() { 
    489         include('php/templates/calendar.php'); 
     523        include('php/templates/calendar.php'); 
    490524    } 
     525     
     526    function calendar_viewable() { 
     527        $calendar_enabled = (int)$this->get_plugin_option('calendar_enabled'); 
     528         
     529        if ($calendar_enabled) { 
     530            $view_calendar_cap = 'ef_view_calendar'; 
     531            $view_calendar_cap = apply_filters( 'ef_view_calendar_cap', $view_calendar_cap ); 
     532 
     533            if( current_user_can( $view_calendar_cap ) ) 
     534                return true; 
     535        } 
     536        return false; 
     537    } 
    491538 
    492539} // END: class edit_flow 
  • edit-flow/trunk/php/upgrade.php

    r256786 r266766  
    22// Handles all current and future upgrades for edit_flow 
    33function edit_flow_upgrade( $from ) { 
    4     if( !$from || $from < 0.1 ) edit_flow_upgrade_01(); 
    5     if( $from < 0.3 ) edit_flow_upgrade_03(); 
     4    if ( !$from || $from < 0.1 ) edit_flow_upgrade_01(); 
     5    if ( $from < 0.3 ) edit_flow_upgrade_03(); 
     6    if ( $from < ef_version_number_float( '0.5.1' ) ) edit_flow_upgrade_051(); 
    67} 
    78 
     
    4243        $admin_role->add_cap('edit_usergroups'); 
    4344    } 
    44     if( $wp_roles->is_role('administrator') ) {  
     45    if( $wp_roles->is_role('editor') ) {     
    4546        $editor_role =& get_role('editor'); 
    4647        $editor_role->add_cap('edit_post_subscriptions'); 
     
    6566    update_option($edit_flow->get_plugin_option_fullname('version'), '0.3'); 
    6667} 
     68 
     69function edit_flow_upgrade_051() { 
     70    global $wp_roles, $edit_flow; 
     71 
     72    if ( ! isset( $wp_roles ) ) 
     73        $wp_roles = new WP_Roles(); 
     74 
     75    // Add necessary capabilities to allow management of calendar 
     76    // view_calendar - administrator --> contributor 
     77    $calendar_roles = array( 'administrator' => array('ef_view_calendar', 'ef_edit_calendar'), 
     78                             'editor' =>        array('ef_view_calendar', 'ef_edit_calendar'), 
     79                             'author' =>        array('ef_view_calendar'), 
     80                             'contributor' =>   array('ef_view_calendar') ); 
     81     
     82    foreach ($calendar_roles as $role => $caps) { 
     83        ef_add_caps_to_role( $role, $caps ); 
     84    } 
     85     
     86    update_option($edit_flow->get_plugin_option_fullname('version'), '0.5.1'); 
     87} 
  • edit-flow/trunk/php/util.php

    r256786 r266766  
    358358    return delete_metadata( 'user', $obj_id, $meta_key, $meta_value, $delete_all ); 
    359359} 
     360 
     361/** 
     362 * Adds an array of capabilities to a role. 
     363 */ 
     364function ef_add_caps_to_role( $role, $caps ) { 
     365    global $wp_roles; 
     366     
     367    if ( $wp_roles->is_role( $role ) ) { 
     368        $role =& get_role( $role ); 
     369        foreach ( $caps as $cap ) 
     370            $role->add_cap( $cap ); 
     371    } 
     372} 
     373 
     374/** 
     375 * Returns a float value representing the provided string version. e.g. 1.0.1 will be returned as 1.01. 
     376 * This is useful for version number comparisons. 
     377 */ 
     378function ef_version_number_float( $version ) { 
     379    $version_numbers = explode('.', $version); 
     380    for ($i = 0, $multiplier = 1; $i < count( $version_numbers ); ++$i, $multiplier /= 10) 
     381        $version_float += $version_numbers[$i] * $multiplier; 
     382    return $version_float; 
     383} 
  • edit-flow/trunk/readme.txt

    r263675 r266766  
    164164Contact us at [feedback@editflow.org](mailto:feedback@editflow.org) and we'll see what we can do. 
    165165 
     166= I don't like the preset roles that are able to view the calendar. How can I edit them? = 
     167 
     168There are two ways you can do this. One is to put something like the following code in your functions.php file: 
     169 
     170`add_filter( 'ef_view_calendar_cap', 'change_editflows_stupid_default_caps' ); 
     171 
     172function change_editflows_stupid_default_caps( $cap ) { 
     173    return 'edit_posts'; 
     174}` 
     175This will allow anyone with the capability to edit posts to view the calendar. See other capabilities you could use [here](http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table). 
     176 
     177The other option is to install a role management plugin, like Justin Tadlock's excellent [Members plugin](http://wordpress.org/extend/plugins/members/), and let the plugin do the heavy lifting of customizing the roles and capabilities to your heart's content. 
     178 
    166179= I'm stuck at WordPress 2.8! How do I use v0.3 onwards? = 
    167180 
Note: See TracChangeset for help on using the changeset viewer.