How to add wp_editor Dynamically

Add this to your php file

wp_enqueue_editor();

Add this on your script after you load the wp_editor elements to your web page.

tinymce.execCommand( ‘mceRemoveEditor’, false, ‘proj_desc’ );
tinymce.execCommand( ‘mceAddEditor’, false, ‘proj_desc’ );
quicktags({id : “proj_desc”});

 

Source: https://carlofontanos.com/loading-wp_editor-via-ajax/

How to Insert Codes to Any Plugin or Theme

If you’re a web developer and you’re trying to modify the output of any plugin or theme without editing the plugin or theme itself, you can only if the plugin or theme developer allows you to.

In order to know if you can manipulate the output, you have to find out where a particular section is located or defined. Once you find the codes you’re looking for, determine the section where you want to insert codes and see if there is a do_action() in that area. If there is one, then you can definitely insert your codes on that section without having to edit that section.

do_action() should have two parameters, the tag and the arguments.

e.g. do_action(‘woocommerce_after_cart_table’)

The above action does not define any arguments. This action allows you to add content after the cart table in the woocommerce cart page.

Now that we know we can insert codes to the section and that the tag is ‘woommerce_after_cart_table’,  we need to call add_action() function so that we can connect to the do_action.

add_action(‘{tag}’, ‘{function_name}’);

The first parameter is the tag which is the first parameter in do_action (see above).

The second parameter is the function name for your function.

Now, let’s define a function that will simple display a test:

[insert-code id=1]

Now, let’s execute that function by adding it to the action ‘woocommerce_after_cart_table’.

[insert-code id=2]

Save your work and go to the cart page and see if the test is added after at the bottom of the cart page.

This is only a simple demonstration of what the do_action and add_action can do. If the do_action provides arguments, you can make use of this so that your custom function can communicate with the action. You can visit here and here for more details about these functions.

How to Use WP Cron

Scheduling an event in WordPress is very common. This functionality is commonly known as CRON. Here are the steps on how to can create CRON tasks.

Step 1: Determine the desired recurrence

There are three predefined recurrences defined by WordPress, namely: daily, twicedaily, & hourly.

If you want to define your own recurrence, you can do so. Below is an example of adding a recurrence every2mins which obviously means that the recurrence every 2 minutes:

[insert-code id=3]

Change values as desired.

Step 2: Register your cron task(s)

Here is a simple way to implement a cron or registering an event which will be executed every hour:

[insert-code id=1]


To change the recurrence, run it every 2 minutes, for example, we can use the recurrence above. In the function my_activation, look for the ff. line:

wp_schedule_event(time(), ‘hourly’, ‘my_hourly_event’);

Change hourly to every2mins, or the name of the recurrence you defined.


You can create as many custom recurrence and events as needed. It’s just a matter of changing values. To make it easier for you, I created a class which will allow you to register events into the WordPress Cron without the need to do the above steps.

Step 1: Copy the Cron Class from WDT-Framework

Step 2: Include/Require the class in your plugin.

Step 3: On the main file of your plugin, add the ff. codes:

new \wdtf\WPCronEvent(__FILE__, 60, 'executeThisFunc');

60 is the interval of the recurrence (in seconds). You can also use ‘daily’, ‘twicedaily’, or ‘hourly’
executeThisFunc is the name of the function that will get executed and you can rename it.

Step 4: Define your function.


Don’t forget to reactivate your plugin to make the cron work.


 

Best WordPress Accordion Plugins

When looking for an accordion plugin, there are so many options to choose from. I did this review so that I can help you minimize the time that you’re going to spend in finding the best ones for your needs.

As of now, I’m able to manage 3 accordion plugins, and I’m planning to review 7 more.

These are the things I’m looking for in an accordion plugin:
[table id=1 /]

You can checkout more accordion plugins here.

How to Create Custom WP Metabox

Default and custom types already have default fields that we can fill in, but what it we need custom data for these post types? In this kind of need, we can opt to create custom metaboxes which will contain custom fields for the desired post types.

To make the implementation of a custom metabox easier, I created an abtract class that you can find here.

So, to create a custom metabox, simply follow the steps below:

Step 1: Copy the Metabox Class from WDT-Framework

Step 2: Extend the class and defined the needed functons:

  • _showForm() – this is where you should define the content of your metabox (normally a set of custom fields)

[insert-code id=1]

  • _saveMetadata() – this is where you should define how the fields are saved.

[insert-code id=2]

Step 3: Instantiate your class.

Parameters:
$metabox_id
(string) the id of your metabox; must be unique

$metabox_title
(string) the title if your metabox

$screens
(array) what screens should the metabox appear; normally an array of post types

$context
(string) options: normal, side, advanced

$priotity
(string) options: high, low, default

Examples:

[insert-code id=3]

 

How to Add & Customize ACF Form in Front End

Advance Custom Fields plugin is one of the best plugins when if you want add custom fields to your post, page, custom post types, and even custom options page .

Entending your dashboard forms can be very easy, however, if you want custom forms for your front end, this plugin does not provide default styling options.

In this tutorial, we will discuss on how to create a custom ACF forms for your website pages.

1> Create an acf form. In this tutorial, we will create an “options page” form.