'Version']); $version = (string) $data['Version']; } return $version; } /** * Base file path * * @return string */ public static function baseFile() { return plugin_dir_path(__DIR__) . Plugin::FILENAME; } /** * Root path. * * @return string */ public static function root() { return plugin_dir_path(__DIR__); } /** * Activate plugin actions. * * @return mixed */ public static function activation() { return register_activation_hook(static::baseFile(), function () { DB::createPluginTable(); static::addOptions(); }); } /** * Register the plugin settings (also needed for REST requests). */ public static function registerSettings() { if (static::isDisabled()) { return; } register_setting( static::_NAME . '_settings', static::PREFIX_ . 'setting_editpage_hidden', [ 'type' => 'boolean', 'show_in_rest' => true, 'default' => false, ] ); } /** * Whether this plugin has to stay quiet because the Pro plugin runs (it takes over the data and the screens). * Pro defines the constant ADMIN_OPTIONS_PAGES_PRO. Checked inside hooks, not when the file loads: the load * order of plugins is not fixed. * * @since 1.0.0 */ public static function isDisabled(): bool { /** * Switch this plugin off (true) or leave it on. * * @since 1.0.0 * * @param bool $disabled True when the constant ADMIN_OPTIONS_PAGES_PRO is defined. */ return (bool) apply_filters('aop_disabled', defined('ADMIN_OPTIONS_PAGES_PRO')); } /** * Who owns the data in the plugin table and the aop_* options: "free" (this plugin, the default) or the name * of the plugin that took it over ("pro"). Pro sets `aop_data_owner` when it takes over. * * @since 1.0.0 */ public static function dataOwner(): string { $owner = get_option(static::PREFIX_ . 'data_owner', 'free'); return is_string($owner) && $owner !== '' ? $owner : 'free'; } /** * Register the REST routes (on rest_api_init). */ public static function registerRestRoutes(): void { if (static::isDisabled()) { return; } (new Rest\PagesController())->register(); (new Rest\FieldTypesController())->register(); (new Rest\ImportController())->register(); } /** * Start the services of the admin screens (on plugins_loaded, admin only). */ public static function registerAdminServices(): void { if (static::isDisabled()) { return; } PluginMetaLinks::getInstance(); Enqueue::getInstance(); Admin\AdminPages\AdminPages::getInstance(); Options\OptionsPages::getInstance(); } /** * Uninstall handler, called from uninstall.php. Data that the Pro plugin took over is left alone. */ public static function uninstallHandler() { if (static::dataOwner() !== 'free') { return; } DB::dropPluginTable(); static::deleteOptions(); } /** * Add options when activating the plugin. */ public static function addOptions() { add_option(static::PREFIX_ . 'db_version', static::DB_VERSION, '', 'no'); add_option(static::PREFIX_ . 'option_names', [], '', 'no'); // Built again on first use: the pages may have changed while the plugin was not active (Pro). delete_option(Frontend\PublicFields::optionName()); } /** * Delete all the plugin owned options and created options on uninstall. */ public static function deleteOptions() { Collection::make(get_option(static::PREFIX_ . 'option_names'))->each(function ($option) { delete_option($option); }); delete_option(static::PREFIX_ . 'option_names'); delete_option(Frontend\PublicFields::optionName()); delete_option(static::PREFIX_ . 'db_version'); Database\Upgrader::deleteBackup(); delete_option(static::PREFIX_ . 'admin_menu_list'); delete_option(static::PREFIX_ . 'setting_editpage_hidden'); delete_option(Admin\AdminPages\SubpageWhatsNew::SHOW_OPTION); Flash::purgeAll(); } /** * Runs update_option() function twice. * It makes it possible always to update the autoload column, even if the value is still the same. * * @param $option * @param $value * @param null $autoload */ public static function updateOption($option, $value, $autoload = null) { update_option($option, uniqid(), $autoload); update_option($option, $value, $autoload); } }