diff --git a/src/bp-activity/bp-activity-filters.php b/src/bp-activity/bp-activity-filters.php index d542b9da73..e0fa806265 100644 --- a/src/bp-activity/bp-activity-filters.php +++ b/src/bp-activity/bp-activity-filters.php @@ -192,8 +192,6 @@ add_filter( 'bp_ajax_querystring', 'bb_activity_directory_set_pagination', 20, 2 ); -add_filter( 'bb_is_enabled_activity_schedule_posts', 'bb_is_enabled_activity_schedule_posts_filter', 999 ); - /** Functions *****************************************************************/ /** @@ -3788,33 +3786,3 @@ function bb_activity_directory_set_pagination( $querystring, $object ) { return http_build_query( $querystring ); } - -/** - * Load the class to schedule the activity post. - * - * @since BuddyBoss [BBVERSION] - */ -function bb_activity_init_activity_schedule() { - BB_Activity_Schedule::instance(); -} - -add_action( 'bp_init', 'bb_activity_init_activity_schedule' ); - -/** - * Filter to check platform pro enabled for scheduled posts. - * - * @since BuddyBoss [BBVERSION] - * - * @param bool $value Schedule posts setting value. - * - * @return bool $value Filtered schedule posts setting value. - */ -function bb_is_enabled_activity_schedule_posts_filter( $value ) { - - // Return false if platform pro is disabled. - if ( ! function_exists( 'bb_platform_pro' ) ) { - $value = false; - } - - return $value; -} diff --git a/src/bp-activity/bp-activity-functions.php b/src/bp-activity/bp-activity-functions.php index 3eff2c83c8..c907ed3059 100644 --- a/src/bp-activity/bp-activity-functions.php +++ b/src/bp-activity/bp-activity-functions.php @@ -6128,7 +6128,9 @@ function bb_activity_migration( $raw_db_version, $current_db ) { } } - bb_create_activity_schedule_cron_event(); + if ( bp_is_active( 'activity' ) && class_exists( 'BB_Schedule_Posts' ) ) { + BB_Schedule_Posts::bb_create_activity_schedule_cron_event(); + } } /** @@ -7186,55 +7188,6 @@ function bb_is_enabled_activity_schedule_posts( $default = false ) { return (bool) apply_filters( 'bb_is_enabled_activity_schedule_posts', (bool) bp_get_option( '_bb_enable_activity_schedule_posts', $default ) ); } -/** - * Check whether user can schedule activity or not. - * - * @since BuddyBoss [BBVERSION] - * - * @param array $args Array of Arguments. - * - * @return bool true if user can post schedule posts, otherwise false. - */ -function bb_can_user_schedule_activity( $args = array() ) { - $r = bp_parse_args( - $args, - array( - 'user_id' => bp_loggedin_user_id(), - 'object' => '', - 'group_id' => 0, - ) - ); - - $retval = false; - if ( - bp_is_active( 'groups' ) && - ( - 'group' === $r['object'] || - bp_is_group() - ) && - bp_user_can( $r['user_id'], 'administrator' ) - ) { - $group_id = 'group' === $r['object'] && ! empty( $r['group_id'] ) ? $r['group_id'] : bp_get_current_group_id(); - $is_admin = groups_is_user_admin( $r['user_id'], $group_id ); - $is_mod = groups_is_user_mod( $r['user_id'], $group_id ); - if ( $is_admin || $is_mod ) { - $retval = true; - } - } elseif ( bp_user_can( $r['user_id'], 'administrator' ) ) { - $retval = true; - } - - /** - * Filters whether user can schedule activity posts. - * - * @since BuddyBoss [BBVERSION] - * - * @param bool $retval Return value for schedule post. - * @param array $args Array of Arguments. - */ - return apply_filters( 'bb_can_user_schedule_activity', $retval, $args ); -} - /** * Return the activity published status. * @@ -7256,17 +7209,3 @@ function bb_get_activity_published_status() { function bb_get_activity_scheduled_status() { return buddypress()->activity->scheduled_status; } - -/** - * Create activity schedule cron event if not exists. - * - * @since BuddyBoss [BBVERSION] - */ -function bb_create_activity_schedule_cron_event() { - - if ( class_exists( 'BB_Activity_Schedule' ) ) { - if ( ! wp_next_scheduled( 'bb_activity_publish' ) ) { - wp_schedule_event( time(), 'bb_schedule_1min', 'bb_activity_publish' ); - } - } -} diff --git a/src/bp-activity/classes/class-bb-activity-schedule.php b/src/bp-activity/classes/class-bb-activity-schedule.php deleted file mode 100644 index bcad3d5795..0000000000 --- a/src/bp-activity/classes/class-bb-activity-schedule.php +++ /dev/null @@ -1,184 +0,0 @@ -id ) || in_array( $activity->privacy, array( 'media', 'video', 'document') ) || bb_get_activity_scheduled_status() !== $activity->status ) { - return; - } - - bb_create_activity_schedule_cron_event(); - } - - /** - * Get all the scheduled activities and publish it. - * - * @since BuddyBoss [BBVERSION] - * - * @return void - */ - public function bb_check_and_publish_scheduled_activity() { - global $wpdb; - - $bp_prefix = bp_core_get_table_prefix(); - $current_time = bp_core_current_time(); - $scheduled_status = bb_get_activity_scheduled_status(); - $published_status = bb_get_activity_published_status(); - - // Get all activities that are scheduled and past due. - $activities = $wpdb->get_results( - $wpdb->prepare( - "SELECT id FROM {$bp_prefix}bp_activity - WHERE type='activity_update' AND privacy NOT IN ( 'media', 'video', 'document' ) AND status = %s AND date_recorded <= %s", - $scheduled_status, $current_time - ) - ); - - foreach ( $activities as $scheduled_activity ) { - $activity = new BP_Activity_Activity( $scheduled_activity->id ); - - if ( $activity ) { - - // Publish the activity. - $activity->status = $published_status; - $activity->save(); - - // Remove edited time from scheduled activities. - bp_activity_delete_meta( $activity->id, '_is_edited' ); - - $metas = bb_activity_get_metadata( $activity->id ); - - // Publish the media. - if ( ! empty( $metas['bp_media_ids'][0] ) ) { - $media_ids = explode( ',', $metas['bp_media_ids'][0] ); - $this->bb_publish_schedule_activity_medias_and_documents( $media_ids ); - } - - // Publish the video. - if ( ! empty( $metas['bp_video_ids'][0] ) ) { - $video_ids = explode( ',', $metas['bp_video_ids'][0] ); - $this->bb_publish_schedule_activity_medias_and_documents( $video_ids, 'video' ); - } - - // Publish the document. - if ( ! empty( $metas['bp_document_ids'][0] ) ) { - $document_ids = explode( ',', $metas['bp_document_ids'][0] ); - $this->bb_publish_schedule_activity_medias_and_documents( $document_ids, 'document' ); - } - - // Send mentioned notifications. - add_filter( 'bp_activity_at_name_do_notifications', '__return_true' ); - - if ( ! empty( $activity->item_id ) ) { - bb_group_activity_at_name_send_emails( $activity->content, $activity->user_id, $activity->item_id, $activity->id ); - bb_subscription_send_subscribe_group_notifications( $activity->content, $activity->user_id, $activity->item_id, $activity->id ); - } else { - bb_activity_at_name_send_emails( $activity->content, $activity->user_id, $activity->id ); - } - - bb_activity_send_email_to_following_post( $activity->content, $activity->user_id, $activity->id ); - } - } - } - - /** - * Publish scheduled activity media/video/document and their individual activities. - * - * @since BuddyBoss [BBVERSION] - * - * @param array $ids Ids of media/video/document. - * @param string $type Media type : 'media', 'video', 'document'. - */ - public function bb_publish_schedule_activity_medias_and_documents( $ids, $type = 'media' ) { - global $wpdb; - - if ( ! empty( $ids ) ) { - $bp_prefix = bp_core_get_table_prefix(); - $table_name = "{$bp_prefix}bp_media"; - if ( 'document' === $type ) { - $table_name = "{$bp_prefix}bp_document"; - } - - // Check table exists. - $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ); - if ( $table_exists ) { - foreach ( $ids as $id ) { - $wpdb->query( $wpdb->prepare( "UPDATE {$table_name} SET status = 'published' WHERE id = %d", $id ) ); - - // Also update the individual medias/videos/document activity. - if ( count( $ids ) > 1 ) { - $activity_id = $wpdb->get_var( $wpdb->prepare( "SELECT activity_id FROM {$table_name} WHERE id = %d", $id ) ); - $activity = new BP_Activity_Activity( $activity_id ); - $activity->status = bb_get_activity_published_status(); - $activity->save(); - } - } - } - } - } - } -} diff --git a/src/bp-core/admin/settings/bp-admin-setting-activity.php b/src/bp-core/admin/settings/bp-admin-setting-activity.php index cdfdda2d3c..eaeb633833 100644 --- a/src/bp-core/admin/settings/bp-admin-setting-activity.php +++ b/src/bp-core/admin/settings/bp-admin-setting-activity.php @@ -87,13 +87,13 @@ public function register_fields() { // Allow scopes/tabs. $this->add_field( '_bb_enable_activity_pinned_posts', __( 'Pinned Post', 'buddyboss' ), 'bb_admin_setting_callback_enable_activity_pinned_posts', 'intval' ); - remove_filter( 'bb_is_enabled_activity_schedule_posts', 'bb_is_enabled_activity_schedule_posts_filter', 999 ); + // remove_filter( 'bb_is_enabled_activity_schedule_posts', 'bb_is_enabled_activity_schedule_posts_filter', 999 ); $args = array(); $args['class'] = esc_attr( $pro_class ); $this->add_field( '_bb_enable_activity_schedule_posts', __( 'Schedule posts', 'buddyboss' ) . bb_get_pro_label_notice(), array( $this, 'bb_admin_setting_callback_enable_activity_schedule_posts' ), 'intval', $args ); - add_filter( 'bb_is_enabled_activity_schedule_posts', 'bb_is_enabled_activity_schedule_posts_filter', 999 ); + // add_filter( 'bb_is_enabled_activity_schedule_posts', 'bb_is_enabled_activity_schedule_posts_filter', 999 ); // Allow follow. $this->add_field( '_bp_enable_activity_follow', __( 'Follow', 'buddyboss' ), 'bp_admin_setting_callback_enable_activity_follow', 'intval' ); diff --git a/src/bp-templates/bp-nouveau/buddypress/common/js-templates/activity/parts/bb-activity-schedule-post.php b/src/bp-templates/bp-nouveau/buddypress/common/js-templates/activity/parts/bb-activity-schedule-post.php index d7366f6298..db3c24d052 100644 --- a/src/bp-templates/bp-nouveau/buddypress/common/js-templates/activity/parts/bb-activity-schedule-post.php +++ b/src/bp-templates/bp-nouveau/buddypress/common/js-templates/activity/parts/bb-activity-schedule-post.php @@ -11,7 +11,7 @@ ?>