Last active
August 29, 2015 13:55
-
-
Save stephanieleary/8718496 to your computer and use it in GitHub Desktop.
Achievements 2.4 plugin for LetterMo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/* | |
Plugin Name: LetterMo Post Types | |
Plugin URI: http://stephanieleary.com/ | |
Version: 1.5 | |
Author: Stephanie Leary | |
Author URI: http://stephanieleary.com/ | |
Description: Setting up the post types and achievements for Month of Letters. | |
License: GPL2 | |
*/ | |
// CPT defined elsewhere is 'letter'; its taxonomy is called 'extras' | |
// user sent a letter | |
function dpa_handle_action_publish_letter() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'publish_letter', $func_get_args ); | |
} | |
function lettermo_set_action_category_name( $category_name, $category ) { | |
if ( __( 'Other', 'dpa' ) == $category_name && 'letter' == $category ) | |
return __( "Month of Letters", 'letter' ); | |
else | |
return $category_name; | |
} | |
add_filter( 'dpa_get_addedit_action_descriptions_category_name', 'lettermo_set_action_category_name', 10, 2 ); | |
function lettermo_filter_draft_to_publish_action_userid( $user_id, $action_name, $action_func_args ) { | |
if ( 'draft_to_publish' != $action_name ) | |
return $user_id; | |
$post = $action_func_args[0]; | |
return $post->post_author; | |
} | |
add_filter( 'dpa_handle_action_user_id', 'lettermo_filter_draft_to_publish_action_userid', 10, 3 ); | |
add_action('save_post', 'lettermo_category_achievements', 10, 1); | |
function lettermo_category_achievements($postid) { | |
if ($parent_id = wp_is_post_revision($postid)) | |
$postid = $parent_id; | |
do_lettermo_actions($postid); | |
} | |
add_action('gform_post_submission', 'lettermo_gform_category_achievements', 99, 2); | |
function lettermo_gform_category_achievements( $entry, $form ) { | |
// Check if the submission contains a WordPress post | |
if ( isset ( $entry['post_id'] ) ) { | |
do_lettermo_actions($entry['post_id']); | |
} | |
} | |
// category-specific achievements | |
// user sent a reply | |
function dpa_handle_action_sent_reply() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'sent_reply', $func_get_args ); | |
} | |
// user sent a package | |
function dpa_handle_action_sent_package() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'sent_package', $func_get_args ); | |
} | |
// user sent something internationally | |
function dpa_handle_action_sent_international() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'sent_international', $func_get_args ); | |
} | |
// user sent something Austen-style | |
function dpa_handle_action_sent_austen() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'sent_austen', $func_get_args ); | |
} | |
// user sent a Valentine | |
function dpa_handle_action_sent_valentine() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'sent_valentine', $func_get_args ); | |
} | |
// user sent something from a new mailbox | |
function dpa_handle_action_sent_new_mailbox() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'sent_new_mailbox', $func_get_args ); | |
} | |
// user sent a zine | |
function dpa_handle_action_sent_zine() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'sent_zine', $func_get_args ); | |
} | |
// user had a letter hand-cancelled | |
function dpa_handle_action_hand_cancelled() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'hand_cancelled', $func_get_args ); | |
} | |
// user sent a letter to a soldier | |
function dpa_handle_action_sent_to_soldier() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'sent_to_soldier', $func_get_args ); | |
} | |
// user sent a letter to a soldier | |
function dpa_handle_action_birthday() { | |
$func_get_args = func_get_args(); | |
dpa_handle_action( 'birthday', $func_get_args ); | |
} | |
function do_lettermo_actions($postid) { | |
if (has_term('reply', 'extras', $postid)) { | |
do_action('sent_reply', $postid); | |
} | |
if (has_term('package', 'extras', $postid)) { | |
do_action('sent_package', $postid); | |
} | |
if (has_term('international', 'extras', $postid)) { | |
do_action('sent_international', $postid); | |
} | |
if (has_term('austen-style', 'extras', $postid)) { | |
do_action('sent_austen', $postid); | |
} | |
if (has_term('valentine', 'extras', $postid)) { | |
do_action('sent_valentine', $postid); | |
} | |
if (has_term('new-mailbox', 'extras', $postid)) { | |
do_action('sent_new_mailbox', $postid); | |
} | |
if (has_term('zine', 'extras', $postid)) { | |
do_action('sent_zine', $postid); | |
} | |
if (has_term('hand-cancelled', 'extras', $postid)) { | |
do_action('hand_cancelled', $postid); | |
} | |
if (has_term('sent_to_soldier', 'extras', $postid)) { | |
do_action('sent_to_soldier', $postid); | |
} | |
if (has_term('birthday-wishes', 'extras', $postid)) { | |
do_action('birthday', $postid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment