{"id":15543623,"url":"https://github.com/michaeluno/wp_shadow","last_synced_at":"2025-04-09T06:27:12.251Z","repository":{"id":14550162,"uuid":"17265522","full_name":"michaeluno/WP_Shadow","owner":"michaeluno","description":"WP Cron alternative","archived":false,"fork":false,"pushed_at":"2014-03-02T18:14:53.000Z","size":152,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-03T12:31:22.670Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaeluno.png","metadata":{"files":{"readme":"README.md","changelog":"change_log.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-27T21:36:19.000Z","updated_at":"2014-03-02T18:14:52.000Z","dependencies_parsed_at":"2022-08-27T00:00:40.758Z","dependency_job_id":null,"html_url":"https://github.com/michaeluno/WP_Shadow","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeluno%2FWP_Shadow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeluno%2FWP_Shadow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeluno%2FWP_Shadow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeluno%2FWP_Shadow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaeluno","download_url":"https://codeload.github.com/michaeluno/WP_Shadow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247989654,"owners_count":21029348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T12:27:48.308Z","updated_at":"2025-04-09T06:27:12.228Z","avatar_url":"https://github.com/michaeluno.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"WP Shadow\n=========\n\nThis is a PHP class for WordPress that loads the site in the background and performs registered WP Cron tasks.\n\n## Scenario ##\nLet's say you have published a plugin that retrieves data from external servers. Since fetching data from external servers takes some time and is slow to process, you used WP Cron to renew the data in the background and it worked well.\n\nA while later, a user came up and said, \"It doesn't update the data on my server! Here is the login info. FIX IT PLEAESE!!\" You investigated the problem and figured out that the problem lies in the fact that the host of the server that the user used had suspended `wp-cron.php`.\n\nYou told the user \"Your host seems to have a restriction on WP Cron. So talk to your host.\" The user replied, \"I have no idea what you are talking about. Please fix the problem or do you want me to write a bad review on your plugin? I'm going crazy!\"\n\nSo here is the solution.\n\n## Basic Usage ##\n\n1. Register a task normally with WP Cron functions such as [wp_schedule_single_event()](http://codex.wordpress.org/Function_Reference/wp_schedule_single_event).\n2. Register the action hook with the WP_Shadow class.\n3. Call the background process with the `see()` static method.\n\nTo register an action hook(s) \n```php\nnew WP_Shadow( array( 'my_action_hook_a', 'my_action_hook_b' ) );\n```\n\nTo call a background process.\n```php\nWP_Shadow::see();\n```\n\n## Demo ##\n```php\n// Load the class\ninclude_once( dirname( __FILE__ ) . '/class/WP_Shadow.php' );\t\nnew WP_Shadow_Demo;\n\nclass WP_Shadow_Demo {\n\t\n\tpublic function __construct() {\n\t\t\n\t\tif ( isset( $_GET['doing_wp_cron' ] ) ) {\n\t\t\treturn;\t// say WP Cron is disabled.\n\t\t}\n\t\t\t\n\t\t// Assume the doTask() method is the one that you need to run in the background.\n\t\tadd_action( 'do_wp_shadow_demo', array( $this, 'doTask' ) );\n\t\t\n\t\t$this-\u003escheduleCronTask();\n\t\t\n\t\tnew WP_Shadow( 'do_wp_shadow_demo' );\n\t\t\n\t}\n\t\t\n\tprivate function scheduleCronTask() {\n\n\t\t$aArgs = array( 'a', 'b', 'c' );\n\t\n\t\tif ( wp_next_scheduled( 'do_wp_shadow_demo', array( $aArgs ) ) ) return; \n\t\twp_schedule_single_event( \n\t\t\ttime(), \t// passing the current time means to do it as soon as possible but WP Cron requires another page load to perform that.\n\t\t\t'do_wp_shadow_demo', \t// the action hook name\n\t\t\tarray( $aArgs )\t// the data to be passed \n\t\t);\t\t\t\t\n\t\tWP_Shadow::see();\n\t\t\n\t}\n\t\n\t/**\n\t * Assuming this is the task that should be performed in the background, this creates a log file in the script directory.\n\t */\n\tpublic function doTask( $aArgs ) {\n\t\t\n\t\tstatic $_iPageLoadID;\n\t\t$_iPageLoadID = $_iPageLoadID ? $_iPageLoadID : uniqid();\t\t\n\t\t\n\t\t$oCallerInfo = debug_backtrace();\n\t\t$sCallerFunction = $oCallerInfo[ 1 ]['function'];\n\t\t$sCallerClasss = $oCallerInfo[ 1 ]['class'];\n\t\tfile_put_contents( \n\t\t\t$sFilePath ? $sFilePath : dirname( __FILE__ ) . '/log.txt', \n\t\t\tdate( \"Y/m/d H:i:s\", current_time( 'timestamp' ) ) . ' ' . \"{$_iPageLoadID} {$sCallerClasss}::{$sCallerFunction} \" . $this-\u003e_getCurrentURL() . PHP_EOL\n\t\t\t. print_r( $aArgs, true ) . PHP_EOL . PHP_EOL,\n\t\t\tFILE_APPEND \n\t\t);\t\t\n\t\t\n\t}\n\t\n\t\t/**\n\t\t * Retrieves the currently loaded page url.\n\t\t */\n\t\tprotected function _getCurrentURL() {\n\t\t\t$sSSL = ( !empty( $_SERVER['HTTPS'] ) \u0026\u0026 $_SERVER['HTTPS'] == 'on' ) ? true:false;\n\t\t\t$sServerProtocol = strtolower( $_SERVER['SERVER_PROTOCOL'] );\n\t\t\t$sProtocol = substr( $sServerProtocol, 0, strpos( $sServerProtocol, '/' ) ) . ( ( $sSSL ) ? 's' : '' );\n\t\t\t$sPort = $_SERVER['SERVER_PORT'];\n\t\t\t$sPort = ( ( !$sSSL \u0026\u0026 $sPort=='80' ) || ( $sSSL \u0026\u0026 $sPort=='443' ) ) ? '' : ':' . $sPort;\n\t\t\t$sHost = isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];\n\t\t\treturn $sProtocol . '://' . $sHost . $sPort . $_SERVER['REQUEST_URI'];\n\t\t}\n\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeluno%2Fwp_shadow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaeluno%2Fwp_shadow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeluno%2Fwp_shadow/lists"}