| 1 |
<?php |
| 2 |
|
| 3 |
use Kibo\PhastPlugins\PhastPress\CDN; |
| 4 |
use Kibo\PhastPlugins\PhastPress\Compat; |
| 5 |
|
| 6 |
if (!defined('PHASTPRESS_VERSION')) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
try { |
| 11 |
new PDO('sqlite::memory:'); |
| 12 |
} catch (\Throwable $e) { |
| 13 |
add_action('admin_notices', function () use ($e) { |
| 14 |
?> |
| 15 |
<div class="error notice"> |
| 16 |
<p><b>Sorry, PhastPress requires a PHP extension that is not installed.</b></p> |
| 17 |
<p> |
| 18 |
The PDO extension needs to be installed with the SQLite3 database driver available.<br> |
| 19 |
Currently we're getting this error: <em><?= esc_html($e->getMessage()); ?></em> |
| 20 |
</p> |
| 21 |
<p> |
| 22 |
Ask your hosting provider to install the <a href="https://www.php.net/manual/en/ref.pdo-sqlite.php" target="_blank" rel="noopener">PDO_SQLITE extension</a>, or downgrade to <a href="https://downloads.wordpress.org/plugin/phastpress.2.1.zip" target="_blank" rel="noopener">PhastPress 2.1</a>. |
| 23 |
</p> |
| 24 |
</div> |
| 25 |
<?php |
| 26 |
}); |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')) { |
| 31 |
define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true); |
| 32 |
} |
| 33 |
|
| 34 |
require_once __DIR__ . '/autoload.php'; |
| 35 |
|
| 36 |
add_action('plugins_loaded', function () { |
| 37 |
if (!get_option('phastpress_1.43')) { |
| 38 |
phastpress_get_plugin_sdk() |
| 39 |
->getPluginConfiguration() |
| 40 |
->update([ |
| 41 |
'img-optimization-tags' => false, |
| 42 |
'img-optimization-css' => false, |
| 43 |
]); |
| 44 |
update_option('phastpress_1.43', gmdate('Y-m-d\TH:i:s\Z')); |
| 45 |
} |
| 46 |
}); |
| 47 |
|
| 48 |
register_activation_hook(PHASTPRESS_PLUGIN_FILE, function () { |
| 49 |
update_option('phastpress_1.43', gmdate('Y-m-d\TH:i:s\Z')); |
| 50 |
}); |
| 51 |
|
| 52 |
add_action('wp_ajax_phastpress_ajax_dispatch', function () { |
| 53 |
wp_send_json( |
| 54 |
phastpress_get_plugin_sdk()->getAJAXRequestsDispatcher()->dispatch($_POST) |
| 55 |
); |
| 56 |
}); |
| 57 |
|
| 58 |
add_action('admin_footer', function () { |
| 59 |
echo phastpress_get_plugin_sdk()->getInstallNotice()->render(); |
| 60 |
}); |
| 61 |
|
| 62 |
add_filter('plugin_action_links_' . plugin_basename(PHASTPRESS_PLUGIN_FILE), function ($links) { |
| 63 |
$link = '<a href="' . admin_url('options-general.php?page=phast-press') . '">' |
| 64 |
. __('Settings', 'phastpress') . '</a>'; |
| 65 |
array_unshift($links, $link); |
| 66 |
return $links; |
| 67 |
}); |
| 68 |
|
| 69 |
add_action('plugins_loaded', function () { |
| 70 |
CDN::installHook(); |
| 71 |
Compat\Log::setup(); |
| 72 |
|
| 73 |
if ((new Compat\Ajax())->setup()) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
if (($priority = has_filter('init', 'wp_cache_late_loader')) !== false) { |
| 78 |
add_action('init', 'phastpress_deploy', $priority + 1); |
| 79 |
Compat\Log::add( |
| 80 |
'wp-super-cache', |
| 81 |
'deploying PhastPress via init hook to support WP Super Cache late init' |
| 82 |
); |
| 83 |
(new Compat\NextGenGallery())->setup($priority + 1); |
| 84 |
} elseif (class_exists(\LiteSpeed\Core::class) |
| 85 |
&& ($priority = (new Compat\LiteSpeedCache())->getHookPriority()) !== null |
| 86 |
) { |
| 87 |
add_action('after_setup_theme', 'phastpress_deploy', $priority + 1); |
| 88 |
Compat\Log::add( |
| 89 |
'litespeed-cache', |
| 90 |
'deploying PhastPress via after_setup_theme hook to support LiteSpeed Cache' |
| 91 |
); |
| 92 |
} else { |
| 93 |
phastpress_deploy(); |
| 94 |
} |
| 95 |
}); |
| 96 |
|
| 97 |
add_action('admin_print_scripts', function () { |
| 98 |
echo phastpress_get_plugin_sdk()->getAutoConfiguration()->renderScript(); |
| 99 |
}); |
| 100 |
|
| 101 |
add_action('admin_menu', function () { |
| 102 |
add_options_page( |
| 103 |
__('PhastPress', 'phastpress'), |
| 104 |
__('PhastPress', 'phastpress'), |
| 105 |
'manage_options', |
| 106 |
'phast-press', |
| 107 |
'phastpress_render_settings' |
| 108 |
); |
| 109 |
}); |
| 110 |
|
| 111 |
add_action('wp_head', function () { |
| 112 |
$style = 'font-family:helvetica,sans-serif'; |
| 113 |
phastpress_console_log( |
| 114 |
"%cOptimized with %cPhastPress%c %s\nhttps://wordpress.org/plugins/phastpress/", |
| 115 |
$style, |
| 116 |
$style . ';font-weight:bold', |
| 117 |
$style, |
| 118 |
PHASTPRESS_VERSION |
| 119 |
); |
| 120 |
}); |
| 121 |
|
| 122 |
function phastpress_console_log(...$args) { |
| 123 |
echo phastpress_script( |
| 124 |
sprintf('console.log(%s)', implode(',', array_map('json_encode', $args))), |
| 125 |
['data-phast-no-defer' => ''] |
| 126 |
); |
| 127 |
} |
| 128 |
|
| 129 |
function phastpress_render_settings() { |
| 130 |
echo sprintf( |
| 131 |
'<div class="wrap"> |
| 132 |
<h1 class="wp-heading-inline">%s</h1> |
| 133 |
%s |
| 134 |
</div> |
| 135 |
', |
| 136 |
__('PhastPress', 'phastpress'), |
| 137 |
phastpress_get_plugin_sdk()->getAdminPanel()->render() |
| 138 |
); |
| 139 |
} |
| 140 |
|
| 141 |
add_action('ai1wm_exclude_content_from_export', function ($filters) { |
| 142 |
if (!is_array($filters)) { |
| 143 |
return $filters; |
| 144 |
} |
| 145 |
foreach (phastpress_get_plugin_sdk()->getCacheRootManager()->getAllCacheRoots() as $dir) { |
| 146 |
$filters[] = $dir; |
| 147 |
} |
| 148 |
return $filters; |
| 149 |
}); |
| 150 |
|