PluginProbe
Cooked – Recipe Management / 1.7.12
Cooked – Recipe Management v1.7.12
1.16.0 1.15.0 trunk 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.12.0 1.13.0 1.14.0 1.7.10 1.7.11 1.7.12 1.7.13 1.7.15.1 1.7.15.3 1.7.15.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 All 36 releases
cooked / includes / class.cooked-users.php

class.cooked-users.php in Cooked – Recipe Management 1.7.12, at includes/class.cooked-users.php

136 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cooked User-Specific Functions
4 *
5 * @package Cooked
6 * @subpackage User-Specific Functions
7 * @since 1.0.0
8 */
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * Cooked_User Class
15 *
16 * This class handles the Cooked Recipe Meta Box creation.
17 *
18 * @since 1.0.0
19 */
20 class Cooked_Users {
21
22 function __construct(){
23 add_action( 'init', array(&$this, 'recipe_author_rewrite'), 10 );
24 }
25
26 public static function recipe_author_rewrite() {
27
28 global $_cooked_settings;
29
30 $browse_page_id = ( isset($_cooked_settings['browse_page']) && $_cooked_settings['browse_page'] ? $_cooked_settings['browse_page'] : false );
31 $front_page_id = get_option( 'page_on_front' );
32 $browse_page_slug = ( $browse_page_id ? basename( get_permalink( $browse_page_id ) ) : false );
33 if ( $browse_page_id != $front_page_id ):
34
35 add_rewrite_tag('%recipe_author%', '([^&]+)');
36 if ( isset( $_cooked_settings['browse_page'] ) ):
37 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' );
38 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' );
39 endif;
40
41 endif;
42 }
43
44 public static function get( $user_id, $basic = false ){
45
46 $_user = get_userdata( $user_id );
47 $_user_meta = get_user_meta( $user_id, 'cooked_user_meta', true );
48
49 if ( !empty($_user) ):
50
51 if ( isset( $_user_meta['profile_photo_id'] ) && $_user_meta['profile_photo_id'] && wp_attachment_is_image( $_user_meta['profile_photo_id'] ) ):
52 $profile_photo = wp_get_attachment_image( $_user_meta['profile_photo_id'], 'cooked-square' );
53 $profile_photo_src = wp_get_attachment_image_src( $_user_meta['profile_photo_id'], 'cooked-square' );
54 $profile_photo_src = ( isset($profile_photo_src[0]) && $profile_photo_src[0] ? $profile_photo_src[0] : false );
55 else :
56 $profile_photo = get_avatar( $_user->user_email, 'cooked-square' );
57 $profile_photo_src = get_avatar_url( $_user->user_email, 'cooked-square' );
58 endif;
59
60 if ( is_array($_user_meta) ):
61 $_user_data = $_user_meta;
62 endif;
63
64 $_user_data['id'] = $user_id;
65 $_user_data['name'] = self::format_author_name( $_user->display_name );
66 $_user_data['profile_photo'] = $profile_photo;
67 $_user_data['profile_photo_src'] = $profile_photo_src;
68
69 if ( !$basic ):
70
71 $_user_data['raw'] = $_user;
72
73 $user_recipe_args = array(
74 'post_type' => 'cp_recipe',
75 'post_status' => 'publish',
76 'posts_per_page' => -1,
77 'author' => $user_id
78 );
79
80 $_user_data['recipes'] = Cooked_Recipes::get( $user_recipe_args, false, true );
81
82 endif;
83
84 return $_user_data;
85
86 else:
87
88 return false;
89
90 endif;
91
92 }
93
94 public static function format_author_name( $name, $format = false ){
95
96 if ( !$name )
97 return false;
98
99 global $_cooked_settings;
100 $_cooked_settings = ( !$_cooked_settings || $_cooked_settings && empty($_cooked_settings) ? Cooked_Settings::get() : $_cooked_settings );
101 if ( !$format && isset($_cooked_settings['author_name_format']) && $_cooked_settings['author_name_format'] ):
102 $format = $_cooked_settings['author_name_format'];
103 elseif(!$format):
104 $format = 'full';
105 endif;
106
107 switch( $format ):
108 case 'full':
109 return $name;
110 break;
111 case 'first_last_initial':
112 $name = explode( ' ', $name );
113 if ( isset($name[1]) ):
114 return $name[0] . ' ' . substr( $name[1], 0, 1) . '.';
115 endif;
116 return $name[0];
117 break;
118 case 'first_initial_last':
119 $name = explode( ' ', $name );
120 if ( isset($name[1]) ):
121 return substr( $name[0], 0, 1) . '. ' . esc_html( $name[1] );
122 endif;
123 return $name[0];
124 break;
125 case 'first_only':
126 $name = explode( ' ', $name );
127 return esc_html( $name[0] );
128 break;
129 endswitch;
130
131 return esc_html( $name );
132
133 }
134
135 }
136