WordPress.org

Plugin Directory

Changeset 631793


Ignore:
Timestamp:
11/29/12 14:47:24 (17 months ago)
Author:
MadtownLems
Message:

updated to 1.7: tested ompatible through 3.4.2

Location:
wpmu-theme-usage-info/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wpmu-theme-usage-info/trunk/cets_theme_info.php

    r487124 r631793  
    11<?php 
    2  
    32/****************************************************************************************************************** 
    43  
    54Plugin Name: Theme Info 
    6  
    7 Plugin URI: 
    8  
     5Plugin URI: http://wordpress.org/extend/plugins/wpmu-theme-usage-info/ 
    96Description: WordPress plugin for letting site admins easily see what themes are actively used on their site 
    10  
    11 Version: 1.5 
    12  
     7Version: 1.7 
    138Author: Kevin Graeme, Deanna Schneider & Jason Lemahieu 
    149 
    15  
    1610Copyright: 
    1711 
    18     Copyright 2009 Board of Regents of the University of Wisconsin System 
     12    Copyright 2009 - 2012 Board of Regents of the University of Wisconsin System 
    1913    Cooperative Extension Technology Services 
    2014    University of Wisconsin-Extension 
     
    2923    global $wp_version; 
    3024     
    31     if ( version_compare( $wp_version, '3.0', '>=' ) ) { 
    32         // Add the site admin config page 
    33          
    34         if (function_exists('is_network_admin')) { 
    35             //3.1+ 
    36             add_action('network_admin_menu', array(&$this, 'theme_info_add_page')); 
    37         } 
    38         else { 
    39             //-3.1 
    40             add_action('admin_menu', array(&$this, 'theme_info_add_page')); 
    41         } 
    42          
     25 
     26        add_action('network_admin_menu', array(&$this, 'theme_info_add_page')); 
     27                 
    4328        add_filter('theme_action_links', array(&$this, 'action_links'), 9, 3); 
    4429        add_action('switch_theme', array(&$this, 'on_switch_theme')); 
     
    4732                 
    4833                add_action('admin_enqueue_scripts', array(&$this, 'cets_theme_info_admin_scripts_theme_page')); 
     34                 
     35                add_action('admin_enqueue_styles', array(&$this, 'cets_theme_info_admin_styles_theme_page')); 
    4936                 
    5037                // run the function to generate the theme blog list (this runs whenever the theme page reloads, but only regenerates the list if it's more than an hour old or not set yet) 
     
    5643                }    
    5744                     
    58             } 
    59          
    60     } 
     45        } 
     46         
     47     
    6148}  // function cets_theme_info 
    6249 
     
    6552    wp_enqueue_script('jquery'); 
    6653    wp_enqueue_script('thickbox'); 
     54    wp_enqueue_style('thickbox'); 
     55} 
     56 
     57function maybe_update() { 
     58    $this_version = "1.6"; 
     59    $plugin_version = get_site_option('cets_theme_info_version', 0); 
     60     
     61    if (version_compare($plugin_version, $this_version, '<')) { 
     62        add_site_option('cets_theme_info_data_freshness', 1); 
     63        update_site_option('cets_theme_info_data_freshness', 2); 
     64    } 
     65     
     66     
     67    if ($plugin_version == 0) { 
     68        add_site_option('cets_theme_info_version', $this_version); 
     69    } else { 
     70        update_site_option('cets_theme_info_version', $this_version); 
     71    } 
     72     
     73     
     74} 
     75 
     76function version_supported() { 
     77    global $wp_version; 
     78    $supported_minimum = "3.4"; 
     79     
     80    if (version_compare($wp_version, $supported_minimum, '<')) { 
     81        return false; 
     82    } else { 
     83        return true; 
     84    } 
     85     
    6786} 
    6887 
    6988function generate_theme_blog_list() { 
    70     global $wpdb, $current_site; 
     89    global $wpdb, $current_site, $wp_version; 
     90         
     91    if (!$this->version_supported()) { 
     92        return; 
     93    } 
    7194         
    7295        //require_once('admin.php'); 
     
    77100        foreach ($blogs as $blog) { 
    78101            switch_to_blog($blog->blog_id); 
    79             $ct = get_current_theme(); 
     102            $cto = wp_get_theme(); 
     103            $ct = $cto->stylesheet; 
    80104             
    81105            if( constant( 'VHOST' ) == 'yes' ) { 
     
    104128    // Set the site option to hold all this 
    105129    update_site_option('cets_theme_info_data', $blogthemes); 
    106      
    107130    update_site_option('cets_theme_info_data_freshness', time()); 
    108      
    109      
    110 } 
    111  
    112 //apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context );  
    113 function action_links($actions, $theme_key, $theme=''){ 
     131 
     132} 
     133 
     134 
     135 
     136// $actions       = apply_filters( 'theme_action_links', $actions, $theme ); 
     137function action_links($actions, $theme){ 
     138 
     139    if (!$this->version_supported()) { 
     140        return $actions; 
     141    } 
     142 
     143    if (!is_object($theme)) { 
     144        $theme = wp_get_theme($theme); 
     145    } 
    114146 
    115147    // Get the toggle to see if users can view this information 
     
    121153    } 
    122154         
    123     if (is_array($theme_key)) { 
    124         //theme choosing page 
    125         $actual_theme_key = $theme_key['Template']; 
    126         $theme = $theme_key; 
    127         $theme_key = $actual_theme_key; 
    128     } 
    129155         
    130156    //get the list of blogs for this theme 
    131157    $data = get_site_option('cets_theme_info_data'); 
    132          
    133     if (isset($data[$theme['Name']])) { 
    134         $blogs = $data[$theme['Name']]; 
     158     
     159     
     160    if (isset($data[$theme->stylesheet])) { 
     161        $blogs = $data[$theme->stylesheet]; 
    135162    } else { 
    136163        $blogs = array(); 
    137164    } 
    138      
     165         
    139166    // get the first param of the actions var and add some more stuff before it  
    140167    //$start = $actions[0]; 
     
    142169    $text = "<div class='cets_theme_info'>Used on "; 
    143170     if (sizeOf($blogs) > 0) { 
    144         $text .=' <a href="#TB_inline?height=155&width=300&inlineId='. $name . '" class="thickbox" title="Blogs that use this theme">'; 
     171        $text .=' <a href="#TB_inline?height=155&width=300&inlineId='. $name . '" class="thickbox" title="Sites that use this theme">'; 
    145172     } 
    146     $text .= sizeOf($blogs) . " blog"; 
     173    $text .= sizeOf($blogs) . " site"; 
    147174    if (sizeOf($blogs) != 1) {$text .= 's';} 
    148175    if (sizeOf($blogs)> 0 ) { 
     
    155182         
    156183        // loop through the list of blogs and display their titles 
    157         $text .=("Activated on the following blogs: <ul>"); 
     184        $text .=("Activated on the following sites: <ul>"); 
    158185        foreach ($blogs as $blog){ 
    159186            $text .= '<li><a href="http://' . $blog['blogurl'] . '" target="new">' . $blog['name'] . '</a></li>'; 
     
    166193    }  
    167194    $text .='</div>'; 
    168      
    169     //$text .= $start; 
    170     //$actions[0] = $text; 
    171      
     195         
    172196    array_push($actions, $text); 
    173197     
    174198    return $actions; 
    175199     
    176     } 
     200} 
    177201     
    178202 
     
    182206    if(is_super_admin()) { 
    183207         
    184          
    185208        if (function_exists('is_network_admin')) { 
    186209            $page=  add_submenu_page('themes.php', 'Theme Usage Info', 'Theme Usage Info', 'manage_network', basename(__FILE__), array(&$this, 'theme_info_page')); 
     
    190213        } 
    191214    } 
    192      
    193      
    194      
    195  
    196 } 
    197  
     215} 
    198216 
    199217 
     
    201219// Create a function to actually display stuff on theme usage 
    202220function theme_info_page(){ 
     221     
     222    $this->maybe_update(); 
     223     
     224    if (!$this->version_supported()) { 
     225        echo "<div class='wrap'><h2>Theme Usage Information</h2>This plugin requires at least WordPress version 3.4 - Please upgrade to stay safe and secure.</div>"; 
     226        return; 
     227    } 
    203228     
    204229    //Handle updates 
     
    219244    } 
    220245     
    221      
    222246    // Get the time when the theme list was last generated 
    223247    $gen_time = get_site_option('cets_theme_info_data_freshness'); 
     
    227251            $this->generate_theme_blog_list();   
    228252    } 
    229     $allowed_themes = get_site_allowed_themes(); 
    230     $themes = get_themes(); 
     253    $allowed_themes = WP_Theme::get_allowed_on_network(); 
     254     
     255    // returns an array of Theme Objects 
     256    $themes = wp_get_themes(); 
     257     
    231258    $list = get_site_option('cets_theme_info_data'); 
    232259    ksort($list); 
    233  
    234260     
    235261    // figure out what themes have not been used at all 
    236262    $unused_themes = array(); 
    237263    foreach($themes as $theme){ 
    238         if (!array_key_exists($theme['Name'], $list)){ 
     264        if (!array_key_exists($theme->stylesheet, $list)) { 
     265        //if (!array_key_exists($theme['Name'], $list)){ 
    239266            array_push($unused_themes, $theme); 
    240267             
     
    281308    $counter = 0; 
    282309    foreach ($list as $theme => $blogs){ 
     310         
     311 
     312        $theme_object = wp_get_theme($theme); 
    283313        $counter = $counter + 1; 
    284         echo('<tr valign="top"><td>' .$theme .'</td><td>'); 
     314        echo('<tr valign="top"><td>' .$theme_object->name .'</td><td>'); 
     315         
    285316         
    286317        // get the array for this theme 
    287318        $thisTheme = $themes[$theme]; 
    288         if (array_key_exists($thisTheme['Stylesheet'], $allowed_themes)) { echo ("Yes");} 
    289         else {echo ("No");} 
     319        if (array_key_exists($thisTheme['Stylesheet'], $allowed_themes)) {  
     320            echo ("Yes"); 
     321        }else { 
     322            echo ("No"); 
     323        } 
    290324        echo ('</td><td>' . sizeOf($blogs) . '</td><td>'); 
    291325         
     
    309343             
    310344        echo ('</ul></td>'); 
    311          
    312          
    313          
    314          
    315          
     345 
    316346    } 
    317347    ?> 
     
    371401 
    372402function on_switch_theme() { 
     403    if (!$this->version_supported()) { 
     404        return; 
     405    } 
    373406    $this->generate_theme_blog_list(); 
    374      
    375407} 
    376408 
     
    380412 
    381413add_action( 'plugins_loaded', create_function( '', 'global $cets_Theme_Info; $cets_Theme_Info = new cets_Theme_Info();' ) ); 
    382  
    383  
    384  
    385 ?> 
  • wpmu-theme-usage-info/trunk/readme.txt

    r487124 r631793  
    22Contributors: DeannaS, kgraeme, MadtownLems 
    33Tags: WPMU, Wordpress Mu, Wordpress Multiuser, Theme Stats  
    4 Requires at least: 3.0 
    5 Tested up to: 3.1.1 
     4Requires at least: 3.4 
     5Tested up to: 3.4.2 
    66Stable tag: trunk 
    77 
     
    1616* cets\_theme\_info folder - lib folder - tablesort.js 
    1717 
    18 WPMU has two ways to activate themes either sitewide, or on a blog-by-blog basis. But, there's no convenient way built-in to know which themes are actually being used, or by whom. This plugin addresses that issue by creating a "Theme Usage Info" sub-menu of the Site Admin menu. Included on the page are two tables of data - one of themes currently being used, and one of themes not currently being used. The currently used themes table provides information on how many blogs are using the theme, which blogs are using it, and whether or not the theme is currently activated site-wide. The table of unused themes provides information on whether the theme is currently activated sitewide. 
     18WordPress Multisite has two ways to activate themes either sitewide, or on a blog-by-blog basis. But, there's no convenient way built-in to know which themes are actually being used, or by whom. This plugin addresses that issue by creating a "Theme Usage Info" sub-menu of the Network Admin theme menu. Included on the page are two tables of data - one of themes currently being used, and one of themes not currently being used. The currently used themes table provides information on how many blogs are using the theme, which blogs are using it, and whether or not the theme is currently activated site-wide. The table of unused themes provides information on whether the theme is currently activated sitewide. 
    1919 
    20 In addition, site admins can choose to provide this information to their users via a toggle on the administration page. 
     20In addition, network admins can choose to provide this information to their users via a toggle on the administration page. 
    2121 
    2222If enabled, users will be able to view data on theme usage in Appearance -> themes for every theme except the currently activated theme. A single line of text is added just before the activate link indicating how many blogs are currently using the theme. When clicked, a scrolling list of themes is displayed in a thickbox: 
     
    3232== Screenshots == 
    3333 
    34 1. Adminstrator view of list of used and unused themes. 
    35 2. Administrator view of list toggle controls for user access. 
     341. Network Admin view of list of used and unused themes. 
     352. Network Admin view of list toggle controls for user access. 
    36363. User view of theme popularity information. 
    37374. User view of blogs using theme. 
     
    4141 
    4242== Changelog == 
     43 
     441.7 Updated for 3.4. Because of the massive Theme info API change with 3.4, this plugin now REQURES 3.4+ to function 
     45 
     461.2 - 1.6 Unkown exactly because I wasn't maintaining this plugin for public use for these versions, but the following occurred in here: 
     47 - Properly enqueue scripts 
     48 - Updated for 3.1.  Then later dropped support for anything below 3.4 
     49 - fixed lots of notices and warnings 
     50 - properly store data after the 3.3 add_site_option changes 
     51 
    43521.1 Adding Show/Hide blogs on the administrative page. 
Note: See TracChangeset for help on using the changeset viewer.