Handler.php
2 weeks ago
Post_Thumbnail_Setter.php
2 weeks ago
Queue.php
2 weeks ago
Tester.php
2 weeks ago
Tester.php
97 lines
| 1 | <?php |
| 2 | /** |
| 3 | * An async process implementation meant to test if the environment is compatible with it. |
| 4 | * |
| 5 | * @since 4.7.23 |
| 6 | */ |
| 7 | |
| 8 | class Tribe__Process__Tester extends Tribe__Process__Handler { |
| 9 | |
| 10 | /** |
| 11 | * The name of the transient this class will set in its async task. |
| 12 | * |
| 13 | * @var |
| 14 | */ |
| 15 | const TRANSIENT_NAME = 'tribe_supports_async_process'; |
| 16 | |
| 17 | /** |
| 18 | * Handles the process immediately, not in an async manner. |
| 19 | * |
| 20 | * @since 4.7.12 |
| 21 | * |
| 22 | * @param array|null $data_source If not provided the method will read the handler data from the |
| 23 | * request array. |
| 24 | * |
| 25 | * @return mixed |
| 26 | */ |
| 27 | public function sync_handle( array $data_source = null ) { |
| 28 | /* |
| 29 | * The purpose of this class is exactly to make sure async processing works |
| 30 | * so it will do nothing if running in synchronous mode. |
| 31 | */ |
| 32 | return null; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Call the dispatch method, in its vanilla form, as the base class would. |
| 37 | * |
| 38 | * Since the purpose of this class is to test for async process support |
| 39 | * we do not want any option or env var to make this work in any other |
| 40 | * way but the async one. |
| 41 | * |
| 42 | * @since 4.7.23 |
| 43 | * |
| 44 | * @return mixed |
| 45 | */ |
| 46 | public function dispatch() { |
| 47 | $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); |
| 48 | $args = $this->get_post_args(); |
| 49 | |
| 50 | return wp_remote_post( esc_url_raw( $url ), $args ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * An override of the method implemented by the base Tribe Handler |
| 55 | * class to make sure the processing is done in async mode. |
| 56 | * |
| 57 | * This is the same code as the base WP_Background_Process class. |
| 58 | * |
| 59 | * @since 4.7.23 |
| 60 | * |
| 61 | * @param null|array $data_source An optional data source. |
| 62 | */ |
| 63 | public function maybe_handle( $data_source = null ) { |
| 64 | // Don't lock up other requests while processing |
| 65 | session_write_close(); |
| 66 | |
| 67 | check_ajax_referer( $this->identifier, 'nonce' ); |
| 68 | |
| 69 | $this->handle(); |
| 70 | |
| 71 | wp_die(); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * The task this class will perform is just setting a transient. |
| 76 | * The transient existence will be used as a canary to detect if |
| 77 | * background processing is supported. |
| 78 | * |
| 79 | * @since 4.7.23 |
| 80 | * |
| 81 | * @param array|null $data_source Unused. |
| 82 | */ |
| 83 | protected function handle( array $data_source = null ) { |
| 84 | set_transient( self::TRANSIENT_NAME, 1, HOUR_IN_SECONDS ); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Returns this handler action identifier. |
| 89 | * |
| 90 | * @since 4.7.23 |
| 91 | * |
| 92 | * @return string This handler action identifier. |
| 93 | */ |
| 94 | public static function action() { |
| 95 | return 'async_process_support_test'; |
| 96 | } |
| 97 | } |