BuddyDev

Search

send message

  • Participant
    Level: Initiated
    Posts: 14
    Abhist on #45346

    i wnd to send buddypress message by PHP code for that i made function as given below

     function send_message(){
    
    messages_new_message(
      array(
        'sender_id'  => 10,
        'thread_id' => 0,
        'recipients' => 11 ,
        'subject'    => 'NOTICE',
        'content'    => 'HELLO',
      )
    );
    } 

    but this is not working and showing error

     Notice: Undefined property: BP_Messages_Component::$table_name_messages in /home/u992033758/domains/site.com/public_html/wp-content/plugins/buddypress/bp-messages/classes/class-bp-messages-message.php on line 143
    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1]
    SELECT MAX(thread_id) FROM
    
    Notice: Undefined property: BP_Messages_Component::$table_name_messages in /home/u992033758/domains/site.com/public_html/wp-content/plugins/buddypress/bp-messages/classes/class-bp-messages-message.php on line 148
    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( thread_id, sender_id, subject, message, date_sent ) VALUES ( 1, 10, 'NOTICE...' at line 1]
    INSERT INTO ( thread_id, sender_id, subject, message, date_sent ) VALUES ( 1, 10, 'NOTICE', 'HELLO', '2022-06-13 10:13:46' )

    please support

  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #45350

    You are calling it too early. Try calling it after init or even better bp_actions hook.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Abhist on #45352

    please elaborate- not understand

    above code is place in function.php in theme folder

  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #45354

    Please see
    https://codex.wordpress.org/Plugin_API/Action_Reference

    In case of WordPress, not everything is available immediately for use. There are some of the features which are enabled at certain stage of loading. For example, you may not use post type before init action and so on.

    If your code is loading early, you need to attach to one of the available hooks to make sure the code you are trying to use is available at that time.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved