Cannot figure out how to change activity action verbs

Solved4.19K viewsCoreaction activity class-activity-helper.php
0

Hello,
I am trying to change the text that describes the last activity on a post (see below).

Based on a suggestion here: https://anspress.io/questions/question/some-translations-dont-seem-to-work/ I added this to my child theme’s functions.php but nothing was changed on the front end.

function my_ap_activity_actions( $actions ) {
$actions['status_publish']['verb'] = 'hello world';
return $actions;
}
add_filter( 'ap_activity_actions', 'my_ap_activity_actions' );


In class-activity-helper.php I found:

/**
* Filter allows adding new activity actions. This hook is only called once
* while class initiate. Hence, later filters will not work. Also make sure
* to keep array key length less then 20 characters.
*
* @param array $actions Originally registered actions.
* @since 4.1.2
*/
$actions = apply_filters( 'ap_activity_actions', $defaults );


I think ‘later filters will not work’ is why adding the code above to my functions.php is not working.
I also tried using the Code Snippets plugin that worked for itomhq but that did not work for me.
So, what is the proper way for me to change the activity actions text?
Thanks
robertg

Question is closed for new answers.
Selected answer as best
0

The solution I came up with is similar to what worked for itomhq – use a plugin.
In my case, using the Code Snippets plugin did not work but creating my own plugin did.
This is the code in my plugin’s file:

function iatd_ap_activity_actions( $actions ) {
    $actions['status_publish']['verb'] = 'Approved question';
 $actions['status_trash']['verb'] = 'Updated question';
    return $actions;
}
add_filter( 'ap_activity_actions', 'iatd_ap_activity_actions' );


I found the actions (e.g., ‘status_publish’ and ‘status_trash’) in /plugins/anspress-question-answer/includes/class/class-activity-helper.php.
I also wanted to change some short titles (I’m not sure how or why these are different from verbs but they are) so I also have this code in my plugin:

function iatd_ap_activity_short_title( $type ) {
 $title['new_question'] = 'Asked question';
 $title['approved_question'] = 'Approved question';
 $title['approved_answer'] = 'Approved answer';
 $title['new_answer'] = 'Answered question';
 $title['delete_answer'] = 'Deleted answer';
 $title['restore_question'] = 'Restored question';
 $title['restore_answer'] = 'Restored answer';
 $title['new_comment'] = 'Commented';
 $title['delete_comment'] = 'Deleted comment';
 $title['new_comment_answer'] = 'Commented';
 $title['edit_question'] = 'Edited question';
 $title['edit_answer'] = 'Edited answer';
 $title['edit_comment'] = 'Edited comment';
 $title['edit_comment_answer'] = 'Edited comment';
 $title['answer_selected'] = 'Selected answer';
 $title['answer_unselected'] = 'Unselected answer';
 $title['status_updated'] = 'Updated status';
 $title['best_answer'] = 'Selected as best answer';
 $title['unselected_best_answer'] = 'Unselected as best answer';
 $title['changed_status'] = 'Changed status';
   return $title;
}
add_filter( 'ap_activity_short_title', 'iatd_ap_activity_short_title' );


note: I am not sure why, but I needed to redefine all titles even those I didn’t want to change.  If I didn’t redefine them all, the ones that were not redefined displayed, for example, ‘new_comment’ instead of ‘Commented’.
I found the titles in /plugins/anspress-question-answer/includes/functions.php
I have not stress tested this solution too much but it appears to be working so I thought I’d documented what I did in case it could help someone.
Thanks.

Selected answer as best