dashed-slug.net › Forums › Tip the Author extension support › Change Button Text
- This topic has 6 replies, 2 voices, and was last updated 3 years, 7 months ago by alexg.
-
AuthorPosts
-
April 13, 2021 at 6:59 pm #10370AnonymousInactive
Hello,
I want to say thank you for your work on these awesome WP Plugins.
I am wondering if there is any way I would be able to change the ‘☞ Tip the Author’ button text to something different (simply ‘Tip’ or ‘Tip the Creator’ would be fine.)
If there was a code snippet you might be able to provide or the option to change some of the plugin’s text options in a future update (after Wallets6, which I have read that you’ve been busy working on), that would be great!
Kind Regards
April 14, 2021 at 6:30 am #10371alexgKeymasterHello and welcome!
Thank you for your interest in the plugins.
The button text is filterable with the WordPress filter
wallets_tips_tip_the_author
.To change the text, you could add the following code in your theme’s
functions.php
file:add_filter( 'wallets_tips_tip_the_author', function( $text ) { return 'YOUR TEXT HERE'; } );
Furthermore, if you wish to modify the UI in some other way, including the button text, you can copy and modify the UI template. Templates are described in the release notes for version 5.0.0: https://www.dashed-slug.net/wallets-5-0-0/
In short, you can do this:
1. Copy the file
wp-content/plugins/wallets-tips/templates/tips.php
towp-content/themes/YOUR_THEME/templates/wallets-tips/tips.php
.2. Edit the template in your theme directory. Be careful not to break the knockout.js
data-bind
directives.wallets6 is an ongoing effort which will be out in a few months’ time. When it’s out it will be possible to also override the JavaScript that controls the UI behavior.
Hope this helps. Let me know if you have any more questions.
with regards
April 14, 2021 at 7:58 am #10372AnonymousInactiveHi Alex,
I was able to customize my template using both the snippet and by modifying the UI template, thanks to your clear and concise instructions.
Cheers!
April 14, 2021 at 8:09 am #10373AnonymousInactiveSorry for the double post.
It seems that I was able to get everything changed except for this one string of text that I cannot find in the tips.php file.
The default text seems to be: “Send a tip to author (@USERNAME) for this article?”
Would you be able to help me change this text as well?
Thanks!
Attachments:
You must be logged in to view attached files.April 14, 2021 at 8:42 am #10375alexgKeymasterCertainly,
You can use the following:
add_filter( 'wallets_tips_ui_message', function( $text ) { return 'YOUR TEXT HERE'; }, 20 );
The original filter is in
frontend.php
, functionfilter_wallets_tips_ui_message()
with regards
April 14, 2021 at 9:57 am #10376AnonymousInactiveHi again,
The snippet provided seemed to work fine, but there are a couple of configurations I was hoping you could guide me on?
I’m a bit of a noob, so I am taking this away as a learning experience. Thank you in advance for your patience.
Question #1. With the Code Snippet provided, I am unsure what to write in the ‘YOUR TEXT HERE’ so that I can have the author’s URL hyperlinked in one of the words. The string I want to create is:
“Send a tip to (@USERNAME)?”, with the @username hyperlinking to that user’s WordPress/BuddyPress member URL. I tried writing in “%s” (which looks like it was used in the ‘frontend.php’ file) in place of the @username, but it didn’t seem to work…
Is there a way I can change the text but still keep the display name / user name hyperlink?
Question #2. I wasn’t able to customize the concerned string of text by going to the frontend.php file, and I was wondering if it is because I should be putting the customized file in a different directory?
I tried putting the edited frontend.php in
wp-content/themes/my_theme/templates/wallets-tips/frontend.php
like done for the previous files, but it did not seem to work.I found the frontend.php in this directory
wp-content/plugins/wallets-tips/includes/frontend.php
and tried to mimic what had been done for the previous tips.php file, by putting the customized file inwp-content/themes/my_theme/includes/wallets-tips/frontend.php
, but that didn’t seem to work either.Would you happen to know where I might be messing up in this process?
Kind regards,
April 15, 2021 at 5:22 am #10379alexgKeymasterHello,
1. Try this:
function get_user_html( $user_name, $user_url, $class = 'tipper' ) { if ( $user_url ) { return sprintf( '<a href="%s" class="user %s" target="_blank">%s</a>', $user_url, $class, $user_name ); } return sprintf( '<span class="user %s">%s</span>', $class, $user_name ); } add_filter( 'wallets_tips_ui_message', function( $message, $author_userdata ) { return sprintf( 'Send a tip to %s?', get_user_html( $author_userdata->display_name ? $author_userdata->display_name : $author_userdata->user_nicename, $author_userdata->user_url ) ); }, 20, 2 );
2. The mechanism that lets you override templates only applies to templates, i.e. files under the
templates
directory. You can’t arbitrarily override any sourcecode file. This way of doing things is pretty standard and common among various well-known plugins.While I can’t teach you PHP and WordPress here, the short story is this: You shouldn’t be editing plugin files directly, because when these get updated, your changes are lost. This is why you should be doing your changes in template overrides, if the changes are about the UI, or use the existing filter/action hooks to modify plugin behavior. Furthermore, to avoid the same problem with your theme, it’s best if you create a child theme for your theme, and do all your custom coding there. All of this is explained in detail in the codex.
If you feel that a filter or action is missing from the plugin, let me know, and I will consider adding it, if it makes sense.
with regards
-
AuthorPosts
- You must be logged in to reply to this topic.