Changeset 2893514
- Timestamp:
- 04/04/2023 11:09:41 AM (3 years ago)
- Location:
- jinx-fast-cache/trunk
- Files:
-
- 2 edited
-
index.php (modified) (1 diff)
-
src/Front.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
jinx-fast-cache/trunk/index.php
r2893345 r2893514 5 5 * Plugin URI: https://wordpress.org/plugins/jixn-fast-cache/ 6 6 * Description: Blazing fast full page cache. 7 * Version: 0.7. 07 * Version: 0.7.1 8 8 * Author: SquareFlower Websolutions (Lukas Rydygel) <hallo@squareflower.de> 9 9 * Author URI: http://squareflower.de -
jinx-fast-cache/trunk/src/Front.php
r2893345 r2893514 67 67 } 68 68 69 }, PHP_INT_MIN); 70 71 add_action('wp_ajax_jinx-fast-cache-inject', function() { 72 73 $path = strip_tags(sanitize_textarea_field($_GET['path'])); 74 $id = intval($_GET['id'])-1; 75 76 self::callInject($path, $id); 77 78 }); 69 }, PHP_INT_MIN); 70 71 add_action('wp_ajax_jinx-fast-cache-inject', [__CLASS__, 'ajaxInject']); 72 add_action('wp_ajax_nopriv_jinx-fast-cache-inject', [__CLASS__, 'ajaxInject']); 79 73 80 74 add_action('jinx_fast_cache_inject', function($function, array $args = [], $placeholder = null) { … … 120 114 /** 121 115 * Call an injection 122 * 123 * @param string $path 124 * @param int $id 125 */ 126 protected static function callInject(string $path, int $id) 127 { 128 129 $files = Helper::getCacheFiles($path); 130 $inject = json_decode(file_get_contents($files['json']), true); 131 132 if (isset($inject[$id])) { 133 134 $function = array_shift($inject[$id]); 135 136 // check if function is a static method 137 if (is_string($function) && strpos($function, '::') !== false) { 138 $function = explode('::', $function); 139 } 140 141 // if function is an array, use method_exists 142 if (is_array($function)) { 143 144 list($object, $method) = $function; 145 $exists = method_exists($object, $method); 146 147 // otherwise use function_exists 148 } else { 149 $exists = function_exists($function); 150 } 151 152 if ($exists) { 153 154 $return = call_user_func_array($function, $inject[$id]); 155 156 if (!empty($return)) { 157 echo $return; 158 } 159 160 } 161 162 } 116 */ 117 public static function ajaxInject() 118 { 119 120 if (isset($_GET['path']) && isset($_GET['id'])) { 121 122 $path = strip_tags(sanitize_textarea_field($_GET['path'])); 123 $id = intval($_GET['id'])-1; 124 125 $files = Helper::getCacheFiles($path); 126 $inject = json_decode(file_get_contents($files['json']), true); 127 128 if (isset($inject[$id])) { 129 130 $function = array_shift($inject[$id]); 131 132 // check if function is a static method 133 if (is_string($function) && strpos($function, '::') !== false) { 134 $function = explode('::', $function); 135 } 136 137 // if function is an array, use method_exists 138 if (is_array($function)) { 139 140 list($object, $method) = $function; 141 $exists = method_exists($object, $method); 142 143 // otherwise use function_exists 144 } else { 145 $exists = function_exists($function); 146 } 147 148 if ($exists) { 149 150 $return = call_user_func_array($function, $inject[$id]); 151 152 if (!empty($return)) { 153 echo $return; 154 } 155 156 } 157 158 } 159 160 } 163 161 164 162 wp_die();
Note: See TracChangeset
for help on using the changeset viewer.