Support » Plugin: Cleverness To-Do List » Can i extend the public Class to create my own display functions?

  • Resolved slashCreations

    (@slashcreations)


    Hi,

    I wan’t to display the admin todo form on front-end (without todo list). Ideally, I would like to create my own display_admin function.
    Using the [todoadmin] shortcode, i can’t display the todo form only.

    Can you explain me how to perform that?
    I tried to create a new plugin and extended your class, as follows:

    class myToDoList extends ClevernessToDoList {
      function display_admin( $completed = 0 ) {
      //some code
      }
      }
    $toDo = new myToDoList();

    But i got an error when activating my custom plugin which says that ClevernessToDoList does not exist.

    Can you show me the good way to create custom displays using class extending, or alternatively, some others ways ?

    Thanks.
    (and sorry for my english)

    http://wordpress.org/extend/plugins/cleverness-to-do-list/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Cindy Kendrick

    (@elusivelight)

    I’m afraid I don’t really have any advice on extending it. I’ve never done that for a plugin outside of the main plugin. This plugin wasn’t really designed for custom displays so I don’t have any good way to go about it.

    It may be that your plugin is loading before mine, which is why it says it doesn’t exist. You could see if the global $ClevernessToDoList is set to see if that is the case. If it’s not set, you may need to look into changing the plugin load order somehow.

    Thread Starter slashCreations

    (@slashcreations)

    Thanks for the fast reply!

    Well, let’s forget that sub-plugin option.

    What can you suggest me so ? The only way to customize display is only editing your core plugin files ? … I can easily copy paste the admin_display function and modify it to my need, and calling it admin_display_custom, and creating a new shortcode for it, but if i create by editing your files, i will lose it on the next update.
    Is there any change that i can put into my theme functions.php that can help me to modify the html display without modifying the plugin files ?

    Thanks!

    Plugin Author Cindy Kendrick

    (@elusivelight)

    I do have action and filter hooks built in to the plugin but I don’t know if there’s any that would fit your needs (you can see them in the code). They’re more to modify small details.

    I can add new ones but I don’t know if it would be possible to get the results you desire. If you do find a way to do it with a newly placed filter/action I can add that filter/action call to the plugin.

    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"]

    Just wondering @cindy would you be able to assist me with implementing the above solution as a snippet that could be included in the theme functions files with modifying the core files in the plugin?

    I’m afraid this kind of class integration from a theme’s functions file is a little over my head.

    Thanks!

    S.

    Plugin Author Cindy Kendrick

    (@elusivelight)

    I have figured out how to do this. It’s best to do it as a new plugin, although you also could just paste the code into functions.php.

    You can see the code at this GitHub gist.

    Thanks Cindy! YOU ROCK!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Can i extend the public Class to create my own display functions?’ is closed to new replies.