Skip to:
Content
Pages
Categories
Search
Top
Bottom

backslash apostrophe bug


  • MBV
    Participant

    @mbv

    I realize this bug has been discussed and troubleshooted many years ago… believe it or not I’m getting this issue right now.

    Most of the time, not quite sure if it’s all the time, when a user posts in activity feed, every apostrophe is preceded by a backslash. For example, It’s becomes It\’s

    When as admin I edit their comment, it does not show the backslash and when saved it does not show. But on page refresh it shows it again. Can only seem to remove it by editing database directly and removing the backslash from the content.

    Not sure but I just seemed to notice that a new comment less than maybe about 24 hours seems to display okay. But then after about 24 hours, that same comment now displays backslashes with the apostrophes.

    I’ve disabled magic_quotes_gpc, magic_quotes_sybase, magic_quotes_runtime.

    I’m now re-trying out the following code just in case I gave up on it too soon.

    //Attempt to strip backslashes
    add_filter( 'get_topic_title', 'strip_the_title_slashes', 20, 2);
    function strip_the_title_slashes( $title, $id ) {
    return stripslashes( $title );
    }
    
    add_filter( 'get_post_text', 'strip_the_text_slashes', 20, 2);
    function strip_the_text_slashes( $text, $id ) {
    return stripslashes( $text );
    }

    Any other suggestions, please?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi @mbv-

    The data should be slashed on the way into the database. When you call the activity content using bp_get_activity_content_body(), many filters are applied, including stripslashes_deep here: https://buddypress.trac.wordpress.org/browser/tags/2.9.3/src/bp-activity/bp-activity-filters.php#L82

    If you’re displaying activity using an activity loop (like BuddyPress does in its default theme parts), then the results are as expected. If you’re accessing the data some other way, you’re going to need to apply the needed filters to it. Check out the link above to see all the filters that applied to bp_get_activity_content_body.


    MBV
    Participant

    @mbv

    Hi @dcavins
    Thank you for your reply! I realized that after deleting them that the backslashes were actually meant to be there in the database….Oops!

    I have now stopped deleting them, hopefully it won’t cause any issues for the ones that are deleted.

    The problem with backslash is ongoing. After re-adding that code, it seems to be a little less, though it could just be part of the randomness of it.

    The activity I refer to is just the standard activity on the /activity page. Seemingly at random, the filters do not apply and the backslash is visible on the front end for some posts. Currently now it’s only happening for update posts and posts on other person’s wall.

    As such, not sure how to go about troubleshooting this.


    James Revillini
    Participant

    @jrevillini

    Confirmed.

    On my installation, this happens on comments on activity. So if I go to my activity feed, post an update, then comment on my own update, then when the page refreshes, the comment will have backslashes preceding any single quote.

    I’m going to dig into this.


    James Revillini
    Participant

    @jrevillini

    MY PREVIOUS POST IS MISSING SO I’M REPOSTING AND HOPING THIS ISN’T JUST LAG…

    OK I found a more targeted way to fix this. Short answer, I added this code add_filter( 'bp_get_activity_content_body', 'stripslashes_deep' );

    HOW I added it is kind of important, I think. I’m running a plugin called Code Snippets https://wordpress.org/plugins/code-snippets/

    By creating a snippet with just the code above, it takes care of removing those backslashes from comments on activity before it is displayed on the front end. If you apply the fix with this plugin, you can also select “run on front end” in the snippet editor for efficiency/performance.

    If you wanted to fix it in your child theme (I don’t know why you’d only want the fix to be theme dependent, but that’s up to you …) then I believe this code would go into your functions.php (untested):

    add_action('plugins_loaded', 'jrevillini_buddypress_get_activty_content_body_stripslashes' );
    function jrevillini_buddypress_get_activty_content_body_stripslashes () {
    add_filter( 'bp_get_activity_content_body', 'stripslashes_deep' );
    }

    Now I know that stripslashes is already applied to bp_get_activity_content_body by buddypress itself because I found it listed in this document, line 00079: https://drive.google.com/file/d/0B2NrrKAXLm0JQ01GT1ZGQlVOMkE/view (so my code *seems* redundant)

    The only thing I can assume at this point is that the code built into buddypress to attach the filter is running too early for all output possibilities at priority 5. By simply adding it into a code snippet which is running as a plugin at the default priority, it seems to do the job before output on the member activity endpoint.

    It should be noted that even without my fix, the same activity post will appear fine at some endpoints and not others.
    The ones that I found that already worked:
    * within a discussion e.g. /members/NAME/activity/73/#acomment-74
    * on /member/NAME *as a reply* but *not* as an activity post


    Abracarambar
    Participant

    @abracarambar

    Following your tip was the best thing I did today. Thank you so much.


    vinitmore
    Participant

    @vinitmore

    hello,
    solution 1: the HTML Apostrophe
    as opposed to without a doubt typing the apostrophe, you can use the HTML code: ‘. So, in place of typing “Matt’s weblog” you would type “Matt ‘s blog” within the problem area.

    One trouble you could run into with that is that it could handiest paintings on the first store. if you store the setting, widget, etc. a 2d time, you may get the backslash again. If the hassle is in an area you may most effective update once, this may not be a problem. in case you replace it regularly, as opposed to getting into the HTML code time after time you will want to try a greater everlasting solution:

    solution 2: The HTML ‘clever’ Apostrophe
    A workaround so as to carry out the identical function as the solution above is rather, to use a “clever” or “curling” apostrophe. WordPress does not see this individual as a “actual” apostrophe and could no longer robotically “reclaim” it whilst the setting is stored like it would within the first solution.

    The only trouble you could run into is if the font set that you are the usage of for this location is a non-preferred font, it is able to no longer be rendered. as an instance, the font in the photograph at the right does not render capitals, nor even the “regular” apostrophe, so if this is the case for you, you may want to pick a extraordinary font for the location that is not rendering well.

    regards
    vinitmore


    MBV
    Participant

    @mbv

    @jrevillini Thanks so much! I’ve just tried your solution. As you say, adding that filter using Code Snippets plugin worked. Whereas adding that code to child theme functions.php didn’t work…I wonder why?

    Another fix is to replace the single ‘ with keyboard code Alt+0146 which gives you a “smart apostrophe” like this ’ . Such that instead of Bob’s car coming out looking like Bob\’s, it will look like this, Bob’s. It kind of looks like a superscript comma, but it works. It does not register as decimal Code 39, which triggers the backslash.

    Good luck guys and thanks for sharing your solutions. It was all your comments that motivated my search in finding this alternative.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar