Plugin Directory

Changeset 706011


Ignore:
Timestamp:
04/30/2013 04:25:11 PM (13 years ago)
Author:
andy
Message:

Jetpack Stats: Counting of registered users' views can now be enabled for specific roles

Location:
jetpack/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • jetpack/trunk/modules/stats.php

    r692359 r706011  
    1212}
    1313
    14 define( 'STATS_VERSION', '8' );
     14define( 'STATS_VERSION', '9' );
    1515defined( 'STATS_DASHBOARD_SERVER' ) or define( 'STATS_DASHBOARD_SERVER', 'dashboard.wordpress.com' );
    1616
     
    8989 */
    9090function stats_map_meta_caps( $caps, $cap, $user_id, $args ) {
    91 
    9291    // Map view_stats to exists
    9392    if ( 'view_stats' == $cap ) {
     
    112111
    113112    $options = stats_get_options();
    114     // Ensure this is always setup for the check below
    115     $options['reg_users'] = empty( $options['reg_users'] ) ? false : true;
    116 
    117     if ( !$options['reg_users'] && !empty( $current_user->ID ) )
    118         return;
     113
     114    // Should we be counting this user's views?
     115    if ( !empty( $current_user->ID ) ) {
     116        $count_roles = stats_get_option( 'count_roles' );
     117        if ( ! array_intersect( $current_user->roles, $count_roles ) )
     118            return;
     119    }
    119120
    120121    add_action( 'wp_footer', 'stats_footer', 101 );
     
    208209        'admin_bar'    => true,
    209210        'roles'        => array( 'administrator' ),
     211        'count_roles'  => array(),
    210212        'blog_id'      => Jetpack::get_option( 'id' ),
    211213        'do_not_track' => true, // @todo
    212214        'hide_smile'   => false,
    213215    );
     216
     217    if ( isset( $options['reg_users'] ) ) {
     218        if ( $options['reg_users'] )
     219            $options['count_roles'] = array_keys( get_editable_roles() );
     220        unset( $options['reg_users'] );
     221    }
    214222
    215223    if ( is_array( $options ) && !empty( $options ) )
     
    487495        $options = stats_get_options();
    488496        $options['admin_bar']  = isset( $_POST['admin_bar']  ) && $_POST['admin_bar'];
    489         $options['reg_users']  = isset( $_POST['reg_users']  ) && $_POST['reg_users'];
    490497        $options['hide_smile'] = isset( $_POST['hide_smile'] ) && $_POST['hide_smile'];
    491498
     
    494501            if ( isset( $_POST["role_$role"] ) && $_POST["role_$role"] )
    495502                $options['roles'][] = $role;
     503
     504        $options['count_roles'] = array();
     505        foreach ( get_editable_roles() as $role => $details )
     506            if ( isset( $_POST["count_role_$role"] ) && $_POST["count_role_$role"] )
     507                $options['count_roles'][] = $role;
    496508
    497509        stats_set_options( $options );
     
    520532function stats_configuration_screen() {
    521533    $options = stats_get_options();
    522     $options['reg_users'] = empty( $options['reg_users'] ) ? false : true;
    523534    ?>
    524535    <div class="narrow">
     
    530541        <tr valign="top"><th scope="row"><label for="admin_bar"><?php _e( 'Admin bar' , 'jetpack' ); ?></label></th>
    531542        <td><label><input type='checkbox'<?php checked( $options['admin_bar'] ); ?> name='admin_bar' id='admin_bar' /> <?php _e( "Put a chart showing 48 hours of views in the admin bar.", 'jetpack' ); ?></label></td></tr>
    532         <tr valign="top"><th scope="row"><label for="reg_users"><?php _e( 'Registered users', 'jetpack' ); ?></label></th>
    533         <td><label><input type='checkbox'<?php checked( $options['reg_users'] ); ?> name='reg_users' id='reg_users' /> <?php _e( "Count the page views of registered users who are logged in.", 'jetpack' ); ?></label></td></tr>
     543        <tr valign="top"><th scope="row"><?php _e( 'Registered users', 'jetpack' ); ?></th>
     544        <td>
     545            <?php _e( "Count the page views of registered users who are logged in.", 'jetpack' ); ?><br/>
     546            <?php
     547            $count_roles = stats_get_option( 'count_roles' );
     548            foreach ( get_editable_roles() as $role => $details ) {
     549                ?>
     550                <label><input type='checkbox' name='count_role_<?php echo $role; ?>'<?php checked( in_array( $role, $count_roles ) ); ?> /> <?php echo translate_user_role( $details['name'] ); ?></label><br/>
     551                <?php
     552            }
     553            ?>
     554        </td></tr>
    534555        <tr valign="top"><th scope="row"><?php _e( 'Smiley' , 'jetpack' ); ?></th>
    535556        <td><label><input type='checkbox'<?php checked( isset( $options['hide_smile'] ) && $options['hide_smile'] ); ?> name='hide_smile' id='hide_smile' /> <?php _e( 'Hide the stats smiley face image.', 'jetpack' ); ?></label><br /> <span class="description"><?php _e( 'The image helps collect stats and <strong>makes the world a better place</strong> but should still work when hidden', 'jetpack' ); ?> <img class="stats-smiley" alt="<?php esc_attr_e( 'Smiley face', 'jetpack' ); ?>" src="<?php echo esc_url( plugins_url( '_inc/images/stats-smiley.gif', dirname( __FILE__ ) ) ); ?>" width="6" height="5" /></span></td></tr>
     
    545566            }
    546567            ?>
    547         </tr>
     568        </td></tr>
    548569        </table>
    549570        <p class="submit"><input type='submit' class='button-primary' value='<?php echo esc_attr( __( 'Save configuration', 'jetpack' ) ); ?>' /></p>
  • jetpack/trunk/readme.txt

    r704411 r706011  
    7979
    8080== Changelog ==
     81
     82= trunk =
     83* Enhancement: Stats: Counting of registered users' views can now be enabled for specific roles
    8184
    8285= 2.2.4 =
Note: See TracChangeset for help on using the changeset viewer.