Run wp_schedule_single_event inside wp_schedule_event hook function? - wordpress

Is it possible to run a single event inside the hook function of a recurring event?
if(!wp_next_scheduled('recurring_event')) {
wp_schedule_event(time(), 'every_15_minutes', 'recurring_event');
}
add_action('recurring_event', 'recurring_event_function');
function recurring_event_function(){
wp_schedule_single_event(time() + 3600, 'single_event');
add_action('single_event', 'single_event_function');
}
function single_event_function() {
//Do stuff here
}
Something like this?
I've tried the code above but it doesn't create a single event in the cron manager when the recurring event fires.

Related

GTM Callback firing multiple times

I've followed the Google docs to add GTM tags to my site. For some reason the call back is firing 3 times, however, I only have this tag on the page.
window.dataLayer.push({
'event': 'add_expense',
'eventCallback': function () {
alert('wtf');
}
});
Anyone have any clues on why this may be?
It could be you have multiple GTM containers on the page, including plugins. You can check to see if the callback is being passed different containers ids:
'eventCallback': function (id) {
alert(id);
}
This happened to me after enabling GA4 in the page. Seems like it is using same container and rules as GTM and caused callbacks to fire twice. My solution:
const buildGtmCallback = (callback) => {
//GA4 is also a container, so need to fire callbacks only once, for GTM container
//GA4 containerId starts with G-
return (containerId) => {
if (containerId.startsWith("GTM-") && typeof callback === "function") {
callback();
}
}
}
And then whatever you wish to be fired only once:
window.dataLayer.push({
'event': 'add_expense',
'eventCallback': buildGtmCallback(function () {
alert('wtf');
})
});
This solution will also work if you have multiple GTM containers by modifying containerId.startsWith("GTM-") and replace “GTM-“ with the container ID you wish the event to fire for. However in that case you won’t be sure event was fired for both containers, just that one

How in Meteor can we call from a template's event code the event code of another template?

So, ho can we trigger a template's event from the event of another template?
A similar question was answered IMPOV unclearly for my need, but Staskoverflow says to avoid asking for clarifications.
Similar question
Two options:
An underlying function
Template.foo.events({
'click .foo': function(e,t) {
doStuff();
}
})
Template.bar.events({
'click .bar': function(e,t) {
doStuff();
}
})
An event trigger
Template.bar.events({
'click .bar': function(e,t) {
$('.foo').trigger('click');
}
})
I think the first is more robust, but either works.

In meteorjs' click event, how do I get the id?

In meteorjs's event, how do I get the id of clicked item, without adding a JQuery binding stuff?
(Ya I investigated other posts, but does not help) IMPOV)
You can do this:
{
'click p': function (event) {
console.log(event.currentTarget.id);
}
}
Read more here.

Meteor reactive on collection.find

So, I know that if I do a collection.find(), it's actually reactive and will update the information displayed when there's new data in the collection.
Like if I do something like this:
Template.test.helpers({
test: function() {
return MyCollection.find({});
}
});
So, I know that my {{test}} part in the HTML will be updated properly.
But I need to parse that data on the client side before. Is there a way to call a function every time the find function is called?
Is there anything that could be like:
function() {
MyCollection.find({}, function(result) {
// this is executed each there's new data
// do some stuff with result
Session.set("mySessionVar", newResultData);
});
}
And then, place Session.get("mySessionVar") in some helper function.

FullCalendar with live event

I need to fire FullCalendar on live() method. So, I tried this:
$('.full-calendar').live('fullCalendar', function(){
return { header : .... //options here }
});
But this doesn't work. Do you think is possible to achieve this?
fullcalendar is not a supported event by .live()ref. Actually, this is not an event at all (unless you created it by yourself but it wouldn't then be supported by .live().
Your full calendar creation must be triggered by a real event (click, double-click,...)
You could probably use something like:
$('.full-calendar').live('click', function() {
$('#calendar').fullCalendar({
// put your options and callbacks here
})
});

Resources