Created
October 28, 2015 20:06
-
-
Save cleverness/837a374c8c1614f8fd00 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Insert new to-do item into the database | |
* @static | |
* @return mixed | |
*/ | |
public static function insert_todo() { | |
global $current_user; | |
if ( $_POST['cleverness_todo_description'] == '' ) return; | |
$permission = CTDL_Lib::check_permission( 'todo', 'add' ); | |
if ( $permission === true ) { | |
if ( ! wp_verify_nonce( $_REQUEST['todoadd'], 'todoadd' ) ) die( esc_html__( 'Security check failed', 'cleverness-to-do-list' ) ); | |
$send_email = apply_filters( 'ctdl_send_email', CTDL_Loader::$settings['email_assigned'] ); | |
$my_post = array( | |
'post_type' => 'todo', | |
'post_title' => substr( $_POST['cleverness_todo_description'], 0, 100 ), | |
'post_content' => $_POST['cleverness_todo_description'], | |
'post_status' => 'publish', | |
'post_author' => $current_user->ID, | |
'comment_status' => 'closed', | |
'ping_status' => 'closed', | |
); | |
$post_id = wp_insert_post( $my_post ); | |
if ( isset( $_POST['cat'] ) ) wp_set_post_terms( $post_id, absint( $_POST['cat'] ), 'todocategories', false); | |
add_post_meta( $post_id, '_status', 0, true ); | |
$priority = ( isset( $_POST['cleverness_todo_priority'] ) ? absint( $_POST['cleverness_todo_priority'] ) : 1 ); | |
add_post_meta( $post_id, '_priority', $priority, true ); | |
$assign_permission = CTDL_Lib::check_permission( 'todo', 'assign' ); | |
// if user can assign to-do items | |
if ( $assign_permission == true ) { | |
$assign = ( isset( $_POST['cleverness_todo_assign'] ) ? $_POST['cleverness_todo_assign'] : -1 ); | |
if ( is_array( $assign ) ) { | |
foreach ( $assign as $value ) { | |
add_post_meta( $post_id, '_assign', $value ); | |
} | |
} else { | |
add_post_meta( $post_id, '_assign', $assign ); | |
} | |
if ( $send_email == '1' && CTDL_Loader::$settings['assign'] == '0' ) { | |
$deadline = ( isset( $_POST['cleverness_todo_deadline'] ) ? $_POST['cleverness_todo_deadline'] : 0 ); | |
$cat = ( isset( $_POST['cat'] ) ? $_POST['cat'] : 0 ); | |
$planner = ( isset( $_POST['cleverness_todo_planner'] ) ? $_POST['cleverness_todo_planner'] : 0 ); | |
CTDL_Lib::email_user( $assign, $deadline, $cat, $planner ); | |
} | |
} else { | |
// if user can't assign items, but settings are set to assign items and show only assigned items, then assign it to that user | |
if ( CTDL_Loader::$settings['list_view'] != 0 && CTDL_Loader::$settings['assign'] == 0 && CTDL_Loader::$settings['show_only_assigned'] == 0 ) { | |
add_post_meta( $post_id, '_assign', $current_user->ID ); | |
} | |
} | |
$deadline = ( isset( $_POST['cleverness_todo_deadline'] ) && $_POST['cleverness_todo_deadline'] != '' ? strtotime( $_POST['cleverness_todo_deadline'] ) : '' ); | |
add_post_meta( $post_id, '_deadline', $deadline, true ); | |
$progress = ( isset( $_POST['cleverness_todo_progress'] ) ? $_POST['cleverness_todo_progress'] : 0 ); | |
add_post_meta( $post_id, '_progress', $progress, true ); | |
if ( isset( $_POST['cleverness_todo_planner'] ) ) add_post_meta( $post_id, '_planner', absint( $_POST['cleverness_todo_planner'] ) ); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment