Hey All,
Potential solution for customizing the front-end list and form.
Love the cleverness to-do plugin. Although the admin looks beauty… it’s a little challenging to access the front-end integration.
What I needed was a front-end solution (we’re talkin in the site templates) that lists to do items on the left and “add new to do” form on the right, The current CTDL_Frontend_Admin class setup and ‘todoadmin’ shortcode groups them together making it difficult to customize on the front-end.
*Fair warning this solution involves editing the core files which is not ideal, but perhaps it will be useful to other developers.
editing the cleverness-to-do-list-frontend.class.php file
add in a new block of code which duplicates the class and shortcode structure used in the plugin to create your own form:
/**
* CUSTOM ADD FORM SHORTCODE
*/
class CTDL_Frontend_AddForm extends ClevernessToDoList {
protected $atts;
public $add_script;
public function __construct() {
add_shortcode( 'todoaddnewform', array( $this, 'display_addnewform' ) );
parent::__construct();
}
public function display_addnewform( $atts ) {
extract( shortcode_atts( array(
'title' => '',
), $atts ) );
$this->atts = $atts;
$this->add_script = true;
$this->list = '';
if ( $title != '' ) {
$this->list .= '<h3 class="todo-title">'.esc_html( $title ).'</h3>';
}
if ( is_user_logged_in() ) {
if ( current_user_can( CTDL_Loader::$settings['add_capability'] ) || CTDL_Loader::$settings['list_view'] == '0' ) {
extract( shortcode_atts( array(
'priority' => 0,
'assigned' => 0,
'deadline' => 0,
'progress' => 0,
'categories' => 0,
'addedby' => 0,
'date' => 0,
'editlink' => 1
), $this->atts ) );
$this->form = '<h3>'.apply_filters( 'ctdl_add_heading', esc_html__( 'Add New To-Do Item', 'cleverness-to-do-list' ) ).'</h3>';
$this->form .= '<form name="addtodo" id="addtodo" action="'.$this->url.'?type=ToDoItem&action=added" method="post">
<table class="todo-form form-table">';
/** @var $priority int */
if ( $priority == 1 ) $this->create_priority_field();
/** @var $deadline int */
if ( $deadline == 1 ) $this->create_deadline_field();
/** @var $categories int */
if ( $categories == 1 ) $this->create_category_field();
if ( CTDL_PP ) $this->create_planner_field();
/** @var $assigned int */
if ( $assigned == 1 ) $this->create_assign_field();
/** @var $progress int */
if ( $progress == 1 ) $this->create_progress_field();
$this->form .= do_action( 'ctdl_add_form' );
$this->create_todo_text_field();
$this->form .= '</table>'.wp_nonce_field( 'todoadd', 'todoadd', true, false ).'<input type="hidden" name="action" value="addtodo" />
<p class="submit"><input type="submit" name="submit" class="button-primary" value="'.apply_filters( 'ctdl_add_text', esc_attr__( 'Add To-Do Item', 'cleverness-to-do-list' ) ).'" /></p>';
$this->form .= '</form>';
return $this->form;
} else {
return '';
}
} else {
$this->list .= esc_html__( 'You must be logged in to view', 'cleverness-to-do-list' );
}
return $this->list;
}
}
This class creates a new shortcode “todoaddnewform” which allows you to add in just the form into your template where needed. All the parameters still work which allow you to add the right fields when creating the form.
For example add into your template:
<?php echo do_shortcode('[todoaddnewform priority="1" categories="1"]'); ?>
or into your page content
[todoaddnewform priority="1" categories="1"]