diff --git a/src/App/App.php b/src/App/App.php index 9771080..09d0855 100644 --- a/src/App/App.php +++ b/src/App/App.php @@ -15,7 +15,6 @@ use Bond\Services\View; use Bond\Utils\Cast; use Bond\Utils\Link; -use Bond\Settings\Wp; use League\Container\Container; use League\Container\ReflectionContainer; use Mobile_Detect; @@ -218,7 +217,7 @@ protected function bootAppFolder() } // admin too - if (Wp::isAdmin() && method_exists($classname, 'bootAdmin')) { + if (app()->isAdmin() && method_exists($classname, 'bootAdmin')) { call_user_func($classname . '::bootAdmin'); } } @@ -239,6 +238,21 @@ public function url(): string return $this->config()->app->url ??= \untrailingslashit(c('WP_HOME') ?: \get_site_url()); } + public function isFrontEnd(): bool + { + return !\is_admin() && c('WP_USE_THEMES') && !$this->isCli(); + } + + public function isAdmin(): bool + { + return \is_admin() && \is_user_logged_in(); + } + + public function isCli(): bool + { + return (bool) c('WP_CLI'); + } + public function isProduction(): bool { return $this->env === 'production'; @@ -278,6 +292,8 @@ public function isDesktop(): bool return $this->is_desktop; } + + public function basePath(): string { return $this->base_path; diff --git a/src/App/Config.php b/src/App/Config.php index 3faff9b..01345ef 100644 --- a/src/App/Config.php +++ b/src/App/Config.php @@ -130,10 +130,6 @@ protected function appSettings() protected function cacheSettings() { - if (Wp::isCli()) { - $this->cache->enabled = false; - } - if ($this->cache->class) { $this->container->addShared('cache', $this->cache->class); } diff --git a/src/Services/AdminColumns.php b/src/Services/AdminColumns.php index d759b1a..e022039 100644 --- a/src/Services/AdminColumns.php +++ b/src/Services/AdminColumns.php @@ -4,7 +4,6 @@ use Bond\Post; use Bond\Settings\Language; -use Bond\Settings\Wp; use Bond\Term; use Bond\User; use Bond\Utils\Cast; @@ -28,7 +27,7 @@ public function config(?bool $enabled = null) public function enable() { - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -146,7 +145,7 @@ public function addHandler( string $css = null ) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } $this->columns[$name] = compact('handler', 'width', 'css'); @@ -186,7 +185,7 @@ protected function handleColumn(string $name, $item) public function setPostTypeColumns(string $post_type, array $columns) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -207,7 +206,7 @@ function ($defaults) use ($columns) { public function setTaxonomyColumns(string $taxonomy, array $columns) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } \add_filter( @@ -221,7 +220,7 @@ function ($defaults) use ($columns) { public function setUsersColumns(array $columns) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } diff --git a/src/Services/Cache/AbstractCache.php b/src/Services/Cache/AbstractCache.php index 9da59c7..102879a 100644 --- a/src/Services/Cache/AbstractCache.php +++ b/src/Services/Cache/AbstractCache.php @@ -2,9 +2,11 @@ namespace Bond\Services\Cache; -use Bond\Settings\Wp; use Bond\Utils\Str; +// TODO implement Service interface too and update the enabled and config methods +// clean Config.php afterwards + abstract class AbstractCache implements CacheInterface { protected int $ttl = 0; @@ -13,7 +15,7 @@ abstract class AbstractCache implements CacheInterface public function __construct() { // disable initially if WP CLI - if (Wp::isCli()) { + if (app()->isCli()) { $this->enabled(false); } diff --git a/src/Services/Meta.php b/src/Services/Meta.php index 3f6222d..f68e8b5 100644 --- a/src/Services/Meta.php +++ b/src/Services/Meta.php @@ -2,7 +2,6 @@ namespace Bond\Services; -use Bond\Settings\Wp; use Bond\Settings\Language; use Bond\Utils\Cast; use Bond\Utils\Image; @@ -79,7 +78,7 @@ public function enable() { // do not enable when it is on WP admin // nor when programatically loading WP - if (Wp::isFrontEnd()) { + if (app()->isFrontEnd()) { \add_action('wp', [$this, 'setDefaults'], 2); \add_action('wp_head', [$this, 'printAllTags'], 99); } diff --git a/src/Services/Rss.php b/src/Services/Rss.php index a120db9..8a7d714 100644 --- a/src/Services/Rss.php +++ b/src/Services/Rss.php @@ -5,7 +5,6 @@ use Bond\Services\View; use Bond\Settings\Language; use Bond\Settings\Rewrite; -use Bond\Settings\Wp; use Bond\Utils\Link; use Bond\Utils\Query; @@ -80,7 +79,7 @@ public function disableWpRss() \remove_action('wp_head', 'feed_links', 2); // rewrite rules - if (Wp::isAdmin()) { + if (app()->isAdmin()) { \add_filter('rewrite_rules_array', function (array $rules) { foreach ($rules as $regex => $match) { diff --git a/src/Settings/Admin.php b/src/Settings/Admin.php index 2b446c7..9ffc739 100644 --- a/src/Settings/Admin.php +++ b/src/Settings/Admin.php @@ -10,7 +10,7 @@ class Admin public static function setEditorImageSizes(array $sizes) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -28,7 +28,7 @@ public static function setEditorImageSizes(array $sizes) public static function removeUpdateNag() { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -45,7 +45,7 @@ public static function removeUpdateNag() public static function addEditorCss() { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -83,7 +83,7 @@ public static function addLoginCss() public static function addColorScheme() { // don't even add the hook if not on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -103,7 +103,7 @@ public static function addColorScheme() public static function addAdminCss() { // don't even add the hook if not on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -157,13 +157,13 @@ public static function cleanupAdminBar() public static function hidePosts() { - if (Wp::isAdmin() || config('html.admin_bar') !== false) { + if (app()->isAdmin() || config('html.admin_bar') !== false) { \add_action('wp_before_admin_bar_render', function () { global $wp_admin_bar; $wp_admin_bar->remove_menu('new-post'); }); } - if (Wp::isAdmin()) { + if (app()->isAdmin()) { \add_action('admin_menu', function () { \remove_menu_page('edit.php'); }, 999); @@ -174,7 +174,7 @@ public static function hidePosts() public static function addFooterCredits() { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -186,7 +186,7 @@ public static function addFooterCredits() public static function removeWpVersion() { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -212,7 +212,7 @@ public static function setSideMenuParams(string $post_type, array $params) public static function replaceDashboard() { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -276,7 +276,7 @@ public static function removeAdministrationMenus() public static function hideTitle($post_types) { - if (empty($post_types) || !Wp::isAdmin()) { + if (empty($post_types) || !app()->isAdmin()) { return; } diff --git a/src/Settings/Api.php b/src/Settings/Api.php index a968c09..c4ac8e6 100644 --- a/src/Settings/Api.php +++ b/src/Settings/Api.php @@ -38,7 +38,7 @@ public static function disableHeader() public static function disableDefaultRoutes() { // do not disable if is on admin - if (Wp::isAdmin()) { + if (app()->isAdmin()) { return; } @@ -50,7 +50,7 @@ public static function disableDefaultRoutes() public static function disableRootRoute() { // does not disable if is on admin - if (Wp::isAdmin()) { + if (app()->isAdmin()) { return; } diff --git a/src/Settings/Rewrite.php b/src/Settings/Rewrite.php index d51367d..5ea3620 100644 --- a/src/Settings/Rewrite.php +++ b/src/Settings/Rewrite.php @@ -12,7 +12,7 @@ class Rewrite public static function reset() { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -61,7 +61,7 @@ public static function tag(string $name, bool $set_global = false) public static function pages() { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -108,7 +108,7 @@ public static function search( array $extra_params = [] ) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -160,7 +160,7 @@ public static function rss( bool $multilanguage = false ) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -214,7 +214,7 @@ public static function archive( array $extra_params = [] ) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -282,7 +282,7 @@ public static function single( array $extra_params = [] ) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -323,7 +323,7 @@ public static function rewrite( array $params = [] ) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } @@ -355,7 +355,7 @@ public static function page( array $extra_params = [] ) { // only needed on admin - if (!Wp::isAdmin()) { + if (!app()->isAdmin()) { return; } diff --git a/src/Settings/Wp.php b/src/Settings/Wp.php index 57be232..165792c 100644 --- a/src/Settings/Wp.php +++ b/src/Settings/Wp.php @@ -8,28 +8,12 @@ // Ideas for later: // Wp::disableComments, for now using plugin disable-comments -// TODO IDEA, migrate to App and remove wp.php config entirelly +// TODO IDEA, migrate everything to App and remove wp.php config entirelly // 'Wp' naming is not being autofilled by VS Code -// looks like the image may become a service +// looks like the image may become a service too, maybe Uploads or Media... class Wp { - public static function isFrontEnd(): bool - { - return !\is_admin() && c('WP_USE_THEMES') && !static::isCli(); - } - - public static function isAdmin(): bool - { - return \is_admin() && \is_user_logged_in(); - } - - public static function isCli(): bool - { - return (bool) c('WP_CLI'); - } - - // Images public static function sanitizeFilenames()