| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | $errors = new \WP_Error(); |
| 17 | 17 | |
| 18 | 18 | $sanitized_user_login = sanitize_user($user_login); |
| 19 | 19 | |
| 20 | - $user_email = apply_filters('user_registration_email', $user_email); | |
| 20 | + $user_email = apply_filters('user_registration_email', $user_email); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound | |
| 21 | 21 | |
| 22 | 22 | // Check the username. |
| 23 | 23 | if ('' === $sanitized_user_login) { |
| 24 | 24 | $errors->add('empty_username', __('<strong>Error</strong>: Please enter a username.', 'fluent-community')); |
| @@ -28,9 +28,9 @@ | ||
| 28 | 28 | } elseif (username_exists($sanitized_user_login)) { |
| 29 | 29 | $errors->add('username_exists', __('<strong>Error</strong>: This username is already registered. Please choose another one.', 'fluent-community')); |
| 30 | 30 | } else { |
| 31 | 31 | /** This filter is documented in wp-includes/user.php */ |
| 32 | - $illegal_user_logins = (array)apply_filters('illegal_user_logins', array()); | |
| 32 | + $illegal_user_logins = (array)apply_filters('illegal_user_logins', array()); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound | |
| 33 | 33 | if (in_array(strtolower($sanitized_user_login), array_map('strtolower', $illegal_user_logins), true)) { |
| 34 | 34 | $errors->add('invalid_username', __('<strong>Error</strong>: Sorry, that username is not allowed.', 'fluent-community')); |
| 35 | 35 | } |
| 36 | 36 | } |
| @@ -43,15 +43,15 @@ | ||
| 43 | 43 | $user_email = ''; |
| 44 | 44 | } elseif (email_exists($user_email)) { |
| 45 | 45 | $errors->add( |
| 46 | 46 | 'email_exists', |
| 47 | - __('<strong>Error:</strong> This email address is already registered. Please login or try reset password', 'fluent-community') | |
| 47 | + __('<strong>Error:</strong> This email address is already registered. Please login or try resetting your password.', 'fluent-community') | |
| 48 | 48 | ); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - do_action('register_post', $sanitized_user_login, $user_email, $errors); | |
| 51 | + do_action('register_post', $sanitized_user_login, $user_email, $errors); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound | |
| 52 | 52 | |
| 53 | - $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email); | |
| 53 | + $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound | |
| 54 | 54 | |
| 55 | 55 | if ($errors->has_errors()) { |
| 56 | 56 | return $errors; |
| 57 | 57 | } |
| @@ -106,15 +106,15 @@ | ||
| 106 | 106 | return $errors; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | if (!empty($_COOKIE['wp_lang'])) { |
| 110 | - $wp_lang = sanitize_text_field($_COOKIE['wp_lang']); | |
| 110 | + $wp_lang = sanitize_text_field(wp_unslash($_COOKIE['wp_lang'])); | |
| 111 | 111 | if (in_array($wp_lang, get_available_languages(), true)) { |
| 112 | 112 | update_user_meta($user_id, 'locale', $wp_lang); // Set user locale if defined on registration. |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - do_action('register_new_user', $user_id); | |
| 116 | + do_action('register_new_user', $user_id); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound | |
| 117 | 117 | |
| 118 | 118 | return $user_id; |
| 119 | 119 | } |
| 120 | 120 | |
| @@ -126,9 +126,9 @@ | ||
| 126 | 126 | |
| 127 | 127 | $user = get_user_by('ID', $user->ID); |
| 128 | 128 | |
| 129 | 129 | if ($user) { |
| 130 | - do_action('wp_login', $user->user_login, $user); | |
| 130 | + do_action('wp_login', $user->user_login, $user); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | return $user; |
| 134 | 134 | } |
| @@ -149,9 +149,9 @@ | ||
| 149 | 149 | $inviteeUser = get_user_by('email', $inviatationData['email']); |
| 150 | 150 | |
| 151 | 151 | if ($inviteeUser) { |
| 152 | 152 | if (empty($spaceId)) { |
| 153 | - return new \WP_Error('user_exist', __('User already exist', 'fluent-community')); | |
| 153 | + return new \WP_Error('user_exist', __('User already exists.', 'fluent-community')); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | if ($spaceId) { |
| 157 | 157 | // Let's check if the user is already a member of the space |
| @@ -159,9 +159,9 @@ | ||
| 159 | 159 | ->where('space_id', $spaceId) |
| 160 | 160 | ->first(); |
| 161 | 161 | |
| 162 | 162 | if ($spaceUser) { |
| 163 | - return new \WP_Error('user_exist', __('User already exist in the space', 'fluent-community')); | |
| 163 | + return new \WP_Error('user_exist', __('User already exists in the space.', 'fluent-community')); | |
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| @@ -194,8 +194,26 @@ | ||
| 194 | 194 | |
| 195 | 195 | return $inviation; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | + public static function createLinkInvite($data) | |
| 199 | + { | |
| 200 | + $formattedData = array_filter([ | |
| 201 | + 'message' => '', | |
| 202 | + 'user_id' => $data['user_id'], | |
| 203 | + 'status' => 'active', | |
| 204 | + 'post_id' => $data['space_id'], | |
| 205 | + 'message_rendered' => md5($data['space_id'] . '_' . time() . '_' . wp_generate_uuid4(10) . '_' . $data['user_id']), | |
| 206 | + 'meta' => Arr::only($data, ['title', 'limit', 'expire_date']) | |
| 207 | + ]); | |
| 208 | + | |
| 209 | + $inviation = Invitation::create($formattedData); | |
| 210 | + | |
| 211 | + do_action('fluent_community/invitation_link_created', $inviation); | |
| 212 | + | |
| 213 | + return $inviation; | |
| 214 | + } | |
| 215 | + | |
| 198 | 216 | public static function sendInvitationEmail(Invitation $invitation) |
| 199 | 217 | { |
| 200 | 218 | $xProfile = $invitation->xprofile; |
| 201 | 219 | if (!$xProfile) { |
| @@ -203,10 +221,10 @@ | ||
| 203 | 221 | } |
| 204 | 222 | |
| 205 | 223 | $portalSettings = Helper::generalSettings(); |
| 206 | 224 | |
| 207 | - $subject = sprintf( | |
| 208 | - __('%1s has invited you to join the %2s', 'fluent-community'), | |
| 225 | + /* translators: %1$s is replaced by the name of the user, %2$s is replaced by the title of the site */ | |
| 226 | + $subject = \sprintf(__('%1$s has invited you to join the %2$s', 'fluent-community'), | |
| 209 | 227 | $xProfile->display_name, |
| 210 | 228 | Arr::get($portalSettings, 'site_title') |
| 211 | 229 | ); |
| 212 | 230 | |
| @@ -213,9 +231,10 @@ | ||
| 213 | 231 | if ($invitation->post_id) { |
| 214 | 232 | $space = $invitation->space; |
| 215 | 233 | if ($space) { |
| 216 | 234 | $subject = \sprintf( |
| 217 | - __('%1s has invited you to join the %2s on %3s', 'fluent-community'), | |
| 235 | + /* translators: %1$s is replaced by the name of the user, %2$s is replaced by the title of the space, %3$s is replaced by the title of the site */ | |
| 236 | + __('%1$s has invited you to join the %2$s on %3$s', 'fluent-community'), | |
| 218 | 237 | $xProfile->display_name, |
| 219 | 238 | $space->title, |
| 220 | 239 | Arr::get($portalSettings, 'site_title') |
| 221 | 240 | ); |
| @@ -221,13 +240,19 @@ | ||
| 221 | 240 | ); |
| 222 | 241 | } |
| 223 | 242 | } |
| 224 | 243 | |
| 225 | - $emailBody = self::getInviationEmailHtml($invitation); | |
| 226 | - | |
| 227 | 244 | $invitation->reactions_count += 1; |
| 228 | 245 | $invitation->save(); |
| 229 | 246 | |
| 247 | + $emailComposer = new \FluentCommunity\App\Services\Libs\EmailComposer(); | |
| 248 | + | |
| 249 | + $emailComposer->addBlock('html_content', self::getInviationEmailHtml($invitation)); | |
| 250 | + $emailComposer->setDefaultLogo(); | |
| 251 | + $emailComposer->setDefaultFooter(); | |
| 252 | + | |
| 253 | + $emailBody = $emailComposer->getHtml(); | |
| 254 | + | |
| 230 | 255 | $mailer = new Mailer($invitation->message, $subject, $emailBody); |
| 231 | 256 | |
| 232 | 257 | return $mailer->send(); |
| 233 | 258 | } |
| @@ -237,9 +262,10 @@ | ||
| 237 | 262 | $portalSettings = Helper::generalSettings(); |
| 238 | 263 | $siteTitle = Arr::get($portalSettings, 'site_title'); |
| 239 | 264 | |
| 240 | 265 | if ($invitation->space) { |
| 241 | - $siteTitle = sprintf(__('%1s on %2s', 'fluent-community'), $invitation->space->title, $siteTitle); | |
| 266 | + /* translators: %1$s is replaced by the title of the space, %2$s is replaced by the title of the site */ | |
| 267 | + $siteTitle = \sprintf(__('%1$s on %2$s', 'fluent-community'), $invitation->space->title, $siteTitle); | |
| 242 | 268 | } |
| 243 | 269 | |
| 244 | 270 | return (string)App::make('view')->make('email.Default._invitation', [ |
| 245 | 271 | 'by_name' => $invitation->xprofile->display_name, |