本文整理汇总了PHP中WYSIJA::set_cron_schedule方法的典型用法代码示例。如果您正苦于以下问题:PHP WYSIJA::set_cron_schedule方法的具体用法?PHP WYSIJA::set_cron_schedule怎么用?PHP WYSIJA::set_cron_schedule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WYSIJA
的用法示例。
在下文中一共展示了WYSIJA::set_cron_schedule方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_cron_schedule
/**
* this function get and sets the cron schedules when Wysija's own cron system is active
* @staticvar type $cron_schedules
* @param type $schedule
* @return type
*/
public static function get_cron_schedule($schedule = 'queue')
{
static $cron_schedules;
//if the cron schedules are already loaded statically then we just have to return the right schedule value
if (!empty($cron_schedules)) {
if ($schedule == 'all') {
return $cron_schedules;
}
if (isset($cron_schedules[$schedule])) {
return $cron_schedules[$schedule];
} else {
WYSIJA::set_cron_schedule($schedule);
return false;
}
} else {
//this is the first time this function is executed so let's get them from the db and store them statically
$cron_schedules = get_option('wysija_schedules', array());
if (!empty($cron_schedules)) {
if (isset($cron_schedules[$schedule])) {
return $cron_schedules[$schedule];
} else {
return false;
}
} else {
WYSIJA::set_cron_schedule();
return false;
}
}
return false;
}
示例2: save
//.........这里部分代码省略.........
$is_network_admin = WYSIJA::current_user_can('manage_network');
$global_MS_settings = array();
foreach ($data as $key => $value) {
// we detect a ms value, so we put it in a separate array to store it somewhere else central
if ($is_multisite && $is_network_admin && strpos($key, 'ms_') !== false) {
$global_MS_settings[$key] = $value;
continue;
}
// verify that the confirm email body contains an activation link
// if it doesn't add it at the end of the email
if ($key == 'confirm_email_body' && strpos($value, '[activation_link]') === false) {
$value .= "\n" . '[activation_link]Click here to confirm your subscription.[/activation_link]';
}
// I'm not sure why do we do that, we separate the DKIm wrappers from teh value saved in the option.. why not, there must be a reason
if ($key == 'dkim_pubk') {
$value = str_replace(array('-----BEGIN PUBLIC KEY-----', '-----END PUBLIC KEY-----', "\n"), '', $value);
}
if (is_string($value)) {
$value = preg_replace('#< *script(?:(?!< */ *script *>).)*< */ *script *>#isU', '', $value);
$value = preg_replace("#<([^><]+?)([^a-z_\\-]on\\w*|xmlns)(\\s*=\\s*[^><]*)([><]*)#i", "<\\1\\4", $value);
}
// for the manage subscription option you can select which list appear publicy to the user in their subscription page.
// this piece of code make sure that they appear or not
if ($key == 'manage_subscriptions_lists') {
$model_list = WYSIJA::get('list', 'model');
$model_list->update(array('is_public' => 0), array('is_public' => 1));
$model_list->reset();
$model_list->update(array('is_public' => 1), array('list_id' => $value));
unset($this->values[$key]);
}
// we have a variable in this class which is defaults
// we save the option only if its value is different than the default one: no need to overload the db.
if (!isset($this->defaults[$key]) || isset($this->defaults[$key]) && $value != $this->defaults[$key]) {
$this->values[$key] = $value;
} else {
unset($this->values[$key]);
}
}
// save the confirmation email in the email table
// IMPORTANT: once we move the confirmation email to the newsletter listing we can get rid of that
if (isset($data['confirm_email_title']) && isset($data['confirm_email_body'])) {
$model_email = WYSIJA::get('email', 'model', false, 'wysija-newsletters', false);
$is_multisite = is_multisite();
// the from email on a multisite with the network method on is coming from the ms value
if ($is_multisite && $data['sending_method'] == 'network') {
$from_email = $data['ms_from_email'];
} else {
$from_email = $data['from_email'];
}
// updating email
$model_email->update(array('from_name' => $data['from_name'], 'from_email' => $from_email, 'replyto_name' => $data['replyto_name'], 'replyto_email' => $data['replyto_email'], 'subject' => $data['confirm_email_title'], 'body' => $data['confirm_email_body']), array('email_id' => $this->values['confirm_email_id']));
}
unset($this->values['confirm_email_title']);
unset($this->values['confirm_email_body']);
}
// serialize and encode the option's values and save them in WP's options
update_option($this->name_option, base64_encode(serialize($this->values)));
// when we are on a multisite, part of the options need to be saved into a global option common to all of the sites
if ($is_multisite) {
// the network admin has access to that extra information through the interfaces when does interfaces are generated then $dataMultisite is filled with values
if (!empty($global_MS_settings)) {
if ($ms_sending_freq_has_changed) {
// if the sending frequency on the network method has changed, we need to update each single cron task on all of the child sites
// we reset an array to clear the cron of every single site using the multisite method
update_site_option('ms_wysija_sending_cron', array());
}
// get the data which was saved in the global option before
$data_saved_ms_before = unserialize(base64_decode(get_site_option('ms_' . $this->name_option)));
// if it's not empty we just merge both sets of values
if (!empty($data_saved_ms_before)) {
$global_MS_settings = array_merge($data_saved_ms_before, $global_MS_settings);
}
// we save the global ms option
update_site_option('ms_' . $this->name_option, base64_encode(serialize($global_MS_settings)));
}
// let's merge the latest MS modified values with the values of the site's config, this is to avoid a bug after saving
$data_saved_ms_fresh = unserialize(base64_decode(get_site_option('ms_' . $this->name_option)));
if (!empty($data_saved_ms_fresh)) {
$this->values = array_merge($this->values, $data_saved_ms_fresh);
}
}
// the sending frequency has changed on that site's settings let's clear the frequency recorded in WP's and wysija's crons
if ($sending_freq_has_changed) {
// WordPress cron clearing
wp_clear_scheduled_hook('wysija_cron_queue');
// MailPoet's cron reset
WYSIJA::set_cron_schedule('queue');
}
// same than above but with the bounce frequency
if ($bouncing_freq_has_changed) {
// WordPress cron clearing
wp_clear_scheduled_hook('wysija_cron_bounce');
// MailPoet's cron reset
WYSIJA::set_cron_schedule('bounce');
}
// if it has been saved through the interface we notify the admin
if ($saved_through_interfaces) {
$this->notice(__('Your settings are saved.', WYSIJA));
}
}
示例3: wysija_exec_process
function wysija_exec_process($process = 'queue')
{
$scheduled_times = WYSIJA::get_cron_schedule($process);
if (isset($scheduled_times['running']) && $scheduled_times['running'] && $scheduled_times['running'] + 900 > time()) {
echo 'already running : ' . $process . '<br/>';
return;
}
//set schedule as running
WYSIJA::set_cron_schedule($process, 0, time());
//execute schedule
switch ($process) {
case 'queue':
WYSIJA::croned_queue($process);
$hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
if (is_object($hPremium)) {
$hPremium->splitVersion_croned_queue_process();
}
break;
case 'bounce':
$hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
if (is_object($hPremium)) {
$hPremium->croned_bounce();
}
break;
case 'daily':
WYSIJA::croned_daily();
break;
case 'weekly':
if (is_object($hPremium)) {
$hPremium->croned_weekly();
}
break;
case 'monthly':
WYSIJA::croned_monthly();
break;
}
//set next_schedule
WYSIJA::set_cron_schedule($process);
if ($report) {
echo 'processed : ' . $process . '<br/>';
}
}
示例4: run_scheduled_task
/**
* run process if it's not detected as already running
* @param type $process
* @return type
*/
function run_scheduled_task($process = 'queue')
{
//first let's make sure that the process asked to be run is not already running
$scheduled_times = WYSIJA::get_cron_schedule($process);
$processes = WYSIJA::get_cron_frequencies();
$process_frequency = $processes[$process];
// check if the scheduled task is already being processed,
// we consider it timed out once the started running time plus the frequency has been passed
if (!empty($scheduled_times['running']) && $scheduled_times['running'] + $process_frequency > time()) {
if ($this->report) {
echo 'already running : ' . $process . '<br/>';
}
return;
}
// set schedule as running
WYSIJA::set_cron_schedule($process, 0, time());
// execute schedule
switch ($process) {
case 'queue':
// check if there are any scheduled newsletters ready for action
WYSIJA::check_scheduled_newsletters();
// if premium is activated we execute the premium cron process
if (defined('WYSIJANLP')) {
$helper_premium = WYSIJA::get('premium', 'helper', false, WYSIJANLP);
$helper_premium->croned_queue_process();
} else {
// run the standard queue process no scheduled tasks will be check since it has already been checked above
WYSIJA::croned_queue(false);
}
break;
case 'bounce':
$helper_premium = WYSIJA::get('premium', 'helper', false, WYSIJANLP);
$model_config = WYSIJA::get('config', 'model');
// if premium is activated we launch the premium function
if (is_multisite()) {
$multisite_prefix = 'ms_';
}
// we don't process the bounce automatically unless the option is ticked
if (defined('WYSIJANLP') && $model_config->getValue($multisite_prefix . 'bounce_process_auto')) {
$helper_premium->croned_bounce();
} else {
$process .= ' (bounce handling not activated)';
}
break;
case 'daily':
WYSIJA::croned_daily();
break;
case 'weekly':
if (defined('WYSIJANLP')) {
$helper_premium = WYSIJA::get('premium', 'helper', false, WYSIJANLP);
$helper_premium->croned_weekly();
}
WYSIJA::croned_weekly();
break;
case 'monthly':
WYSIJA::croned_monthly();
break;
}
// set next_schedule details
WYSIJA::set_cron_schedule($process);
if ($this->report) {
echo 'processed : ' . $process . '<br/>';
}
}
示例5: save
//.........这里部分代码省略.........
unset($data['dkim_privk']);
unset($this->values['dkim_privk']);
unset($data['dkim_regenerate']);
}
}
}
$is_multisite=is_multisite();
$is_network_admin=WYSIJA::current_user_can('manage_network');
$dataMultisite=array();
foreach($data as $key => $value){
//store the ms values somewhere central
//$is_multisite=$is_network_admin=true;//PROD comment that line
if($is_multisite && $is_network_admin && strpos($key, 'ms_')!==false){
$dataMultisite[$key]=$value;
continue;
}
//verify that the confirm email body contains an activation link if it doesn't add i at the end of the email
if($key=='confirm_email_body' && strpos($value, '[activation_link]')=== false){
//the activation link was not found
$value.="\n".'[activation_link]Click here to confirm your subscription.[/activation_link]';
}
if($key=='dkim_pubk'){
$value = str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\n"),'',$value);
}
if($key=='manage_subscriptions_lists'){
$mList=WYSIJA::get('list','model');
$mList->update(array('is_public'=>0),array('is_public'=>1));
$mList->reset();
$mList->update(array('is_public'=>1),array('list_id'=>$value));
unset($this->values[$key]);
}
if(is_string($value)) $value=$value;
//we save it only if it is different than the default no need to overload the db
if(!isset($this->defaults[$key]) || (isset($this->defaults[$key]) && $value!=$this->defaults[$key])){
$this->values[$key]= $value;
}else{
unset($this->values[$key]);
}
}
//save the confirmation email in the email table
if(isset($data['confirm_email_title']) && isset($data['confirm_email_body'])){
$mailModel=WYSIJA::get('email','model',false,'wysija-newsletters',false);
$is_multisite=is_multisite();
//$is_multisite=true;//PROD comment that line
if($is_multisite && $data['sending_method']=='network') {
$from_email=$data['ms_from_email'];
}
else $from_email=$data['from_email'];
$mailModel->update(array('from_name'=>$data['from_name'],'from_email'=>$from_email, 'replyto_name'=>$data['replyto_name'],'replyto_email'=>$data['replyto_email'],
'subject'=>$data['confirm_email_title'],'body'=>$data['confirm_email_body']),array('email_id'=>$this->values['confirm_email_id']));
}
unset($this->values['confirm_email_title']);
unset($this->values['confirm_email_body']);
}
//serialize and encode the option's values and save them in WP's options
update_option($this->name_option,base64_encode(serialize($this->values)));
//we are in a multisite case
if($is_multisite){
//the network admin has access to that extra information through the interfaces when does interfaces are generated then $dataMultisite is filled with values
if(!empty($dataMultisite)){
if($ms_sending_freq_has_changed){
//we reset an array to clear the cron of every single site using the multisite method
update_site_option('ms_wysija_sending_cron',array());
}
$data_saved_ms_before= unserialize(base64_decode(get_site_option('ms_'.$this->name_option)));
if(!empty($data_saved_ms_before)) $dataMultisite=array_merge($data_saved_ms_before, $dataMultisite);
update_site_option('ms_'.$this->name_option,base64_encode(serialize($dataMultisite)));
}
//let's merge the latest MS modified values with the values of the site's config, this is to avoid a bug after saving
$data_saved_ms_fresh=unserialize(base64_decode(get_site_option('ms_'.$this->name_option)));
if(!empty($data_saved_ms_fresh)) $this->values=array_merge($this->values, $data_saved_ms_fresh);
}
//the sending frequency has changed on that site's settings let's clear the frequency recorded in WP's and wysija's crons
if($sending_freq_has_changed){
wp_clear_scheduled_hook('wysija_cron_queue');
WYSIJA::set_cron_schedule('queue');
}
//same than above but with the bounce frequency
if($bouncing_freq_has_changed){
wp_clear_scheduled_hook('wysija_cron_bounce');
WYSIJA::set_cron_schedule('bounce');
}
//if it has been saved through the interface we notify the admin
if($savedThroughInterface) $this->notice(__('Your settings are saved.',WYSIJA));
}
示例6: run_scheduled_task
function run_scheduled_task($process = 'queue')
{
$scheduled_times = WYSIJA::get_cron_schedule($process);
if (isset($scheduled_times['running']) && $scheduled_times['running'] && $scheduled_times['running'] + 900 > time()) {
if ($this->report) {
echo 'already running : ' . $process . '<br/>';
}
return;
}
WYSIJA::set_cron_schedule($process, 0, time());
switch ($process) {
case 'queue':
WYSIJA::croned_queue($process);
if (defined('WYSIJANLP')) {
$hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
$hPremium->croned_queue_process();
}
break;
case 'bounce':
if (defined('WYSIJANLP')) {
$hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
$hPremium->croned_bounce();
}
break;
case 'daily':
WYSIJA::croned_daily();
break;
case 'weekly':
if (defined('WYSIJANLP')) {
$hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
$hPremium->croned_weekly();
}
WYSIJA::croned_weekly();
break;
case 'monthly':
WYSIJA::croned_monthly();
break;
}
WYSIJA::set_cron_schedule($process);
if ($this->report) {
echo 'processed : ' . $process . '<br/>';
}
}
示例7: save
//.........这里部分代码省略.........
$userHelper =& WYSIJA::get('user', 'helper', false, 'wysija-newsletters', false);
if (isset($data['from_email']) && !$userHelper->validEmail($data['from_email'])) {
if (!$data['from_email']) {
$data['from_email'] = __('empty', WYSIJA);
}
$this->error(sprintf(__('The <strong>from email</strong> value you have entered (%1$s) is not a valid email address.', WYSIJA), $data['from_email']), true);
$data['from_email'] = $this->values['from_email'];
}
if (isset($data['replyto_email']) && !$userHelper->validEmail($data['replyto_email'])) {
if (!$data['replyto_email']) {
$data['replyto_email'] = __('empty', WYSIJA);
}
$this->error(sprintf(__('The <strong>reply to</strong> email value you have entered (%1$s) is not a valid email address.', WYSIJA), $data['replyto_email']), true);
$data['replyto_email'] = $this->values['replyto_email'];
}
/* in that case the admin changed the frequency of the wysija cron meaning that we need to clear it */
if ($data['sending_emails_each'] != $this->getValue('sending_emails_each')) {
$sending_freq_has_changed = true;
$data['last_save'] = time();
}
if (isset($data['bouncing_emails_each']) && $data['bouncing_emails_each'] != $this->getValue('bouncing_emails_each')) {
$bouncing_freq_has_changed = true;
$data['last_save'] = time();
}
/* if saved with gmail then we set up the smtp settings */
if ($data['sending_method'] == 'gmail') {
$data['smtp_host'] = 'smtp.gmail.com';
$data['smtp_port'] = '465';
$data['smtp_secure'] = 'ssl';
$data['smtp_auth'] = true;
}
$data['smtp_host'] = trim($data['smtp_host']);
/* specific case to identify common action to different rules there some that doesnt show in the interface, yet we use them.*/
foreach ($data as $key => $value) {
$fs = 'bounce_rule_';
if (strpos($key, $fs) !== false) {
if (strpos($key, '_forwardto') === false) {
$indexrule = str_replace($fs, '', $key);
$helpRules =& WYSIJA::get('rules', 'helper', false, 'wysija-newsletters', false);
$rules = $helpRules->getRules();
foreach ($rules as $keyy => $vals) {
if (isset($vals['behave'])) {
$ruleMain = $helpRules->getRules($vals['behave']);
$data[$fs . $vals['key']] = $value;
}
}
}
}
}
if (!isset($data['emails_notified_when_unsub'])) {
$data['emails_notified_when_unsub'] = false;
}
}
foreach ($data as $key => $value) {
/*verify that the confirm email body contains an activation link if it doesn't add i at the end of the email*/
if ($key == 'confirm_email_body' && strpos($value, '[activation_link]') === false) {
/*the activation link was not found*/
$value .= "\n" . '[activation_link]Click here to confirm your subscription.[/activation_link]';
}
if ($key == 'dkim_pubk') {
$value = str_replace(array('-----BEGIN PUBLIC KEY-----', '-----END PUBLIC KEY-----', "\n"), '', $value);
}
if ($key == 'manage_subscriptions_lists') {
$mList =& WYSIJA::get('list', 'model');
$mList->update(array('is_public' => 0), array('is_public' => 1));
$mList->reset();
$mList->update(array('is_public' => 1), array('list_id' => $value));
unset($this->values[$key]);
}
if (is_string($value)) {
$value = $value;
}
/* we save it only if it is different than the default no need to overload the db*/
if (!isset($this->defaults[$key]) || isset($this->defaults[$key]) && $value != $this->defaults[$key]) {
$this->values[$key] = $value;
} else {
unset($this->values[$key]);
}
}
/* save the confirmation email in the email table */
if (isset($data['confirm_email_title']) && isset($data['confirm_email_body'])) {
$mailModel =& WYSIJA::get('email', 'model', false, 'wysija-newsletters', false);
$mailModel->update(array('from_name' => $data['from_name'], 'from_email' => $data['from_email'], 'replyto_name' => $data['replyto_name'], 'replyto_email' => $data['replyto_email'], 'subject' => $data['confirm_email_title'], 'body' => $data['confirm_email_body']), array('email_id' => $this->values['confirm_email_id']));
}
unset($this->values['confirm_email_title']);
unset($this->values['confirm_email_body']);
}
update_option($this->name_option, base64_encode(serialize($this->values)));
if ($savedThroughInterface) {
if ($bouncing_freq_has_changed) {
wp_clear_scheduled_hook('wysija_cron_bounce');
WYSIJA::set_cron_schedule('bounce');
}
if ($sending_freq_has_changed) {
wp_clear_scheduled_hook('wysija_cron_queue');
WYSIJA::set_cron_schedule('queue');
}
$this->notice(__('Your Wysija settings have been updated!', WYSIJA));
}
}
示例8: get_cron_schedule
public static function get_cron_schedule($schedule = 'queue')
{
static $cron_schedules;
if (!empty($cron_schedules)) {
if ($schedule == 'all') {
return $cron_schedules;
}
if (isset($cron_schedules[$schedule])) {
return $cron_schedules[$schedule];
} else {
WYSIJA::set_cron_schedule($schedule);
return false;
}
} else {
$cron_schedules = get_option('wysija_schedules', array());
if (!empty($cron_schedules)) {
if (isset($cron_schedules[$schedule])) {
return $cron_schedules[$schedule];
} else {
return false;
}
} else {
WYSIJA::set_cron_schedule();
return false;
}
}
return false;
}