This is just a quick note for developers who want to allow custom statuses in Post Pay Counter stats. By default PPC allows publish, future, pending and private, but you’ll see it’s not difficult to add your own ones. I’ll assume you are a developer, so I will only provide the details on where to hook and assume you know what to do at that point.
You will need two functions hooking to two different points:
- Filter settings retrieval adding your custom statuses to the array of allowed ones. The filter in this case is ppc_get_settings, line 111 of classes/ppc_general_functions_class.php. Have a look at the structure of the array and add your status to the sub-array counting_allowed_post_statuses.
- Tweak the WP_Query arguments to include your custom statuses. Here the filter is ppc_get_requested_posts_args, line 100 of classes/ppc_generate_stats_class.php. You want to edit the post_status parameter (which is an array), adding your custom ones.
(Advanced note: don’t make the WP_Query settings-dependent. You can see that by default PPC includes all possible statuses in the WP_Query post_status parameter, and not only active ones. This is to make stats quicker, and only discard irrelevant results in PPC_counting_stuff::data2cash().
This is an example code to allow drafts to be included in stats:
1 2 3 4 5 6 7 8 9 10 11 |
add_filter( 'ppc_get_settings', 'ppc_add_draft_status_settings', 10 ); function ppc_add_draft_status_settings( $settings ) { $settings['counting_allowed_post_statuses']['draft'] = 1; return $settings; } add_filter( 'ppc_get_requested_posts_args', 'ppc_draft_status_wp_query', 10 ); function ppc_draft_status_wp_query ( $status ) { $status['post_status'][] = 'draft'; return $status; } |
Leave a Reply