Initiate a CloudFunnels Plugin

  1. Inside the root of the CloudFunnels there is a folder available `plugins` inside this create your own folder for the plugin, the folder name should be unique and should not contain any spaces.

  2. To avoid naming collisions use prefix. For example, if your plugin name is “PRO Mailer” , name the folder “prmlr_pro_mailer”.

  3. Now, you need a configuration file inside the plugin to initiate. The file name should be config.json

  4. Here is the demo of config.json file

    									
    {
    	"name": "Test Plugin",
    	"version": "1.1",
    	"description": "This Plugin was created for Testing/Learning Purpose",
    	"start": "index.php",
    	"author": "Teknikforce",
    	"author_url": "https://teknikforce.com",
    	"plugin_url": "https://teknikforce.com",
    	"logo": "assets/img/logo.png",
    	"required_version": "4.2.3",
    	"auto_update_callback_url": "http://localhost/test/plugins/update.json"
    }										
    									
    								
    Description of all the required fields
    • name (optional)
      - Plugin name (Required to publish in market place)

    • version (optional)
      - Plugin version (Highly required in purpose of auto update)

    • description (optional)
      - Plugin description

    • start (required)
      - The entry point/index file for your plugin

    • author (optional)
      - Author name

    • author_url (optional)
      - Author URL

    • plugin_url (optional)
      - Plugin URL

    • logo (optional)
      - Your plugin logo that can be an image URL or a file inside plugin directory. (It will be displayed only) (To be continued...)

    • required_version (optional)
      - Required CloudFunnels version to activate the plugin

    • auto_update_callback_url (optional)
      - The URL from where it will be decided all the auto update related data for the plugin

    Pack your plugin

    It’s very easy to pack your plugin to share with others. In “Initiate a CloudFunnels Plugin” section we studied how to create directory and configuration file for the plugin, now all you need to do is zip the main folder and that’s it you are ready to install the plugin from the Plugins section of CloudFunnels.

    You can select all the files/directories inside the main folder and can zip them in a file In that case, the zip name should be as unique as the main directory link was described in the first point in “Initiate a CloudFunnels Plugin”

    Prepare autoupdate for a plugin

    There, two fields are very important for preparing an auto-update for any plugin in config.json file “version” that will describe your current version of the plugin and “auto_update_callback_url” where you will have the URL from where CloudFunnels will decide all the update related requirements.

    Now let’s see what should be the content of the URL that used in “auto_update_callback_ur”

    The content of the file should be a JSON formatted data. And the structure should be like this

    										
    {
    	"name":"Test Plugin",
    	"version": "1.2",
    	"message": "-Updates
    -Added Something
    - Bug fixes", "file": "http://localhost/test/plugins/test_plugin_v_2.zip", "required_cf_version":"4.2.3" }
    • name (optional)
      - Plugin name (Required to publish in the marketplace) (To be continued….)

    • version (required)
      - Current plugin version, if it’s greater than the installed version CloudFunnels will

    • message (optional)
      - Can describe your current update in this field (HTML also allowed)

    • file (required)
      - The current plugin file(zip) URL

    • required_cf_version (required)
      - Specify CloudFunnels version that you need for the update

**Few Important things that will be applied with all registered functions for Plugin development

=>$tag(Required) and it should be a string

=>Callback functions can be a string that is already defined as a function or an inline function. To pass an object method, use an Array where the first index of it should contain the object, and the second index should contain the name of the method name(string).

Trigger a Function during Plugin activation or deactivation

register_activation_hook(callable $callback_function, $args);

This function will be called when someone activates the plugin, the first parameter will contain your callback function and the second parameter (optional) will contain a parameter (Use an array to pass multiple data)

register_deactivation_hook(callable $callback_function, $args);

This function will be called when someone activates the plugin, the first parameter will contain your callback function and the second parameter (optional) will contain a parameter (Use an array to pass multiple data)

  • $callback_function
    - The function you want to execute, if you are passing arguments($args) through the second parameter to get it inside your callback function uses a parameter (To be continued...)

  • $args
    - Arguments that you want to provide in your callback

Action Hooks & add_action function

Action Hooks: Actions are the hooks that the CloudFunnels core launches at specific points during execution, or when specific events occur. Plugins can specify that one or more of its PHP functions are executed at these points, using the Action API.

add_action(string $tag, callable $callback_function, $arg)
  • $tag=(string) (Required)
    - The name of the action to which the $callback_function is hooked.

  • $call_back=(Required)
    - The name of the action to which the $callback_function is hooked.

  • $arg=(optional)
    - Can be used to pass additional data.

Callback Function Parameter Structure

function call_back($data, $provided_arguments){ //process your stuff inside }
  • $data
    - CloudFunnels will provide this, based on specific event/tag/action_name or sometimes it may be an blank array

  • $provided_arg
    - This is the argument that was provided as the third parameter($arg) in add_action method. By default, if there was no argument, it will return an empty array.

Name & Description of all the action hooks($tag):

  • cf_head
    - To execute something before closing header () in funnel pages, if there is something required to display then you can use “echo” or can include files

  • cf_footer
    - To execute something before closing body () tag in funnel pages, if there is something required to display then you can use “echo” or can include files

For both cf_head & cf_footer action hook, at the first parameter of the call back (if exists), it provides an array of current page detail

							
Array(
	[next_url] => 0
	[has_ab] => 0
	[current_folder] => registration-page
	[viewed] => 0
	[is_membership] => register
	[title] =>
	[metadata] => {"description":"","icon":"","keywords":"","robots":"","copyright":"","DC_title":""}
	[header] =>
	[footer] =>
	[settings] => {
		"cookie_notice":0,
		"redirect_for_post":0,
		"redirect_for_post_url":"",
		"snippet_integrations":[],
		"page_cache":0,
		"zapier_enable":false,
		"active_amp":false
	}
	[label] => 1
	[category] => register
	[varient] => 1597984109
	[b_varient] =>
	[selected_template] => a
	[funnel_id] => 27
)			
							
						
  • init
    - To execute something before sending any header, this will work only in user side i.e. when the funnels/pages are going to be viewed

  • admin_menu
    - This will be used to add menu page in the admin area

    All the functions for adding menu page and the sub-menu pages should be called inside the callback

    Example

    									
    	add_action(‘admin_menu’,function(){
    		add_menu_page('Page Title','Menu Title','menu_slug','call_back','https://something.com/menu.png');
    		add_submenu_page('menu_slug','Page Title','Sub-menu Title','menu_slug','call_back');	
    	});											
    									
    								
  • admin_head
    - To execute something before closing header () in admin area, if there is something required to display then you can use “echo” or can include files

  • admin_footer
    - To execute something before the closing body () tag in the admin area, if there is something required to display then you can use “echo” or can include files.

  • admin_init
    - To execute something before sending any header, this will work only in the admin area.

  • cf_sale
    - To execute something for successful/failed sale

    For both kind of execution at the first parameter contains an array which has three fields

    1. success
    2. payment_data
    3. payment_setup

    Below is the description of all the fields in detail

    1. success

      success => true/false (To be continued...)

    2. payment_data

      payment_data => Data (It is also a general indexed array) that is generated after a successful payment if the payment is not successful it should contain a blank array. When the payment is successful each index will contain some data for each product.

      For Example:

      array(0=>array( ),1=>array())

      Now in each index, it will have all the same data except the ‘product_id’ and ‘parent_id

      Here how it will look alike

      											
      	Array(
      		‘payment_method’=> It will contain payment method Id
      		‘payment_id’=> This is a unique payment code/order id that generates after the sales
      		‘funnel_id’=> Will contain the funnel id
      		‘page_id’=> The order form page id
      		‘payment_data’=> This will contain a JSON data that will be generated for a sale
      		‘payer_name’=> The name used in payment page(Not in order form page, If there is no such option it will be replaced with the email present in Order form page)
      		‘payer_email’=> The name used in payment page(Not in order form page, If there is no such option it will be replaced with the email present in Order form page)
      		‘data’=> This will contain a JSON data that will be generated for a sale same as `payment_data`
      		‘shipping_data’=> This will contain another array which will contain all the fields were posted in order form page as an associative array depending on the input names
      		‘membership’=> This will contain all the membership Ids in an array that was created in separate membership funnel if attached
      		‘product_id’=> This will contain the product id
      		‘product_title’=> This will contain the product title
      		‘product_url’=> Product URL
      		‘parent_id’=> It will be zero(0) if it is the main product otherwise if it is anoptional/sub-product it will contain the parent product id (main `id` not the user-provided ID)
      		‘step_sales’=> It will contain a mini data of the sale in HTML format
      	) 
      											
      										
    3. payment_setup

      payment_setup => This will be generated after the submission in order form page, It generally contains all the setup that is going to be used to make the payment. here , how it is going to look alike.

      											
      	Array(
      		‘funnel_id’=> Will contain the funnel id
      		‘page_id’=> It is the order-form page Id
      		‘folder’=> It is only the portion for page from entire funnel and page URL (For example if the order form page url is https://something.com/funnel/page it will contain the “page” only)
      		‘ab_type’=> a/b template type will contain ‘a’ or ‘b’
      		‘product_id’=> The main product ID (main `id` not the user-provided ID)
      		‘other_products’=> this will contain all the selected optional products by a visitor including the sub-products (main `id` not the user provided ID)
      		‘lists’=> Array of selected list IDs
      		‘payment_method’=> Again this is the payment method ID
      		‘confirmation_url’=> URL where to redirect af the successful payment
      		‘cancel_url’=> URL where to redirect for a failed payment
      		‘checkout_url’=> This will contain checkout page URL if exists otherwise will contain order-form page URL
      		‘data’=> It will be also an array which will contain all the form submitted data in order form page based on the input names,
      		‘membership_registration_pages’=> Will contain of all the registration page Ids
      	)
      											
      										
  • cf_funnel_create
    - To execute something when a funnel is created, it provides the funnel id as the first parameter in the provided callback function.

  • cf_funnel_delete
    - To execute something when a funnel got deleted, it provides the funnel id as the first parameter in the provided callback function

  • cf_funnel_page_create
    - To execute something when a page got created, the first parameter contains an array with indexes `funnel_id`,`page_id`, `page_level`, `ab_type`

    **It is highly recommended to not to process anything depending on page_id instead process depending on the funnel_id & page_level

  • cf_funnel_page_level_change
    - To execute something when someone changes the page level, provide an array in the first index of the callback function. The first index looks like

    	Array(
    		‘funnel_id’=> Current funnel Id
    		‘changes’=> Array(1=>2,2=>1)
    	)
    									

    So by looking at the example you can understand the `changes`.In the associative array ,each index contains an older level and it’s value contains an updated level.

  • cf_funnel_page_delete
    - This will be triggered during removal of a page and in the first parameter of the callback function it contains an array which indexes are ‘funnel_id’, ‘page_level’

  • cf_funnel_page_setup_change
    - TThis will be triggered when someone changes the page setup. And in the first parameter of the callback function it provides an array and indexes are `funnel_id` and `level`

  • cf_funnel_page_content_change
    - This will be triggered during the page content change, it provides an array at the first parameter of the callback function. Indexes are ‘funnel_id’, ’page_id’, ’level’, ’ab_type’

  • cf_member_create
    - This will be triggered during the creation of a Membership funnel, at the first parameter of the callback function it will provide an array and the indexes are ‘id’, ‘name’, ‘email’, ‘funnel_id’, ‘page_id’,’data'

    **‘id’ will contain the member id

    **’data’ contains an array it will contain other fields like if some one provided ‘address’ during the registration process, it will be present inside this array

  • cf_member_update
    - This will be triggered while updating one’s membership credentials, at the first parameter of the callback function it will provide an array and the indexes are ‘id’, ‘name’, ‘email’, ‘funnel_id’, ‘page_id’,’data’

    **‘id’ will contain the member id

    **’data’ contains an array it will contain other fields like if some one provided ‘address’ during the registration process, it will be present inside this array

  • cf_member_delete
    - It will be triggered during removal of membership credentials, and in the first parameter of the callback function it provides the member id

  • cf_product_create
    - This will be triggered during creation of a product, and it will provide an array in the first parameter with the following parameters.

    									
    	Array(
    		‘id’=> Product actal id
    		'product_id'=> Id that given by user
    		'title'=> Product title
    		'description'=> Product description
    		'url'=> Product URL
    		'price'=> Product price
    		'currency'=> Product currency
    		'shipping_charge'=>Shipping charge
    		'sub_products'=>array() array of product ids
    		'optional_products'=>array() array of product ids
    		'tax'=>Tax amount
    	) 
    									
    								
  • cf_product_update
    - This will be triggered during creation of a product, and it will provide an array in the first parameter with the following parameters

    									
    	Array(
    		‘id’=> Product actal id
    		'product_id'=> Id that given by user
    		'title'=> Product title
    		'description'=> Product description
    		'url'=> Product URL
    		'price'=> Product price
    		'currency'=> Product currency
    		'shipping_charge'=>Shipping charge
    		'sub_products'=>array() array of product ids
    		'optional_products'=>array() array of product ids
    		'tax'=>Tax amount
    	)
    									
    								
  • cf_product_delete
    - This will be triggered during removal of a product and it will provide the product id in the first parameter of the callback function.

Register a payment method

register_payment_method(String $id, Array $detail, Callable $call_back, $args, Bool $not_ipn=true)
  • $id (Required) : It should be a unique id for your payment method

    **This should not be numeric and will not contain any space

  • $detail (Required) : It should be an array where you have to specify a `title`(Required) and `method` (Required) you can also add a field `tax`(Optional) to add a tax for your payment method now you can also add other indexes that you may need to process your payment like for example ‘api_key’, ‘api_secret’ etc

  • $call_back (Required) : This is the callback function that will actually process the payment. Now the parameters and the returned value for the function are very important here.

During the payment process it will provide 4 parameters in this way

call_back($detail, $product_detail, $execution_url,$args);

Now let’s see what should each parameter contain

  • $detail = This will contain the detail that you provided in the second parameter of register_payment_method() function

  • $product_detail = This will be provided by the system during the payment process so it is an array. Below it’s described how should the array look like and it contains complete detail for all the products

    										
    	Array(
    		‘total’=> Total price of all products including taxes and shipping charges,
    		‘totalprice’=> This is the sum of all total price for product main price,
    		‘currency’=> Currency 
    		‘tax’=> Total tax
    		‘sheepingcharge’=> Total shipping charge
    		‘items’=> This is an array of all products that was going to be purchased
    	)
    										
    									

    Here how it will look alike (To be continued)

    										
    	Array(
    		0=>array(
    				‘id’=> The product main id
    				‘productid’ => product 
    				‘title’ => Product title
    				‘url’ => Product URL
    				‘description’ => Product description
    				‘price’ => Product price
    				‘currency’ => Payment currency
    				‘shipping’ => Shipping cost
    				‘subproducts’ => subproducts that will be separated with a string ‘@brk@’
    				‘opproducts’ => Optional products that will be separated with ‘@brk@’
    				‘tax’ => Tax
    				‘createdon’ => Date of product creation in second
    			)
    		)
    		‘allproductdetail’=> A small description of the order (HTML) format
    	)
    												
    										
    									
  • $execution_url = The execution URL is the URL which should be the callback or return URL for the payment, you can add additional GET parameters also to assume whether the payment was successful or not.

    Now sometimes you may need to provide the return URL manually, so here how to get it.

    The execution URL will be

    installation_url/index.php?do_payment&execute=1

    Now you can add additional query parameters according to the requirement.

    To get the installation URL, use get_option(‘install_url’);

    $execution_url=add_query_arg(get_option(‘install_url’) , array(‘page’=>’do_payment’, ’execute’=>1) );

Now let’s see what should be the return value of the callback

If the payment was not successful then return 0 or false or may be a blank array

In case of a successful payment, it should contain few specific fields and you can also add your own, so the specific fields are written below

								
	Array(
		'payer_name'=> Name
		'payer_email'=> Payment email
		'payment_id'=>  A payment ID/Order id
		'total_paid'=> Total payment amount
		'payment_currency'=> Payment currency
		'ipn_tax'(optional)=> If you are using an IPN and want to add any tax amount consider adding value in it 
	)
								
							
  • $args : Arguments that you will pass

  • $not_ipn : By default this is true i.e its payment method will make it true if you want to process it as IPN

Get Current Sale Details That Going To happen

get_requested_order()

When there is a payment method going to be used (not IPN) to make a sale, after successful submission in order form page.It creates a session that holds all the users who have submitted data including some additional data.

Returned Data

This returns false if there is no info otherwise it will return an associative array. Below is an example of how the array will look like.

									
	Array
		(
			[data] =>This is an array of buyer submitted data in order form page
			[funnel_id] => Funnel Id
			[page_id] => Page ID
			[folder] => Last slot of order form page URL
			[ab_type] => Page type (A/B)
			[product_id] => Main product id (Database `id` not user provided Id)
			[lists] => Array of selected lists
			[optional_products] => Selected optional products by buyer
			[payment_method] => Payment method Id
			[membership] => Array of selected membership page ID
			[confirmation_url] => Confirmation page URL
			[cancel_url] => Cancelation page URL
			[checkout_url] => Checkout page URL (If exists, otherwise it will contain payment  
			page URL)
		)
									
								

Register an Autoresponder

register_autoresponder(String $id,String $name,Callable $call_back, $arg)
  • $id (Required) - A non numeric string

  • $name (Required) - Your autoresponder name

  • $call_back (Required) - There you can use two parameter in to your callback_function Through the first argument the system will provide you the user data as an array and in the second argument it will pass the data that you passed as $arg in register_autoresponder() function. The user data will contain name and email field mandatory but its recommended to filter the email for validation

Let’s see an example:

									
	register_autoresponder(‘myauto_20’, ’MyAutoresponder’,function($data,$arg){
		/*$data may look like (
		‘name’=>’something.com’,
		’email’=>’something@gmail.com’,
		‘additional_1’=> ‘Additional data1’,
		‘additional_2’=> ‘Additional data2’
		)
		*/
	})	
									
								
  • $arg - (Optional) Additional data if you want to pass;

Register Your Own Action

You can register your action hooks through the add_action method.
You can register any name (please make sure about using the built in action hooks).

do_action(String $action_name, $settings)
  • $action_name (Required) = The action name that you registered through add_action method.

  • $settings (Optional) = If you want to pass an additional parameter through it, should be provided at the first parameter for the callback function.

Here is an example of how you can register your own action
add_action(‘my_action’, function($settings, $arg){ /*code*/ }, $arg);
  • $settings = This will be provided at your first parameter if you passed it through the second parameter in do_action. otherwise there will be a blank array

  • $arg = is optional as we described before and it will be passed in the second parameter.

Now if you want to execute the call back for ‘my_action’

Just call like do_action($action_name, ‘hello’).

Filter Hook

CloudFunnels offers filter hooks to allow plugins to modify various types of internal data at runtime.

A plugin can modify data by binding a callback to a filter hook. When the filter is applied later , each bound callback runs in order of priority, and is given the opportunity to modify a value by returning a new value.

The following example shows how a callback function is bound to a filter hook.

Note that $content is passed to the callback, (maybe) modified, then returned:

add_filter(String $tag,Callable $call_back, $args)
  • $tag = (string) (Required) The name of the action to which the $callback_function is hooked.

  • $call_back = (Required) The name of the action to which the $callback_function is hooked.

Here how to deal with the arguments

								
	function call_back($content, $settings, $args){
		//$content= Will contain the main content
		//$settings= may contain an array of settings related to the filter type/name
		//$args= The arguments that will be passed by you
										
		return $content;
	}									 
								
							
  • $arg = (optional) Can be used to pass additional data in third parameter

The following example shows how a callback function is bound to a filter hook.
Note that $content is passed to the callback, (maybe) modified, then returned:
								
	function modify_content($content, $settings, $args){
		//modify the $content according to you
		return $content;
	}								  
								
							
Here are all the reserved filter names
  • the_content = Can use this filter to modify funnel page content before printing.

    **CloudFunnels provides functionality to create cache. filter will not applied directly for the cached content but during creating the cache if it was effected then it should work until the user clear the cache again

Example
								
	function add_filter(‘the_content’, function($content, $settings, $args){
		return $content;
	}, array(‘hello’) )		  
								
							
Here are the detail for all parameters for the callback function
  • $content = This will contain the page content

  • $settings = It will contain all the detail of the current page

								
	Array(
		[next_url] => 0
		[has_ab] => 0
		[current_folder] => registration-page
		[viewed] => 0
		[is_membership] => register
		[title] =>
		[metadata] => {"description":"","icon":"","keywords":"","robots":"","copyright":"","DC_title":""}
		[header] =>
		[footer] =>
		[settings] => {
			"cookie_notice":0,
			"redirect_for_post":0,
			"redirect_for_post_url":"",
			"snippet_integrations":[],
			"page_cache":0,
			"zapier_enable":false,
			"active_amp":false
		}
		[label] => 1
		[category] => register
		[varient] => 1597984109
		[b_varient] =>
		[selected_template] => a
		[funnel_id] => 27
	)	
								
							
  • $args = (Optional) it will contain the arguments that you will provide

  • the_email_content = Can be used to modify email body The $content parameter for the callback will contain the email body and $settings will be an blank array

  • the_email_subject = Can be used to modify the email subject, the $content parameter will contain the subject and $settings will be a blank array.

Shortcode

A shortcode is a small piece of code, indicated by brackets like [this] , that performs a dedicated function on your site. You can place it just about anywhere you'd like, and it will add a specific feature to your page data and other content (for other continents we have feature for do_shortcode)

Lets see some examples of shortcodes.

**the short_code can be replaced with any string that you registered

  • [short_code] = This kind of shortcodes contain only the tag. You can attach some callback and can return some data to display where the content is placed.

  • [short_code param=”something” param2=”Something 2”] = This is an example of a shortcode with parameters where you can pass some data and we will provide these data into the first parameter of the call back function as an associative array.

  • [short_code] some data [/short_code] = This is how you can wrap some content with shortcode closure and can even process the middle data. return the processed data that you want to display. The middle content will be passed through the second parameter of your callback function.

  • [short_code param=”something” param2=”Something 2”] some data [/short_code] = You can use parameter and shortcode closure same time, CloudFunnels will provide all the parameters in first parameter through the first parameter as an associative array and the content through the second parameter.

Here how to add a shortcode
add_shortcode(String $tag, Callable $callback_function, $arg)
  • $tag = This is the unique shortcode name

  • $callback_function = Function that will be executed for the specific tag

The call back function contains three parameters,please watch the example above

To understand the parameters for the callback in detail.

Here is the detail of callbacks

								
	function call_back($params, $content, $arg)
		{
			//$params will contain the parameters that will be passed through the shortcode parameter, if there are no parameters it will contain a blank array.
									
			//$content that will be present inside the shortcode closure, if there is no closure or no middle content it will contain a blank string
									
			//$arg that you will passed through the third parameter of add_action function 
		}										 
								
							

do_shortcode

do_shortcode(String $str)
  • $str = (Required)Pass any string through the parameter and all the register shortcodes will be executed if they are present inside the string and will replace the expected data.

do_shortcode(String $str, String $short_code_name)
  • $str = Same as before

  • $short_code_name = Any registered shortcode that you want to execute if that is present inside the string.

CloudFunnels Nonce functions

Nonce can be used as a CSRF token. There are two functions available one for creating a unique string for one time depending on the specific string that will be provided as argument and another function to verify that in backend

cf_create_nonce(String $key)

This function will return a unique token depending on a specific string that will be provided through $key, This token will exist depending on session

cf_verify_nonce(String $token, String $key)

Use this function to validate a token

  • $token = This is the token that you created through cf_create_nonce.

  • $key = Key for what the token was generated.

Deal with CloudFunnels users

is_admin()

is_admin()

This function is used to verify whether the user is inside the admin area and is logged in

current_user_can()

current_user_can()

This will return an array of pages for what the current user has access. So if the user is an admin the array will contain ‘admin’.

So for example whenever you are inside CloudFunnels, each section is assigned with a page.

If you take a look at the URL you will see at the end of the URL we have

index.php?page=page_name
So to check whether user can access the page follow the way written below

Let’s assume we are in dashboard

So the ending of the URL will be something like index.php?page=dashboard

Let’s get all the permitted pages first

							
	$permissions=current_user_can();

		if($permissions){
			if(in_array(‘admin’, $permissions) || in_array($_GET[‘page’],  $permissions)){
				//the user can access the page
			}
		}
							
						
get_user($user);

It returns all the user data in array if the user exists or it will return false

$user= It can be a user id( Numeric) or if you want to get for email use Array like get_user(array(‘email’=> ’something@domain.com’)); it will do the same.You can even pass the `id` as an array same as `email` or can pass both at the same time

Here is the expected output demo if the user exist otherwise it will return false
							
Array(
	[id] => 1
	[name] => Test
	[email] =>test@teknikforce.com
	[ip_lastsignin] => ::1
	[ip_created] => ::1
	[date_created] => 1592913277
	date_signin] => 1598243493
	[permission] => Array
(
	[0] => admin
)
								
	[profile_picture] => 'http://something.com/af/user.png'
)																			 
							
						
get_loggedin_user()

If the user is logged in it will return the user data as an array like get_user method otherwise it will return false.

get_users()

It will return all user data as an indexed array. If there is no user available it will return a blank array.

**Same as a user you can pass an array of id/email to get a specific user but if there the user does not exist it will return a blank array.

Work with sessions in CloudFunnels

**It is highly recommended to use our Session API to work with session in CloudFunnels

do_session_start()

Use this function to start a PHP session, It is recommended to use init or admin_init action hook to start a session

do_session_destroy();

Use this function to destroy a session

Set single session
set_session(String $key, Any $value )
  • $key = It should be a string

  • $value = The value you want to assign

Set multiple sessions
set_session(Array $arr)

You can use an associative array, so set multiple session through set_session() at a time

Example

set_session(  array(‘test’=> ’Something 2’, ‘test2’=> ‘Something 2’)  )
unset_session(String $key)

Pass the session key that you want to unset

has_session($key);

Pass your key if the session exists it will return true or false

get_session($name);

Pass the session name to get the value if exist otherwise it will return null

Work with cookies

**Its highly recommended to use our Cookie API

set_cookie(String $name,String $value,Int $time,String $path)
  • $name = (Required) Cookie name

  • $value = (Required) Cookie value

  • $time = (Required) add cookie max age in second and to unset the cookie use time -1

  • $path = (Optional) This specifies the directories for which the cookie is valid. A single forward slash character permits the cookie to be valid for all directories.

has_cookie(String $name)

To check if a cookie exists or not, if yes it will return true otherwise it will return false (To be continued...)

get_cookie(String $name)

$name=To get your cookie value pass the key if it exist it will return the value or null

Works with Plugin Directory and URL

plugin_dir_path

plugin_dir_path(String $file)

Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.

plugin_dir_url

plugin_dir_url(String $file)

Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in.

plugins_url

plugins_url(String $path, String $plugin)

Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in.

  • $path = (Optional) Extra path appended to the end of the URL, including the relative directory if $plugin is supplied.

  • $plugin = (Optional) A full path to a file inside a plugin. The URL will be relative to its directory. Typically this is done by passing __FILE__ as the argument.

Defaults to the plugins directory URL if no arguments are supplied.

add_query_arg

add_query_arg($args);

You can rebuild the URL and append query variables to the URL query by using this function. There are two ways to use this function; either a single key and value, or an associative array.

Using a single key and value:

add_query_arg( 'key', 'value', 'http://example.com' );

Output will be http://example.com?key=value

Using an associative array:

							
add_query_arg( array(
	'key1' => 'value1',
	'key2' => 'value2',
	), 'http://example.com' );
							
						

Output will be http://example.com?key1=value1&key2=value2

All funnels and page related functions and global variables

  • $the_funnel_id = This will contain current funnel that is opened by visitor

  • $the_page_level = This will contain current funnel page level that is opened by visitor

  • $the_page_type = This will contain current funnel page type that is opened by visitor

get_funnels(String $type)
  • $type = (Optional) Funnel type like sell, webinar,and membership. Keep them all blank if you want them at the same time.

It will return an indexed array that contains all funnel data. If there is no funnel it will return a blank Array.

Here is an Example of output

							
	Array
		(
			[0] => Array
				(
					[id] => 19
					[name] => test
					[type] => webinar
					[date_created] => 1596714746
					[token] => 7651802145
					[url] => http://localhost/cloud-funnels/test
					[valid_inputs] => Array
						(
							[0] => firstname
							[1] => lastname
							[2] => name
							[3] => email
							[4] => phone
							[5] => password
							[6] => reenterpassword
							[7] => remember_user
						)
								
					[smtp] => phpmailer
			)
	)
										
							
						
get_funnel($id)

Get a specific funnel data through Id, if the funnel does not exist it will return false. Expected output

							
	Array
		(
			[id] => 19
			[name] => test
			[type] => webinar
			[date_created] => 1596714746
			[token] => 7651802145
			[url] => http://localhost/cloud-funnels/test
			[valid_inputs] => Array
				(
					[0] => firstname
					[1] => lastname
					[2] => name
					[3] => email
					[4] => phone
					[5] => password
					[6] => reenterpassword
					[7] => remember_user
				)
						
			[smtp] => phpmailer
		)		
							
						
get_page_by_id(String $id)

This function can be used to get detail of a funnel page by Id.

$id=(Required) Page id

The function will return false, if there is no such page otherwise it will return an associative array of setup for the page.

							
	Array(
		[id] => 46
		[name] => 
		[title] => 
		[metadata] => Array
			(
				[description] => 
				[icon] => 
				[keywords] => 
				[robots] => 
				[copyright] => 
				[DC_title] => 
			)
								
		[type] => a
		[level] => 3
		[category] => orderform
		[custom] => 0
		[bouncecount] => 0
		[bouncecountbpage] => 0
		[downsellpage] => 0
		[upsellpage] => 0
		[lists] => Array
			(
				[0] => 4
				[1] => 2
				[2] => 1
			)
								
		[product] => 1
		[paymentmethod] => sdfgh45852
		[valid_inputs] => Array
			(
				[0] => firstname
				[1] => lastname
				[2] => name
				[3] => email
				[4] => password
				[5] => reenterpassword
				[6] => remember_user
			)
								
		[settings] => Array
			(
				[cookie_notice] => 0
				[redirect_for_post] => 0
				[redirect_for_post_url] => 
				[snippet_integrations] => Array
			(
		)
								
			[page_cache] => 0
			[zapier_enable] => 
			[active_amp] => 
		)
								
			[date_created] => 1597822355
			[funnel_id] => 23
			[url] => http://localhost/cloud-funnels/testvgbhnj/order-form
			[file_name] => order-form
			[page_header] => 
			[page_footer] => 
			[view_count] => 2
			[has_ab_test] => 0
			[autoresponders] => Array
				(
					[0] => 8
					[1] => 7
					[2] => 6
				)
								
			[membership_registration_pages] => Array
				(
					[0] => 39
					[1] => 47
				)
								
	)
										
							
						
get_page(Int $funnel_id, Int $page_level,String $type)

This function allows you to get a page detail by Funnel Id, Page Level,and Page type(Optional)

  • $funnel_id = (Required) Funnel Id for what you want to get

  • $level = (Optional) This is the level of the page (eg. 1, 2, 3, 4), if you don’t provide any level, the function will return data for the first page for the funnel if available.

  • $type = (Optional) the type should be ‘a’ or ‘b’ this variable can be ignored completely as both `a` or `b` have the same setup.

Expected output if exist same as get_page_by_id(String $id)

get_funnel_pages(Int $funnel_id)

This function will return all the available page setup as an indexed array

  • $funnel_id = (Required) Funnel for what you want to get the pages.

Expected output format

							
	Array
		(
			[0] => Array
				(
					[id] => 44
					[name] => 
					[title] => 
					[metadata] => Array
						(
							[description] => 
							[icon] => 
							[keywords] => 
							[robots] => 
							[copyright] => 
							[DC_title] => 
						)
								
					[type] => a
					[level] => 1
					[category] => optin
					[custom] => 0
					[bouncecount] => 0
					[bouncecountbpage] => 0
					[downsellpage] => 0
					[upsellpage] => 0
					[lists] => Array
						(
				)
								
					[product] => 0
					[paymentmethod] => 0
					[valid_inputs] => Array
						(
							[0] => firstname
							[1] => lastname
							[2] => name
							[3] => email
							[4] => phone
							[5] => password
							[6] => reenterpassword
							[7] => remember_user
						)
								
							[settings] => Array
								(
									[cookie_notice] => 0
									[redirect_for_post] => 0
									[redirect_for_post_url] => 
									[snippet_integrations] => Array
										(
										)
								
									[page_cache] => 0
									[zapier_enable] => 
									[active_amp] => 
								)
								
							[date_created] => 1597822294
							[funnel_id] => 23
							[url] => http://localhost/cloud-funnels/testvgbhnj/optin
							[file_name] => optin
							[page_header] => 
							[page_footer] => 
							[view_count] => 1
							[has_ab_test] => 0
							[autoresponders] => Array
								(
								)
								
							[membership_registration_pages] => Array
								(
								)
								
			)
		)
										
							
						

Work with funnel meta

CloudFunnels provides you a dedicated table and three functions to get, set,and delete specific data for a funnel, funnel-page/level even with a templet (a/b)

add_funnel_meta(Array/Int $funnel_data, String $key,String $meta_value)
  • $funnel_data = (Required) This may be an array or integer, if you are passing a number, it will be treated as Funnel Id or if you want to set some data with specific funnel page or specific funnel page template (a/b) then you have to provide an associative array with some required indexes with it.

So, here if you are providing an array this is how it should look like

Array(
	‘funnel_id’=> 10
)
						

So, if you provide only funnel_id it will be same as passing just the $funnel_id directly without creating an array

Array(
	‘funnel_id’=>10,
	‘page_level’=>1
)
						

So in this case it will create the meta for the funnel 10 and its page level 1 for

Array(
	‘funnel_id’=>10,
	‘page_level’=>1,
	‘page_type’=>’a’
)						
						

So it will store the data for funnel Id 10 and it’s page level 1 and type ‘a’

  • $key = (Required) This is the metadata name

  • $meta_value = (Required) The data you want to store for the funnel data and the key.

**Here is a very important thing to note, the data you provided in $funnel_data & $key, when you are updating, deleting or accessing you have to use the same data and format.

update_funnel_meta(Array/Int $funnel_data, String $key,String $meta_value)

Use this function to modify the value for a specific funnel data & key that was added through add_funnel_meta() method.

The parameter structure for this function is the same as add_funnel_meta so you have to provide the same $funnel_data & $key as you provided during the meta tag. Remember the one thing that can be changed is $meta_value

get_funnel_meta(Array/Int $funnel_data, String $key)

Use this to get the meta value for specific funnel/funnel-page(data) and $key

  • $funnel_data = (Required) Please take a look at the complete add_funnel_meta() method to know the details of this variable.

  • $key = (Required) This is the metadata name.

delete_funnel_meta(Int/Array $funnel_data, String $key)

To delete a meta information for a specific funnel info and key

Follow add_funnel_meta() method to know about the parameter structure.

Works with Sales

get_sales(Int/String/Array $data)
  • $data = (Required) If you want to get all sales pass -1 , If you want to get detail of a sale for specific “payment_id” pass the Payment_id/order_code.

Or you can even provide required fields as an associative array. It's not necessary to provide all fields at a time, you can pass according to the requirement.

The fields are

‘payment_id’, ‘product_id’ (this is the actual product id not user provided id),
‘payment_method_id’, ‘membership_id’, ‘funnel_id’, ‘payer_email’

Example
  • get_sales(-1) = Will return all sales

  • get_sales(‘pay_id_ertyuk856g’) = Will return sales for the specific payment id ‘pay_id_ertyuk856g’.

  • get_sales(array( ‘payment_id’=> ‘1845frgjk45’, ‘product_id’=>10 )) = Will return the sale detail for the payment id ‘1845frgjk45’ and product id 10

Output: The output of get_sale method is always an array, even if there is no sale it will provide a blank array

That’s how the result looks like when there are any sales available.

							
Array
	(
		[0] => Array
			(
				[id] => The database/table id for the payment
				[payment_id] => The payment id
				[shipping_detail] => Shipping detail in JSON
				[shipped] => It will contain 0 if not shipped otherwise 1
				[page_id] => It will contain the order page id
				[payment_data] => all the payment info in JSON format
				[parent] => It will contain ‘0’ if this was the main product otherwise will contain
							the parent product main Id not user provided Id
				[purchase_name] => This will be the buyer name
				[total_paid] => 10 (USD) The format will be like this price including the currency
				[step_payments] => This will contain a mini data for the sale as HTML
				[valid] => It will contain 1 if the payment was not canceled by admin  otherwise 0
				[exf] => {//all the data that came for }
				[added_on] => Time of sale in second depending on server default time zone for max it is UTC 
				[product_id] => The product Id (The main id, not user provided ID)
				[payment_method_id] => The payment method Id
				[membership_id] => return array of membership ids
				[funnel_id] => The funnel id, from where it was sold out
				[payer_email] => This will contain the payer email Id
			)
	)											
							
						

Sending Mail in CloudFunnels

cf_mail(Array $data)

This function can be used to send mail through CloudFunnels. It reverts true if the mail was sent successfully and reverts false when there is an error.

Here how the $data should be provided,

							
	$data=array(
        'mailer'=> (optional) Primarily it will use default mailer to send the mail if this field is      
        not present in this array, You can also add this field and can pass the SMTP Id to    
        send mail through a SMTP or if you are thinking to send the mail     
        through hosting mailer assign ‘php’

        'name'=>(Optional) Recipient name,

        'email'=>(Required) Recipient email,

        'subject'=>(Optional) Email subject,

        'body'=>(Optional) Email body,

        'unsubscription_message'=>(Optional) Here you can put your unsubscripted message,

        'debug'=>(Optional) true or false (bool) , if this is true (Currently only      
        for the SMTP), If this is true the cf_mail will display a debugged data, only if you     
         are testing the mailer then consider making it active.

        'from_name'=>(Optional) ’The name from where to send the mail (Currently only      
        for the SMTP)’,

        'from_email'=>(Optional) The email from where you want to send the mail 
        (Currently only for the SMTP),

        'reply_name'=>(Optional) The name where you want to get the reply (Currently 
         only for the SMTP),

        'reply_email'=>(Optional) The email where you want to receive reply (Currently 
         only for the SMTP)

    );
							
						

Work with Membership Funnel Members

is_member_loggedin(Int $funnel_id)

This function can be used to verify if someone logged into the given membership funnel id, It will return true if someone logged in otherwise false

  • $funnel_id=(Required) The membership funnel id

get_current_member(Int $funnel_id)

Get detail of current logged in user in a membership funnel, it will return an array of data if user is logged in otherwise it will return false

  • $funnel_id=(Required) The membership funnel id

Example output for the logged in user
							
	Array
		(
			[id] => Member id
			[name] => Member Name
			[email] => Member email
			[verified] => It will be 1 if the membership is verified otherwise 0
			[date_verifycodegen] => It contains some system generated code
			[ip_created] => Creation IP
			[ip_lastsignin] => Last logged in IP
			[date_created] => Date creation time in second
			[date_lastsignin] => Last sign in date in second
			[valid] => It will be 0 if the membership is canceled or will contain 1
			[exf] => A JSON data that comes up for extra fields in registration page or generates during the sell
			[funnel_id] => Membership funnel id
			[page_id] => Membership page ID
			[verify_code] => This will generate a System generated code
		)
							
						
get_member(Array/Int $id)

This function can be used to get a member detail by ID or depending on some specific detail

  • $id=(Required) the $id may be just the member Id(INT) or an array of query If you want to get a member depending on some specification you can pass an array with some specific index, all the indexes are optional you can pass according to the requirement.

So here are all the valid indexes if you are providing an Array

							
	Array(
		id=> Member id
		funnel_id=> Funnel id
		email=> Member email
		valid_only=> (Bool) true or false to check whether the membership active or not
		verified_only=> (Bool) To check whether the member registered successfully through the invitation code 
		verify_code=> it will contain only the verification code
	)	
							
						
Example function call
  • get_member(10)=Will return member detail for id 10 if exist

  • get_member( array(‘funnel_id’=>10, ’email’=>’test@gmail.com’) )=Will return detail for the given email ‘test@gmail.com’ and Funnel id 10 if exist.

Output: The output will be an array if member exist otherwise it will be false So here is an example of how the array look alike

							
	Array
		(
			[id] => Member id
			[name] => Member Name
			[email] => Member email
			[verified] => It will be 1 if the membership is verified otherwise 0
			[date_verifycodegen] => It contains some system generated code
			[ip_created] => Creation IP
			[ip_lastsignin] => Last logged in IP
			[date_created] => Date creation time in second
			[date_lastsignin] => Last sign in date in second
			[valid] => It will be 0 if the membership is canceled or will contain 1
			[exf] => A JSON data that comes up for extra fields in registration page or generates during the sell
			[funnel_id] => Membership funnel id
			[page_id] => Membership page ID
			[verify_code] => This will generate a System generated code
		)
								
							
						
get_members(Array/Int $id=-1)

This method can be used to get more than one member detail

  • $id=(Optional) Pass -1 to get all members at a time or the $id may be just the member Id(INT) or an array of query If you want to get a member depending on some specification you can pass an array with some specific index, all the indexes are optional you can pass according to the requirement.

So here are all the valid indexes, if you are providing an Array

							
	Array(
		id=> Member id
		funnel_id=> Funnel id
		email=> Member email
		valid_only=> (Bool) true or false to check whether the membership active or not
		verified_only=> (Bool) To check whether the member registered successfully through the invitation code 
		verify_code=> it will contain only the verification code
	)	
							
						
Example function call
  • get_members(10)=Will return member detail for id 10 if exist

  • get_members( array(‘funnel_id’=>10, ’email’=>’test@gmail.com’) )=Will return detail for the given email ‘test@gmail.com’ and Funnel id 10 if exist.

Output: The output can be an indexed array which will contain detail of members in each index. If there is no member, it will return a blank array

So that’s how the array will look like

							
	Array
		(
		[0]=>
			Array
			(
				[id] => Member id
				[name] => Member Name
				[email] => Member email
				[verified] => It will be 1 if the membership is verified otherwise 0
				[date_verifycodegen] => It contains some system generated code
				[ip_created] => Creation IP
				[ip_lastsignin] => Last logged in IP
				[date_created] => Date creation time in second
				[date_lastsignin] => Last sign in date in second
				[valid] => It will be 0 if the membership is canceled or will contain 1
				[exf] => A JSON data that comes up for extra fields in registration page or 
				generates during the sell
				[funnel_id] => Membership funnel id
				[page_id] => Membership page ID
				[verify_code] => This will generate a System generated code
			)
		)	
							
						
get_products_for_member(Int $funnel_id, String $member_email, Bool $active_only=false)

This function will return specific product ids as an array that present for a specific membership funnel and a member email in it

  • $funnel_id=(Required) the membership funnel id.

  • $member_email=(Required) member email for which you want to get all the purchased products.

  • $active_only=(Optional) By default the function will return all the products that have/had access to the member, if you make it true it will display only the products the user has access.

Output: The output should be a array of purchased product ids if there is

Get single product & multiple product detail

get_product(Int $id,String $by='id')

It will return all the details for a product by product main/database ID or by ID provided by the user.

  • $id = (Required) This may be product main ID or User provided Id depending on $by parameter.

  • $by = (Optional) by default it is ‘id’ (main Id) you can also pass ‘product_id’ i.e user provided product id.

Example output:

							
	Array
		(
			[id] => Main product id
			[title] => Product title
			[url] => Product URL
			[description] => Product description
			[price] => Product price
			[currency] => Product price currency
			[tax] => Product tax
			[createdon] => Time in second
			[sub_products] => Array of subproduct ids(main)
			[optional_products] => Array of optional product ids
			[product_id] => User provided product id
			[shipping_charge] => Shipping charge
		)								
							
						
get_products(Int/Array $data)
  • $data = (Optional) By default it is -1 that will provide all the available product detail, you can pass an array of query to get specific products

The query array will contain only

		Array(
			‘id’=>(Optional) Main product id
			‘product_id’=>(Optional) User provided product id
		) 
						
Example function call:
  • get_products(-1) = Will return all product detail

  • get_products(array(‘product_id’=>’154hvj12’)) = Will return product for the user provided product id ‘154hvj12’

Expected output: It will contain an indexed array, each index will contain one product detail, if there are no products available it will contain a blank array.

							
	Array(
		[0]=>Array
			(
				[id] => Main product id
				[title] => Product title
				[url] => Product URL
				[description] => Product description
				[price] => Product price
				[currency] => Product price currency
				[tax] => Product tax
				[createdon] => Time in second
				[sub_products] => Array of subproduct ids(main)
				[optional_products] => Array of optional product ids
				[product_id] => User provided product id
				[shipping_charge] => Shipping charge
			)
		)										
							
						

Get SMTP Detail

get_smtp(Int $id)
  • $id=(Required) Get SMTP detail for a specific ID

Will return a array of the SMTP detail for the ID if exist

get_smtps()

Will give you all the SMTP detail in an Indexed array, even if there is no SMTP it will return a blank array.

Here how the SMTP detail look like (This type of single array you will get for get_smtp() method for get_smtps() each index will contain the same type of array for each SMTP)

							
	Array
		(
			[id] => The SMTP Id
			[title] => SMTP title
			[port] => PORT
			[encryption] => Encryption
			[user_name] => SMTP user name
			[password] => SMTP password
			[reply_email] => SMTP reply email
			[created_at] => Time in second
			[host_name] => SMTP host name
			[from_name] => From name
			[from_email] => From Email
			[reply_name] => Reply Name
		)						
							
						

Work With Lists In CloudFunnels

get_list(Int $id, Bool $attach_subscribers=false)

Get a list detail including subscribers

  • $id = (Required) List Id

  • $attach_subscribers = (Optional) by default it is false, so with the returned data it will not contain any subscriber, if you make it true with the returned data for the function it will contain all the subscriber detail including the list detail

It will return an array of list detail if the list is available otherwise it will return false

Here is a demo output: It will return an associative array of list detail if it’s available otherwise it will return false (Assuming you made the $attach_subscribers=true so now we will get a subscriber field with the array if the list exists)

							
	Array
		(
			[id] => List Id
			[title] => test
			[creationdate] => Will hold the addition date in second
			[subscribers] => Array
				(
					[0] =>Array
					(
						[id] => Subscriber Id
						[name] => Subscriber name
						[email] => Subscriber email
						[date] => Subscriber addition date in second
						[list_id] => List id
						[additional_data] => Array of additional data
						[ip] => IP address
					) 
				)
		)
							
						
get_lists(Int $id=-1,Bool $show_subscribers=false)

It will provide an indexed array of all the available lists including subscribers (Not by default)

  • $id = (Optional) By default it is -1 that will provide all the lists, a specific list id can be provided to get detail of a specific list

  • $show_subscribers = (optional) The definition of show_subscribers is same as described for get_list()

Output: It will be always an indexed array, that will contain an individual list detail like we described in get_list().

add_to_list(Int $list_id, Array $data)

This function can be used to add a subscriber into a list

  • $list_id = (Required) the list id where you want to store the data

  • $data = (Required) The associative array of detail that will be inserted into database The array should contain these data()

							
	Array(
		'name'=> Subscriber Name,
		'email'=> Subscriber Email,
		'additional_data'=> Array of other data that you want to store,
		'process_sequence'=> true or false (Bool) by default it is false, 
							make it true if it needs to put the subscriber in connected sequence
	)
									
							
						

The function will return true if the subscriber added successfully or it will return false

update_list_user(Int $subscriber_id, Array $data)

This function can be used to to update a subscriber detail

  • $subscriber_id = (Required) Id of the subscriber for whom you want to add the subscriber.

  • $data = (Required) The definition of data same as add_to_list() method

delete_list_user(Int $subscriber_id)

Use this function to delete a subscriber from a list

  • $subscriber_id = (Required) The subscriber id

Will return true or false according to the success status

get_list_user(Int/String $id, Bool/String $email=false)

This function can retrieve user for specific subscriber Id or Email & List id

  • $id = (Required) This will be treated as subscriber Id if the $email parameter is false otherwise if the $email is a valid email id by pattern, $id will be treated as List Id

  • $email = (Optional) It may be false(bool) to make the $id subscriber Id or an email to make the $id a list id

Output: It will return an associative array of subscriber detail if the user exist otherwise will return false

Here how the Array will look like if the subscriber is available

							
	Array
		(
			[id] => Subscriber Id
			[name] => Subscriber name
			[email] => Subscriber email
			[date] => Subscriber addition date in second
			[list_id] => List id
			[additional_data] => Array of additional data
			[ip] => IP address
		)	
							
						

Work with Options in CloudFunnels

CloudFunnels provides a table to store, update, retrieve, and delete settings with three easy to use functions.

add_option(), get_option(), update_option() and delete_option() CloudFunnels use to store/manage all the options in a specific global variable also, so that each time we can access an option directly, which has already been fetched from the database.

add_option(String $option_name, String $value)

To store something in option table, if it not exists

update_option(String $option_name, String $value)

To update a specific option value that was added before or if the option name does not exist it will create the option field in the database field.

get_option(String $option_name)

To get value of a specific option name if exist, otherwise it will return false

delete_option(String $option_name)

To delete a specific function this function can be called

  • $option_name = (Required) The option name

  • $option_value = (Required for add_option(), update_option()) The value for the option

Work with AJAX in CloudFunnels

cf_ajax_

This hook allows you to create custom handlers for your own custom AJAX requests. The cf_ajax_ hook follows the format “cf_ajax_$youraction”, where $youraction is your AJAX request’s ‘action’ property.

The cf_ajax_ hook only fires for logged-in users. If you need to also listen for Ajax requests that don’t come from logged-in users.

cf_ajax_nopriv_

This hook is functionally the same as wp_ajax_(action), however it is used to handle AJAX requests on the front-end for unauthenticated users, i.e. when current_user_can() returns false. So the hook follows the format “cf_ajax_nopriv_$actionname”

For both cases the request URL will be

Installation_URL/index.php?page=ajax

So if you want to get the installation URL you can simple call get_option(‘install_url’);

Example

So here is an example of how to register a AJAX action in backend

							
	add_action( 'cf_ajax_action_name', 'my_ajax_foobar_handler' );

	function my_ajax_foobar_handler() {
		// Make your response and echo it.
								
		// Don't forget to stop execution afterward.
		die(); 
	}
							
						

**Now please note when you are trying cf_ajax_nopriv_ just in the place of cf_ajax write cf_ajax_nopriv_

Now how here the example of writing the AJAX request

Let's assume you are putting it in cf_footer somewhere in frontend

So the code will look like

							
	add_action(‘cf_footer’, function(){
		$request_url=get_option(‘install_url’);
		$request_url .=’/index.php?page=ajax’;
									
		echo “
			
			”;
			});	
							
						

**So one thing to note here is the request parameter and , please match it with the backend code.There should be an action parameter that (May be GET/POST) and it should hold the action name which is same as written in your registered backend code (cf_ajax_action_name), for here it is action_name

**Passing argument in callback function:

By default CloudFunnels supports passing argument through the third parameter in add_action method, so if you would like to pass a parameter ton my_ajax_foobar_handler() , you could write like this

							
	add_action( 'cf_ajax_action_name', 'my_ajax_foobar_handler', $some_args );

		function my_ajax_foobar_handler($unused, $provided_args)
			{
				//so the $provided_args will contain the argument, so you have to access this through the second parameter
			}
							
						

Making API CALL

In CloudFunnels , we have specific ways to make API calls also like AJAX, here we don't have any difference between logged in or logged out users.

The action hook is cf_api_$actionname

So the main URL for handling API request is

installation_url/index.php?page=callback_api

So if you want to get the installation URL you can simple call get_option(‘install_url’);

Now, it does not matter what kind of request you are making maybe GET/POST you should have a request parameter “action” and it’s value should contain the action name

Example:

Here how to register the API request in backend

							
	add_action(‘cf_api_action_name’ ,’my_call_back_function’);

	function my_call_back_function(){
		//process whatever you want.
		//Display something if you want
		//don’t forget to die() at the end
		die();
	}
							
						

Here, let’s assume our installation URL is https://something.com and we are going to process a GET request with action ‘action_name’ according to the backend example

So the URL will be

https://something.com/index.php?page=callback_api&action=action_name&data=12345

So here we are making a GET request where the “action” parameter holding the action name and as it is registered with “my_call_back_function()” through cf_api so that particular function will be executed

**Passing argument in callback function:

By default CloudFunnels supports passing argument through the third parameter in add_action method, so if you would like to pass a parameter ton my_call_back_function(), you could write like this

							
	add_action( 'cf_ajax_action_name', 'my_call_back_function', $some_args );

	function my_call_back_function($unused, $provided_args)
		{
			//so the $provided_args will contain the argument, so you have to access this through the second parameter
		 }
							
						

Creating Menu and Submenu page(s) for a plugin

The admin_menu action hook will allow you to create menu and submenu pages. There we have two function add_menu_page() and add_submenu_page() to register a menu and submenu page

  • admin_menu = This will be used to add a menu page in the admin area

All the functions for adding menu page and the sub-menu pages should be called inside

the callback

add_menu_page(String $page_title, String $menu_title, String $menu_slug, Callable $callback_function, String $icon_url = “”, Bool/String $submenu=false)

This function takes a capability which will be used to determine whether or not a page is included in the menu.

  • $page_title = (Required) Title that will be shown in the browser tab

  • $menu_title = (Required) Title that will be shown in the menu

  • $menu_slug = (Required) The slug name to refer to this menu by. Should be unique for this menu page and only include lowercase alphanumeric, dashes, and underscore characters

  • $callback_function = (Required) The function to be called to output the content for this page.

  • $icon_url = (Optional) The URL for the icon

  • $submenu = (Optional) By default it is false, but if you want to make a submenu for the menu make provide a string, which will be your submenu title.

add_submenu_page(String $parent_slug, String $page_title, String $menu_title, String $menu_slug, Callable $callback_function)

This function takes a capability which will be used to determine whether or not a page is included in the menu.

  • $parent_slug = (Required) The slug name for the parent menu

  • $page_title = (Required) Title that will be shown in the browser tab

  • $menu_title = (Required) Title that will be shown in the menu

  • $menu_slug = (Required) The slug name to refer to this menu by. Should be unique for this menu page and only include lowercase alphanumeric, dashes, and underscore characters

  • $callback_function = (Required) The function to be called to output the content for this page.

Example:
							
	add_action(‘admin_menu’,function(){
		add_menu_page('Page Title','Menu Title','menu_slug','call_back','https://something.com/menu.png');							
		add_submenu_page('menu_slug','Page Title','Sub-menu Title','menu_slug','call_back');						
	});	
							
						

Working with database in CloudFunnels

global $mysqli

We are using MYSQLI to deal with databases. CloudFunnels provides a global variable $mysqli, which can be used to make SQL queries.

Example:
							
	global $mysqli;
	$mysqli->query(“select * from `some_table`”);
							
						
global $dbpref

To make tables unique, we always have to use a prefix with table name, and it's highly recommended to use the same prefix for all the tables that are going to be created through your plugin.

The global variable $dbpref contains the prefix that the user has chosen during the installation of CloudFunnels, also all the tables that were created by default, using the same prefix.

Example:
							
	global $mysqli;
	global $dbpref;
								
	$table=$dbpref.’your_table_name’;
								
	$mysqli->query(“create table if not exists `”.$table.”` ...”);
							
						

Use tinyMCE editor

This function can convert any text box or set of textbox with different selector into a tinyMCE editor in admin area of CloudFunnels.

$selector (string or array)= The CSS selector for the text area
Example:

Single
								
	
<textarea id=”#editor”>content</textarea>
<?php register_tiny_editor(“#editor”); ?>

Double
									
	
<textarea id=”#editor1”>content</textarea>
<textarea id=”#editor2”>content</textarea>
<?php register_tiny_editor( array(“#editor”, “#editor2”)) ; ?>

Use default media

The CloudFunnels media can be use anywhere in admin area with help of cf_media function and some javascript function to handle the UI.

cf_media($show=bool)

$show (true| false)= If the value is true it will echo the content required for media otherwise it will return which you can store in any variable.

** One thing to notice to work with cf_media you need to display(echo) the content anyway on the desired page.

** You need to display only once for a page(otherwise unwanted error may appear) but can use anywhere required on that pge, can consider taking a look at the example plugin given below for detail.

Here are the JavaScript function to handle the media

openMedia(callback= function| bool, html=bool)

callback (function or false)= If you provide a callback function it will be executed and pass the media through its first parameter during media Import

html (true|false)= If it’s false it will return the media URL or will return with a html wrapper, for example if its a image it will return <img src=”media_url”/>

Example:
Here is a example plugin, can install and check how its working https://cloudfunnels.in/storage/market_place/example_plugins/cf_media_example.zip

Add Custom Language

A custom language can also be hooked into CloudFunnels, it can be merged with default languages or can be added separately, you can create a JSON file about your translation and can use it with the custom language registration method.

Here is a demo of JSON, you can create a JSON which contains translation like this and can keep in any directory inside your plugin

							
	{
		“Hello”: “Hola”,
		“Hi, ${1} how do you do”: “Hola, ${1} ¿cómo estás?”
	}
								  
							
						

So you may be confused by seeing ${1} right, no worries these are called variables we describe it later where we are informed about w() or t() function

register_custom_lang(Array $langs, Callable $cb)

This can initiate and hook in your language file and the language code into CloudFunnels

Note: There is another function needs to generate actual language called
generate_custom_lang($language_code) that we described later

$langs (Array)= An associative array of languages, each index of the array will contain a unique language code and will hold another array which defines the JSON file location for the language inside the plugin, the language name for viewers.

Example of the array:
								
	Array
	(
		‘My_plugin_lang’ =>  array(‘file’=> ’Location of the JSON based language file’, ‘name’=>’My language’),
	
		‘My_plugin_lang2’ => array(‘file’=> ’Location of the JSON based language file’, ‘name’=>’My language2’),
	)
								
							

The indexes ‘My_plugin_lang’, ‘My_plugin_lang2’ are going to be treated as unique Language code.

CloudFunnels itself has some built in language codes.
Here the language codes and the corresponding names are given

								
	lang_english_en =>  English US
    lang_hindi_hi => हिन्दी
    lang_dutch_nl => Nederlands
    lang_french_fr => français
    lang_german_de => Deutsch
    lang_greek_gr => ελληνικά
    lang_italian_itl => italiano
    lang_japanese_ja => 日本語
    lang_arabic_ar => عربى
    lang_danish_da => dansk
    lang_korean_ko => 한국어
    lang_romanian_ro Română
    lang_spanish_sp => Española
    lang_polish_pl => Polskie
    lang_portuguese_po => Portuguesa
    lang_malay_ml => Bahasa Melayu
    lang_norwegian_no => Norwegian

								
							

So For example, if you want to add or modify something in our existing German language (id: lang_german_de), below the procedure you need to follow.

								
	register_custom_lang(array(
 		‘lang_german_de’=> array (‘file’=> ‘location of the file’, ‘name’=>”This is optional here”)
	))
								
							

$cb (Callable function| Optional)= This is an optional callback function which will be triggered when generate_custom_lang() is going to be called, it will return two parameters first one is language generated or not (true or false) and in second parameter it gives an array contains the language code(lang) and the file location for the language in you plugin (file). Below demonstrating the callback function

								
	function($stat, $data){
		//$stat= True if language generated successfully
		//$data= array(‘lang’=> The language code, ‘file’=> Language file location for your plugin)
		}
									   
								
							
generate_custom_lang($cb= Callable| Optional)

The function register_custom_lang() will just add the raw language file that you will add. But until you call this function the language from your file is not going to be added into main flow until someone changes language manually from the language setup box.

Important to know: this is a unique function, don’t call it again and again. It's recommended to call during installation with register_activation_hook() or if you are updating your language file best to call it once when you will based on the version number of your plugin, the logic is if there is something changed in your language file call this function and call only during installation.

$cb (Callback function| Optional) = If you are using a call back function, after the execution, it will give an array through the first parameter with the active language code. For example of German language it will like array(‘lang’ => ‘lang_german_de’)

** Make sure to call register_custom_lang() before executing generate_custom_lang()

So far we described how to hook in a language, now here we will describe how to affect the languages in frontend.

There are two common functions to use in both cases: PHP or in the backend JS or into the frontend. One function directly displays translate text ( w() ) Another function use to return translated text ( t() )

w(String $text, Array|Optional $variables)

$text (String)= Text that you want to translate, If the translation for the text is available into your language file or in our default language file it will be translated and displayed according to the active language into the app. If there is no translation found for the text, it will stay as it is.

So W($text) is working same as PHP echo, just with translation.

For Example:

In case of backend or PHP

									
	<?php 
	
		echo  “Hello CloudFunnels”;     //this will display the text as it is.
	
		w(“Hello CloudFunnels”)     //this will also display the same text but if there a translation      
		  available for it, then it will display the translated text according to the active language.
	
	?>
	
									
								

Same thing can be done in frontend with javascript, for example.

									
		Hello I am in <script>  w(“frontend”); </script>
									
								

So now if there translation for the text “frontend” is available it will translated and displayed or will remain as it is “Hello I am in frontend”

$variables (Array|Optional) = Sometimes you may need to pass some data into your translated text which will remain unchanged, for example you need a special icon or HTML tag in specific place into your translation. You can pass those as a separated value here. And in translation can write like ${index_number}, which is going to be replaced with the value in that specific index number

Here is an example,
								
		w(‘Hi ${1}, What do you think about ${2} ?’, array(‘Joe’, ‘Peter’)  )
								
							

So the output will be:

Hi Joe, What do you think about Peter?

** One thing to note when you using a double inverted comma ( “ ) for PHP to wrap a string or using backtick ( ` ) in JavaScript you need to escape the $ sign with backslash ( \ ), so if we use double braces in above example it will look like.

w(“Hi \${1}, What do you think about \${2} ?”, array(‘Joe’, ‘Peter’) )

t(String $text, Array|Optional $variables)

All the things in this function works same as w(), the difference is it does not display this function just returns the translated text.

All the things in this function works same as w(), the difference is it does not display this function just returns the translated text.

For Example:

$translated_text= t(“Hello”);

So it will translate the text “Hello”, if the translation available and will store it into the variable $translated_text.

This works in same manner for Javascript too

Global variables & helper functions

**Never Ever modify these data

  • global $document_root = Will hold the root directory for the installation

  • get_option(‘site_token’) = Will give you a unique string for the installation

  • get_option(‘default_smtp’) = Will return the default SMTP

  • get_option(‘install_url’) = Will return the installation URL

  • get_option(‘qfnl_current_version’) = Will give you current CloudFunnels version

  • getProtocol() = get current protocol http:// or https:// (only “http” or “https” can be treated as a valid protocol)

  • getOS() = Will return current OS

  • getBrowser() = Will return Current browser

  • getIP() = Will return current user IP

  • getLocation() = Will return current user location

  • cf_enc(String $string , $do="encrypt") = CloudFunnels supports two way encryption with openssl_encrypt and decrypt method

  • $string = (Required) String that you want to encrypt or decrypt

  • $do = (Optional) by default it is ‘encrypt’ when you are trying to decrypt something try pass ‘decrypt

Handling Known Exceptions

Many of the specified functions for Plugins use to throw known exceptions if there is something wrong in the provided parameter, return values etc.

So, it is always recommended to use a Exception handler i.e try catch block

Example
							
	try{
		//here the plugin function calls that are registered inside CloudFunnels
	}catch(Exception $e)
	{
			// handle your exception
			//to get message $e->getMessage()
	}	
							
						

Procedural & OOP way of writing your Plugin

Procedural Example

Let’s assume your plugin just adds some script in to the page footer

So here you can follow to way by calling your callback function directly

							
	add_action(‘cf_footer’, function(){
		//some code
	}  )
									
	>> Define your function and call it with the function name
									
	add_action(‘cf_footer’, ‘my_callback’);
	//it’s always recommended to check whether the function already defined or not
	//always use a unique prefix name with your function name 
	if( ! function_exists(‘my_callback’)){
			function my_callback(){
			//do something
			}
	}	
							
						
Object oriented way
							
	//It's always recommended to check whether the class already exist or not
	//it's always recommended to use a unique class name for your class name
								
	if(!class_exists(‘my_class’)){
		class my_class{
			function __construct(){
				//let’s call add_action with footer hook here and will execute a method //doSomething 
				add_action(‘cf_footer’,array($this,’doSomething’)); 
			}
			function doSomething(){
				//display something
			}
		}
	}
							
						

**so the point to note here is when you pass the callback function, in case of an object method, pass an array. Where the first index will contain the object and second parameter the method name.

	array($object, ’Method name’)