Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pippinsplugins/3bcde150511101e23f9e to your computer and use it in GitHub Desktop.
Save pippinsplugins/3bcde150511101e23f9e to your computer and use it in GitHub Desktop.
A Slash command to retrieve earnings in Restrict Content Pro for the specified time period. Based on http://wpninjas.com/using-slack-slash-commands-to-get-edd-sales-info/
<?php
function pw_rcp_earnings_slash_command() {
# Check to make sure this is a Slash Command Request
if ( ! isset( $_REQUEST['slack_slash'] ) && 'your_custom_string' != $_REQUEST['slack_slash'] )
return false;
# Check to see if a token has been passed as well
if ( ! isset( $_REQUEST['token'] ) )
return false;
# Set additional text strings if sent
$text = isset ( $_REQUEST['text'] ) ? $_REQUEST['text'] : '';
# Check that the token is the one that was set in Slack
if ( 'your_slack_token' == $_REQUEST['token'] ) {
# Gather EDD sales data
$stats = new RCP_Payments;
$args = array();
# check additional text to display appriate data
switch ( $_REQUEST['text'] ) {
case 'day':
$args['date']['day'] = date( 'd' );
$args['date']['month'] = date( 'n' );
$args['date']['year'] = date( 'y' );
break;
case 'month':
$args['date']['month'] = date( 'n' );
$args['date']['year'] = date( 'y' );
break;
case 'year':
$args['date']['year'] = date( 'y' );
break;
case 'lifetime':
// Default for get_earnings()
break;
}
echo '$' . $stats->get_earnings( $args );
# We need to die or you will send a bunch of html that Slack won't be able to handle
die();
}
}
add_action( 'init', 'pw_rcp_earnings_slash_command' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment