WordPress.org

Plugin Directory

Changeset 535925


Ignore:
Timestamp:
04/25/12 02:31:50 (2 years ago)
Author:
jmdodd
Message:

General cleanup

Location:
shadow-screen-options/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • shadow-screen-options/trunk/readme.txt

    r430951 r535925  
    11=== Shadow Screen Options === 
    22Contributors: jmdodd 
    3 Tags: screen options, meta boxes, multisite 
     3Tags: screen options, meta boxes, multisite, network 
    44Requires at least: 3.1.4  
    5 Tested up to: 3.2.1 
    6 Stable tag: 0.2 
     5Tested up to: 3.3.2 
     6Stable tag: 0.3 
    77 
    8 Create a shadow system of blog-specific screen layout options in a multisite  
    9 environment. 
     8Create a shadow system of blog-specific screen layout options in a multisite environment. 
    109 
    1110== Description == 
    1211 
    13 Shadow Screen Options is used in a multisite environment to allow blog-specific 
    14 screen layout options for users. Blogs on which it is not active will share  
    15 user-set preferences (the default WordPress behavior). 
     12Shadow Screen Options is used in a multisite environment to allow blog-specific screen layout options  
     13for users. Blogs on which it is not active will share user-set preferences (the default  
     14WordPress behavior). 
    1615 
    17 This is most useful in situations where users have several blogs, and have 
    18 different sets of plugins active on each blog. 
     16This is most useful in situations where users have several blogs, and have different sets of plugins  
     17active on each blog. 
    1918 
    2019== Installation == 
    2120 
    22 1. Upload the directory `shadow-screen-options` and its contents to the `/wp-content/plugins/` directory. 
    23 1. Activate the plugin through the 'Plugins' menu in WordPress. 
     211. Upload the `shadow-screen-options` folder and its contents your `/wp-content/plugins/` directory. 
     221. Activate the "Shadow Screen Options" plugin in your WordPress Plugins administration interface as 
     23needed for individual blogs, or Network Activate. 
    2424 
    2525== Changelog == 
     26 
     27= 0.3 = 
     28* General cleanup to object-oriented code. 
     29* Fix PHP notice on undefined offset: 0. 
     30* WordPress version bump. 
    2631 
    2732= 0.2 = 
     
    3439== Upgrade Notice == 
    3540 
     41= 0.3 = 
     42* General cleanup. 
     43 
    3644= 0.2 = 
    3745* Make the code more efficient. 
  • shadow-screen-options/trunk/shadow-screen-options.php

    r430951 r535925  
    22/* 
    33Plugin Name: Shadow Screen Options 
    4 Plugin URI: http://uncommoncontent.com/wordpress/plugins/shadow-screen-options 
    54Description: Create a shadow system of blog-specific screen layout options in a multisite environment.  
    6 Version: 0.2 
     5Version: 0.3 
    76Author: Jennifer M. Dodd 
    8 Author URI: http://bajada.net 
     7Author URI: http://uncommoncontent.com/ 
    98*/  
    109 
    1110/* 
    12     Copyright 2011 Jennifer M. Dodd (email: jmdodd@gmail.com) 
     11    Copyright 2012  Jennifer M. Dodd  <jmdodd@gmail.com> 
    1312 
    14     This program is free software; you can redistribute it and/or modify 
    15     it under the terms of the GNU General Public License as published by 
    16     the Free Software Foundation; either version 2 of the License, or 
    17     (at your option) any later version. 
     13    This program is free software; you can redistribute it and/or modify 
     14    it under the terms of the GNU General Public License, version 2, as  
     15    published by the Free Software Foundation. 
    1816 
    19     This program is distributed in the hope that it will be useful, 
    20     but WITHOUT ANY WARRANTY; without even the implied warranty of 
    21     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    22     GNU General Public License for more details. 
     17    This program is distributed in the hope that it will be useful, 
     18    but WITHOUT ANY WARRANTY; without even the implied warranty of 
     19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     20    GNU General Public License for more details. 
    2321 
    24     You should have received a copy of the GNU General Public License 
    25     along with this program; if not, write to the Free Software 
    26     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     22    You should have received a copy of the GNU General Public License 
     23    along with this program; if not, see <http://www.gnu.org/licenses/>.  
    2724*/ 
    2825 
    2926 
    30 function ucc_sso_needs_shadow( $meta_key ) { 
    31     $actions = array( 'closedpostboxes', 'metaboxhidden', 'meta-box-order', 'screen-layout' ); 
    32     $objects = array( 'post', 'page', 'link', 'nav-menus', 'dashboard' ); 
     27if ( ! defined( 'ABSPATH' ) ) exit; 
    3328 
    34     // Fix screen_layout issue. 
    35     $meta_key = str_replace( 'screen_layout', 'screen-layout', $meta_key ); 
    36     $arr = explode( '_', $meta_key ); 
    37     if (    isset( $arr[0] ) && in_array( $arr[0], $actions ) && 
    38         isset( $arr[1] ) && in_array( $arr[1], $objects ) &&   
    39         !isset( $arr[2] ) ) { 
    40         return true; 
    41     } else { 
     29 
     30if ( ! class_exists( 'UCC_Shadow_Screen_Options' ) ) { 
     31class UCC_Shadow_Screen_Options { 
     32    public static $instance; 
     33    public static $prefix; 
     34    public static $actions; 
     35    public static $objects; 
     36 
     37    public function __construct() { 
     38        self::$instance = $this; 
     39 
     40        global $blog_id; 
     41        $this->prefix = 'ucc_sso_' . $blog_id . '_'; 
     42        $this->actions = array( 'closedpostboxes', 'metaboxhidden', 'meta-box-order', 'screen_layout' ); 
     43        $this->objects = array( 'post', 'page', 'link', 'nav-menus', 'dashboard' ); 
     44 
     45        add_filter( 'get_user_metadata', array( $this, 'get_user_metadata' ), 10, 4 ); 
     46        add_filter( 'update_user_metadata', array( $this, 'update_user_metadata' ), 10, 5 ); 
     47 
     48        foreach ( $this->objects as $object ) { 
     49            add_filter( 'get_user_option_closedpostboxes_' . $object, array( $this, 'get_user_option' ), 10, 3 ); 
     50            add_filter( 'get_user_option_metaboxhidden_'   . $object, array( $this, 'get_user_option' ), 10, 3 ); 
     51            add_filter( 'get_user_option_meta-box-order_'  . $object, array( $this, 'get_user_option' ), 10, 3 ); 
     52            add_filter( 'get_user_option_screen_layout_'   . $object, array( $this, 'get_user_option' ), 10, 3 ); 
     53        } 
     54    } 
     55 
     56    public function needs_shadow( $meta_key ) { 
     57        foreach ( $this->actions as $action ) { 
     58            if ( strpos( $meta_key, $action ) === 0 ) { 
     59                foreach ( $this->objects as $object ) { 
     60                    if ( strpos( $meta_key, $object ) > 0 ) 
     61                        return true; 
     62                } 
     63            } 
     64        } 
    4265        return false; 
    4366    } 
    44 } 
     67 
     68    public function get_user_metadata( $meta_type = null, $user_id, $meta_key, $single ) { 
     69        if ( $this->needs_shadow( $meta_key ) ) { 
     70            $meta_key = $this->prefix . $meta_key; 
     71            $result = get_user_meta( $user_id, $meta_key, $single ); 
     72            if ( $single ) 
     73                return array( $result ); 
     74            else 
     75                return $result; 
     76        } else { 
     77            return null; 
     78        } 
     79    } 
     80 
     81    public function update_user_metadata( $meta_type = null, $user_id, $meta_key, $meta_value, $prev_value = '' ) { 
     82        if ( $this->needs_shadow( $meta_key ) ) { 
     83            $meta_key = $this->prefix . $meta_key; 
     84            $result = update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ); 
     85            return $result; 
     86        } else { 
     87            return null; 
     88        } 
     89    } 
     90  
     91    public function get_user_option( $result, $option, $user ) { 
     92        $option = $this->prefix . $option; 
     93        $result = get_user_option( $option, $user->ID ); 
     94        return $result; 
     95    } 
     96} } 
    4597 
    4698 
    47 function ucc_sso_update_user_metadata( $meta_type = null, $user_id, $meta_key, $meta_value, $prev_value = '' ) { 
    48     global $blog_id; 
    49   
    50     $prefix = 'ucc_sso_' . $blog_id . '_'; 
    51     if ( ucc_sso_needs_shadow( $meta_key ) ) { 
    52         $meta_key = $prefix . $meta_key; 
    53         $result = update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ); 
    54         return $result; 
    55     } else { 
    56         return null; 
    57     } 
    58 } 
    59 add_filter( 'update_user_metadata', 'ucc_sso_update_user_metadata', 10, 5 ); 
    60   
    61   
    62 function ucc_sso_get_user_metadata( $meta_type = null, $user_id, $meta_key, $single ) { 
    63     global $blog_id; 
    64   
    65     $prefix = 'ucc_sso_' . $blog_id . '_'; 
    66     if ( ucc_sso_needs_shadow( $meta_key ) ) {  
    67         $meta_key = $prefix . $meta_key; 
    68         $result = get_user_meta( $user_id, $meta_key, $single ); 
    69         return $result; 
    70     } else { 
    71         return null; 
    72     } 
    73 } 
    74 add_filter( 'get_user_metadata', 'ucc_sso_get_user_metadata', 10, 4 ); 
     99new UCC_Shadow_Screen_Options; 
    75100 
    76   
    77 function ucc_sso_get_user_option( $result, $option, $user ) { 
    78     global $blog_id; 
    79   
    80     $prefix = 'ucc_sso_' . $blog_id . '_'; 
    81     $option = $prefix . $option; 
    82     $result = get_user_option( $option, $user->ID ); 
    83   
    84     return $result; 
    85 } 
    86  
    87  
    88 function ucc_sso_init() { 
    89         $objects = array( 'post', 'page', 'link', 'nav-menus', 'dashboard' ); 
    90  
    91     foreach ( $objects as $object ) { 
    92         add_filter( 'get_user_option_closedpostboxes_' . $object, 'ucc_sso_get_user_option', 10, 3 ); 
    93         add_filter( 'get_user_option_metaboxhidden_' . $object, 'ucc_sso_get_user_option', 10, 3 ); 
    94         add_filter( 'get_user_option_meta-box-order_' . $object, 'ucc_sso_get_user_option', 10, 3 ); 
    95         add_filter( 'get_user_option_screen_layout_' .  $object, 'ucc_sso_get_user_option', 10, 3 ); 
    96     } 
    97 } 
    98 add_filter( 'init', 'ucc_sso_init' );    
    99  
    100 ?> 
Note: See TracChangeset for help on using the changeset viewer.