WordPress.org

Forums

WP-PostViews
[resolved] Adding code customisation (4 posts)

  1. gates
    Member
    Posted 1 year ago #

    I always edited the plugin to get a dot instead of a comma between thousands, because that's how we roll in Europe: thousand is not 1,000 but 1.000. (I guess that using another language for the WP installation solves this, but I'd like to keep the backend in English). So I go to line 197 and change it this
    $output = $prefix.str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']).$postfix;
    in
    $output = $prefix.str_replace('%VIEW_COUNT%', number_format($post_views, 0, ',', '.'), $views_options['template']).$postfix;

    But then saw this post about adding code customisation in WordPress the right way. How should I add this in my custom plugin? I'm afraid to screw something up.

    add_filter( 'the_views', 'customisation_of_the_views' );
    
    function customisation_of_the_views( /* keep this empty or copy the same code from the plugin? */) {
        // How to swap my customisation in line 197
    }

    https://wordpress.org/plugins/wp-postviews/

  2. Lester Chan
    Member
    Plugin Author

    Posted 1 year ago #

    The filter will not work because both backend and front end will use it. If you change the language, it will be "."

    it is not possible to have both "." and "," without some modifications to the plugin. You will probably have to duplicate the the_views function to the_views_2 or something and in https://github.com/lesterchan/wp-postviews/blob/master/wp-postviews.php#L772 change it to call the_views_2

  3. gates
    Member
    Posted 1 year ago #

    Aha... thanks for letting me know. So even if I only want to change the output in the front-end it won't work? I don't mind the commas in the back end.

    Edit: I see you've updated your post. About duplicating the function; I'm afraid that something like that increases the chance to break something in a future update. So I'll just use the method in my first post.

  4. Lester Chan
    Member
    Plugin Author

    Posted 1 year ago #

    Nope, that is because the function is called by both front end and back end.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.