esc_html__('Number of items per page', 'simple-tags'), 'default' => 20, 'option' => 'st_autoterms_schedule_logs_per_page' ]; $this->logs_table = new SimpleTags_Schedule_Logs(); add_screen_option($option, $args); } public function save_autoterms_schedule_settings() { if( !empty($_POST['taxopress_autoterm_schedule_test_run']) && !empty($_POST['_nonce']) && wp_verify_nonce(sanitize_text_field($_POST['_nonce']), 'taxopress_autoterm_schedule_nonce') && current_user_can('simple_tags') ) { $autoterms_schedule = taxopress_get_autoterms_schedule_data(); $cron_schedule = isset($autoterms_schedule['cron_schedule']) ? $autoterms_schedule['cron_schedule'] : 'disable'; if ($cron_schedule === 'disable') { add_action('admin_notices', function () { echo taxopress_admin_notices_helper( esc_html__('Schedule is disabled. Please enable a schedule frequency to run a test.', 'simple-tags'), false ); }); return; } $hook_name = 'taxopress_cron_autoterms_' . $cron_schedule; wp_schedule_single_event(time(), $hook_name); spawn_cron(); add_action('admin_notices', function () use ($hook_name) { echo taxopress_admin_notices_helper( sprintf( esc_html__('Scheduled the cron event %s to run now. The original event will not be affected.', 'simple-tags'), '' . esc_html($hook_name) . '' ), true ); }); return; } if( !empty($_POST['taxopress_autoterm_schedule_submit']) && !empty($_POST['_nonce']) && wp_verify_nonce(sanitize_text_field($_POST['_nonce']), 'taxopress_autoterm_schedule_nonce') && current_user_can('simple_tags') ) { $auto_term_ids = !empty($_POST['taxopress_autoterm_schedule']['autoterm_id']) ? array_map('intval', (array)$_POST['taxopress_autoterm_schedule']['autoterm_id']) : []; $cron_schedule = !empty($_POST['taxopress_autoterm_schedule']['cron_schedule']) ? taxopress_sanitize_text_field($_POST['taxopress_autoterm_schedule']['cron_schedule']) : 'disable'; $schedule_terms_batches = !empty($_POST['taxopress_autoterm_schedule']['schedule_terms_batches']) ? (int)$_POST['taxopress_autoterm_schedule']['schedule_terms_batches'] : ''; $schedule_terms_sleep = !empty($_POST['taxopress_autoterm_schedule']['schedule_terms_sleep']) ? (int)$_POST['taxopress_autoterm_schedule']['schedule_terms_sleep'] : ''; $schedule_terms_limit_days = !empty($_POST['taxopress_autoterm_schedule']['schedule_terms_limit_days']) ? taxopress_sanitize_text_field($_POST['taxopress_autoterm_schedule']['schedule_terms_limit_days']) : ''; $autoterm_schedule_exclude = !empty($_POST['taxopress_autoterm_schedule']['autoterm_schedule_exclude']) ? (int)$_POST['taxopress_autoterm_schedule']['autoterm_schedule_exclude'] : ''; $response_message = esc_html__('An error occured.', 'simple-tags'); $response_sucess = false; if (empty($schedule_terms_batches)) { $response_message = esc_html__('Limit per batches is required.', 'simple-tags'); } elseif (empty($schedule_terms_sleep)) { $response_message = esc_html__('Batches wait time is required.', 'simple-tags'); } else { $auto_term_schedule_settings = [ 'autoterm_id' => $auto_term_ids, 'cron_schedule' => $cron_schedule, 'schedule_terms_batches' => $schedule_terms_batches, 'schedule_terms_sleep' => $schedule_terms_sleep, 'schedule_terms_limit_days' => $schedule_terms_limit_days, 'autoterm_schedule_exclude' => $autoterm_schedule_exclude, ]; update_option('taxopress_autoterms_schedule', $auto_term_schedule_settings); wp_clear_scheduled_hook('taxopress_cron_autoterms_weekly'); do_action('taxopress_clear_schedule_cron_hooks'); if ($cron_schedule == 'weekly') { wp_schedule_event(time(), 'weekly', 'taxopress_cron_autoterms_weekly'); } do_action('taxopress_schedule_cron_events', $cron_schedule); $autoterm_data = taxopress_get_autoterm_data(); $autoterm_data_selected = []; if (!empty($auto_term_ids)) { foreach ($auto_term_ids as $term_id) { if (isset($autoterm_data[$term_id])) { $autoterm_data_selected[$term_id] = $autoterm_data[$term_id]; } } } $autoterm_data = $autoterm_data_selected; $schedule_enabled = false; foreach ($autoterm_data_selected as $term_data) { if (!empty($term_data['autoterm_for_schedule'])) { $schedule_enabled = true; break; } } if (!$schedule_enabled) { $response_message = esc_html__('Schedule is not enabled for selected Auto Terms.', 'simple-tags'); $response_sucess = false; } else { $response_message = esc_html__('Settings updated successfully.', 'simple-tags'); $response_sucess = true; } } add_action('admin_notices', function () use($response_message, $response_sucess) { echo taxopress_admin_notices_helper($response_message, $response_sucess); }); } } public function page_manage_autoterms_schedule() { if (!isset($_GET['order'])) { $_GET['order'] = 'name-asc'; } settings_errors(__CLASS__); ?>

'', 'text' => __('Select an option...', 'simple-tags') ] ]; else : $auto_term_opionts = []; foreach ($autoterm_data as $autoterm_settings) { $current_option = []; $current_option['attr'] = $autoterm_settings['ID']; $current_option['text'] = $autoterm_settings['title']; if (in_array($autoterm_settings['ID'], $selected_autoterm)) { $current_option['default'] = 'true'; } $auto_term_opionts[] = $current_option; } endif; $select = []; $select['options'] = $auto_term_opionts; $select['selected'] = ''; echo $ui->get_select_checkbox_input_main([ 'namearray' => 'taxopress_autoterm_schedule', 'name' => 'autoterm_id', 'class' => 'taxopress-multi-select2', 'labeltext' => esc_html__('Auto Terms setting', 'simple-tags'), 'aftertext' => esc_html__('Select Auto Terms settings to use when running the "Schedule" feature.', 'simple-tags') . ' ', 'selections' => $select, 'multiple' => true, ]); $cron_options = [ 'disable' => __('Do not run on a schedule', 'simple-tags'), 'weekly' => __('Weekly', 'simple-tags'), ]; ?> [ [ 'attr' => '0', 'text' => esc_attr__('False', 'simple-tags'), 'default' => 'true', ], [ 'attr' => '1', 'text' => esc_attr__('True', 'simple-tags'), ], ], ]; $selected = (isset($autoterms_schedule) && isset($autoterms_schedule['autoterm_schedule_exclude'])) ? taxopress_disp_boolean($autoterms_schedule['autoterm_schedule_exclude']) : ''; $select['selected'] = !empty($selected) ? $autoterms_schedule['autoterm_schedule_exclude'] : ''; echo $ui->get_select_checkbox_input([ 'namearray' => 'taxopress_autoterm_schedule', 'name' => 'autoterm_schedule_exclude', 'class' => '', 'labeltext' => esc_html__('Exclude previously analyzed content', 'simple-tags'), 'aftertext' => esc_html__('This enables you to skip posts that have already been analyzed by the Schedule feature.', 'simple-tags'), 'selections' => $select, ]); echo $ui->get_number_input([ 'namearray' => 'taxopress_autoterm_schedule', 'name' => 'schedule_terms_batches', 'textvalue' => isset($autoterms_schedule['schedule_terms_batches']) ? esc_attr($autoterms_schedule['schedule_terms_batches']) : '20', 'labeltext' => esc_html__( 'Limit per batches', 'simple-tags' ), 'helptext' => esc_html__('This enables your scheduled Auto Terms to run in batches. If you have a lot of content, set this to a lower number to avoid timeouts.', 'simple-tags'), 'min' => '1', 'required' => true, ]); echo $ui->get_number_input([ 'namearray' => 'taxopress_autoterm_schedule', 'name' => 'schedule_terms_sleep', 'textvalue' => isset($autoterms_schedule['schedule_terms_sleep']) ? esc_attr($autoterms_schedule['schedule_terms_sleep']) : '10', 'labeltext' => esc_html__('Batches wait time', 'simple-tags'), 'helptext' => esc_html__('This is the wait time (in seconds) between processing batches of Auto Terms. If you have a lot of existing content, set this to a higher number to avoid timeouts.', 'simple-tags'), 'min' => '0', 'required' => true, ]); $select = [ 'options' => [ [ 'attr' => '1', 'text' => esc_attr__('24 hours ago', 'simple-tags') ], [ 'attr' => '7', 'text' => esc_attr__('7 days ago', 'simple-tags') ], [ 'attr' => '14', 'text' => esc_attr__('2 weeks ago', 'simple-tags') ], [ 'attr' => '30', 'text' => esc_attr__('1 month ago', 'simple-tags'), 'default' => 'true' ], [ 'attr' => '180', 'text' => esc_attr__('6 months ago', 'simple-tags') ], [ 'attr' => '365', 'text' => esc_attr__('1 year ago', 'simple-tags') ], [ 'attr' => '0', 'text' => esc_attr__('No limit', 'simple-tags') ], ], ]; if (isset($autoterms_schedule) && is_array($autoterms_schedule)) { $select = [ 'options' => [ [ 'attr' => '1', 'text' => esc_attr__('24 hours ago', 'simple-tags') ], [ 'attr' => '7', 'text' => esc_attr__('7 days ago', 'simple-tags') ], [ 'attr' => '14', 'text' => esc_attr__('2 weeks ago', 'simple-tags') ], [ 'attr' => '30', 'text' => esc_attr__('1 month ago', 'simple-tags'), ], [ 'attr' => '180', 'text' => esc_attr__('6 months ago', 'simple-tags') ], [ 'attr' => '365', 'text' => esc_attr__('1 year ago', 'simple-tags') ], [ 'attr' => '0', 'text' => esc_attr__('No limit', 'simple-tags'), 'default' => 'true' ], ], ]; } $selected = (isset($autoterms_schedule) && isset($autoterms_schedule['schedule_terms_limit_days'])) ? taxopress_disp_boolean($autoterms_schedule['schedule_terms_limit_days']) : ''; $select['selected'] = !empty($selected) ? $autoterms_schedule['schedule_terms_limit_days'] : ''; echo $ui->get_select_number_select([ 'namearray' => 'taxopress_autoterm_schedule', 'name' => 'schedule_terms_limit_days', 'labeltext' => esc_html__( 'Limit Auto Terms, based on published date', 'simple-tags' ), 'aftertext' => esc_html__('This setting can limit your scheduled Auto Terms query to only recent content. We recommend using this feature to avoid timeouts on large sites.', 'simple-tags'), 'selections' => $select, ]); ?>

$label) { $checked_status = ($cron_schedule === $option) ? 'checked' : ''; ?>