Post Pay Counter

The best way to pay authors on WordPress

  • Features
    • Addons
  • Cart
  • PRO version
  • Addons
  • Support
  • Tutorials
    • Questions and Answers
    • Developer documentation

Extracting selected information from stats table

May 19, 2020 by Stefano 1 Comment

Post Pay Counter already displays payment information nicely in the stats table by default, and allows it to be included in public pages through its flexible shortcode. However, there are custom cases where you might need to extract individual bits/figures from the stats table, raw as they are.

This is easily achieved through the high-level functions exposed by the plugin. The main player here is the function PPC_generate_stats::produce_stats. The following example snippet will extract the total adsense revenue for the given $author_ID:

1
2
3
4
5
6
7
8
PPC_general_functions::get_default_stats_time_range( PPC_general_functions::get_settings('general') );
$start_time = $ppc_global_settings['stats_tstart'];
$end_time = $ppc_global_settings['stats_tend'];
$author_ID = 1;
$stats = PPC_generate_stats::produce_stats($start_time, $end_time, array( $author_ID ));
$raw_stats = $stats['raw_stats'];
$total_adsense = $raw_stats[$author_ID]['total']['ppc_payment']['due_payment']['adsense_revenues'];

It will work with the default time range, but it can be changed by feeding UNIX timestamps as values of $start_time and $end_time.

Such a call of produce_stats will generate stats only for the given author, and is thus efficient. Taking away the third argument is possible, and will result in posts from any authors to be queried (and is more performant than making multiple calls with different author parameters). It is technically possible to query posts for a set of authors (in fact, notice the array-like third parameter), but there is no UI that exposes that feature in the stats page.

Adding

var_dump($raw_stats[$author_ID]['total']);

will result in exposing the data structure and show all possible choices of payment criteria and information that can be extracted.

Filed Under: Developer documentation, Tutorials

Post Pay Counter caching features

November 18, 2019 by Stefano 2 Comments

Post Pay Counter supports caching and is compatible with WordPress caching plugins.
Post Pay Counter mostly implements caching for post stats, plugin settings, user settings and active payment criteria.

Since Post Pay Counter version 2.716 (May 2017), server side caching improves stats performance significantly.

On our tests, with several payment criteria active (words, visits, Facebook shares, comments), we manage to load around 10k posts in under 5 seconds on an average VPS with memcached. Un-cached stats may take up to 15 seconds to show up though, so the performance boost is clear. Post stats caching is active by default, and its status can be tweaked in the Miscellanea >  Performance section.


The standard caching caches stats details for each post, but actually rebuilds the stats table for every visit. Websites with massive amounts of data to handle may want to also cache the whole stats page for a given view. In other words, they may take a snapshot of a particular stats page that takes long to load, and then serve it quickly multiple times after.

[Read more…]

Filed Under: Developer documentation, Questions & Answers, Tutorials Tagged With: caching, performance, wp-cli

Add a custom column to the stats table

December 3, 2018 by Stefano 2 Comments

Sometimes you may want to add an additional custom column to the stats table. This cannot be achieved through native plugin features, but some light custom coding is enough.

This tutorial will provide developers a sketch code of how this can be done. It should be easily be adapted to your needs with some (PHP) coding skills. Be sure to review the code, because there are several optional checks just to showcase them (for example, permission checks).

In the example, we add a custom column to show the user email address.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
add_filter( 'ppc_general_stats_format_stats_after_cols_default', 'ppc_add_email_col_html', 10 );
add_filter( 'ppc_general_stats_each_field_empty_value', 'ppc_email_td_html', 10, 4 );
 
/**
* Adds custom field column to stats page.
*
* Hooks to PPC_HTML_functions::get_html_stats() - ppc_general_stats_html_cols_after_default.
*
* @param $cols array Stats columns
*/
function ppc_add_email_col_html( $cols ) {
global $ppc_global_settings;
 
//Only add column to general stats page
if( $ppc_global_settings['current_page'] != 'stats_general' ) return $cols;
 
$perm = new PPC_permissions();
if( $perm->can_mark_as_paid() )
$cols['author_email'] = __( 'Email', 'ppc' );
 
return $cols;
}
 
/**
* Populates custom field in stats page.
*
* Hooks to PPC_HTML_functions::get_html_stats() - ppc_general_stats_html_after_each_default.
*
* @param $author int author id
* @param $formatted_data array formatted stats
* @param $raw_data array sorted stats
*/
function ppc_email_td_html( $field_value, $column_name, $author_stats, $author_id ) {
global $ppc_global_settings;
 
//Only add column to general stats page
if( $ppc_global_settings['current_page'] != 'stats_general' ) return $field_value;
if( $column_name != 'author_email' ) return $field_value;
$perm = new PPC_permissions();
if( $perm->can_mark_as_paid() OR $perm->can_see_paypal_functions() ) {
$user_data = get_userdata( $author_id );
$author_email = $user_data->user_email;
 
return $author_email;
}
 
return $field_value;
}

Filed Under: Developer documentation, Tutorials

Exclude columns from stats in BuddyPress page

November 10, 2017 by Stefano Leave a Comment

The BuddyPress addon allows you to display Post Pay Counter author’s stats in the BuddyPress Member page. However, by default, all columns are displayed. This may include columns that you are not interested into, or that you may not want to show to authors.

Below is a PHP code that allows to exclude some columns from display.

1
2
3
4
5
6
7
8
9
/**
* Exclude post status and post type from BuddyPress stats table
*/
function ppc_buddypress_exclude_stats_columns( $shortcode ) {
$exclude_columns = ''; //comma separated list of columns to be excluded
 
return substr( $shortcode, 0, strlen( $shortcode )-1 ) . ' exclude="'.$exclude_columns.'"]';
}
add_filter( 'ppc_buddypress_stats_shortcode', 'ppc_buddypress_exclude_stats_columns' );

You should change the following line with the columns IDs you would like to hide:

1
$exclude_columns = ''; //comma separated list of columns to be excluded

Valid columns IDs are: post_id, post_title, post_type, post_status, post_publication_date, post_words, post_visits, post_adsense_revenues, post_images, post_comments, post_bonus, post_total_payment, post_due_payment.

[Read more…]

Filed Under: Developer documentation, Tutorials Tagged With: buddypress

Backup Post Pay Counter data

January 15, 2017 by Stefano Leave a Comment

There are cases in which you may want to backup data from Post Pay Counter (and maybe Post Pay Counter PRO). If you have access to PhpMyAdmin, this can be easily achieved through a handful of custom queries that can pull out all relevant data. Selected rows can then be exported in a sql file, serving as a backup. The three queries are the following:

PPC backup
1
2
3
4
5
SELECT * FROM wp_options WHERE option_name IN ("ppc_settings", "ppc_errors", "ppcp_ga_stuff", "ppc_dismissed_notifications", "ppc_addons_list", "_ppcp_payment_history", "ppcp_ga_first_request", "ppcp_ga_last_request")
 
SELECT * FROM wp_postmeta WHERE meta_key IN ( "_ppcp_ga_visits", "_ppcp_adsense_revenue", "_ppcp_ga_data", "_ppcp_payment_history",  "_ppcp_exclude")
 
SELECT * FROM wp_usermeta WHERE meta_key IN ( "_ppcp_payment_history" ) OR meta_key LIKE "%ppcp_paypal_email"

These queries will extract ALL Post Pay Counter and Post Pay Counter PRO data (general settings, custom user settings, Analytics authorization information and visits for each post, payment history both for posts and authors, user PayPal emails, excluded posts from stats – it should really include ALL possible database data). Notice that other addons may need additional backup to be done.

You can then use the PhpMyAdmin Export feature to download the sql file for each query and store them safely. Below is an animated example of the process (for one query):

Post Pay Counter Backup

Filed Under: Developer documentation, Tutorials Tagged With: backup

What is the meta key for the user_meta PayPal email address?

August 15, 2016 by Stefano Leave a Comment

The user’s PayPal email address is stored as a WordPress user_meta with the meta_key wp_ppcp_paypal_email.

Note: if you changed the default WP table prefix, the meta_key should be changed to yourprefix_ppcp_paypal_email.

Filed Under: Developer documentation, Questions & Answers Tagged With: paypal, post pay counter pro

Add custom statuses to Post Pay Counter stats

July 22, 2016 by Stefano Leave a Comment

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;
}

 

Filed Under: Developer documentation, Questions & Answers Tagged With: developer documentation, post statuses

Set up an effective payment flow for lifetime visits

May 27, 2016 by Stefano Leave a Comment

If you already know how to pay your writers per visits, you may want to pay them for all the visits their posts record through all time, not just for the current month. This can be easily achieved through the PRO version mark as paid feature. This tutorial will guide you through how to set up the payment flow in order to achieve that.

How to pay authors per views across multiple months

  1. If you use Google Analytics, make sure you have selected the desired start day for visits. This can be done through the Update Analytics Data feature in the Google Analytics Status box. For example, if you want to pay writers for views since the beginning of 2016, then you need to select 2016/01/01. You may well want to start counting visits since the day you install the plugin, in which case just select that day or don’t do anything.
    [Read more…]

Filed Under: Developer documentation, Tutorials Tagged With: google analytics, mark as paid, post pay counter pro, visits

Add custom payment types to Post Pay Counter stats

September 28, 2015 by Stefano 2 Comments

Post Pay Counter allows by default paying for words, visits, comments and images. The PRO version allows you to pay for Adsense revenues and to give a custom bonus to each post, whereas other addons allow to further expand the things that can be paid for. But what if you want to add your own custom payment type? Well, PPC has some handy functions that allow you do that with ease.

[Read more…]

Filed Under: Developer documentation, Tutorials Tagged With: post pay counter

Your cart

Number of items in cart: 0

  • Your cart is empty.
  • Total: €0.00
  • Checkout

What are you looking for?

Connect on Facebook

Follow the Post Pay Counter page on Facebook to be up-to-date with discounts and latest releases!

Copyright © 2021 · Centric Theme on Genesis Framework · WordPress · Log in

This site uses cookies, as all sites on the planet do -- More info