BuddyDev

Search

Replies

  • Participant
    Level: Guru
    Posts: 885

    I found another solution below

     function disable_admin_new_user_registration_email( $wp_new_user_notification_email_admin, $user, $blogname )
    {
    	//Stop wp_mail() from working
    	add_filter( 'pre_wp_mail', '__return_false' );
    
    	//Return an unchanged value from this filter
    	return $wp_new_user_notification_email_admin;
    }
    add_filter( 'wp_new_user_notification_email_admin', 'disable_admin_new_user_registration_email', 10, 3 ); 
  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: Plugin question in relation to buddypress #50863

    Hello Brajesh

    Have you been able to test this plugin and see how if affects buddypress performance

    Thanks

  • Participant
    Level: Guru
    Posts: 885

    After all the stress there is something so simple

     add_filter('wp_new_user_notification_email', '__return_false');
     
  • Participant
    Level: Guru
    Posts: 885

    This code seemed to work

     // Disable new user registration email in WordPress for admin users only
    function disable_send_new_user_notifications($user_id, $notify = 'user') {
        // Check if user role is administrator
        $user_role = get_user_meta($user_id, 'wp_capabilities', true);
        if (isset($user_role['administrator'])) {
            // User is an administrator, skip sending notification
            return;
        }
    
        if (empty($notify) || 'admin' === $notify) {
            return;
        } elseif ('both' === $notify) {
            // Send new users the email but not the admin.
            $notify = 'user';
        }
        wp_send_new_user_notifications($user_id, $notify);
    }
    
    // Disable default email notifications
    add_action('init', function () {
        remove_action('register_new_user', 'wp_send_new_user_notifications');
        remove_action('edit_user_created_user', 'wp_send_new_user_notifications');
    
        // For BuddyPress
        remove_action('bp_core_activated_user', 'wp_send_new_user_notifications');
    
        // For WooCommerce
        remove_action('woocommerce_created_customer', 'wp_send_new_user_notifications');
    });
    
    // Replace default notifications with custom function
    add_action('register_new_user', 'disable_send_new_user_notifications');
    add_action('edit_user_created_user', 'disable_send_new_user_notifications', 10, 2);
    
    // For BuddyPress
    add_action('bp_core_activated_user', 'disable_send_new_user_notifications');
    
    // For WooCommerce
    add_action('woocommerce_created_customer', 'disable_send_new_user_notifications'); 
  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: [Resolved] auto follow featured members #50846

    I have done as you instructed with is_user_loggdin() but now how can I resolve the performance issue with count_user_posts and simplify the code

    Thanks

  • Participant
    Level: Guru
    Posts: 885

    Hello Ravi,

    I have added the processing and on-hold but the code did not empty the cart when the unpaid (pending) post was deleted. I aslo tried both empty cart and delete order together with code below

    
     function empty_cart_and_delete_order_on_pending_post_deletion( $post_id ) {
        $post = get_post($post_id);
    
        if ( ! $post ) {
            return;
        }
    
        if ($post->post_status === 'pending' && $post->post_type === 'post') {
            if (function_exists('bbl_ppp_get_post_order_id') && function_exists('wc_get_order')) {
                $order_id = bbl_ppp_get_post_order_id($post_id);
    
                if ($order_id) {
                    $order = wc_get_order($order_id);
    
                    if ($order && in_array($order->get_status(), array('processing', 'on-hold', 'pending', 'draft'))) {
                        // Empty the cart
                        WC()->cart->empty_cart(true);
    					
    		    // Delete the pending order
                        $order->delete_order(true);
                    }
                }
            }
        }
    }
    add_action('before_delete_post', 'empty_cart_and_delete_order_on_pending_post_deletion'); 
    

    This also did not work

  • Participant
    Level: Guru
    Posts: 885

    Gentle reminder sir thanks

  • Participant
    Level: Guru
    Posts: 885

    I tested the edited code but it did not work

  • Participant
    Level: Guru
    Posts: 885

    Thanks Ravi After giving this a better thought I think emptying woocommerec cart might be better so I edited your code

     function empty_cart_pending_post_order( $post_id, $post ) {
    	if ( empty( $post->post_type ) || 'post' !== $post->post_type ) {
    		return;
    	}
    
    	if ( ! function_exists( 'bbl_ppp_get_post_order_id' ) || ! function_exists( 'wc_get_order' ) || ! function_exists( 'WC' ) ) {
    		return;
    	}
    
    	$order_id = bbl_ppp_get_post_order_id( $post_id );
    
    	if ( $order_id ) {
    		$order = wc_get_order( $order_id );
    
    		if ( $order && in_array( $order->get_status(), array( 'pending', 'draft' ) ) ) {
    			// Empty the cart instead of deleting the order.
    			WC()->cart->empty_cart();
    		}
    	}
    }
    add_action( 'before_delete_post', 'empty_cart_pending_post_order', 10, 2 );
     
  • Participant
    Level: Guru
    Posts: 885

    Thanks for the feedback Ill like to proceed with this as my product setup is simple direct transactions and associated product orders only contain a single product related to the post. I set up 1 product per pricing. I dont use multiple products for the same order

    I have this example code below

     function delete_pending_post_order($post_id) {
        if (get_post_type($post_id) === 'post') {
            $order_id = get_post_meta($post_id, '_order_id', true);
    
            if ($order_id) {
                $order = wc_get_order($order_id);
    
                if ($order && in_array($order->get_status(), array('pending', 'draft'))) {
                    $order->delete(true);
                }
            }
        }
    }
    add_action('before_delete_post', 'delete_pending_post_order');