diff --git a/README.md b/README.md index 58e16e7..5c5aae6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -~Current Version:1.3.2~ +~Current Version:1.3.3~ # Task Breaker diff --git a/controllers/tasks.php b/controllers/tasks.php index 91b9a80..15ee8cf 100644 --- a/controllers/tasks.php +++ b/controllers/tasks.php @@ -31,15 +31,16 @@ public function addTicket( $params = array() ) { $args[ $key ] = $value; } + } $this->setTitle( $args['title'] ) - ->setDescription( $args['description'] ) - ->setMilestoneId( $args['milestone_id'] ) - ->setProjectId( $args['project_id'] ) - ->setUser( $args['user_id'] ) - ->setPriority( $args['priority'] ) - ->setAssignUsers( $args['user_id_collection'] ); + ->setDescription( $args['description'] ) + ->setMilestoneId( $args['milestone_id'] ) + ->setProjectId( $args['project_id'] ) + ->setUser( $args['user_id'] ) + ->setPriority( $args['priority'] ) + ->setAssignUsers( $args['user_id_collection'] ); if ( empty( $this->title ) || empty( $this->description ) ) { @@ -51,7 +52,7 @@ public function addTicket( $params = array() ) { } - public function deleteTicket( $id = 0, $project_id = 0 ) { + public function deleteTask( $id = 0, $project_id = 0 ) { // delete the ticket if ( 0 === $id ) { @@ -66,7 +67,7 @@ public function deleteTicket( $id = 0, $project_id = 0 ) { } - public function updateTicket( $id = 0, $args = array() ) { + public function updateTask( $id = 0, $args = array() ) { // Make sure the current user is able to update the task. if ( ! task_breaker_can_update_task( $args['project_id'] ) ) { @@ -93,18 +94,6 @@ public function renderTasks( $args = array() ) { } - public function renderTicketsByMilestone( $milestone_id = 0 ) { - - return array(); - } - - public function renderTicketsByUser( $user_id = 0 ) { - - return array(); - - } - - public function completeTask( $task_id = 0, $user_id = 0 ) { parent::prepare(); @@ -117,12 +106,12 @@ public function renewTask( $task_id = 0 ) { parent::prepare(); - return parent::renewTask( $task_id ); + return parent::renewTask( absint( $task_id ) ); } public function getPriority( $priority = 1 ) { - return parent::getPriority( $priority ); + return parent::getPriority( absint( $priority ) ); } diff --git a/core/conditional-tags.php b/core/conditional-tags.php index 51f42d6..7b469c0 100644 --- a/core/conditional-tags.php +++ b/core/conditional-tags.php @@ -44,12 +44,12 @@ function task_breaker_current_user_is_member_of_group( $group_id = 0 ) { } - /** - * Check if current user can access projects. Only group members can access - * the project - * - * @return boolean - */ +/** + * Check if current user can access projects. Only group members can access + * the project + * + * @return boolean + */ function task_breaker_can_view_project( $project_id ) { if ( ! is_user_logged_in() ) { @@ -69,12 +69,12 @@ function task_breaker_can_view_project( $project_id ) { return false; } - /** - * Check if current user can add project to group. Only admin and - * moderators can add project to group. - * - * @return boolean - */ +/** + * Check if current user can add project to group. Only admin and + * moderators can add project to group. + * + * @return boolean + */ function task_breaker_can_add_project_to_group( $group_id ) { if ( ! is_user_logged_in() ) { @@ -96,12 +96,12 @@ function task_breaker_can_add_project_to_group( $group_id ) { return false; } - /** - * Check if current user can edit project. Only admin and moderators can edit - * the projects. - * - * @return boolean - */ +/** + * Check if current user can edit project. Only admin and moderators can edit + * the projects. + * + * @return boolean + */ function task_breaker_can_edit_project( $project_id = 0 ) { if ( ! is_user_logged_in() ) { @@ -165,8 +165,8 @@ function task_breaker_can_delete_project( $project_id = 0 ) { } - // Tasks - // Check if current user can see tasks inside the project +// Tasks +// Check if current user can see tasks inside the project function task_breaker_can_see_project_tasks( $project_id ) { if ( ! is_user_logged_in() ) { @@ -386,5 +386,4 @@ function task_breaker_is_project_group_public( $project_id = 0 ) { return false; -} - +} \ No newline at end of file diff --git a/emails/class-buddypress-mail-register.php b/emails/class-buddypress-mail-register.php index a4177de..c7aca91 100644 --- a/emails/class-buddypress-mail-register.php +++ b/emails/class-buddypress-mail-register.php @@ -12,14 +12,13 @@ final class Task_Breaker_BP_Mail_Register { - public function __construct() { // Register the new task email template. add_action( 'bp_core_install_emails', array( $this, 'new_task_email_template' ) ); // Register our new email post type and template. - add_action( 'bp_core_install_emails', array( $this, 'new_task_comment_email_template', ) ); + add_action( 'bp_core_install_emails', array( $this, 'new_task_comment_email_template' ) ); // Register the new task mailer. add_action( 'tb_new_task', array( $this, 'tb_new_task' ), 10, 1); @@ -31,6 +30,7 @@ public function __construct() { add_action( 'bp_notification_settings', array( $this, 'tb_render_task_email_settings', ), 0 ); return $this; + } function new_task_email_template() { @@ -145,6 +145,12 @@ function new_task_comment_email_template() { * @return void */ function tb_new_task( $task_object ) { + + // Bail out if notifications are disabled or BP version does not support e-mail api. + if ( ! function_exists( 'bp_send_email' ) ) { + return; + } + // Add the tokens to parse in the email template. $args = array( 'tokens' => array( @@ -192,6 +198,11 @@ function tb_new_task( $task_object ) { * @return void */ function tb_new_task_comment( $task_comment_object ) { + + // Bail out if notifications are disabled or BP version does not support e-mail api. + if ( ! function_exists( 'bp_send_email' ) ) { + return; + } // Add tokens to parse in email. $args = array( diff --git a/models/tasks.php b/models/tasks.php index dce084b..b6a99c7 100644 --- a/models/tasks.php +++ b/models/tasks.php @@ -534,6 +534,11 @@ public function fetch( $args = array() ) { return array(); } + /** + * Saves the instance of new task in the database. + * @param array $args The arguments we need to pass in the save() method. + * @return boolean Returns true on success, otherwise false. + */ public function save( $args = array() ) { global $wpdb; @@ -664,19 +669,24 @@ public function save( $args = array() ) { // Send a notification to the assigned member. $exploded_members = explode( ',', $this->group_members_assigned ); - foreach ( (array) $exploded_members as $ua_id ) { - - bp_notifications_add_notification( - array( - 'user_id' => $ua_id, - 'item_id' => $last_insert_id, - 'secondary_item_id' => $this->user_id, - 'component_name' => 'task_breaker_ua_notifications_name', - 'component_action' => 'task_breaker_ua_action', - 'date_notified' => bp_core_current_time(), - 'is_new' => 1, - ) - ); + // Check if notification component is enabled. + if ( function_exists( 'bp_notifications_add_notification' ) ) { + + foreach ( (array) $exploded_members as $ua_id ) { + + bp_notifications_add_notification( + array( + 'user_id' => $ua_id, + 'item_id' => $last_insert_id, + 'secondary_item_id' => $this->user_id, + 'component_name' => 'task_breaker_ua_notifications_name', + 'component_action' => 'task_breaker_ua_action', + 'date_notified' => bp_core_current_time(), + 'is_new' => 1, + ) + ); + } + } // Send them ssome snazzy email! diff --git a/task-breaker.php b/task-breaker.php index ab18e39..28f12a8 100644 --- a/task-breaker.php +++ b/task-breaker.php @@ -2,7 +2,7 @@ /** * Plugin Name: Task Breaker * Description: A WordPress plug-in that will help you break some task! - * Version: 1.3.2 + * Version: 1.3.3 * Author: Dunhakdis * Author URI: http://dunhakdis.me * Text Domain: task_breaker @@ -22,7 +22,7 @@ exit(); } -define( 'TASK_BREAKER_VERSION', '1.3.2' ); +define( 'TASK_BREAKER_VERSION', '1.3.3' ); define( 'TASK_BREAKER_PROJECT_LIMIT', 10 ); diff --git a/transactions/controller.php b/transactions/controller.php index c28f77a..95ec7ef 100644 --- a/transactions/controller.php +++ b/transactions/controller.php @@ -7,7 +7,8 @@ */ // check if access directly -if ( ! defined( 'ABSPATH' ) ) { die(); +if ( ! defined( 'ABSPATH' ) ) { + die(); } $action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING ); @@ -21,7 +22,6 @@ return; } - // Format our page header when Unit Testing if ( ! defined( 'WP_TESTS_DOMAIN' ) ) { @@ -74,7 +74,6 @@ function task_breaker_transactions_callblack() { } $allowed_callbacks = array( - // Tickets/Tasks callbacks 'task_breaker_transaction_add_ticket', 'task_breaker_transaction_delete_ticket', @@ -177,13 +176,12 @@ function task_breaker_transaction_delete_ticket() { $ticket_id = (int) filter_input( INPUT_POST, 'id', FILTER_VALIDATE_INT ); $project_id = (int) filter_input( INPUT_POST, 'project_id', FILTER_VALIDATE_INT ); - ; $task = new ThriveProjectTasksController(); - $deleteTicket = $task->deleteTicket( $ticket_id, $project_id ); + $deleteTask = $task->deleteTask( $ticket_id, $project_id ); - if ( $deleteTicket ) { + if ( $deleteTask ) { task_breaker_api_message( array( @@ -248,22 +246,19 @@ function task_breaker_transaction_fetch_task() { $task = new ThriveProjectTasksController(); $args = array( - 'project_id' => $project_id, - 'id' => $task_id, - 'page' => $page, - 'priority' => $priority, - 'search' => $search, - 'show_completed' => $show_completed, - 'orderby' => 'priority', - 'order' => 'desc', - 'echo' => 'no', + 'project_id' => $project_id, + 'id' => $task_id, + 'page' => $page, + 'priority' => $priority, + 'search' => $search, + 'show_completed' => $show_completed, + 'orderby' => 'priority', + 'order' => 'desc', + 'echo' => 'no', ); $task_collection = $task->renderTasks( $args ); - // Push the ticket ID in the task_collection stack. - $task_collection->task_id = absint( $task_id ); - if ( 0 === $task_id ) { $task_id = null; @@ -341,7 +336,7 @@ function task_breaker_transaction_edit_ticket() { // Make sure the current user is able to update the task. if ( task_breaker_can_update_task( $project_id ) ) { - if ( $task->updateTicket( $task_id, $args ) ) { + if ( $task->updateTask( $task_id, $args ) ) { $json_response['message'] = 'success';