snoepys
Forum Replies Created
-
Forum: Plugins
In reply to: [Site Reviews] Slack IntegrationNow It Works!!!!! WOW!!! ??
Your plugin and your support really are the best that I have found ever!
Never imagine that only need to replace $this with $slack, but it has all the sense, haha.
You saved my day, Sir!
Thank you a lot!
Forum: Plugins
In reply to: [Site Reviews] Slack IntegrationSame ??
This is the code implemented:
function site_reviews_modify_slack_notification($notification, $slack) {
$fields = $notification[‘attachments’][‘fields’];// START: Remove the IP address
/* if (isset($fields[3][‘value’])) {
$fields[3][‘value’] = str_replace($slack->review->ip_address, ”, $fields[3][‘value’]);
$fields[3][‘value’] = trim($fields[3][‘value’], ‘ -‘);
}*/
// END: Remove the IP address// START: Add the assigned post titles
$posts = $this->review->assignedPosts();
$postTitles = array_filter(wp_list_pluck($posts, ‘post_title’));
if (!empty($postTitles)) {
$titles = \GeminiLabs\SiteReviews\Helpers\Str::naturalJoin($postTitles);
$fields[] = [
‘value’ => ‘Review of: ‘.$titles,
];
}
// END: Add the assigned post titles$notification[‘attachments’][‘fields’] = $fields;
return $notification;
}
add_filter(‘site-reviews/slack/compose’, ‘site_reviews_modify_slack_notification’, 10, 2);Maybe I need to add something in the functions.php like in core slack.php?
use GeminiLabs\SiteReviews\Database\OptionManager;
use GeminiLabs\SiteReviews\Defaults\SlackDefaults;
use GeminiLabs\SiteReviews\Review;
use WP_Error;
use WP_Post;
use GeminiLabs\SiteReviews\Helpers\Str;Forum: Plugins
In reply to: [Site Reviews] Slack IntegrationYes, I have deleted all and put only your snippet.
Forum: Plugins
In reply to: [Site Reviews] Slack IntegrationHi! Thank you a lot for the code!
Maybe is some incompatibility with my child theme, because it doesn’t send data to the webhook. ??
Don’t worry. I will use the core and make changes in every plugin update.
Anyways, thank you a lot again for your help. it has been the best!!! ??
Forum: Plugins
In reply to: [Site Reviews] Slack IntegrationSorry again for my inexperience and for disturbing you with so many posts, English is not my native language. But after almost an hour I still can’t get it works. If I put this code:
function site_reviews_modify_slack_notification($notification, $slack) {
$fields = $notification[‘attachments’][‘fields’][] = [
‘value’ => $this->review->assignedPosts() // add a new line to the notification here
];
$posts = $this->review->assignedPosts();
$postTitles = array_filter(wp_list_pluck($posts, ‘post_title’));$notification[‘attachments’][‘fields’] = $fields;
return $notification;
}
add_filter(‘site-reviews/slack/compose’, ‘site_reviews_modify_slack_notification’, 10, 2);It doesn’t send the data to Slack.
Only send the data with plain text with this code:
function site_reviews_modify_slack_notification($notification, $slack) {
$fields = $notification[‘attachments’][‘fields’][] = [
‘value’ => ‘$this->review->assignedPosts()’ // add a new line to the notification here
];
$notification[‘attachments’][‘fields’] = $fields;
return $notification;
}
add_filter(‘site-reviews/slack/compose’, ‘site_reviews_modify_slack_notification’, 10, 2);And, the webhook only receive this text:
attachments/fields: $this->review->assignedPosts()
attachments/fields/value: $this->review->assignedPosts()Forum: Plugins
In reply to: [Site Reviews] Slack IntegrationHi! I have tried with:
function site_reviews_modify_slack_notification($notification, $slack) {
$fields = $notification[‘attachments’][‘fields’][] = [
‘value’ => ‘post_title’ // add a new line to the notification here
];}
add_filter(‘site-reviews/slack/compose’, ‘site_reviews_modify_slack_notification’, 10, 2);And the webhook prints: No data received
if i add the ; after ‘value’ => ‘post_title’;];
The editor sais that expecting error with the ;Also, I have tried with ‘value’ => ‘$this->review->email’
And same, no data received. ??
Forum: Plugins
In reply to: [Site Reviews] Slack IntegrationHi!
1.- Yes, I Know. But really don’t know how to add the new field with the link in functions.php. Maybe is related to these 2 lines?
use WP_Post;
use GeminiLabs\SiteReviews\Helpers\Str;2.- Ok!
3.- Nice! I can use the same function in order to add the post title in a new field, like fields[4]? Or it’s only to modify an existing field?
Sorry about so many questions, I am new in php.
Thank you a lot!
Forum: Plugins
In reply to: [Site Reviews] Slack IntegrationHi again, and sorry for the double post. Finally, I have found the solution after adding at the top of Slack.php these 2 lines:
use WP_Post;
use GeminiLabs\SiteReviews\Helpers\Str;??
At this moment, only need to make it works in functions.php instead of modifying the slack.php file.
Forum: Plugins
In reply to: [Site Reviews] Slack IntegrationHi! Thank you for your fast answer.
I cannot achieve that in functions.php of my theme. But it works if I modify the plugin in Slack.php adding these lines:
protected function buildFields()
{
$fields = [
$this->buildStarsField(),
$this->buildTitleField(),
$this->buildContentField(),
$this->buildAuthorField(),
$this->buildEmailField(),
$this->buildUrlField(),
];
return array_filter($fields);
}protected function buildEmailField()
{
$email = !empty($this->review->email)
? ‘<‘.$this->review->email.’>’
: ”;
$author = trim(rtrim($this->review->author).’ ‘.$email);
return [‘value’ => implode(‘ – ‘, array_filter([$this->review->email]))];
}/**
* @return array
*/
protected function buildUrlField()
{
$posts = $this->review->assignedPosts();
$postTitles = array_filter(wp_list_pluck($posts, ‘post_title’));
return Str::naturalJoin($postTitles);
}The problem is that I can’t get the Post_Title. When I use the buildUrlField Slack didn’t receive the webhook. But, if I delete buildUrlField it sends to slack without the URL.
I have tried to retreive only the URL via:
global $wp;
$current_url = home_url( add_query_arg( array(), $wp->request ) );But only get the home URL, not the post URL.
And with this code:
$actual_link = “https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]”;
return $actual_link;It prints https://mydomain.com/wp-cron.php
What I am doing wrong?
Hi! And sorry for the delay!
The website isn’t yet live. Is under construction.
With the CSS already posted, it works fine. Is there another code better?
Thank you for your kind answer! ??