Search Results for 'code'
-
AuthorSearch Results
-
September 16, 2021 at 3:54 pm #223204
In reply to: User registration email not sending to user
jappan
Participantadd_filter('bp_email_use_wp_mail', function () { return true; });you should add this code in function.php
September 16, 2021 at 2:55 am #223185In reply to: Why “Login Here” shows up instead of Form?
Robin W
Moderatorok, the line
echo esc_html__( 'You must be logged in to create new topics.', 'bbpress' ) . ' <a href="' . esc_url( thim_get_login_page_url() ) . '">' . esc_html__( 'Login here', 'bbpress' ) . '</a>';is doing the Login Here
This line chooses the location from a setting in your theme
thim_get_login_page_url()so I suspect it is as simple as changing that setting to the page you want it to say, so look at your theme settings
If that doesn’t work, come back
September 15, 2021 at 9:13 pm #223182In reply to: Why “Login Here” shows up instead of Form?
cosmiclove1978
ParticipantHi Robin,
Yes, I can see form-topic.php in the parent theme.
<?php /** * New/Edit Topic * * @package bbPress * @subpackage Theme */ ?> <?php if ( !bbp_is_single_forum() ) : ?> <div id="bbpress-forums"> <?php bbp_breadcrumb(); ?> <?php endif; ?> <?php if ( bbp_is_topic_edit() ) : ?> <?php bbp_topic_tag_list( bbp_get_topic_id() ); ?> <?php bbp_single_topic_description( array( 'topic_id' => bbp_get_topic_id() ) ); ?> <?php endif; ?> <?php if ( bbp_current_user_can_access_create_topic_form() ) : ?> <div id="new-topic-<?php bbp_topic_id(); ?>" class="bbp-topic-form"> <form id="new-post" name="new-post" method="post" action="<?php the_permalink(); ?>"> <?php do_action( 'bbp_theme_before_topic_form' ); ?> <fieldset class="bbp-form"> <legend> <?php if ( bbp_is_topic_edit() ) printf( __( 'Now Editing “%s”', 'bbpress' ), bbp_get_topic_title() ); else bbp_is_single_forum() ? printf( __( 'Create New Topic in “%s”', 'bbpress' ), bbp_get_forum_title() ) : _e( 'Create New Topic', 'bbpress' ); ?> </legend> <?php do_action( 'bbp_theme_before_topic_form_notices' ); ?> <?php if ( !bbp_is_topic_edit() && bbp_is_forum_closed() ) : ?> <div class="bbp-template-notice"> <p><?php _e( 'This forum is marked as closed to new topics, however your posting capabilities still allow you to do so.', 'bbpress' ); ?></p> </div> <?php endif; ?> <?php if ( current_user_can( 'unfiltered_html' ) ) : ?> <div class="bbp-template-notice"> <p><?php _e( 'Your account has the ability to post unrestricted HTML content.', 'bbpress' ); ?></p> </div> <?php endif; ?> <?php do_action( 'bbp_template_notices' ); ?> <div> <?php bbp_get_template_part( 'form', 'anonymous' ); ?> <?php do_action( 'bbp_theme_before_topic_form_title' ); ?> <p> <label for="bbp_topic_title"><?php printf( __( 'Topic Title (Maximum Length: %d):', 'bbpress' ), bbp_get_title_max_length() ); ?></label><br /> <input type="text" id="bbp_topic_title" value="<?php bbp_form_topic_title(); ?>" tabindex="<?php bbp_tab_index(); ?>" size="40" name="bbp_topic_title" maxlength="<?php bbp_title_max_length(); ?>" /> </p> <?php do_action( 'bbp_theme_after_topic_form_title' ); ?> <?php do_action( 'bbp_theme_before_topic_form_content' ); ?> <?php bbp_the_content( array( 'context' => 'topic' ) ); ?> <?php do_action( 'bbp_theme_after_topic_form_content' ); ?> <?php if ( ! ( bbp_use_wp_editor() || current_user_can( 'unfiltered_html' ) ) ) : ?> <p class="form-allowed-tags"> <label><?php _e( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:','bbpress' ); ?></label><br /> <code><?php bbp_allowed_tags(); ?></code> </p> <?php endif; ?> <?php if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags' ) ) : ?> <?php do_action( 'bbp_theme_before_topic_form_tags' ); ?> <p> <label for="bbp_topic_tags"><?php _e( 'Topic Tags:', 'bbpress' ); ?></label><br /> <input type="text" value="<?php bbp_form_topic_tags(); ?>" tabindex="<?php bbp_tab_index(); ?>" size="40" name="bbp_topic_tags" id="bbp_topic_tags" <?php disabled( bbp_is_topic_spam() ); ?> /> </p> <?php do_action( 'bbp_theme_after_topic_form_tags' ); ?> <?php endif; ?> <?php if ( !bbp_is_single_forum() ) : ?> <?php do_action( 'bbp_theme_before_topic_form_forum' ); ?> <p> <label for="bbp_forum_id"><?php _e( 'Forum:', 'bbpress' ); ?></label><br /> <?php bbp_dropdown( array( 'show_none' => __( '(No Forum)', 'bbpress' ), 'selected' => bbp_get_form_topic_forum() ) ); ?> </p> <?php do_action( 'bbp_theme_after_topic_form_forum' ); ?> <?php endif; ?> <?php if ( current_user_can( 'moderate' ) ) : ?> <?php do_action( 'bbp_theme_before_topic_form_type' ); ?> <p> <label for="bbp_stick_topic"><?php _e( 'Topic Type:', 'bbpress' ); ?></label><br /> <?php bbp_form_topic_type_dropdown(); ?> </p> <?php do_action( 'bbp_theme_after_topic_form_type' ); ?> <?php do_action( 'bbp_theme_before_topic_form_status' ); ?> <p> <label for="bbp_topic_status"><?php _e( 'Topic Status:', 'bbpress' ); ?></label><br /> <?php bbp_form_topic_status_dropdown(); ?> </p> <?php do_action( 'bbp_theme_after_topic_form_status' ); ?> <?php endif; ?> <?php if ( bbp_is_subscriptions_active() && !bbp_is_anonymous() && ( !bbp_is_topic_edit() || ( bbp_is_topic_edit() && !bbp_is_topic_anonymous() ) ) ) : ?> <?php do_action( 'bbp_theme_before_topic_form_subscriptions' ); ?> <p> <input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe" <?php bbp_form_topic_subscribed(); ?> tabindex="<?php bbp_tab_index(); ?>" /> <?php if ( bbp_is_topic_edit() && ( bbp_get_topic_author_id() !== bbp_get_current_user_id() ) ) : ?> <label for="bbp_topic_subscription"><?php _e( 'Notify the author of follow-up replies via email', 'bbpress' ); ?></label> <?php else : ?> <label for="bbp_topic_subscription"><?php _e( 'Notify me of follow-up replies via email', 'bbpress' ); ?></label> <?php endif; ?> </p> <?php do_action( 'bbp_theme_after_topic_form_subscriptions' ); ?> <?php endif; ?> <?php if ( bbp_allow_revisions() && bbp_is_topic_edit() ) : ?> <?php do_action( 'bbp_theme_before_topic_form_revisions' ); ?> <fieldset class="bbp-form"> <legend> <input name="bbp_log_topic_edit" id="bbp_log_topic_edit" type="checkbox" value="1" <?php bbp_form_topic_log_edit(); ?> tabindex="<?php bbp_tab_index(); ?>" /> <label for="bbp_log_topic_edit"><?php _e( 'Keep a log of this edit:', 'bbpress' ); ?></label><br /> </legend> <div> <label for="bbp_topic_edit_reason"><?php printf( __( 'Optional reason for editing:', 'bbpress' ), bbp_get_current_user_name() ); ?></label><br /> <input type="text" value="<?php bbp_form_topic_edit_reason(); ?>" tabindex="<?php bbp_tab_index(); ?>" size="40" name="bbp_topic_edit_reason" id="bbp_topic_edit_reason" /> </div> </fieldset> <?php do_action( 'bbp_theme_after_topic_form_revisions' ); ?> <?php endif; ?> <?php do_action( 'bbp_theme_before_topic_form_submit_wrapper' ); ?> <div class="bbp-submit-wrapper"> <?php do_action( 'bbp_theme_before_topic_form_submit_button' ); ?> <button type="submit" tabindex="<?php bbp_tab_index(); ?>" id="bbp_topic_submit" name="bbp_topic_submit" class="button submit"><?php _e( 'Submit', 'bbpress' ); ?></button> <?php do_action( 'bbp_theme_after_topic_form_submit_button' ); ?> </div> <?php do_action( 'bbp_theme_after_topic_form_submit_wrapper' ); ?> </div> <?php bbp_topic_form_fields(); ?> </fieldset> <?php do_action( 'bbp_theme_after_topic_form' ); ?> </form> </div> <?php elseif ( bbp_is_forum_closed() ) : ?> <div id="no-topic-<?php bbp_topic_id(); ?>" class="bbp-no-topic"> <div class="bbp-template-notice"> <p><?php printf( __( 'The forum ‘%s’ is closed to new topics and replies.', 'bbpress' ), bbp_get_forum_title() ); ?></p> </div> </div> <?php else : ?> <div id="no-topic-<?php bbp_topic_id(); ?>" class="bbp-no-topic"> <div class="bbp-template-notice"> <p> <?php if(is_user_logged_in()) { _e( 'You cannot create new topics.', 'bbpress' ); } else { echo esc_html__( 'You must be logged in to create new topics.', 'bbpress' ) . ' <a href="' . esc_url( thim_get_login_page_url() ) . '">' . esc_html__( 'Login here', 'bbpress' ) . '</a>'; } ?> </p> </div> </div> <?php endif; ?> <?php if ( !bbp_is_single_forum() ) : ?> </div> <?php endif; ?>September 13, 2021 at 1:30 pm #223158In reply to: Why “Login Here” shows up instead of Form?
Robin W
Moderatorok, delete ALL of the contents of form-user-login.php and instead put
<a href="https://mydomain.com/login/">Login here</a>and that’s what will show 🙂
September 13, 2021 at 8:51 am #223155In reply to: Why “Login Here” shows up instead of Form?
cosmiclove1978
ParticipantHi Robin!
Thanks for your quick reply and assistance. But there’s only one major challenge (at least to me) I am currently facing, which I’ll describe below:Re: — “Then amend this file to take out the current form and put in a link”
I get the “what” to-do part (i.e. amending file…, creating a folder in my child theme, etc) but as for the “how?”, I have absolutely no idea. In all humility, I make no pretense of familiarity with php syntax or anything php code-related.
I see the <form>….</form> tags in my file below, should I remove it all and place https://mydomain.com/login?
<?php /** * User Login Form * * @package bbPress * @subpackage Theme */ // Exit if accessed directly defined( 'ABSPATH' ) || exit; ?> <form method="post" action="<?php bbp_wp_login_action( array( 'context' => 'login_post' ) ); ?>" class="bbp-login-form"> <fieldset class="bbp-form"> <legend><?php esc_html_e( 'Log In', 'bbpress' ); ?></legend> <div class="bbp-username"> <label for="user_login"><?php esc_html_e( 'Username', 'bbpress' ); ?>: </label> <input type="text" name="log" value="<?php bbp_sanitize_val( 'user_login', 'text' ); ?>" size="20" maxlength="100" id="user_login" autocomplete="off" /> </div> <div class="bbp-password"> <label for="user_pass"><?php esc_html_e( 'Password', 'bbpress' ); ?>: </label> <input type="password" name="pwd" value="<?php bbp_sanitize_val( 'user_pass', 'password' ); ?>" size="20" id="user_pass" autocomplete="off" /> </div> <div class="bbp-remember-me"> <input type="checkbox" name="rememberme" value="forever" <?php checked( bbp_get_sanitize_val( 'rememberme', 'checkbox' ) ); ?> id="rememberme" /> <label for="rememberme"><?php esc_html_e( 'Keep me signed in', 'bbpress' ); ?></label> </div> <?php do_action( 'login_form' ); ?> <div class="bbp-submit-wrapper"> <button type="submit" name="user-submit" id="user-submit" class="button submit user-submit"><?php esc_html_e( 'Log In', 'bbpress' ); ?></button> <?php bbp_user_login_fields(); ?> </div> </fieldset> </form>My question is and where do I amend this form-user-login.php file with my login url https://mydomain.com/login/?
If given a blueprint, I can certainly reproduce the steps faithfully when dealing with a similar issue
Can you (or anyone willing) please pinpoint the parts/lines to modify with the url? Thanks so much in advance.
September 12, 2021 at 4:02 pm #223140In reply to: Remove “archive” from main forum title
Sascha
ParticipantFound solutions in an other forum, just to add in the functions.php:
add_filter( 'get_the_archive_title', function ($title) { if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); } elseif ( is_author() ) { $title = '<span class="vcard">' . get_the_author() . '</span>' ; } elseif ( is_tax() ) { //for custom post types $title = sprintf( __( '%1$s' ), single_term_title( '', false ) ); } elseif (is_post_type_archive()) { $title = post_type_archive_title( '', false ); } return $title; });September 11, 2021 at 6:52 pm #223130In reply to: Add ‘@’ when replying
jappan
Participantadd_filter( 'bbp_get_form_reply_content', function( string $reply_content ) { if ( isset( $_GET['bbp_reply_to'] ) && (int) $_GET['bbp_reply_to'] ) { $display_name = get_the_author_meta( 'display_name', get_post_field( 'post_author', (int) $_GET['bbp_reply_to'] ) ); return '@' . $display_name . PHP_EOL . $reply_content; } return $reply_content; });You should add this code in “functions.php”.
September 11, 2021 at 10:32 am #223129In reply to: Forums index vs custom page shorturl
cosmiclove1978
ParticipantHello Regnalf,
I’m happy to report that your fix worked. I had to apply the new class to all the previous CSS code, but it did the trick!!!
This is truly got the time to appreciate firsthand php notions such hook and filters, etc and see them at work. It was neat to be able to fine-tune the bbpress-index class vs bbpress and target one vs all parts of the site. I’m grateful.
Pushing my luck a bit further and modeling your code above and another post I saw elsewhere, I was hoping to get a bit more granular in the way I applied my css to parts of the forum, so I tried this bit of code below to target individual topic pages (or replies?)
but it didn’t work. If it’s not too much to ask, whenever it’s convenient for you or anyone, could you tell me if this code below somewhat does what you just provided me.function my_topic_class($classes) { $classes[] = 'herman-topic-class'; return $classes; } add_filter( 'bbp_get_topic_class','my_topic_class' );Nowhere, when viewing the topic page or thread did I see the new class ‘herman-topic-class’ in the Inspect Element utility. With your code, the bbpress and bbpress-index appeared.
thanks in advance for all the support.H
September 11, 2021 at 6:09 am #223125In reply to: Forums index vs custom page shorturl
regnalf
ParticipantI don’t know how you excactly you want to style the forum index page, but i found out that the index page doesn’t have the bbpress class included in the body tag like the sub pages. So i had the problem too that i couldn’t style the index page.
Here is my code i use to add this class, and others, to the body tag for the index page. Then you can style the index page with css.
add_filter( 'body_class', 'bbpress_add_body_class' ); function bbpress_add_body_class( $classes ) { global $wp; $bbpress_index = get_option ('_bbp_root_slug'); $bbpress_search = get_option ('_bbp_search_slug'); if (strpos($wp->request, $bbpress_index) !== false) { $classes[] = "bbpress"; } if ($wp->request == $bbpress_index) { $classes[] = "bbpress-index"; } if (strpos($wp->request, $bbpress_index . "/" . $bbpress_search) !== false) { $classes[] = "bbpress-search"; } return $classes; }September 11, 2021 at 5:38 am #223124In reply to: Forums index vs custom page shorturl
cosmiclove1978
ParticipantHi Robin,
Thanks as always for your assistance.
Starting with the last question, I have BuddyPress installed but not activated…As for the slug, I’ve now ditched the underscore thing and went with /lab for the shortcode page, and in settings, /forums for the root and /forum for the forum. My permalinks are back to %postname%. This current setting guarantees that all my styles are displayed properly when accessing the page with the bbp-forum-index shortcode.
If I visit the /lab page, it’s all good until I clicked on a specific forum. Then the /lab is lost to acquire /forums (declared the settings) and thus display a 404 error page since there’s no page with that /forums/forum/topic, etc.
When I switch to having the shortcode page slug and settings slug be the same, no 404 error message, but all customizations vanish.
I’ve read some other post talking of templates not being properly referenced and honestly, so I created a bbpress folder in my childtheme. Since I’m not sure which templates/file to copy inside the newly-created BBPRESS there, I tried copying all php files included in the default template folder inside the BBPress plugin, and it didn’t go to well, so I removed them.
Still not sure where else to look. 🙁
I appreciate other pointers you or other bbpress-ers might have.Best,
HSeptember 11, 2021 at 3:25 am #223116In reply to: Forums index vs custom page shorturl
cosmiclove1978
ParticipantHello,
I don’t know if anyone here was able to resolve their issue, but mine is quite similar to the OP.
Scenario: Created a forum with the shortcode [bbp-forum-index] on page with having slug /custom_forum to output index page. Used css to style the page (no theme builder).. In the forum settings, the root is set to /forums. When visiting /custom_forum, all the style appears great.
However, if I head to Settings–> Forums to change the root from /forums to /custom_forum (where my shortcode is placed), I lose all the styling.
I reset the permalinks as suggested above to no avail. I know it’s been over 7 years this has been reported and I hope anyone out who’s found a solution can assist me. Thanks in advance for your support.
September 10, 2021 at 1:07 pm #223106In reply to: Remove “archive” from main forum title
Robin W
ModeratorThis is theme related, but if you can give me a link to a live example, I might be able to give you some code
September 10, 2021 at 10:12 am #223097In reply to: Way to prevent duplicate post blocking?
bhkh
ParticipantHmm. The code given in your first reply doesn’t seem to work. Subscribers/Participants still get the error message, “Error: Duplicate reply detected; it looks as though you’ve already said that.”
I have removed all other php and disabled plugins.
Ideas?
September 10, 2021 at 9:23 am #223092In reply to: Way to prevent duplicate post blocking?
Robin W
Moderatorline 309 of includes/replies/functions calls a function called
bbp_check_for_duplicatewithin the bbp_new_reply_handler functionThat function checks for duplicates and is in includes/common/functions line 663
within that function line 676 for a check
if ( user_can( (int) $r['post_author'], 'throttle' ) ) { return true; }so allowing participants to throttle allows duplicates
It is a bit of a fudge, but should work !!
September 10, 2021 at 12:38 am #223085In reply to: Way to prevent duplicate post blocking?
bhkh
ParticipantThanks!
It seems that for an admin/moderator user this works. But for a regular subscriber/participant it still blocks duplicates.
I kind of understand what the code is doing but not enough to understand why it’s not working. It doesn’t seem to be saying what role is allowed to bypass. Was I supposed to do something with this:
the easiest way to do this is to allow participant to ‘throttle’
I don’t see a setting for that. Could you explain more what I should do to allow participants to throttle?
September 9, 2021 at 1:14 pm #223084In reply to: Way to prevent duplicate post blocking?
Robin W
Moderatorthe easiest way to do this is to allow participant to ‘throttle’ – this then lets them bypass this check
so the code (untested) should be :
add_filter( 'bbp_get_caps_for_role', 'rew_throttle_bypass', 10, 2); function rew_throttle_bypass ($caps, $role) { if ($role == bbp_get_participant_role() ) { $caps['throttle'] = true ; } return $caps ; }ut this in your child theme’s function file –
ie wp-content/themes/%your-theme-name%/functions.php
where %your-theme-name% is the name of your theme
or use
September 9, 2021 at 12:12 pm #223082Topic: Way to prevent duplicate post blocking?
in forum Troubleshootingbhkh
ParticipantIs there a way to disable the “Duplicate reply detected” error checking? My forum will mostly be people uploading audio attachments and they may very well just say the same thing each time they post. But in the short term it’s a bother to my testers since they can’t just write “test” each time.
I know that the error code is in \wp-content\plugins\bbpress\includes\common\functions.php
I’m guessing there is some way to filter the bbp_check_for_duplicate function, but I don’t know enough php to do that.
I’ve seen some others post this question in the past but didn’t see answers.
(BTW, I posted this question a few hours ago but it got marked as spam. Not sure why. I included some code in it but have removed it in this one. Hope it’s ok to repost.)
September 8, 2021 at 10:06 am #223062In reply to: Filtering text in replies
bhkh
ParticipantThat will get you to lots of bits of code which are usually around what you are trying to find
I’ll give it a go, thanks!
I heard back and GD bbPress Attachments doesn’t have anything I can hook into, so i will just have to increase the priority number.
Thanks for your help
September 8, 2021 at 4:00 am #223055In reply to: Filtering text in replies
Robin W
Moderatorbbpress is very large, and finding the right bit of code not easy !!
have you heard of notepadd++ ?
Google it and install it.
Then download bbpress 2.6 to your PC and unzip it.
Then when you are looking in your browser at bbpress, you’ll usually find a class or ID wrapped around the code you want to change.
In Notepad++ do ‘search>find in files’ and search the class ot ID name in the bbpress directory you created.
That will get you to lots of bits of code which are usually around what you are trying to find
I do this a lot !!
September 8, 2021 at 12:49 am #223050In reply to: Filtering text in replies
bhkh
Participantquite a few bbpress additional plugins authors use ‘bbp’ as a prefix to indicate the the class/code is bbpress related.
Oh, that’s really good to know. Thank you.
I was able to find the event (is that the proper name for it??)
bbp_get_reply_contentand that allowed me to filter the reply content but not the attachment area. Then I changed the priority of the filter to 1000 and I was able to achieve my intended outcome. What I don’t know is if this is good coding practice or not. I thought I read somewhere that super high priorities are not a good idea. In any case, I did post to the plugin company’s forum to see if there is a better/more specific event to filter. I’ll report back what I learn.But a general bbPress question if I may. How is one supposed to learn about events such as
bbp_get_reply_content? I did a search in the bbPress documentation and there are no results. I was only able to find it by discecting the GD bbPress Attachments code. I did come across a site called hookr.io. Is that the best resource?I recently spent several hours trying to fix an issue and when I posted all I got back was ‘already fixed elsewhere’
🙁 that’s a bummer.
I really appreciate your work supporting the forum and bbPress. Open Source software is nothing without people who dedicate time to support users. Thank you and all who help here.
September 7, 2021 at 1:00 pm #223047In reply to: Filtering text in replies
Robin W
Moderatoron 2. – no problem 🙂 🙂 🙂 I recently spent several hours trying to fix an issue and when I posted all I got back was ‘already fixed elsewhere’ as the response, so this is a current hot button for me – apologies if I sounded irritable 🙂
on your filter – quite a few bbpress additional plugins authors use ‘bbp’ as a prefix to indicate the the class/code is bbpress related. bbpress itself does not have a class of
bbp-attachmentsso suspect this is attachments plugin related.I would try Milan as a first port of call, he is usually helpful, but do come back if he can’t help.
September 7, 2021 at 9:59 am #223042In reply to: Filtering text in replies
bhkh
ParticipantThanks again for such a quick reply!
1. since this relates to bbpress attachments plugin specifically, it would be better to ask there – Milan should be able to help
So I just now tested putting the code (in this case a link) I’m trying to filter in the body of a reply in addition to having it be in the attachment (hadn’t thought about trying that before) but before I posted I saw
<div class="bbp-attachments">in the page source and so figured that attachments were something in core bbP, not just the GD bbPress Attachments plugin.And the result of that test now is that the link in the body of the reply is also not filtered. So I think I’m back to this being a bbP thing and not a GD bbPress Attachments.
I notice that you also asked about empty replies in that forum as well as this forum where I gave you a fix – it is very frustrating for plugin authors and helpers when they spend time on an issue only to find that the original poster has already fixed it
I totally get that! At the time, I had no idea what the response rate was going to be. Sometimes communities/companies reply within the hour (as you did, thanks!!) or if they will take weeks. So not being sure which was causing the problem, I did post in both places. Please forgive me. I was surprised that both places replied so quickly.
It would be polite to do this
I did! Within minutes of seeing his response. Wasn’t it visible to you? Should I have linked back to the forum as well? I’m happy to, I just thought the code was enough. I totally know the frustration of support posts that end with “Oh, never mind, I fixed it.” and no solution.
Anyway, since I now know that my filter also doesn’t catch things in the body of the reply either (and I would like it to) are we back to this being a bbP thing? Are there other troubleshooting things I’m missing? I have disabled all other plugins and tried a default theme.
September 7, 2021 at 9:07 am #223037Topic: Filtering text in replies
in forum Troubleshootingbhkh
ParticipantHello!
I’m trying to filter links that appear in responses. More specifically, they are links that appear in attachments that have been added through GD bbPress Attachments if that matters. I’m fairly sure the code works because it can filter in the content of a page just fine. Here is the code:
add_filter( 'the_content', 'myprefix_use_audio_short_tag' ); function myprefix_use_audio_short_tag( $content ) { $reg = "#<a .+ href=\"(.+?\.mp3)\".+?</a>#"; $content = preg_replace($reg, "[audio mp3='$1' class='asset-audio' title='']", $content); return $content; }I’m guessing that it shouldn’t be the_content, but I am really working beyond my actual understanding of WordPress. I don’t know if I should be putting a theme file name there or if there is some equivalent to the_content that targets responses in bbP.
Feel free to criticize my regex as well. I’ve actually never used regex in WP/php before.
BTW, my code has been adapted from here: https://stackoverflow.com/questions/55814952/how-to-generate-audio-shortcode-when-theres-an-mp3-in-a-link-tag-in-wordpress
WP 5.8
bbP 2.6.6September 6, 2021 at 1:44 pm #222995Robin W
Moderatorok, so in the example above, what does $value2 equal
$value2 = get_post_meta( $topic_id, 'bbp_extra_field2', true);and what is the full url that you want?
September 6, 2021 at 1:19 pm #222994jappan
ParticipantI’m sorry to ask you many questions.
I asked a question before, but I haven’t solved it yet.
so I really need a code to solve it.I want to add “http://www.example.com/wp-content/uploads/○○” to the image.
This is the code I made from Mr.Robin, but i haven’t been able to add the url to the image and display it yet.
I’ve been studying for 2 days, and expecting that using
<?php $upload_dir = wp_upload_dir(); ?>will come closer to solution, but…

add_action ( 'bbp_theme_before_topic_form_content', 'bbp_extra_fields'); function bbp_extra_fields() { $value11 = get_post_meta( bbp_get_topic_id(), 'bbp_extra_field2', true); echo '<label for="bbp_extra_field2">pic</label><br>'; echo "<input type='file' name='bbp_extra_field2' accept='.jpg,.jpeg,.png,.gif' value='".$value11."'>"; } add_action ( 'bbp_new_topic', 'bbp_save_extra_fields', 10, 1 ); add_action ( 'bbp_edit_topic', 'bbp_save_extra_fields', 10, 1 ); function bbp_save_extra_fields($topic_id=0) { if (isset($_POST) && $_POST['bbp_extra_field2']!='') update_post_meta( $topic_id, 'bbp_extra_field2',$_POST['bbp_extra_field2'] ); } add_action('bbp_template_before_replies_loop', 'bbp_show_extra_fields'); function bbp_show_extra_fields() { $topic_id = bbp_get_topic_id(); $value2 = get_post_meta( $topic_id, 'bbp_extra_field2', true); $img = '<img src=".$value2.">' ; echo "pic: ".$value2."<br>"; echo "picture:".$img."<br>"; } -
AuthorSearch Results