| @@ -30,9 +30,8 @@ | ||
| 30 | 30 | * |
| 31 | 31 | * @since 0.7 |
| 32 | 32 | */ |
| 33 | 33 | function __construct( ) { |
| 34 | - global $edit_flow; | |
| 35 | 34 | |
| 36 | 35 | $this->module_url = $this->get_module_url( __FILE__ ); |
| 37 | 36 | |
| 38 | 37 | // Register the User Groups module with Edit Flow |
| @@ -65,9 +64,9 @@ | ||
| 65 | 64 | 'content' => __('<p>For those with many people involved in the publishing process, user groups helps you keep them organized.</p><p>Currently, user groups are primarily used for subscribing a set of users to a post for notifications.</p>', 'edit-flow'), |
| 66 | 65 | ), |
| 67 | 66 | 'settings_help_sidebar' => __( '<p><strong>For more information:</strong></p><p><a href="http://editflow.org/features/user-groups/">User Groups Documentation</a></p><p><a href="http://wordpress.org/tags/edit-flow?forum_id=10">Edit Flow Forum</a></p><p><a href="https://github.com/danielbachhuber/Edit-Flow">Edit Flow on Github</a></p>', 'edit-flow' ), |
| 68 | 67 | ); |
| 69 | - $this->module = $edit_flow->register_module( 'user_groups', $args ); | |
| 68 | + $this->module = EditFlow()->register_module( 'user_groups', $args ); | |
| 70 | 69 | |
| 71 | 70 | } |
| 72 | 71 | |
| 73 | 72 | /** |
| @@ -161,9 +160,9 @@ | ||
| 161 | 160 | // Set all of the user group terms to our new taxonomy |
| 162 | 161 | $wpdb->update( $wpdb->term_taxonomy, array( 'taxonomy' => self::taxonomy_key ), array( 'taxonomy' => 'following_usergroups' ) ); |
| 163 | 162 | |
| 164 | 163 | // Get all of the users who are a part of user groups and assign them to their new user group values |
| 165 | - $query = $wpdb->prepare( "SELECT * FROM $wpdb->usermeta WHERE meta_key='wp_ef_usergroups';" ); | |
| 164 | + $query = "SELECT * FROM $wpdb->usermeta WHERE meta_key='wp_ef_usergroups';"; | |
| 166 | 165 | $usergroup_users = $wpdb->get_results( $query ); |
| 167 | 166 | |
| 168 | 167 | // Sort all of the users based on their usergroup(s) |
| 169 | 168 | $users_to_add = array(); |
| @@ -189,9 +188,14 @@ | ||
| 189 | 188 | // Technically we've run this code before so we don't want to auto-install new data |
| 190 | 189 | $edit_flow->update_module_option( $this->module->name, 'loaded_once', true ); |
| 191 | 190 | |
| 192 | 191 | } |
| 193 | - | |
| 192 | + // Upgrade path to v0.7.4 | |
| 193 | + if ( version_compare( $previous_version, '0.7.4', '<' ) ) { | |
| 194 | + // Usergroup descriptions become base64_encoded, instead of maybe json_encoded. | |
| 195 | + $this->upgrade_074_term_descriptions( self::taxonomy_key ); | |
| 196 | + } | |
| 197 | + | |
| 194 | 198 | } |
| 195 | 199 | |
| 196 | 200 | /** |
| 197 | 201 | * Individual Usergroups are stored using a custom taxonomy |
| @@ -274,9 +278,9 @@ | ||
| 274 | 278 | wp_die( $this->module->messages['invalid-permissions'] ); |
| 275 | 279 | |
| 276 | 280 | // Sanitize all of the user-entered values |
| 277 | 281 | $name = strip_tags( trim( $_POST['name'] ) ); |
| 278 | - $description = strip_tags( trim( $_POST['description'] ) ); | |
| 282 | + $description = stripslashes( strip_tags( trim( $_POST['description'] ) ) ); | |
| 279 | 283 | |
| 280 | 284 | $_REQUEST['form-errors'] = array(); |
| 281 | 285 | |
| 282 | 286 | /** |
| @@ -339,13 +343,13 @@ | ||
| 339 | 343 | if ( !current_user_can( $this->manage_usergroups_cap ) ) |
| 340 | 344 | wp_die( $this->module->messages['invalid-permissions'] ); |
| 341 | 345 | |
| 342 | 346 | if ( !$existing_usergroup = $this->get_usergroup_by( 'id', (int)$_POST['usergroup_id'] ) ) |
| 343 | - wp_die( $this->module->messsage['usergroup-error'] ); | |
| 347 | + wp_die( $this->module->messages['usergroup-missing'] ); | |
| 344 | 348 | |
| 345 | 349 | // Sanitize all of the user-entered values |
| 346 | 350 | $name = strip_tags( trim( $_POST['name'] ) ); |
| 347 | - $description = strip_tags( trim( $_POST['description'] ) ); | |
| 351 | + $description = stripslashes( strip_tags( trim( $_POST['description'] ) ) ); | |
| 348 | 352 | |
| 349 | 353 | $_REQUEST['form-errors'] = array(); |
| 350 | 354 | |
| 351 | 355 | /** |
| @@ -380,9 +384,9 @@ | ||
| 380 | 384 | 'description' => $description, |
| 381 | 385 | ); |
| 382 | 386 | // Gracefully handle the case where all users have been unsubscribed from the user group |
| 383 | 387 | $users = isset( $_POST['usergroup_users'] ) ? (array)$_POST['usergroup_users'] : array(); |
| 384 | - array_map( 'intval', $users ); | |
| 388 | + $users = array_map( 'intval', $users ); | |
| 385 | 389 | $usergroup = $this->update_usergroup( $existing_usergroup->term_id, $args, $users ); |
| 386 | 390 | if ( is_wp_error( $usergroup ) ) |
| 387 | 391 | wp_die( __( 'Error updating user group.', 'edit-flow' ) ); |
| 388 | 392 | |
| @@ -434,12 +438,12 @@ | ||
| 434 | 438 | die( $this->module->messages['invalid-permissions'] ); |
| 435 | 439 | |
| 436 | 440 | $usergroup_id = (int) $_POST['usergroup_id']; |
| 437 | 441 | if ( !$existing_term = $this->get_usergroup_by( 'id', $usergroup_id ) ) |
| 438 | - die( $this->module->messsage['usergroup-error'] ); | |
| 442 | + die( $this->module->messages['usergroup-missing'] ); | |
| 439 | 443 | |
| 440 | 444 | $name = strip_tags( trim( $_POST['name'] ) ); |
| 441 | - $description = strip_tags( trim( $_POST['description'] ) ); | |
| 445 | + $description = stripslashes( strip_tags( trim( $_POST['description'] ) ) ); | |
| 442 | 446 | |
| 443 | 447 | /** |
| 444 | 448 | * Form validation for editing Usergroup |
| 445 | 449 | */ |
| @@ -634,8 +638,12 @@ | ||
| 634 | 638 | global $user_id, $profileuser; |
| 635 | 639 | |
| 636 | 640 | if ( !$user_id || !current_user_can( $this->manage_usergroups_cap ) ) |
| 637 | 641 | return; |
| 642 | + | |
| 643 | + //Don't allow display of user groups from network | |
| 644 | + if ( ( !is_null( get_current_screen() ) ) && ( get_current_screen()->is_network ) ) | |
| 645 | + return; | |
| 638 | 646 | |
| 639 | 647 | // Assemble all necessary data |
| 640 | 648 | $usergroups = $this->get_usergroups(); |
| 641 | 649 | $selected_usergroups = $this->get_usergroups_for_user( $user_id ); |
| @@ -678,8 +686,17 @@ | ||
| 678 | 686 | |
| 679 | 687 | if ( !$update ) |
| 680 | 688 | return array( &$errors, $update, &$user ); |
| 681 | 689 | |
| 690 | + // `get_current_screen()` is defined on most admin pages, but not all. | |
| 691 | + if( function_exists( 'get_current_screen' ) ){ | |
| 692 | + //Don't allow update of user groups from network | |
| 693 | + $screen = get_current_screen(); | |
| 694 | + if ( ! is_null( $screen ) && $screen->is_network ) { | |
| 695 | + return; | |
| 696 | + } | |
| 697 | + } | |
| 698 | + | |
| 682 | 699 | if ( current_user_can( $this->manage_usergroups_cap ) && wp_verify_nonce( $_POST['ef_edit_profile_usergroups_nonce'], 'ef_edit_profile_usergroups_nonce' ) ) { |
| 683 | 700 | // Sanitize the data and save |
| 684 | 701 | // Gracefully handle the case where the user was unsubscribed from all usergroups |
| 685 | 702 | $usergroups = isset( $_POST['ef_usergroups'] ) ? array_map( 'intval', (array)$_POST['ef_usergroups'] ) : array(); |
| @@ -748,9 +765,9 @@ | ||
| 748 | 765 | <?php |
| 749 | 766 | } else { |
| 750 | 767 | |
| 751 | 768 | ?> |
| 752 | - <ul id="<?php echo $list_id ?>" class="<?php echo $list_class ?>"> | |
| 769 | + <ul id="<?php echo esc_attr( $list_id ) ?>" class="<?php echo esc_attr( $list_class ) ?>"> | |
| 753 | 770 | <?php |
| 754 | 771 | foreach( $usergroups as $usergroup ) { |
| 755 | 772 | $checked = ( in_array( $usergroup->term_id, $selected ) ) ? ' checked="checked"' : ''; |
| 756 | 773 | ?> |
| @@ -755,9 +772,11 @@ | ||
| 755 | 772 | $checked = ( in_array( $usergroup->term_id, $selected ) ) ? ' checked="checked"' : ''; |
| 756 | 773 | ?> |
| 757 | 774 | <li> |
| 758 | 775 | <label for="<?php echo $input_id . esc_attr( $usergroup->term_id ); ?>" title="<?php echo esc_attr($usergroup->description) ?>"> |
| 759 | - <input type="checkbox" id="<?php echo $input_id . esc_attr( $usergroup->term_id ) ?>" name="<?php echo $input_id ?>[]" value="<?php echo esc_attr( $usergroup->term_id ) ?>"<?php echo $checked ?> /> | |
| 776 | + <div class="ef-user-subscribe-actions"> | |
| 777 | + <input type="checkbox" id="<?php echo esc_attr( $input_id . $usergroup->term_id ) ?>" name="<?php echo esc_attr( $input_id )?>[]" value="<?php echo esc_attr( $usergroup->term_id ) ?>"<?php echo $checked ?> /> | |
| 778 | + </div> | |
| 760 | 779 | <span class="ef-usergroup_name"><?php echo esc_html( $usergroup->name ); ?></span> |
| 761 | 780 | <span class="ef-usergroup_description" title="<?php echo esc_attr($usergroup->description) ?>"> |
| 762 | 781 | <?php echo (strlen($usergroup->description) >= 50) ? substr_replace(esc_html($usergroup->description), '...', 50) : esc_html($usergroup->description); ?> |
| 763 | 782 | </span> |
| @@ -831,8 +850,11 @@ | ||
| 831 | 850 | foreach( $unencoded_description as $key => $value ) { |
| 832 | 851 | $usergroup->$key = $value; |
| 833 | 852 | } |
| 834 | 853 | } |
| 854 | + | |
| 855 | + $usergroup = apply_filters( 'ef_usergroup_object', $usergroup ); | |
| 856 | + | |
| 835 | 857 | return $usergroup; |
| 836 | 858 | } |
| 837 | 859 | |
| 838 | 860 | /** |
| @@ -863,9 +885,9 @@ | ||
| 863 | 885 | |
| 864 | 886 | // Encode our extra fields and then store them in the description field |
| 865 | 887 | $args_to_encode = array( |
| 866 | 888 | 'description' => $args['description'], |
| 867 | - 'user_ids' => array_unique( $user_ids, SORT_NUMERIC ), | |
| 889 | + 'user_ids' => array_unique( $user_ids ), | |
| 868 | 890 | ); |
| 869 | 891 | $encoded_description = $this->get_encoded_description( $args_to_encode ); |
| 870 | 892 | $args['description'] = $encoded_description; |
| 871 | 893 | $usergroup = wp_insert_term( $name, self::taxonomy_key, $args ); |
| @@ -899,9 +921,9 @@ | ||
| 899 | 921 | // Encode our extra fields and then store them in the description field |
| 900 | 922 | $args_to_encode = array(); |
| 901 | 923 | $args_to_encode['description'] = ( isset( $args['description'] ) ) ? $args['description'] : $existing_usergroup->description; |
| 902 | 924 | $args_to_encode['user_ids'] = ( is_array( $users ) ) ? $users : $existing_usergroup->user_ids; |
| 903 | - $args_to_encode['user_ids'] = array_unique( $args_to_encode['user_ids'], SORT_NUMERIC ); | |
| 925 | + $args_to_encode['user_ids'] = array_unique( $args_to_encode['user_ids'] ); | |
| 904 | 926 | $encoded_description = $this->get_encoded_description( $args_to_encode ); |
| 905 | 927 | $args['description'] = $encoded_description; |
| 906 | 928 | |
| 907 | 929 | $usergroup = wp_update_term( $id, self::taxonomy_key, $args ); |
| @@ -1235,5 +1257,5 @@ | ||
| 1235 | 1257 | <?php |
| 1236 | 1258 | } |
| 1237 | 1259 | |
| 1238 | 1260 | } |
| 1239 | -} | |
| 1261 | +} | |