Hi,
I managed to add an additional field to the comment box - name: 'city'.
Now I want to display this like:
Tim from LondonΒ - 3 days ago
...
but I only managed to show this in the backend were you manage the comments in wp:
Can you point me towards the direction where to change what to archive what I'm looking for?
Is there anything you also need to know to be able to help me?
Thanks in advance!
to be more precise I want it to look like this:
Β
and if the field has no value it should look like this
Β
but of course this is a matter of logic in the code (change) itself.
Β
...again thanks a lot for any help!
Β
Sorry for the late response.Β
We're really sorry, but there is not any simple solution we can post here. We may suggest you use the wpdiscuz_comment_authorΒ hook for this customization.
In case you want to say thank you! π
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.
@asti Thank you, at least this is a "point towards the direction where to change what to archive what I'm looking for"!
I update this Post when I find a solution to let you all know what to do in similar cases.
Β
I managed to insert the desired field into the code:
- $headerComponent = str_replace(["{AUTHOR}", "{DATE}", "{STATUS}", "{SHARE}", "{LINK}"], [$args["components"]["author.html"], $showDate ? $args["components"]["date.html"] : "", $showStatus ? $args["components"]["status.html"] : "", $showShare ? $args["components"]["share.html"] : "", $showLink ? $args["components"]["link.html"] : ""], $args["components"]["header.html"]);
+ $headerComponent = str_replace(["{AUTHOR}", "{CITY}", "{DATE}", "{STATUS}", "{SHARE}", "{LINK}"], [$args["components"]["author.html"], $showCity ? $args["components"]["city.html"] : "", $showDate ? $args["components"]["date.html"] : "", $showStatus ? $args["components"]["status.html"] : "", $showShare ? $args["components"]["share.html"] : "", $showLink ? $args["components"]["link.html"] : ""], $args["components"]["header.html"]);
the related variable (is) should be evaluated like
+
+ $showCity = false;
+ //$city .= apply_filters("wpdiscuz_comment_city", "", $comment, $user["user"], $args["city"]);
+ //$city = isset($commentMetas[self::META_KEY_CITY]) ? strval($commentMetas[self::META_KEY_CITY]);
+ $city .= 'London';
+ if ($city) {
+ $search[] = "{CITY_WRAPPER_CLASSES}";
+ $search[] = "{PRE_CITY}";
+ $search[] = "{CITY}";
+ $replace[] = "wpd-comment-city";
+ $replace[] = "from"; //TODO: language depended 'from'
+ $replace[] = $city;
+ $showCity = true;
+ }
+
The [code]city.html[/code] is simple as:
<div class="{CITY_WRAPPER_CLASSES}">
<span class="pre">{PRE_CITY}</span> {CITY}
</div>
My Problem now is that I did not manage to load the META-VAR {CITY} - which is saved with the comment - from the database. Both variants (see above) won't work.
How do I get the value?
Β
...and how can I make my changes persistent without loosing them on Update/Upgrade of the Plugin? Simply copy the changes to the 'plugins' folder of my Child-Theme?
Thanks for any constructive help!
The update safe way for this kind of customization is described here: https://wpdiscuz.com/docs/wpdiscuz-7/customization/custom-template-and-style/
I may suggest you to get the value of the city field using the $commentMetas variable in the class.WpdiscuzWalker.php file.
The meta_key you can find by editing the current field, click on the "Advanced Options" button.Β Β
Here is an example:Β
isset($commentMetas["META_KEY"][0]) ? $commentMetas["META_KEY"][0] : ""
You'll need to change the red marked part with corresponding meta_key.Β
In case you want to say thank you! π
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.
Thanks again @asti,
unfortunately this doesn't work as expected. I changed the META_KEY to 'CITY' and also applied it to older entries.
$city = isset($commentMetas["CITY"][0]) ? $commentMetas["CITY"][0] : "";
but it seems the Key is not in the List. I failed to `print_r` or `var_dump` the variable so I can't say for sure.
In the Database in Table `commentmeta` I see entries like
| meta_id | comment_id | meta_key | meta_value |
|---|---|---|---|
| 50 | 9 | city | Dublin |
Β It doesn't matter if I write the `meta_key` in upper or lower case.
In our case the solution works fine.Β
Could you please send the admin login details to info[at]gvectors.com email address? I'll ask the developers to check the issue.Β
In case you want to say thank you! π
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.
@asti
I upgraded to the last recent version and pushed back my changes. When my customer checked with the results a few days later we realized that the changes in fact work as intended.
I will post a final message recompiling all my changes so others my implement the same or similar solutions.
Thanks for your help! 😍Β
Hi @ll,
finally I will summarize what I have done to archive this. It might inspire in similar situation.
Start by adding your additional Field in your Form
You might want to change the META-KEY under Advanced Options to something more readable to use in your code.
Have a look into the Database in Table `commentmeta` to see the real META-KEY because it is case-sensitive!
| meta_id | comment_id | meta_key | meta_value |
|---|---|---|---|
| 50 | 9 | city | Dublin |
In my case, even I wrote the META-KEY in uppercase on the Form Editor, it is saved in lowercase to the database.
Now you can start coding.
Create a Child-Theme to make all your changes update proof!
Add the following folder structure to it:
wpdiscuz/
βββ class.WpdiscuzWalker.php
βββ layouts
βββ 1
βΒ Β βββ author.html
βΒ Β βββ city.html
βΒ Β βββ header.html
βΒ Β βββ style.css
Create the fileΒ city.htmlΒ is simple as:
<div class="{HEADER_WRAPPER_CLASSES}">
{AUTHOR}
{CITY}
{DATE}
{STATUS}
{SHARE}
<div class="wpd-space"></div>
{LINK}
</div>
#wpdcom .wpd-comment-header .wpd-comment-city{ }
#wpdcom .wpd-comment-header .wpd-comment-city .pre{font-style: italic;}
@@ -93,6 +93,33 @@
$commentWrapperClass[] = "wpd-reply";
}
+ $showCity = false;
+ $city = isset($commentMetas["city"][0]) ? strval($commentMetas["city"][0]) : "";
+ if ($city) {
+ $search[] = "{CITY_WRAPPER_CLASSES}";
+ $search[] = "{PRE_CITY}";
+ $search[] = "{CITY}";
+ $replace[] = "wpd-comment-city";
+ switch( get_locale() ) {
+ case 'de_DE':
+ $replace[] = "aus";
+ break;
+ case 'fr_FR':
+ case 'es_ES':
+ $replace[] = "de";
+ break;
+ case 'it_IT':
+ $replace[] = "da";
+ break;
+ case 'pl_PL':
+ $replace[] = "z";
+ break;
+ default:
+ $replace[] = "from";
+ }
+ $replace[] = $city;
+ $showCity = true;
+ }
+
$showDate = false;
if ($this->options->thread_layouts["showCommentDate"]) {
@@ -429,7 +451,8 @@
$replace[] = $content . $comment->comment_content;
$replace[] = "wpd-comment-left " . esc_attr($commentLeftClass);
$leftComponent = $showAvatar || $showLabel || $showFollow ? str_replace(["{AVATAR}", "{LABEL}", "{FOLLOW}"], [$showAvatar ? $args["components"]["avatar.html"] : "", ($showLabel ? $args["components"]["label.html"] : "") . apply_filters("wpdiscuz_after_label", "", $comment), $showFollow ? $args["components"]["follow.html"] : ""], $args["components"]["left.html"]) : "";
- $headerComponent = str_replace(["{AUTHOR}", "{DATE}", "{STATUS}", "{SHARE}", "{LINK}"], [$args["components"]["author.html"], $showDate ? $args["components"]["date.html"] : "", $showStatus ? $args["components"]["status.html"] : "", $showShare ? $args["components"]["share.html"] : "", $showLink ? $args["components"]["link.html"] : ""], $args["components"]["header.html"]);
+// $headerComponent = str_replace(["{AUTHOR}", "{DATE}", "{STATUS}", "{SHARE}", "{LINK}"], [$args["components"]["author.html"], $showDate ? $args["components"]["date.html"] : "", $showStatus ? $args["components"]["status.html"] : "", $showShare ? $args["components"]["share.html"] : "", $showLink ? $args["components"]["link.html"] : ""], $args["components"]["header.html"]);
+ $headerComponent = str_replace(["{AUTHOR}", "{CITY}", "{DATE}", "{STATUS}", "{SHARE}", "{LINK}"], [$args["components"]["author.html"], $showCity ? $args["components"]["city.html"] : "", $showDate ? $args["components"]["date.html"] : "", $showStatus ? $args["components"]["status.html"] : "", $showShare ? $args["components"]["share.html"] : "", $showLink ? $args["components"]["link.html"] : ""], $args["components"]["header.html"]);
$footerComponent = $showVote || $showReply || $afterReplyButton || $showTools || $showToggle ? str_replace(["{VOTE}", "{REPLY}", "{TOOLS}", "{TOGGLE}"], [$showVote ? $args["components"]["vote.html"] : "", ($showReply ? $args["components"]["reply.html"] : "") . $afterReplyButton, $showTools ? $args["components"]["tools.html"] : "", $showToggle ? $args["components"]["toggle.html"] : ""], $args["components"]["footer.html"]) : "";
$rightComponent = str_replace(["{HEADER}", "{REPLY_TO}", "{TEXT}", "{FOOTER}"], [$headerComponent, $showReplyTo ? $args["components"]["reply_to.html"] : "", $args["components"]["text.html"] . $lastEdited, $footerComponent], $args["components"]["right.html"]);
$wrapperComponent = str_replace(["{LEFT}", "{RIGHT}"], [$leftComponent, $rightComponent], $args["components"]["wrapper.html"]);
I found an error which I can't correct in my previous Post so here is the correct folder structure within your child theme:
Add the following folder structure to it:
wpdiscuz/
βββ class.WpdiscuzWalker.php
βββ layouts/
βΒ Β βββ 1/
βΒ Β βΒ Β Β βββ author.html
βΒ Β βΒ Β Β βββ city.html
βΒ Β βΒ Β Β βββ header.html
βΒ Β βΒ Β Β βββ style.cssΒ Β








