Please or Register to create posts and topics.

Add action in new function php

I tried to make a new function, and paste it in the Asgaros forum … in that function,

I want to take the author id variable from each new topic,

I tried entering the $author_id variable, but it displays something that is not appropriate is there an example to get the variable I want?

 

Thank you very much 🙂

function notifForum($topic_name){

    $content = array(
        "en"  => $topic_name.' Topic Baru Saja Di Tambahkan'
        );
}

add_action('asgarosforum_after_post_author', 'notifForum' , 10 , 1);

it only produces  : 69 Topic Baru Saja Di Tambahkan !,

 

how to get the name of the topic author ???

 

 

any answer I will appreciate

tanks.

Hello @kapitayan

What exactly do you plan to do with those variables. Depending on what you want to code and during which time you need access to those variables, you have to use different hooks.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

so I added a special function sent to the onesignal notification,
by following the onesignal script rules, i managed to make it work by inserting a php script in the forum ,,

I want the topic title and topic creator to also be visible on the notification …

do I need another code from asgaros or do I need to add other functions, please tell me clearer direction, thank you

function notifForum($title){

    $content = array(
        "en"  => $title.' Topic Baru Saja Di Tambahkan'
        );

    $hashes_array = array();
    array_push($hashes_array, array(
        "id" => "like-button",
        "text" => "Like",
        "icon" => "http://i.imgur.com/N8SN8ZS.png",
        "url" => "https://forummep.com"
    ));


    $fields = array(
        'app_id' => "XXXXXXX-2b9b-415d-bb1e-c2655d0db2c3",
        'include_player_ids' => array("XXXXXX-929e-40e9-94a8-65e5262ced38"),
        'data' => array("foo" => "bar"),
        'large_icon' =>"ic_launcher_round.png",
        'contents' => $content,
        'web_buttons' => $hashes_array
    );

    $fields = json_encode($fields);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
                                               'Authorization: Basic ODM0ZWEzNTYtM2IwZi00ODgxLWJhNjItZmNkMzI5Zjg5OGEy'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
  }

  add_action('asgarosforum_after_post_author', 'notifForum' , 10 , 1);

 

here’s the script

 

 

Hello @kapitayan

I guess that the message should be sent after creating a new topic or post. So you have to use one of the following – or both – hooks:

  • asgarosforum_after_add_post_submit
  • asgarosforum_after_add_topic_submit

The hooks take the following arguments (in this order):

  • post-ID
  • topic-ID
  • title
  • content
  • link
  • author-ID
If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Helo @asgaros

Thank you for answering.
but I have implemented my code with your asgaros forum ,,

I have successfully retrieved that variable in my message script,
I have added a little script in your forum-content.php file and I directed it to forum-notification.php,
and it worked ..
whether it will make a gap in the future I do not know,

please let me know whether my way will affect other scripts in the forum, thanks ,,

$this->asgarosforum->notifications->KaNotif($this->asgarosforum->current_topic, $receivers); //in the forum-content.php 


   function KaNotif($topic_id, $ignore_list = false){
    

   
        $post = $this->asgarosforum->content->get_first_post($topic_id);
        $topic = $this->asgarosforum->content->get_topic($post->parent_id);
        $forum = $this->asgarosforum->content->get_forum($topic->parent_id);

    
        $post = $this->asgarosforum->content->get_first_post($topic_id);
        $topic = $this->asgarosforum->content->get_topic($post->parent_id);
        $forum = $this->asgarosforum->content->get_forum($topic->parent_id);

     
        $topic_link = $this->asgarosforum->rewrite->get_link('topic', $topic_id);
        $topic_name = esc_html(stripslashes($topic->name));
        $author_name = $this->asgarosforum->getUsername($topic->author_id);
        $nama     = strip_tags($author_name);

        
        $content = array(
        "en" => $nama.' Membuat Sebuah Topic '.$topic_name
        );

    $fields = array(
        'app_id' => "xxxxxx-c253-49a6-a44b-5c06bd6b8c4a",
        'include_player_ids' => array("xxxx7-cb2c-4234-8cce-47afb5170a4e"),
        'data' => array("foo" => "bar"),
        'large_icon' =>"ic_launcher_round.png",
        'contents' => $content
    );

    $fields = json_encode($fields);
     
    

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
                                               'Authorization: Basic xxxxxxxBhLTliMWItNGE5OTE0YTg5NmJk'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
    } //in the forum-notification.php

 

Hello @kapitayan

Looks fine so far. But keep in mind that with this solution you have to re-apply your changes after an update. So keep a backup of your modifications. 🙂

kapitayan has reacted to this post.
kapitayan
If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!