wpDiscuz - WordPress Comment Plugin
Share:
Notifications
Clear all

Change Frontend Appearance


nstoeckigt
Posts: 8
Topic starter
(@nstoeckigt)
Active Member
Joined: 1 year ago

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:

image

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!

9 Replies
nstoeckigt
Posts: 8
Topic starter
(@nstoeckigt)
Active Member
Joined: 1 year ago

to be more precise I want it to look like this:

image

 

and if the field has no value it should look like this

image

 

but of course this is a matter of logic in the code (change) itself.

 

...again thanks a lot for any help!

 

Reply
5 Replies
nstoeckigt
(@nstoeckigt)
Joined: 1 year ago

Active Member
Posts: 8

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

Spoiler
$showCity
+
+        $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>&nbsp;{CITY}&nbsp;
</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!

Reply
Asti
 Asti
Support
(@asti)
Joined: 4 years ago

Support member
Posts: 4131

@nstoeckigt,

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.  

image

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. 

Reply
nstoeckigt
(@nstoeckigt)
Joined: 1 year ago

Active Member
Posts: 8

Thanks again @asti,

unfortunately this doesn't work as expected. I changed the META_KEY to 'CITY' and also applied it to older entries.

image
$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.

Reply
Asti
 Asti
Support
(@asti)
Joined: 4 years ago

Support member
Posts: 4131

@nstoeckigt,

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. 

Reply
nstoeckigt
(@nstoeckigt)
Joined: 1 year ago

Active Member
Posts: 8

@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! 😍 

Reply
nstoeckigt
Posts: 8
Topic starter
(@nstoeckigt)
Active Member
Joined: 1 year ago

Any Idea from the wpdiscuz-Team itself?

Mayby you, @asti, might help me with this?

Reply
2 Replies
Asti
 Asti
Support
(@asti)
Joined: 4 years ago

Support member
Posts: 4131

@nstoeckigt,

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.

Reply
nstoeckigt
(@nstoeckigt)
Joined: 1 year ago

Active Member
Posts: 8

@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.

 

Reply
Share: