Title: Custom Request
Last modified: September 10, 2022

---

# Custom Request

 *  Resolved [ct1601](https://wordpress.org/support/users/ct1601/)
 * (@ct1601)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/custom-request-4/)
 * Hi, great Plugin!
 * But im facing an issue and thought maybe you could help me out.
 * I am using a Plugin in WordPress which has a Button integrated. I want to schedule
   the function of the button into a Cron task, which will execute the function 
   of the button automatically so i dont have to click that button.
 * But I cant find the right snippet of php code to enter. (Or create a hook? If
   so, how?)
 * The code I have of the function i want to automate:
 *     ```
       namespace SabaiApps\Directories\Component\System\Tool;
   
           class RunCronTool extends AbstractTool
           {
               protected function _systemToolInfo()
               {
                   return [
                       'label' => __('Run cron', 'directories'),
                       'description' => __('Use this tool to manually run cron.', 'directories'),
                       'weight' => 15,
                   ];
               }
   
               public function systemToolRunTask($task, array $settings, $iteration, $total, array &$storage, array &$logs)
               {
                   $this->_application->callHelper('System_Cron', [&$logs, true]);
   
                   return 1;
               }
           }
       ```
   
 * and
 *     ```
       namespace SabaiApps\Directories\Component\System\Helper;
   
       use SabaiApps\Directories\Application;
   
       class CronHelper
       {
           public function help(Application $application, array &$logs = null, $force)
           {
               // Init progress
               if (!isset($logs)) {
                   $logs = ['success' => [], 'error' => [], 'warning' => [], 'info' => []];
                   $log = true;
               }
               $logs['info'][] = __('Running cron...', 'directories');
               // Get timestamp of last cron
               $last_run = $application->getPlatform()->getOption('system_cron_last');
               if (!is_array($last_run)) {
                   $last_run = ['' => time()];
               } else {
                   $logs['info'][] = sprintf(
                       __('Cron was last run at %s', 'directories'),
                       $application->System_Date_datetime($last_run[''])
                   );
               }
               // Invoke cron
               $application->Action('system_cron', [&$logs, &$last_run, $force]);
               // Save timestamp
               $application->getPlatform()->setOption('system_cron_last', $last_run);
               // Log
               if (!empty($log)) {
                   foreach (array_keys($logs) as $level) {
                       foreach ((array)$logs[$level] as $log) {
                           switch ($level) {
                               case 'success':
                                   $application->logDebug(strip_tags($log));
                                   break;
                               case 'info':
                               case 'notice':
                                   $application->logNotice(strip_tags($log));
                                   break;
                               case 'warning':
                                   $application->logWarning(strip_tags($log));
                                   break;
                               case 'error':
                                   $application->logError(strip_tags($log));
                                   break;
                               default:
                           }
                       }
                   }
               }
           }
       }
       ```
   
 * Would be really nice if you could help me out with that.
 * If not, all good. I know that its none of your business
 * But still
 * Many thanks
 * EDIT:
 * Additional Info: The button force runs a hidden Cron Job created by the Plugin
   itself. (Also not visible through your Plugin.) So what im trying to do is:
 * Create a Cron Task of the function of the ‘Force run Cron’ button.
    -  This topic was modified 3 years, 9 months ago by [ct1601](https://wordpress.org/support/users/ct1601/).

Viewing 1 replies (of 1 total)

 *  Plugin Author [John Blackbourn](https://wordpress.org/support/users/johnbillion/)
 * (@johnbillion)
 * WordPress Core Developer
 * [3 years, 9 months ago](https://wordpress.org/support/topic/custom-request-4/#post-15997990)
 * There isn’t really enough information for me to go on here, sorry. Your best 
   bet is to contact the author of the code in question.
 * Best of luck!

Viewing 1 replies (of 1 total)

The topic ‘Custom Request’ is closed to new replies.

 * ![](https://ps.w.org/wp-crontrol/assets/icon.svg?rev=3539529)
 * [WP Crontrol](https://wordpress.org/plugins/wp-crontrol/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-crontrol/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-crontrol/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-crontrol/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-crontrol/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-crontrol/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [John Blackbourn](https://wordpress.org/support/users/johnbillion/)
 * Last activity: [3 years, 9 months ago](https://wordpress.org/support/topic/custom-request-4/#post-15997990)
 * Status: resolved