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.
Add your custom payment type to Post Pay Counter stats
The class which handles all payment types is PPC_counting_types. It contains a method called register_counting_type, which accepts as input an array of parameters as follow (bold means compulsory):
- id – unique identifier of the counting type (counting types are usually prefixed by a shortened version of the addon that registered them, for example ppc, ppcp, ppcp_fb…).
- label – text that will be displayed in stats and everywhere else to refer to this counting type.
- apply_to – whether counting type applies to posts or authors (or both). Possible values are post, author, both.
- settings_status_index – (optional) the name of the settings index of the plugin settings to check whether the counting type is enabled. This method can only be used if the setting is stored among the default ones, in the same wp_option. Otherwise you will have to check the enabled status in another way.
- count_callback – (optional) method to count “how many of the counting_type there are (eg. how many words, visits…)”.
Needs to return an array in the form array( ‘to_count’ => int, ‘real’ => int ).
Can (and should) be a class method, in which case an array is needed (e.g. array( ‘classname’, ‘static_method’ ) or array( $object, ‘method’ ) ). In any case, it will receive the $post WP_Post_Object as parameter if apply_to = post, will receive author stats and author id if apply_to = author.- display – (optional) whether you want the count, the payment, both or nothing in the stats, possible values are count, payment, both, none. Default is ‘both’.
- payment_callback – method to compute payment of the counted “how many”. Will receive the counting output array as parameter.
- other_params – (optional) whatever you may need to store.
- not_to_pay – (bool) exclude counting from payments (for PPC PRO).
Please note that this will only add a new column to the stats table, as well as in the confirm payment and in payment history: you will have to take care yourself of adding any settings to the options page to set up the counting type, if needed.
What follows is an example of registering a counting type. taken from the PRO version code.
/** * Registers payment bonus counting type. * * Hooks to ppc_registered_built_in_counting_types - PPCP_payment_bonus::register_counting_type_payment_bonus */ static function register_counting_type_payment_bonus() { global $ppc_global_settings; $payment_bonus_counting_type = array( 'id' => 'bonus', 'label' => __( 'Bonus', 'ppcp' ), 'apply_to' => 'post', 'settings_status_index' => 'enable_payment_bonus', 'display' => 'payment', 'payment_only' => true, 'count_callback' => array( 'PPCP_payment_bonus', 'get_post_payment_bonus_count' ), 'payment_callback' => array( 'PPCP_payment_bonus', 'get_post_payment_bonus' ) ); $ppc_global_settings['counting_types_object']->register_counting_type( $payment_bonus_counting_type ); } /** * Gets payment. (similar for counting) * * @access public * @param $countings array countings * @param $post_id int post id * @return object WP post */ static function get_post_payment_bonus( $countings, $post_id ) { global $ppcp_global_settings; $post_bonus = (float) get_post_meta( $post_id, 'ppcp_payment_bonus', true ); return $post_bonus; }
Larry Gomez says
Hey Guys,
I am looking to pay each person that leaves a comment and the original person who post? Is this an option?
Stefano says
Hi Larry, thanks for your patience ๐
Post Pay Counter allows to pay the post author, but it’s not possible to pay who leaves a comment. You could add that payment criteria to native ones through the tutorial above though (with some developer work) ๐
Does this help?
Have a nice day,
Stefano
Brian says
Is it possible to use Post Pay Counter to pay my blog users (readers, social media influencers or owners of other websites) who share my blog articles without them having to publish any post?
Stefano says
Hi Brian,
it should be possible to achieve that. With the Referral Visits addon you can pay authors for traffic they bring, and there is an apt setting in Post Pay Counter to display all users in stats, regardless of whether they have published posts (Options > Miscellanea > Performance > Display all users in stats) ๐
Ashen says
Hey Stefano,
I edited above code to suit my needs. But where do I need to put it? In functions.php?
Stefano says
Hi Ashen! Yes, your theme’s functions.php would work! ๐