Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
mehedi-bb committed Jun 25, 2024
2 parents fa0a4f7 + a85fbed commit 0b8020e
Show file tree
Hide file tree
Showing 43 changed files with 747 additions and 323 deletions.
2 changes: 1 addition & 1 deletion bp-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: The BuddyBoss Platform adds community features to WordPress. Member Profiles, Activity Feeds, Direct Messaging, Notifications, and more!
* Author: BuddyBoss
* Author URI: https://buddyboss.com/
* Version: 2.6.30
* Version: 2.6.40
* Text Domain: buddyboss
* Domain Path: /bp-languages/
* License: GPLv2 or later (license.txt)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
},
"license": "GPL-2.0-or-later",
"version": "3.1.0",
"BBVersion": "2.6.30"
"BBVersion": "2.6.40"
}
16 changes: 14 additions & 2 deletions src/bp-core/bp-core-attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ function bp_attachments_create_item_type( $type = 'avatar', $args = array() ) {
)
);

$created = ! empty( $cover_image['cover_file'] );
$created = ! is_wp_error( $cover_image ) && ! empty( $cover_image['cover_file'] );
}

// Remove copied file if it fails.
Expand Down Expand Up @@ -1377,6 +1377,7 @@ function bp_attachments_get_group_has_cover_image( $group_id = 0 ) {
* @type string $cover_image_dir The cover photo dir to write the image into. Required.
* }
* @param BP_Attachment_Cover_Image|null $cover_image_class The class to use to fit the cover photo.
*
* @return false|array An array containing cover photo data on success, false otherwise.
*/
function bp_attachments_cover_image_generate_file( $args = array(), $cover_image_class = null ) {
Expand Down Expand Up @@ -1406,6 +1407,10 @@ function bp_attachments_cover_image_generate_file( $args = array(), $cover_image

// Resize the image so that it fit with the cover photo dimensions.
$cover_image = $cover_image_class->fit( $args['file'], $dimensions );
if ( is_wp_error( $cover_image ) ) {
return false;
}

$is_too_small = false;

// Image is too small in width and height.
Expand Down Expand Up @@ -1656,11 +1661,18 @@ function bp_attachments_cover_image_ajax_upload() {
);

if ( ! $cover ) {

$error_code = 'upload_error';
if ( ! bb_is_gd_or_imagick_library_enabled() ) {
$error_message = sprintf( esc_html__( 'Upload Error: %s', 'buddyboss' ), esc_html__( 'Missing image editor! Enable GD or Imagick library.', 'buddyboss' ) );
$error_code = 'image_no_editor';
}

bp_attachments_json_response(
false,
$is_html4,
array(
'type' => 'upload_error',
'type' => $error_code,
'message' => $error_message,
)
);
Expand Down
12 changes: 11 additions & 1 deletion src/bp-core/bp-core-avatars.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,11 @@ function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
$bp->avatar_admin->resized = $avatar_attachment->shrink( $bp->avatar_admin->original['file'], $ui_available_width );
$bp->avatar_admin->image = new stdClass();

if ( is_wp_error( $bp->avatar_admin->resized ) ) {
bp_core_add_message( sprintf( __( 'Upload Error: %s', 'buddyboss' ), $bp->avatar_admin->resized->get_error_message() ), 'error' );
return false;
}

// We only want to handle one image after resize.
if ( empty( $bp->avatar_admin->resized ) ) {
$bp->avatar_admin->image->file = $bp->avatar_admin->original['file'];
Expand Down Expand Up @@ -1474,9 +1479,14 @@ function bp_avatar_ajax_set() {
}

if ( ! bp_avatar_handle_capture( $webcam_avatar, $avatar_data['item_id'] ) ) {
$feedback_code = 1;
if ( ! bb_is_gd_or_imagick_library_enabled() ) {
$feedback_code = 5;
}

wp_send_json_error(
array(
'feedback_code' => 1,
'feedback_code' => $feedback_code,
)
);

Expand Down
68 changes: 68 additions & 0 deletions src/bp-core/bp-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9774,3 +9774,71 @@ function bb_mention_add_user_dynamic_link( $content ) {
function bb_pro_schedule_posts_version() {
return '2.5.20';
}

/**
* Function for writing logs to debug.log
*
* @param [mixed] $log The log entry that needs to be written into the debug.log.
* @param [boolean] $always_print Optional. True then always print the log. Default false.
*
* @since BuddyBoss 2.6.40
*
* @return void
*/
function bb_error_log( $log = '', $always_print = false ) {
if (
(
defined( 'BB_DEBUG_LOG' ) &&
true === BB_DEBUG_LOG
) ||
true === $always_print
) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}

/**
* Function to check if GD or Imagick library is enabled.
*
* @since BuddyBoss 2.6.40
*
* @return bool
*/
function bb_is_gd_or_imagick_library_enabled() {
static $is_enabled = '';

if ( '' === $is_enabled ) {

// Check if editor loaded successfully.
if ( function_exists( '_wp_image_editor_choose' ) ) {
$lib_loaded = _wp_image_editor_choose();
if (
! empty( $lib_loaded ) &&
! is_wp_error( $lib_loaded ) &&
(
'WP_Image_Editor_GD' === $lib_loaded ||
'WP_Image_Editor_Imagick' === $lib_loaded
)
) {
$is_enabled = true;
} else {
$is_enabled = false;
}
} else {
$is_enabled = extension_loaded( 'gd' ) || extension_loaded( 'imagick' );
}
}

/**
* Filters the enabled/disabled value for image library.
*
* @since BuddyBoss 2.6.40
*
* @param bool $is_enabled True if enabled else false.
*/
return apply_filters( 'bb_is_gd_or_imagick_library_enabled', (bool) $is_enabled );
}
2 changes: 1 addition & 1 deletion src/bp-core/classes/class-bb-background-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ protected function complete() {
*/
protected function completed() {
// phpcs:ignore
error_log( 'Data update completed' );
bb_error_log( 'Data update completed' );
do_action( $this->identifier . '_completed' );
}

Expand Down
6 changes: 3 additions & 3 deletions src/bp-core/classes/class-bb-background-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function task( $callback ) {

if ( is_callable( $callback ) ) {
// phpcs:ignore
error_log( sprintf( 'Running %s callback', json_encode( $callback ) ) );
bb_error_log( sprintf( 'Running %s callback', json_encode( $callback ) ) );

if ( empty( $args ) ) {
$result = (bool) call_user_func( $callback, $this );
Expand All @@ -50,10 +50,10 @@ protected function task( $callback ) {

if ( $result ) {
// phpcs:ignore
error_log( sprintf( '%s callback needs to run again', json_encode( $callback ) ) );
bb_error_log( sprintf( '%s callback needs to run again', json_encode( $callback ) ) );
} else {
// phpcs:ignore
error_log( sprintf( 'Finished running %s callback', json_encode( $callback ) ) );
bb_error_log( sprintf( 'Finished running %s callback', json_encode( $callback ) ) );
}
} else {
// phpcs:ignore
Expand Down
1 change: 1 addition & 0 deletions src/bp-core/classes/class-bp-attachment-avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ public function script_data() {
2 => __( 'Your new profile photo was uploaded successfully.', 'buddyboss' ),
3 => __( 'There was a problem deleting your profile photo. Please try again.', 'buddyboss' ),
4 => __( 'Your profile photo was deleted successfully!', 'buddyboss' ),
5 => __( 'Missing image editor! Enable GD or Imagick library.', 'buddyboss' ),
);
} elseif ( ! empty( $group_id ) ) {
$script_data['bp_params'] = array(
Expand Down
4 changes: 4 additions & 0 deletions src/bp-core/classes/class-bp-attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ public static function edit_image( $attachment_type, $args = array() ) {
$editor = wp_get_image_editor( $r['file'] );

if ( is_wp_error( $editor ) ) {
if ( ! bb_is_gd_or_imagick_library_enabled() ) {
return new WP_Error( 'image_no_editor', esc_html__( 'Missing image editor! Enable GD or Imagick library.', 'buddyboss' ) );
}

return $editor;
}

Expand Down
10 changes: 5 additions & 5 deletions src/bp-core/classes/class-bp-background-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function dispatch() {
$dispatched = parent::dispatch();

if ( is_wp_error( $dispatched ) ) {
error_log( sprintf( 'Unable to dispatch BuddyPress updater: %s', $dispatched->get_error_message() ) );
bb_error_log( sprintf( 'Unable to dispatch BuddyPress updater: %s', $dispatched->get_error_message() ) );
}
}

Expand Down Expand Up @@ -104,7 +104,7 @@ protected function task( $callback ) {
}

if ( is_callable( $callback ) ) {
error_log( sprintf( 'Running %s callback', json_encode( $callback ) ) );
bb_error_log( sprintf( 'Running %s callback', json_encode( $callback ) ) );

if ( empty( $args ) ) {
$result = (bool) call_user_func( $callback, $this );
Expand All @@ -113,9 +113,9 @@ protected function task( $callback ) {
}

if ( $result ) {
error_log( sprintf( '%s callback needs to run again', json_encode( $callback ) ) );
bb_error_log( sprintf( '%s callback needs to run again', json_encode( $callback ) ) );
} else {
error_log( sprintf( 'Finished running %s callback', json_encode( $callback ) ) );
bb_error_log( sprintf( 'Finished running %s callback', json_encode( $callback ) ) );
}
} else {
error_log( sprintf( 'Could not find %s callback', json_encode( $callback ) ) );
Expand All @@ -131,7 +131,7 @@ protected function task( $callback ) {
* performed, or, call parent::complete().
*/
protected function complete() {
error_log( 'Data update complete' );
bb_error_log( 'Data update complete' );
parent::complete();
}

Expand Down
8 changes: 4 additions & 4 deletions src/bp-core/classes/class-bp-email-background-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function task( $callback ) {
}

if ( is_callable( $callback ) ) {
error_log( sprintf( 'Running %s callback', json_encode( $callback ) ) );
bb_error_log( sprintf( 'Running %s callback', json_encode( $callback ) ) );

if ( empty( $args ) ) {
$result = (bool) call_user_func( $callback, $this );
Expand All @@ -113,9 +113,9 @@ protected function task( $callback ) {
}

if ( $result ) {
error_log( sprintf( '%s callback needs to run again', json_encode( $callback ) ) );
bb_error_log( sprintf( '%s callback needs to run again', json_encode( $callback ) ) );
} else {
error_log( sprintf( 'Finished running %s callback', json_encode( $callback ) ) );
bb_error_log( sprintf( 'Finished running %s callback', json_encode( $callback ) ) );
}
} else {
error_log( sprintf( 'Could not find %s callback', json_encode( $callback ) ) );
Expand All @@ -131,7 +131,7 @@ protected function task( $callback ) {
* performed, or, call parent::complete().
*/
protected function complete() {
error_log( 'Data update complete' );
bb_error_log( 'Data update complete' );
parent::complete();
}

Expand Down
30 changes: 27 additions & 3 deletions src/bp-core/classes/trait-bp-rest-attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,22 @@ protected function upload_cover_from_file( $file ) {
);

// Bail if any error happened.
if ( false === $cover ) {
if ( ! $cover ) {

$error_message = esc_html__( 'There was a problem uploading the cover image.', 'buddyboss' );
$error_reason = 'unknown';

if ( ! bb_is_gd_or_imagick_library_enabled() ) {
$error_message = sprintf( esc_html__( 'Upload Error: %s', 'buddyboss' ), esc_html__( 'Missing image editor! Enable GD or Imagick library.', 'buddyboss' ) );
$error_reason = 'image_no_editor';
}

return new WP_Error(
"bp_rest_attachments_{$this->object}_cover_upload_error",
__( 'There was a problem uploading the cover image.', 'buddyboss' ),
$error_message,
array(
'status' => 500,
'reason' => 'unknown',
'reason' => $error_reason,
)
);
}
Expand Down Expand Up @@ -300,6 +309,21 @@ protected function resize( $file ) {

$resized = $this->avatar_instance->shrink( $file, $ui_available_width );

if ( is_wp_error( $resized ) ) {
return new WP_Error(
"bp_rest_attachments_{$this->object}_avatar_upload_error",
sprintf(
/* translators: %s: the upload error message */
__( 'Upload Error: %s', 'buddyboss' ),
$resized->get_error_message()
),
array(
'status' => 500,
'reason' => 'resize_error',
)
);
}

// We only want to handle one image after resize.
if ( empty( $resized ) ) {
$image_file = $file;
Expand Down
13 changes: 13 additions & 0 deletions src/bp-core/compatibility/bp-incompatible-plugins-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ function( $builder_load_requests ) {
if ( in_array( 'cdn-enabler/cdn-enabler.php', $bp_plugins ) && class_exists( 'CDN_Enabler_Engine' ) ) {
require buddypress()->compatibility_dir . '/class-bb-cdn-helpers.php';
}

/**
* Include plugin when plugin is activated.
* - Fixed the issue with user register and issue with clear API cache.
*
* Support AffiliateWP.
*
* @since BuddyBoss 2.6.40
*/
if ( function_exists( 'affwp_do_actions' ) ) {
remove_action( 'init', 'affwp_do_actions', 9 );
add_action( 'init', 'affwp_do_actions', 10 );
}
}

add_action( 'init', 'bp_helper_plugins_loaded_callback', 0 );
Expand Down
Loading

0 comments on commit 0b8020e

Please sign in to comment.