Torro Forms // Using Form Access Control API

For adding your own access control, the class Torro_Form_Access_Control have to be extended by your own class.

The Torro Forms access control API adds a new selectable entry under Your Form > Settings > Access Control.  With the option_content() method you can add your HTML for your option, which you can save in the save() method of the class.

The Torro Forms access control API comes with the function check(). Return your true for access or false if the user don't have access to the form.

This page contains the technical documentation for the Torro Forms Access Control API and is written for developers. If you're not a developer you may want to review the Form Settings.

Default Usage

class My_Access_Control extends Torro_Form_Access_Control{
    /**
     * Sets up the contol name etc
     */
    protected function init() {
        $this->title = __( 'My ACL', 'torro-forms' );
        $this->name = 'my_acl';
        $this->option_name = __( 'My Access Control', 'torro-forms' );
    }
	
    /**
     * The content of the widget, displayed in formbuilder if control is selected
     *
     * @param int $form_id
     * @return string $html
     */
    public function option_content( $form_id ) {
        // HTML content 
    }
	
    /**
     * Saving the data of the option content in the formbuilder
     *
     * @param int $form_id
     */
    public function save( $form_id ) {
    	// Save your options
    }
	
    /**
     * Cheks if user has access
     * 
     * @param int $form_id
     * @return boolean $has_access
     */
    public function check( $form_id ) {
        // Do your check here and return true or false
    }
}

Registering the Access Control

    torro()->access_controls()->register( 'My_Access_Control' );

Example

class My_Access_Control extends Torro_Form_Access_Control{
    /**
     * Sets up the contol name etc
     */
    protected function init() {
        $this->title = __( 'My ACL', 'torro-forms' );
        $this->name = 'my_acl';
        $this->option_name = __( 'My Access Control', 'torro-forms' );
    }
	
    /**
     * The content of the widget, displayed in formbuilder if control is selected
     *
     * @param string $html
     */
    public function option_content( $form_id ) {
        $has_access = get_post_meta( $form_id, 'my_acl_has_access', true );
        
        if( 'yes' == 'has_access' )
            $checked = ' checked="checked"';
    
        $html = 'This are my option settings.';
        $html.= '<input type="checkbox" name="my_acl_has_access" value="yes"' . $checked . '> Have access';
        
        return $html;
    }
	
    /**
     * Saving the data of the option content in the formbuilder
     *
     * @param int $form_id
     */
    public function save( $form_id ) {
    	update_post_meta( $form_id, 'my_acl_has_access', $_POST[ 'my_acl_has_access' ] )
    }
	
    /**
     * Cheks if user has access
     *
     * @param int $form_id
     * @return boolean $has_access
     */
    public function check( $form_id ) {
        // Do your check here and return true or false
        
        $has_access = get_post_meta( $form_id, 'my_acl_has_access', true );
        
        if( 'yes' == $has_access ) {
            return true;
        }
        return false;
    }
}
torro()->access_controls()->register( 'My_Access_Control' );

How to add your code

To add your code, we have created your the function torro_load(). Put in your function to the parameters and it will be loaded in the right way.

function your_torro_functionality(){
    require_once 'my-element-type.php';

// Also take care of the other functionality here,
// like registering the template location. } function my_plugin() { if ( ! function_exists( 'torro_load' ) ) { return; // Torro Forms is not active } torro_load( 'your_torro_functionality' ); } add_action( 'plugins_loaded', 'my_plugin' );
Fork me on GitHub