| @@ -18,9 +18,9 @@ | ||
| 18 | 18 | * @since 1.0.0 |
| 19 | 19 | */ |
| 20 | 20 | class Cooked_Users { |
| 21 | 21 | |
| 22 | - function __construct() { | |
| 22 | + function __construct(){ | |
| 23 | 23 | add_action( 'init', [&$this, 'recipe_author_rewrite'], 10 ); |
| 24 | 24 | |
| 25 | 25 | add_filter( 'manage_users_columns', [&$this, 'recipe_count_column'] ); |
| 26 | 26 | add_filter( 'manage_users_sortable_columns', [&$this, 'recipe_count_column_sortable'] ); |
| @@ -30,54 +30,33 @@ | ||
| 30 | 30 | |
| 31 | 31 | public static function recipe_author_rewrite() { |
| 32 | 32 | global $_cooked_settings; |
| 33 | 33 | |
| 34 | + $browse_page_id = ( isset($_cooked_settings['browse_page']) && $_cooked_settings['browse_page'] ? $_cooked_settings['browse_page'] : false ); | |
| 34 | 35 | $front_page_id = get_option( 'page_on_front' ); |
| 36 | + $browse_page_slug = ( $browse_page_id ? basename( get_permalink( $browse_page_id ) ) : false ); | |
| 35 | 37 | |
| 36 | - // Get all browse page translations for rewrite rules | |
| 37 | - $browse_pages = Cooked_Multilingual::get_all_browse_pages(); | |
| 38 | - | |
| 39 | - if ( empty( $browse_pages ) ) { | |
| 40 | - return; | |
| 41 | - } | |
| 42 | - | |
| 43 | - add_rewrite_tag('%recipe_author%', '([^&]+)'); | |
| 44 | - | |
| 45 | - // Create rewrite rules for each browse page translation | |
| 46 | - foreach ( $browse_pages as $lang => $page_data ) { | |
| 47 | - $browse_page_id = $page_data['id']; | |
| 48 | - $browse_page_slug = $page_data['slug'] ? basename( $page_data['slug'] ) : false; | |
| 49 | - | |
| 50 | - if ( ! $browse_page_slug || $browse_page_id == $front_page_id ) { | |
| 51 | - continue; | |
| 38 | + if ( $browse_page_id != $front_page_id ) { | |
| 39 | + add_rewrite_tag('%recipe_author%', '([^&]+)'); | |
| 40 | + if ( isset( $_cooked_settings['browse_page'] ) ) { | |
| 41 | + add_rewrite_rule('^' . $browse_page_slug . '/' . $_cooked_settings['recipe_author_permalink'] . '/([^/]*)/([^/]*)/page/([^/]*)/?', 'index.php?page_id=' . esc_attr( $_cooked_settings['browse_page'] ) . '&paged=$matches[3]&recipe_author=$matches[1]', 'top' ); | |
| 42 | + add_rewrite_rule('^' . $browse_page_slug . '/' . $_cooked_settings['recipe_author_permalink'] . '/([^/]*)/?', 'index.php?page_id=' . esc_attr( $_cooked_settings['browse_page'] ) . '&recipe_author=$matches[1]', 'top' ); | |
| 52 | 43 | } |
| 53 | - | |
| 54 | - add_rewrite_rule('^' . $browse_page_slug . '/' . $_cooked_settings['recipe_author_permalink'] . '/([^/]*)/page/([^/]*)/?', 'index.php?page_id=' . esc_attr( $browse_page_id ) . '&paged=$matches[2]&recipe_author=$matches[1]', 'top' ); | |
| 55 | - add_rewrite_rule('^' . $browse_page_slug . '/' . $_cooked_settings['recipe_author_permalink'] . '/([^/]*)/?', 'index.php?page_id=' . esc_attr( $browse_page_id ) . '&recipe_author=$matches[1]', 'top' ); | |
| 56 | 44 | } |
| 57 | 45 | } |
| 58 | 46 | |
| 59 | - public static function get( $user_id = false, $basic = false, $user_nicename = false ) { | |
| 60 | - if ( !$user_id && $user_nicename ) { | |
| 61 | - $user = get_user_by( 'slug', $user_nicename ); | |
| 62 | - if ( $user ) { | |
| 63 | - $user_id = $user->ID; | |
| 64 | - } else { | |
| 65 | - return false; | |
| 66 | - } | |
| 67 | - } | |
| 68 | - | |
| 47 | + public static function get( $user_id, $basic = false ) { | |
| 69 | 48 | $_user = get_userdata( $user_id ); |
| 70 | 49 | $_user_meta = get_user_meta( $user_id, 'cooked_user_meta', true ); |
| 71 | 50 | |
| 72 | 51 | if ( !empty($_user) ) { |
| 73 | 52 | if ( isset( $_user_meta['profile_photo_id'] ) && $_user_meta['profile_photo_id'] && wp_attachment_is_image( $_user_meta['profile_photo_id'] ) ) { |
| 74 | - $profile_photo = wp_get_attachment_image( $_user_meta['profile_photo_id'], 'cooked-profile-photo' ); | |
| 75 | - $profile_photo_src = wp_get_attachment_image_src( $_user_meta['profile_photo_id'], 'cooked-profile-photo' ); | |
| 76 | - $profile_photo_src = isset($profile_photo_src[0]) && $profile_photo_src[0] ? $profile_photo_src[0] : false; | |
| 53 | + $profile_photo = wp_get_attachment_image( $_user_meta['profile_photo_id'], 'cooked-square' ); | |
| 54 | + $profile_photo_src = wp_get_attachment_image_src( $_user_meta['profile_photo_id'], 'cooked-square' ); | |
| 55 | + $profile_photo_src = ( isset($profile_photo_src[0]) && $profile_photo_src[0] ? $profile_photo_src[0] : false ); | |
| 77 | 56 | } else { |
| 78 | - $profile_photo = get_avatar($_user->user_email, 96); | |
| 79 | - $profile_photo_src = get_avatar_url($_user->user_email, ['size' => 96]); | |
| 57 | + $profile_photo = get_avatar( $_user->user_email, 700); | |
| 58 | + $profile_photo_src = get_avatar_url( $_user->user_email, ['size' => 700]); | |
| 80 | 59 | } |
| 81 | 60 | |
| 82 | 61 | if ( is_array($_user_meta) ) { |
| 83 | 62 | $_user_data = $_user_meta; |
| @@ -83,9 +62,8 @@ | ||
| 83 | 62 | $_user_data = $_user_meta; |
| 84 | 63 | } |
| 85 | 64 | |
| 86 | 65 | $_user_data['id'] = $user_id; |
| 87 | - $_user_data['user_nicename'] = $_user->user_nicename; | |
| 88 | 66 | $_user_data['name'] = self::format_author_name( $_user->display_name ); |
| 89 | 67 | $_user_data['profile_photo'] = $profile_photo; |
| 90 | 68 | $_user_data['profile_photo_src'] = $profile_photo_src; |
| 91 | 69 | |
| @@ -93,9 +71,9 @@ | ||
| 93 | 71 | $_user_data['raw'] = $_user; |
| 94 | 72 | |
| 95 | 73 | $user_recipe_args = [ |
| 96 | 74 | 'post_type' => 'cp_recipe', |
| 97 | - 'post_status' => ['publish', 'pending', 'draft'], | |
| 75 | + 'post_status' => 'publish', | |
| 98 | 76 | 'posts_per_page' => -1, |
| 99 | 77 | 'author' => $user_id |
| 100 | 78 | ]; |
| 101 | 79 | |
| @@ -119,26 +97,11 @@ | ||
| 119 | 97 | elseif (!$format): |
| 120 | 98 | $format = 'full'; |
| 121 | 99 | endif; |
| 122 | 100 | |
| 123 | - $filtered = apply_filters( 'cooked_format_author_name', $name, $format ); | |
| 124 | - | |
| 125 | - // If the filter returns an array with a second element true, treat as safe. | |
| 126 | - if ( is_array( $filtered ) && isset( $filtered[1] ) && $filtered[1] === true ) { | |
| 127 | - $name = $filtered[0]; | |
| 128 | - $safe = true; | |
| 129 | - } else { | |
| 130 | - $name = is_array( $filtered ) ? $filtered[0] : $filtered; | |
| 131 | - $safe = false; | |
| 132 | - } | |
| 133 | - | |
| 134 | 101 | switch ( $format ) { |
| 135 | 102 | case 'full': |
| 136 | - if ( $safe ) { | |
| 137 | - return $name; | |
| 138 | - } else { | |
| 139 | - return esc_html( $name ); | |
| 140 | - } | |
| 103 | + return $name; | |
| 141 | 104 | case 'first_last_initial': |
| 142 | 105 | $name = explode( ' ', $name ); |
| 143 | 106 | if ( isset($name[1]) ): |
| 144 | 107 | return $name[0] . ' ' . substr( $name[1], 0, 1) . '.'; |
| @@ -154,13 +117,9 @@ | ||
| 154 | 117 | $name = explode( ' ', $name ); |
| 155 | 118 | return esc_html( $name[0] ); |
| 156 | 119 | } |
| 157 | 120 | |
| 158 | - if ( $safe ) { | |
| 159 | - return $name; | |
| 160 | - } else { | |
| 161 | - return esc_html( $name ); | |
| 162 | - } | |
| 121 | + return esc_html( $name ); | |
| 163 | 122 | } |
| 164 | 123 | |
| 165 | 124 | function recipe_count_column($column_headers) { |
| 166 | 125 | $column_headers['cooked_recipe_count'] = __('Recipes', 'cooked'); |
| @@ -181,24 +140,25 @@ | ||
| 181 | 140 | |
| 182 | 141 | return $value; |
| 183 | 142 | } |
| 184 | 143 | |
| 144 | + | |
| 185 | 145 | function pre_user_query( $query ) { |
| 186 | 146 | global $wpdb, $current_screen; |
| 187 | 147 | |
| 188 | - // Only filter in the admin. | |
| 148 | + // Only filter in the admin | |
| 189 | 149 | if ( ! is_admin() ) return; |
| 190 | 150 | |
| 191 | - // Only filter on the users screen. | |
| 151 | + // Only filter on the users screen | |
| 192 | 152 | if ( ! ( isset( $current_screen ) && 'users' === $current_screen->id ) ) return; |
| 193 | 153 | |
| 194 | - // Only filter if orderby is set to 'cooked_recipe_count'. | |
| 154 | + // Only filter if orderby is set to 'cooked_recipe_count' | |
| 195 | 155 | if ( isset( $query->query_vars ) && isset( $query->query_vars[ 'orderby' ] ) && ( 'cooked_recipe_count' == $query->query_vars[ 'orderby' ] ) ) { |
| 196 | - // We need the order - default is ASC. | |
| 156 | + // We need the order - default is ASC | |
| 197 | 157 | $order = isset( $query->query_vars ) && isset( $query->query_vars[ 'order' ] ) && strcasecmp( $query->query_vars[ 'order' ], 'desc' ) == 0 ? 'DESC' : 'ASC'; |
| 198 | 158 | |
| 199 | - // Order the posts by recipe count. | |
| 200 | - $query->query_orderby = "ORDER BY ( SELECT COUNT(*) FROM {$wpdb->posts} posts WHERE posts.post_type = 'cp_recipe' AND posts.post_status IN ('publish', 'pending', 'draft') AND posts.post_author = {$wpdb->users}.ID ) {$order}"; | |
| 159 | + // Order the posts by recipe count | |
| 160 | + $query->query_orderby = "ORDER BY ( SELECT COUNT(*) FROM {$wpdb->posts} posts WHERE posts.post_type = 'cp_recipe' AND posts.post_status = 'publish' AND posts.post_author = {$wpdb->users}.ID ) {$order}"; | |
| 201 | 161 | } |
| 202 | 162 | } |
| 203 | 163 | |
| 204 | 164 | } |