WordPress.org

Plugin Directory

Changeset 610734


Ignore:
Timestamp:
10/11/12 09:12:00 (19 months ago)
Author:
garyc40
Message:

Fix: Remove redundant capability checks for dashboard widgets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-e-commerce/branches/branch-3.8/wpsc-admin/admin.php

    r610732 r610734  
    688688 
    689689function wpsc_dashboard_widget_setup() { 
    690     if ( is_admin() && current_user_can( 'manage_options' ) ) { 
    691         $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION; 
    692         // Enqueue the styles and scripts necessary 
    693         wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' ); 
    694         wp_enqueue_script( 'datepicker-ui', WPSC_URL . "/wpsc-core/js/ui.datepicker.js", array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), $version_identifier ); 
    695  
    696         $news_cap            = apply_filters( 'wpsc_dashboard_news_cap'           , 'manage_options' ); 
    697         $sales_cap           = apply_filters( 'wpsc_dashboard_sales_summary_cap'  , 'manage_options' ); 
    698         $quarterly_sales_cap = apply_filters( 'wpsc_dashboard_quarterly_sales_cap', 'manage_options' ); 
    699         $monthly_sales_cap   = apply_filters( 'wpsc_dashboard_monthly_sales_cap'  , 'manage_options' ); 
    700  
    701         // Add the dashboard widgets 
    702         if ( current_user_can( $news_cap ) ) 
    703             wp_add_dashboard_widget( 'wpsc_dashboard_news', __( 'Getshopped News' , 'wpsc' ), 'wpsc_dashboard_news' ); 
    704         if ( current_user_can( $sales_cap ) ) 
    705             wp_add_dashboard_widget( 'wpsc_dashboard_widget', __( 'Sales Summary', 'wpsc' ), 'wpsc_dashboard_widget' ); 
    706         if ( current_user_can( $quarterly_sales_cap ) ) 
    707             wp_add_dashboard_widget( 'wpsc_quarterly_dashboard_widget', __( 'Sales by Quarter', 'wpsc' ), 'wpsc_quarterly_dashboard_widget' ); 
    708         if ( current_user_can( $monthly_sales_cap ) ) 
    709             wp_add_dashboard_widget( 'wpsc_dashboard_4months_widget', __( 'Sales by Month', 'wpsc' ), 'wpsc_dashboard_4months_widget' ); 
    710  
    711         // Sort the Dashboard widgets so ours it at the top 
    712         global $wp_meta_boxes; 
    713         $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core']; 
    714  
    715         // Backup and delete our new dashbaord widget from the end of the array 
    716         $wpsc_widget_backup = array(); 
    717         if ( isset( $normal_dashboard['wpsc_dashboard_news'] ) ) { 
    718             $wpsc_widget_backup['wpsc_dashboard_news'] = $normal_dashboard['wpsc_dashboard_news']; 
    719             unset( $normal_dashboard['wpsc_dashboard_news'] ); 
    720         } 
    721         if ( isset( $normal_dashboard['wpsc_dashboard_widget'] ) ) { 
    722             $wpsc_widget_backup['wpsc_dashboard_widget'] = $normal_dashboard['wpsc_dashboard_widget']; 
    723             unset( $normal_dashboard['wpsc_dashboard_widget'] ); 
    724         } 
    725         if ( isset( $normal_dashboard['wpsc_quarterly_dashboard_widget'] ) ) { 
    726             $wpsc_widget_backup['wpsc_quarterly_dashboard_widget'] = $normal_dashboard['wpsc_quarterly_dashboard_widget']; 
    727             unset( $normal_dashboard['wpsc_quarterly_dashboard_widget'] ); 
    728         } 
    729         if ( isset( $normal_dashboard['wpsc_dashboard_4months_widget'] ) ) { 
    730             $wpsc_widget_backup['wpsc_dashboard_4months_widget'] = $normal_dashboard['wpsc_dashboard_4months_widget']; 
    731             unset( $normal_dashboard['wpsc_dashboard_4months_widget'] ); 
    732         } 
    733  
    734         // Merge the two arrays together so our widget is at the beginning 
    735         $sorted_dashboard = array_merge( $wpsc_widget_backup, $normal_dashboard ); 
    736  
    737         // Save the sorted array back into the original metaboxes 
    738  
    739         $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; 
    740     } 
     690    $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION; 
     691    // Enqueue the styles and scripts necessary 
     692    wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' ); 
     693    wp_enqueue_script( 'datepicker-ui', WPSC_URL . "/wpsc-core/js/ui.datepicker.js", array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), $version_identifier ); 
     694 
     695    $news_cap            = apply_filters( 'wpsc_dashboard_news_cap'           , 'manage_options' ); 
     696    $sales_cap           = apply_filters( 'wpsc_dashboard_sales_summary_cap'  , 'manage_options' ); 
     697    $quarterly_sales_cap = apply_filters( 'wpsc_dashboard_quarterly_sales_cap', 'manage_options' ); 
     698    $monthly_sales_cap   = apply_filters( 'wpsc_dashboard_monthly_sales_cap'  , 'manage_options' ); 
     699 
     700    // Add the dashboard widgets 
     701    if ( current_user_can( $news_cap ) ) 
     702        wp_add_dashboard_widget( 'wpsc_dashboard_news', __( 'Getshopped News' , 'wpsc' ), 'wpsc_dashboard_news' ); 
     703    if ( current_user_can( $sales_cap ) ) 
     704        wp_add_dashboard_widget( 'wpsc_dashboard_widget', __( 'Sales Summary', 'wpsc' ), 'wpsc_dashboard_widget' ); 
     705    if ( current_user_can( $quarterly_sales_cap ) ) 
     706        wp_add_dashboard_widget( 'wpsc_quarterly_dashboard_widget', __( 'Sales by Quarter', 'wpsc' ), 'wpsc_quarterly_dashboard_widget' ); 
     707    if ( current_user_can( $monthly_sales_cap ) ) 
     708        wp_add_dashboard_widget( 'wpsc_dashboard_4months_widget', __( 'Sales by Month', 'wpsc' ), 'wpsc_dashboard_4months_widget' ); 
     709 
     710    // Sort the Dashboard widgets so ours it at the top 
     711    global $wp_meta_boxes; 
     712    $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core']; 
     713 
     714    // Backup and delete our new dashbaord widget from the end of the array 
     715    $wpsc_widget_backup = array(); 
     716    if ( isset( $normal_dashboard['wpsc_dashboard_news'] ) ) { 
     717        $wpsc_widget_backup['wpsc_dashboard_news'] = $normal_dashboard['wpsc_dashboard_news']; 
     718        unset( $normal_dashboard['wpsc_dashboard_news'] ); 
     719    } 
     720    if ( isset( $normal_dashboard['wpsc_dashboard_widget'] ) ) { 
     721        $wpsc_widget_backup['wpsc_dashboard_widget'] = $normal_dashboard['wpsc_dashboard_widget']; 
     722        unset( $normal_dashboard['wpsc_dashboard_widget'] ); 
     723    } 
     724    if ( isset( $normal_dashboard['wpsc_quarterly_dashboard_widget'] ) ) { 
     725        $wpsc_widget_backup['wpsc_quarterly_dashboard_widget'] = $normal_dashboard['wpsc_quarterly_dashboard_widget']; 
     726        unset( $normal_dashboard['wpsc_quarterly_dashboard_widget'] ); 
     727    } 
     728    if ( isset( $normal_dashboard['wpsc_dashboard_4months_widget'] ) ) { 
     729        $wpsc_widget_backup['wpsc_dashboard_4months_widget'] = $normal_dashboard['wpsc_dashboard_4months_widget']; 
     730        unset( $normal_dashboard['wpsc_dashboard_4months_widget'] ); 
     731    } 
     732 
     733    // Merge the two arrays together so our widget is at the beginning 
     734    $sorted_dashboard = array_merge( $wpsc_widget_backup, $normal_dashboard ); 
     735 
     736    // Save the sorted array back into the original metaboxes 
     737 
     738    $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; 
    741739} 
    742740 
     
    855853 
    856854function wpsc_dashboard_widget() { 
    857     if ( current_user_can( 'manage_options' ) ) { 
    858         do_action( 'wpsc_admin_pre_activity' ); 
    859         do_action( 'wpsc_admin_post_activity' ); 
    860     } 
     855    do_action( 'wpsc_admin_pre_activity' ); 
     856    do_action( 'wpsc_admin_post_activity' ); 
    861857} 
    862858 
Note: See TracChangeset for help on using the changeset viewer.