| @@ -8,8 +8,9 @@ | ||
| 8 | 8 | |
| 9 | 9 | use Extendify\AdminPageRouter; |
| 10 | 10 | use Extendify\Assist\Admin as AssistAdmin; |
| 11 | 11 | use Extendify\Agent\Admin as AgentAdmin; |
| 12 | +use Extendify\ComingSoon\Frontend as ComingSoonFrontend; | |
| 12 | 13 | use Extendify\Config; |
| 13 | 14 | use Extendify\Draft\Admin as DraftAdmin; |
| 14 | 15 | use Extendify\HelpCenter\Admin as HelpCenterAdmin; |
| 15 | 16 | use Extendify\Insights; |
| @@ -16,21 +17,36 @@ | ||
| 16 | 17 | use Extendify\Launch\Admin as LaunchAdmin; |
| 17 | 18 | use Extendify\AutoLaunch\Admin as AutoLaunchAdmin; |
| 18 | 19 | use Extendify\Library\Admin as LibraryAdmin; |
| 19 | 20 | use Extendify\Library\Frontend as LibraryFrontend; |
| 21 | +use Extendify\Mcp\Server as McpServer; | |
| 22 | +use Extendify\Mcp\OAuth\Metadata as McpMetadata; | |
| 23 | +use Extendify\Mcp\OAuth\Authorize as McpAuthorize; | |
| 24 | +use Extendify\Mcp\OAuth\TokenEndpoint as McpTokenEndpoint; | |
| 25 | +use Extendify\Mcp\OAuth\RegistrationEndpoint as McpRegistrationEndpoint; | |
| 26 | +use Extendify\Mcp\Profile as McpProfile; | |
| 27 | +use Extendify\Mcp\Lifecycle as McpLifecycle; | |
| 28 | +use Extendify\Mcp\Jobs as McpJobs; | |
| 20 | 29 | use Extendify\Agent\Frontend as AgentFrontend; |
| 21 | 30 | use Extendify\QuickEdit\Frontend as QuickEditFrontend; |
| 22 | 31 | use Extendify\PageCreator\Admin as PageCreatorAdmin; |
| 23 | 32 | use Extendify\PartnerData; |
| 33 | +use Extendify\Notifications\Admin as NotificationsAdmin; | |
| 34 | +use Extendify\Notifications\Frontend as NotificationsFrontend; | |
| 24 | 35 | use Extendify\Toolbar\Admin as ToolbarAdmin; |
| 25 | 36 | use Extendify\Toolbar\Frontend as ToolbarFrontend; |
| 26 | 37 | use Extendify\Recommendations\Admin as RecommendationsAdmin; |
| 27 | 38 | use Extendify\PluginNotifications\Admin as PluginNotificationsAdmin; |
| 28 | 39 | use Extendify\Shared\Admin as SharedAdmin; |
| 40 | +use Extendify\Shared\DataProvider\NotificationData; | |
| 29 | 41 | use Extendify\Shared\DataProvider\ResourceData; |
| 42 | +use Extendify\Shared\Services\BlockStyleVariations; | |
| 43 | +use Extendify\Shared\Services\ForcePluginReinstall; | |
| 30 | 44 | use Extendify\Shared\Services\Import\ImagesImporter; |
| 31 | 45 | use Extendify\Shared\Services\PluginRedirectDisabler; |
| 46 | +use Extendify\Shared\Services\PluginsActivation\SimplyBook; | |
| 32 | 47 | use Extendify\Shared\Services\VersionMigrator; |
| 48 | +use Extendify\SiteVisibility; | |
| 33 | 49 | |
| 34 | 50 | if (!defined('EXTENDIFY_REQUIRED_CAPABILITY')) { |
| 35 | 51 | define('EXTENDIFY_REQUIRED_CAPABILITY', 'manage_options'); |
| 36 | 52 | } |
| @@ -46,8 +62,45 @@ | ||
| 46 | 62 | if (is_readable(EXTENDIFY_PATH . 'vendor/autoload.php')) { |
| 47 | 63 | require EXTENDIFY_PATH . 'vendor/autoload.php'; |
| 48 | 64 | } |
| 49 | 65 | |
| 66 | +// Registered after the autoloader — these callbacks reference classes it loads. | |
| 67 | +add_filter('http_request_args', function ($args, $url) { | |
| 68 | + $extendifyHosts = array_filter(array_map(function ($host) { | |
| 69 | + return wp_parse_url($host, PHP_URL_HOST); | |
| 70 | + }, \Extendify\Constants::serviceUrls())); | |
| 71 | + | |
| 72 | + $host = wp_parse_url($url, PHP_URL_HOST); | |
| 73 | + if ($host && (str_contains($host, 'extendify') || in_array($host, $extendifyHosts, true))) { | |
| 74 | + $args['timeout'] = 45; | |
| 75 | + } | |
| 76 | + | |
| 77 | + return $args; | |
| 78 | +}, 100, 2); | |
| 79 | + | |
| 80 | +add_action('update_option', function ($option) { | |
| 81 | + if (in_array($option, ['WPLANG', 'blogname'], true)) { | |
| 82 | + \delete_transient('extendify_recommendations'); | |
| 83 | + \delete_transient('extendify_domains'); | |
| 84 | + \delete_transient('extendify_supportArticles'); | |
| 85 | + } | |
| 86 | + | |
| 87 | + // Delete the partner transient so we can fetch new data when the locale is switched. | |
| 88 | + if (($option === 'WPLANG') && get_transient('extendify_partner_data_cache_check')) { | |
| 89 | + delete_transient('extendify_partner_data_cache_check'); | |
| 90 | + PartnerData::getPartnerData(); | |
| 91 | + } | |
| 92 | +}); | |
| 93 | + | |
| 94 | +// Delete the partner transient so we can fetch new data when the locale is switched via WP-CLI. | |
| 95 | +add_action('cli_init', function () { | |
| 96 | + $command = sanitize_text_field(wp_unslash(($_SERVER['argv'][1] ?? ''))); | |
| 97 | + if ($command === 'language' && get_transient('extendify_partner_data_cache_check')) { | |
| 98 | + delete_transient('extendify_partner_data_cache_check'); | |
| 99 | + PartnerData::getPartnerData(); | |
| 100 | + } | |
| 101 | +}); | |
| 102 | + | |
| 50 | 103 | if (!defined('EXTENDIFY_IS_THEME_EXTENDABLE')) { |
| 51 | 104 | define('EXTENDIFY_IS_THEME_EXTENDABLE', get_option('stylesheet') === 'extendable'); |
| 52 | 105 | } |
| 53 | 106 | |
| @@ -61,8 +114,17 @@ | ||
| 61 | 114 | |
| 62 | 115 | // Run various database updates depending on the plugin version. |
| 63 | 116 | new VersionMigrator(); |
| 64 | 117 | |
| 118 | + // Force-reinstall support for /wp/v2/plugins (opt-in via request header). | |
| 119 | + ForcePluginReinstall::register(); | |
| 120 | + | |
| 121 | + // Keeps our design variation names registered so global styles can hold them. | |
| 122 | + BlockStyleVariations::register(); | |
| 123 | + | |
| 124 | + // Their registration callback comes in unauthenticated, so this cannot sit behind the capability gate. | |
| 125 | + SimplyBook::register(); | |
| 126 | + | |
| 65 | 127 | // This class will fetch and cache partner data to be used |
| 66 | 128 | // throughout every class below. If opt in. |
| 67 | 129 | new PartnerData(); |
| 68 | 130 | |
| @@ -71,11 +133,28 @@ | ||
| 71 | 133 | |
| 72 | 134 | // Set up scheduled cache (if opt-in and active). |
| 73 | 135 | if (!PartnerData::setting('deactivated')) { |
| 74 | 136 | ResourceData::scheduleCache(); |
| 137 | + NotificationData::scheduleCache(); | |
| 75 | 138 | } |
| 76 | 139 | |
| 140 | + // A token request carries no session and would fail the capability check. | |
| 141 | + if (defined('EXTENDIFY_PARTNER_ID') && !PartnerData::setting('deactivated')) { | |
| 142 | + McpServer::register(); | |
| 143 | + McpMetadata::register(); | |
| 144 | + McpAuthorize::register(); | |
| 145 | + McpTokenEndpoint::register(); | |
| 146 | + McpRegistrationEndpoint::register(); | |
| 147 | + McpProfile::register(); | |
| 148 | + McpLifecycle::register(); | |
| 149 | + McpJobs::register(); | |
| 150 | + } | |
| 151 | + | |
| 77 | 152 | if (!current_user_can(EXTENDIFY_REQUIRED_CAPABILITY)) { |
| 153 | + if (!SiteVisibility::isPublished()) { | |
| 154 | + new ComingSoonFrontend(); | |
| 155 | + } | |
| 156 | + | |
| 78 | 157 | return; |
| 79 | 158 | } |
| 80 | 159 | |
| 81 | 160 | // The config class will collect information about the |
| @@ -146,8 +225,11 @@ | ||
| 146 | 225 | |
| 147 | 226 | if (PartnerData::setting('showProductRecommendations') || constant('EXTENDIFY_DEVMODE')) { |
| 148 | 227 | new RecommendationsAdmin(); |
| 149 | 228 | } |
| 229 | + | |
| 230 | + new NotificationsAdmin(); | |
| 231 | + new NotificationsFrontend(); | |
| 150 | 232 | |
| 151 | 233 | if (PartnerData::setting('showDraft') || constant('EXTENDIFY_DEVMODE')) { |
| 152 | 234 | new DraftAdmin(); |
| 153 | 235 | } |