PHP - action hook 'ninja_forms_daily_action' - wordpress

I am looking at the source code for Ninja forms plugin. There is an action hook scheduled to execute daily in the file activation.php(line:51), but I cannot find the implementation of the action itself. I am assuming there should be a function called ninja_forms_daily_action somewhere in the code, but I can't seem to find it.
Am I missing something?

There is no associated function. The full code is the following:
wp_schedule_event( time(), 'daily', 'ninja_forms_daily_action' );
What this essentially translates to is:
Schedule a hook called ninja_forms_daily_action to be executed by the WordPress actions core on a daily interval, starting now.
This has been added so that developers can hook into it with their own functions...but the Ninja Forms core doesn't make use of it.
Read more about wp_schedule_event() in the docs.

Related

Cron Wordpress Update four post every hour

I have function that update post content automatically based from custom field like this:
function update_content(){
$mycustomfield = get_post_meta( get_the_ID(), 'customfield', true);
$post = array();
$post['ID'] = get_the_ID();
$post['post_content' ] = $mycustomfield ;
$post['post_title' ] = $mycustomfield ;
// Update the post into the database
wp_update_post( $post );
We update only custom field to make content. For now, we launch this function manually on save_post hook, but the articles are so many and we need now a cron to automate this function: process 4 posts every hour until all posts are completed, then start over.
How to make this, thank you
WordPress actually has a built-in psuedo cron system called WP Cron. It doesn't function exactly like a proper server cron, but can perform a similar function in many cases. You can find documentation on it here:
https://developer.wordpress.org/plugins/cron/#:~:text=WP%2DCron%20is%20how%20WordPress,post%2C%20utilize%20WP%2DCron.&text=WP%2DCron%20works%20by%20checking,what%20needs%20to%20be%20run.
However thinking about your use case and looking at your function above, I'm wondering what the purpose of your cron is? It looks from that function like all you're doing is taking some content already in your database and putting it somewhere else. Why? Why not simply display your custom field in the correct spot? Or better yet, use the fields as intended?
Even if that is necessary - maybe I don't understand fully from the example above - I think your initial inclination to run this on save_post is much more correct. Unless there's some information external to your site that's changing, the only time these values will change is when you save the post. So what is the purpose of running it on a schedule?

Call to undefined function add_options_page()

I developed the plugin for my wordpress project. I successfully tested it on my local xampp server with 5.3 php. Then I uploaded my project to the web hosting with php 5.2. First trouble which with I faced off was unsupporting anonymous functions in php 5.2. No issue, I redeclared all functions with names. But then I got error Call to undefined function add_options_page(), which I counldn't explain. Plz help me guys with your advices
My part of code:
function mainPage(){
///some code
}
function mainPage2(){
add_options_page('Submissions of MAIN page contact form', 'Submissions of MAIN page contact form', 'manage_options','ea_submissions2', mainPage());
}
add_action('admin_menu',mainPage2());
I think something wrong with my funcitons, look through it please.
There is no issue with php 5.2 as I thought, this part of code also doesn't work with php 5.3! Something wrong with my code
I had a similar problem, turns out I was running a function too early:
Use admin_init hook instead of init
Hopefully that helps someone out :D
This doesn't work because you have normal function not wrapped in a class, and because add_options_page does not work yet by that time that is why you get the error.
A fix would be to use an anonymous function in the add action call, but hence that does not work on php 5.2.
So long story short, this is fixable though, but you shouldn't run php 5.2 anymore in the first place. PHP 5.5 is already in development and 5.3 is facto standard these days. A solution is to ask your hosting company to upgrade php to at least 5.3 so that you can use anonymous functions and you can hook it to the add action call.
Or, wrap it all in a class and on the admin init function create the new class.
You have to call your code inside admin_menu like this
add_action( 'admin_menu', array(&$this, 'addWidgetSettingsMenu' ));
Aware that this is an old question, this is your problem:
add_action('admin_menu',mainPage2());
Here you are invoking the mainPage2() function and adding the return value of that function as an argument to the add_action method.
You should do
add_action('admin_menu', 'mainPage2');
This way, the mainPage2 function will be called when admin_menu happens.
Try it without giving space in title :-
SubmissionsOfMainPageContactForm

wordpress wp_enqueue_script is not working in actions but working normally .

add_action("publish_post", "php_func");
function php_func(){
wp_register_script("customscript","link to js file");
wp_enqueue_script("customerscript")
}
I think above process is right, but thats not working . The two lines in above func are working normally when written in the php file directly(without actions), but with actions, above is not working .
function php_func(){
echo "<script>alert("hiii");</script>"; //working but not good method. Also, getting errors like headers sent already .
}
Every action is registered to a specific hook. When that hook is reached in the code, all actions registered to that hook is run.
When you publish a post the publish_post hook will run you function, and enqueue you javascript.
Your problem is that the code, then loops through all enqueued scripts and run them, has already been run.
You need to enqueue them in an earlier hook. And the specific hook build for this is called wp_enqueue_scripts.
add_action("wp_enqueue_scripts", "php_func");
function php_func(){
wp_register_script("customscript","link to js file");
wp_enqueue_script("customerscript")
}
There is a lot more information to be found in the Codex.

How do I call functions from my Plugin in WP template?

I've created a calendar plugin and now I want to show a event list in one of my templates.
The code I'm using now, is this:
include_once(WP_CAL_PLUGIN_DIR.'eventcal.class.php');
$calendar = new EventCalendar();
$events = $calendar->getMultipleEvents('5');
(...)
<table>
<?php foreach($events as $event) : ?>
<tr>
<td><span><?php echo $calendar->formatEventTime($event->startTime,'dm'); ?></span></td>
<td><span><?php echo $calendar->formatEventTime($event->startTime,'time'); ?></span></td>
<td><?php echo $event->name; ?></td>
</tr>
<?php endforeach; ?>
</table>
Is there a way I can call functions within my plugin without having to include the WP plugin and creating a new class instance?
In order to execute shortcode inside a template, use the function do_shortcode('[my-shortcode-handle]'). Your shortcode needs to be registered as like normal (see WordPress codex on shortcode API) before you can use this in the template. Any attributes, inside content, etc. should be in there as well.
echo do_shortcode( '[my-shortcode foo="bar"]Shortcode content[/my-shortcode]' );
Also, remember to echo the return (or at least assign it to a variable), since it only returns the shortcode's output.
From: http://codex.wordpress.org/Plugin_API
Hooks are provided by WordPress to allow your plugin to 'hook into' the rest of WordPress; that is, to call functions in your plugin at specific times, and thereby set your plugin in motion. There are two kinds of hooks:
Actions: Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API.
Filters: Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API.
Actions
Actions are triggered by specific events that take place in WordPress, such as publishing a post, changing themes, or displaying a page of the admin panel. Your plugin can respond to the event by executing a PHP function, which might do one or more of the following:
* Modify database data
* Send an email message
* Modify what is displayed in the browser screen (admin or end-user)
The basic steps to making this happen (described in more detail below) are:
Create the PHP function that should execute when the event occurs, in your plugin file.
Hook to the action in WordPress, by calling add_action()
Put your PHP function in a plugin file, and activate it.
EXAMPLE:
function email_friends($post_ID) {
$friends = 'bob#example.org,susie#example.org';
mail($friends, "sally's blog updated",
'I just put something on my blog: http://blog.example.com');
return $post_ID;
}
Hook to WordPress
After your function is defined, the next step is to "hook" or register it with WordPress. To do this, call add_action() in the global execution space of your plugin file:
add_action ( 'hook_name', 'your_function_name', [priority], [accepted_args] );
where:
hook_name
The name of an action hook provided by WordPress, that tells what event your function should be associated with.
your_function_name
The name of the function that you want to be executed following the event specified by hook_name. This can be a standard php function, a function present in the WordPress core, or a function defined by you in the plugin file (such as 'email_friends' defined above).
priority
An optional integer argument that can be used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
accepted_args
An optional integer argument defining how many arguments your function can accept (default 1), useful because some hooks can pass more than one argument to your function. This parameter is new in release 1.5.1.
In the example above, we would put the following line in the plugin file:
add_action ( 'publish_post', 'email_friends' );

trying to find the comment hook I need for wordpress?

I'm writing a wordpress plugin that will execute a certain function when a user submits a comment. The only issue is I'm using the hook "comment_post" which works but if that comment gets stopped by akismet I'm still logging that comment but now my numbers are off from what's on the actual site. Is there a comment_approved type hook I should be using instead?
this is something I was looking at not too long ago,
Only thing is the admin has to approve/edit the comment before the function would run..
using the wordpress admin hook:
wp_set_comment_status()
This function is run after changing the status of the comment by the admin..,
this looks for the status from 4 options
status ("delete", "approve", "spam", "hold").
You can check for the status approve?
do your caculation from there?

Resources