Documentation

EasyViewControlGeneralExtend

Quick page navigation

Wow a Code whoooaaa… this supposed to be Drag & Drop!

Don’t worry if you are not going to create completely new View or Control brick that does not exists yet, then this is not for you.
In that case check the View or Control or General documentation.

But if you want to extend the Easy of your own functions, this is small guide will help you.

Create View brick

Define the brick in a form of a simple array

/*
* Here we create the View brick 
* make it simple and name the value and the array key by the same name  
* default keys start with "b2046_" so omit such names
*/
$my_test_brick = array('my_test_brick' => array(
	'block' => 'view', // choices: general, view, view_after, logic, resistor 
		'item_title' => __('Test','p_2046s_easy_widget'), // the name of the brick
		'gui' => array(
			array(
				'ui_note' => __('Test text', 'p_2046s_easy_widget'), // the of the field (if the field is input it'll be placed inside as placeholder)
				'ui_type' => 'input', // user inputs - choices are: input,select_box,check_box,radio_group,textarea
				'choices' => '', // string OR array
				'value' =>'', // default value
				'esc' => 'stip_tags' // data validation (you can simply use WP validations or your own)
			)
		)
	),
);

Add the brick to the default bricks.

Easy_2046_builder::$EasyItems = array_merge(Easy_2046_builder::$EasyItems, $my_test_brick  );

By this line of code we will add a new brick to the list of default bricks.

If you check the Easy widget you’ll see a new View brick “Test”. …That was easy :)
It does not do anything “special” yet. If you drop the brick in to the slot, you can edit the text in the input field and save it, but it will not be visible on the front end of your website.

What you actually get on the front end now, is an error message that a function with the name my_test_brick does not exist.

Which is true.

We have not created any function of that name we made the brick only.

Create the function

The next thing is to create a function that will return the input field we have set up in the brick.

function my_test_brick($easy_query, $values){
	$output = ''; // define empty output
	$input_content = $values[0]; // get the data from the brick - from the first input
        // if the user wrote anything in the brick input field, process it
	if(!empty($input_content)){
		$output .= $input_content; // put the data from the brick to the output
	}
	return $output; // output the result to frontend
}

As you can see we have used the same name for the function as we used for the key name in the our testing brick array.
Easy easily creates a function based on the array key name so we keep the flow as transparent as possible.
It checks all the keys in the Easy_2046_builder::$EasyItems array process them, make a View or Control what ever brick we want and looks for a function with the same name and process the function at the right place in the right time.

This whole thing can be place wherever in the WordPress structure. You can make a simple plugin, or extend your own plugin and hook your self in the Easy widget. You can even place this code in your template, presumably in the function.php it is totally up to you …don’t forget the Easy plugin has to be installed and active.

This is it :)