To make a plugin for wordpress using RedFruits is very simple. In the wordpress’ forum was a question about this and we are using that example to show how simple is to make it.
In this example the developer wants to make a plugin that shows a form in a post. Ok, we are going to make a shortcode to show the form.
First of all is to make the plugin folder an file. The plugin’s name will be ‘FormInPost’.
You have to create a folder in the plugins folder called FormInPost and to create a file, inside it,called FormInPost.php. Write the next code in the new file:
Plugin Name: FormInPost
Plugin URI: http://FormInPost.com
Description: FormInPost example!!
Author: RedFruits team
Author URI: http://redfruits.wordpress.com
if (!defined('REDFRUITS_PATH')) define('REDFRUITS_PATH', dirname(dirname(__FILE__)).'/redfruits/');
if (!defined('FORMINPOST_PATH')) define('FORMINPOST_PATH', dirname(__FILE__).'/');
if (!defined('ADMIN_RENDER')) define('ADMIN_RENDER', 'ADWordpressRender');
class FormInPost extends ADWPPlugin
$this->addShortCode('FormInPost', FORMINPOST_PATH.'shortcodes/FormInPostSC.class.php', 'FormInPostSC');
Now, the shortcode will be created in a folder (inside FormInPost folder). The new folder will be named like shortcodes. Inside it, you have to create FormInPostSC.class.php. You have to Write the next code in the new file:
class FormInPostSC extends ADLayer
if (is_single()) //only shows when the post is being displayed, not in the category list
$form = $this->add(new ADForm('FormInPost_form'));
$form->add(new ADLabeledField('First name:', new ADTextField('first_name', '', 20, 40)));
$form->add(new ADLabeledField('Last name:', new ADTextField('last_name', '', 20, 40)));
$form->add(new ADSubmit('FormInPost_save', 'save'));
$form->addRequirement('first_name', 'required', 'the first name field must be completed');
//TODO save the data
echo 'TODO: Save data \'', $_REQUEST['first_name'], '\' and \'', $_REQUEST['last_name'], '\' in post id ',$post->ID, '';
The most important thing is to make a class (RedFruits is an Object Oriented API) that implements ADWPPlugin.
The form in the second file draws in the explorer two Textboxes, first name and last name, and a submit button. the first name is a required field (see the addRequirement function). When the submit is pressed the page is reloaded and the if (isset($_REQUEST['FormInPost_save'])) is true. The runRequirements function test for the required field.
Remember to write [FormInPost] (see the first param in the addShortCode function) in the post where you want to show the form.
But now you want to change the look. This must be made with the renders. In next posts we are going to see how to make a render.