Plugin Directory

Changeset 1522922


Ignore:
Timestamp:
10/27/2016 07:56:22 AM (9 years ago)
Author:
neoxx
Message:

3.33

  • added two actions to equip other plugins with a cache purging mechanism
  • improved forced cache purging of posts, pages & comments
  • SSLified further links
Location:
generalstats/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • generalstats/trunk/generalstats.php

    r1410813 r1522922  
    66Description: Counts the number of users, categories, posts, comments, pages, links, tags, link-categories, words in posts, words in comments and words in pages.
    77Author: Dr. Bernhard Riedl
    8 Version: 3.32
     8Version: 3.33
    99Author URI: http://www.bernhard-riedl.com/
    1010*/
     
    424424
    425425        add_action('save_post', array($this, 'save_post_force_cache_refresh'), 10, 2);
    426 
    427         /*
    428         posts
    429         */
    430 
    431         add_action('after_delete_post', array($this, 'force_post_cache_refresh'));
    432         add_action('trashed_post', array($this, 'force_post_cache_refresh'));
    433         add_action('untrashed_post', array($this, 'force_post_cache_refresh'));
    434 
    435         /*
    436         pages
    437         */
    438 
    439         add_action('after_delete_post', array($this, 'force_page_cache_refresh'));
    440         add_action('trashed_post', array($this, 'force_page_cache_refresh'));
    441         add_action('untrashed_post', array($this, 'force_page_cache_refresh'));
     426        add_action('transition_post_status', array($this, 'transition_post_status_force_cache_refresh'), 10, 3);
     427
     428        /*
     429        posts & pages
     430        for sites with
     431        trash days = 0
     432        */
     433
     434        if (!EMPTY_TRASH_DAYS) {
     435            add_action('after_delete_post', array($this, 'force_post_cache_refresh'));
     436            add_action('after_delete_post', array($this, 'force_page_cache_refresh'));
     437        }
    442438
    443439        /*
     
    445441        */
    446442
    447         add_action('comment_post', array($this, 'comment_status_force_cache_refresh'), 10, 2);
    448         add_action('edit_comment', array($this, 'force_comment_cache_refresh'));
    449 
    450         /*
    451         deleted/trashed comment can be realized
    452         by using wp_set_comment_status
    453         */
    454 
    455         add_action('wp_set_comment_status', array($this, 'force_comment_cache_refresh'));
    456 
    457         /*
    458         special hooks for trashing/untrashing
    459         all comments of a certain post
    460         */
    461 
    462         add_action('trashed_post_comments', array($this, 'force_comment_cache_refresh'));
    463         add_action('untrashed_post_comments', array($this, 'force_comment_cache_refresh'));
     443        add_action('comment_post', array($this, 'comment_post_force_cache_refresh'), 10, 2);
     444        add_action('edit_comment', array($this, 'edit_comment_force_cache_refresh'));
     445        add_action('transition_comment_status', array($this, 'transition_comment_status_force_cache_refresh'), 10, 3);
    464446
    465447        /*
     
    17301712
    17311713    function head_meta() {
    1732         echo("<meta name=\"".$this->get_nicename()."\" content=\"3.32\"/>\n");
     1714        echo("<meta name=\"".$this->get_nicename()."\" content=\"3.33\"/>\n");
    17331715    }
    17341716
     
    28412823
    28422824    /*
    2843     check comment-status before force cache refresh
    2844     */
    2845 
    2846     function comment_status_force_cache_refresh($id=-1, $status=false) {
    2847         if ($status==1 || $status===false)
    2848             $this->force_comment_cache_refresh();
    2849     }
    2850 
    2851     /*
    2852     check post-status and
    2853     visibility before force cache refresh
     2825    check post-status
     2826    before force cache refresh
    28542827    */
    28552828
    28562829    function save_post_force_cache_refresh($id=-1, $post=false) {
    2857 
    28582830        if (is_object($post)) {
    28592831
     
    28632835
    28642836            if (wp_is_post_autosave($post)>0)
     2837                return;
     2838
     2839            /*
     2840            check if post is published
     2841            */
     2842
     2843            if ($post->post_status!='publish')
    28652844                return;
    28662845
     
    28812860        /*
    28822861        we didn't receive an object
    2883         and could check for post details
     2862        so we couldn't check
     2863        for post details
    28842864        => refresh post and page caches
    28852865        */
     
    28872867        $this->force_post_cache_refresh();
    28882868        $this->force_page_cache_refresh();
     2869    }
     2870
     2871    /*
     2872    check post-status
     2873    before force cache refresh
     2874    */
     2875
     2876    function transition_post_status_force_cache_refresh($new_status, $old_status, $post) {
     2877        if (is_object($post)) {
     2878
     2879            /*
     2880            here we handle only transitions
     2881            from non-publish to publish
     2882            and vice versa
     2883            */
     2884
     2885            if (($old_status=='publish' && $new_status=='publish') || ($old_status!='publish' && $new_status!='publish'))
     2886                return;
     2887
     2888            if ($post->post_type=='post') {
     2889                $this->force_post_cache_refresh();
     2890                return;
     2891            }
     2892            else if ($post->post_type=='page') {
     2893                $this->force_page_cache_refresh();
     2894                return;
     2895            }
     2896        }
     2897
     2898        /*
     2899        we didn't receive an object
     2900        so we couldn't check
     2901        for post details
     2902        => refresh post and page caches
     2903        */
     2904
     2905        $this->force_post_cache_refresh();
     2906        $this->force_page_cache_refresh();
     2907    }
     2908
     2909    /*
     2910    check comment-status
     2911    before force cache refresh
     2912    */
     2913
     2914    function edit_comment_force_cache_refresh($comment_ID) {
     2915
     2916        /*
     2917        check if comment is approved
     2918        */
     2919
     2920        if (wp_get_comment_status($comment_ID)!='approved')
     2921            return;
     2922
     2923        $this->force_comment_cache_refresh();
     2924    }
     2925
     2926    /*
     2927    check comment-status
     2928    before force cache refresh
     2929    */
     2930
     2931    function comment_post_force_cache_refresh($id=-1, $status=false) {
     2932        if ($status==1 || $status===false)
     2933            $this->force_comment_cache_refresh();
     2934    }
     2935
     2936    /*
     2937    check comment-status
     2938    before force cache refresh
     2939    */
     2940
     2941    function transition_comment_status_force_cache_refresh($new_status, $old_status, $comment) {
     2942
     2943        /*
     2944        here we handle only transitions
     2945        from non-approved to approved
     2946        and vice versa
     2947        */
     2948
     2949        if (($old_status=='approved' && $new_status=='approved') || ($old_status!='approved' && $new_status!='approved'))
     2950            return;
     2951
     2952        $this->force_comment_cache_refresh();
    28892953    }
    28902954
     
    29393003
    29403004    function force_term_cache_refresh($term=null, $tt_id=-1, $taxonomy='') {
    2941 
    29423005        if ($taxonomy=='category')
    29433006            $this->force_category_cache_refresh();
     
    30123075                if (array_key_exists($stat, $this->stats_selected))
    30133076                    set_transient($this->get_prefix(false), '', -1);
     3077
     3078                /*
     3079                triggers custom action on
     3080                specific stat
     3081                */
     3082
     3083                do_action($this->get_prefix().'force_cache_refresh_stat', $stat);
    30143084            }
    30153085        }
     3086
     3087        /*
     3088        triggers custom action on
     3089        stats array
     3090        */
     3091
     3092        do_action($this->get_prefix().'force_cache_refresh_stats', $stats);
    30163093    }
    30173094
  • generalstats/trunk/readme.txt

    r1410813 r1522922  
    1717* possible to integrate in "Right Now" box or to display as widget on the dashboard
    1818* high performing with caching technology and customizable memory usage
     19* cache-purge mechanism via actions (triggers) for other plugins
    1920* optional Ajax refresh with jQuery
    2021* fully compatible with [https/SSL/TLS-sites](https://codex.wordpress.org/Administration_Over_SSL)
     
    7576With GeneralStats 2.00 and higher you can use a function-call to display individual stat(-blocks) on different positions on your page.
    7677
    77 Parameters can either be passed [as an array or a URL query type string (e.g. "display=0&format=0")](https://codex.wordpress.org/Function_Reference/wp_parse_args). Please note that WordPress parses all arguments as strings, thus booleans have to be 0 or 1 if used in query type strings whereas for arrays [real booleans](https://php.net/manual/en/language.types.boolean.php) should be used. Furthermore you have to use the prefix `stats_` to select different stats in a query_string. - For example: `stat_0=Community&stat_12=Pages Word-Count`.
     78Parameters can either be passed [as an array or a URL query type string (e.g. "display=0&format=0")](https://codex.wordpress.org/Function_Reference/wp_parse_args). Please note that WordPress parses all arguments as strings, thus booleans have to be 0 or 1 if used in query type strings whereas for arrays [real booleans](https://secure.php.net/manual/en/language.types.boolean.php) should be used. Furthermore you have to use the prefix `stats_` to select different stats in a query_string. - For example: `stat_0=Community&stat_12=Pages Word-Count`.
    7879
    7980**`function $generalstats->count($params=array())`**
     
    208209Receives an array which is used for the mail-stats-function call to `$generalstats->output($params)`. `display` and `use_container` will automatically be set to false.
    209210
     211**Available Actions:**
     212
     213`generalstats_force_cache_refresh_stat`
     214
     215Gets triggered by GeneralStats' forced cache refresh; receives a stat-id as parameter.
     216
     217`generalstats_force_cache_refresh_stats`
     218
     219Gets triggered by GeneralStats' forced cache refresh; receives an array with stat-ids as parameter.
     220
    210221== Screenshots ==
    211222
     
    229240
    230241== Changelog ==
     242
     243= 3.33 =
     244
     245* added two actions to equip other plugins with a cache purging mechanism
     246* improved forced cache purging of posts, pages & comments
     247* SSLified further links
    231248
    232249= 3.32 =
Note: See TracChangeset for help on using the changeset viewer.