• Resolved gerd.neumann

    (@gerdneumann)


    Hi,

    It would be nice if there would be a simple filter like the following (I think there is none at the moment):

    shariff_share_counts with two arguments: name of the service (e.g “facebook” or “tumblr”) and count (the number), or just pass the whole $share_counts object. Something like this. The filter could be called somewhere in backend/index.php at the end.

    I could add the filter myself there, but then it wouldn’t be upgrade safe.
    This way I get at the number in WordPress itself. Could such filter be added?

    Best regards,
    Gerd

    https://ww.wp.xz.cn/plugins/shariff/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter gerd.neumann

    (@gerdneumann)

    I had a look at the code now. In backend/index.html it would be nice to have the following:

    $share_counts = apply_filters( 'shariff_share_counts', $share_counts, $post_url, $post_hash );

    just before the

    // save transient, if we have counts
    	if ( isset( $share_counts ) && $share_counts != null ) {
    		set_transient( $post_hash, $share_counts, $ttl );
    	}

    PS FWIW, I saw the variable $post_url2 but it seems not to be used.

    Plugin Author Jan-Peter

    (@starguide)

    Hi Gerd,

    the $post_url2 is needed for some of the services, e.g. googleplus.

    What I didn’t understand yet is, what are you trying to achieve? If you just want the share counts for a certain url, just simply make a call to /wp-content/plugins/shariff/backend/index.php?url=http://www.example.com/somepost. It delivers a json with the share counts for the specified url. The filter at the mentioned location would only work, if new numbers need to be fetched. So you wouldn’t get results for urls that are in the cache and still valid.

    JP

    Thread Starter gerd.neumann

    (@gerdneumann)

    What I didn’t understand yet is, what are you trying to achieve? If you just want the share counts for a certain url, just simply make a call to /wp-content/plugins/shariff/backend/index.php?url=http://www.example.com/somepost. It delivers a json with the share counts for the specified url.

    I’d like to hook in on the data and store it away, that is work with it, using a 3rd party app. Filters/Actions are a nice way of wordpress doing this without overriding original templates. I don’t want to do an extra JSON call to the backend for this. Filter would be more straight forward.

    The filter at the mentioned location would only work, if new numbers need to be fetched. So you wouldn’t get results for urls that are in the cache and still valid.

    You’re right. AFAIS the filter would need to be placed a bit further down just before the last if clause at

    // draw results, if we have some
    if ( isset( $share_counts ) && $share_counts != null ) {
    	echo json_encode( $share_counts );
    }

    Plugin Author Jan-Peter

    (@starguide)

    I see. The apply_filters in your first example got me a bit confused there, since you do not want to modify any data. So you actually want a do_action() hook, so you can catch the data every time the backend is called and store it somewhere else.

    do_action( 'shariff_share_counts', $share_counts );

    Do you want a hook every time the backend is called or just when new data is being fetched from the services? Every time seems a bit of an overkill, since there is no new information.

    JP

    Thread Starter gerd.neumann

    (@gerdneumann)

    1. You’re right, do_action is what I meant.
    2. Everytime the backend is called would be perfect.

    Plugin Author Jan-Peter

    (@starguide)

    Just to be on the safe side: You know any function you hook on to this will be called A LOT even though no new data is being generated. This can slow your server down significantly, if, for example, you do a database query every time. The backend gets called every time anybody visits any of your pages and on a blog overview page up to as many times as you have blog posts on it for every visitor. This is why we are using the whole cache and transient thing. You might want to think about it, if this is really necessary or if it wouldn’t be sufficient to be called only when new data is actually being processed.

    JP

    Thread Starter gerd.neumann

    (@gerdneumann)

    Does not really matter to me since I immediately detach after the hook. Anyway, having the action just before the data is put into the db would be fine. I agree.

    Anyway, thinking it over at night, there probably aren’t many people with the same need for such a hook. So no worries if you might decide not to integrate it directly… Then I’d have to patch the template myself. A hook would be appreciated though, maybe I am wrong and some other people other come up with 3rd party ideas as well…

    Plugin Author Jan-Peter

    (@starguide)

    Well, I don’t know, if the demand for this is very high, but it isn’t a lot of work either. So I don’t see a problem at the moment, to put this hook into our plugin. I’ll put it on my list for the next version and will let you know, so you can test it.

    JP

    Plugin Author Jan-Peter

    (@starguide)

    The new hook (shariff_share_counts) is now in place with version 4.0. Please see the FAQ (https://ww.wp.xz.cn/plugins/shariff/faq/) for more details.

    JP

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘filter for share counts’ is closed to new replies.