| @@ -2,379 +2,445 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace WPDeveloper\BetterDocs; |
| 4 | 4 | |
| 5 | 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | - exit; // Exit if accessed directly | |
| 6 | + exit; // Exit if accessed directly | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | +use WPDeveloper\BetterDocs\Admin\Analytics; | |
| 10 | +use WPDeveloper\BetterDocs\Admin\Customizer\Customizer; | |
| 11 | +use WPDeveloper\BetterDocs\Admin\HelpScoutMigration; | |
| 12 | +use WPDeveloper\BetterDocs\Admin\ReportEmail; | |
| 9 | 13 | use WPDeveloper\BetterDocs\Core\Admin; |
| 10 | -use WPDeveloper\BetterDocs\Core\Query; | |
| 11 | -use WPDeveloper\BetterDocs\Core\Roles; | |
| 12 | -use WPDeveloper\BetterDocs\Core\WriteWithAI; | |
| 13 | -use WPDeveloper\BetterDocs\Dependencies\DI\Container; | |
| 14 | -use WPDeveloper\BetterDocs\Utils\Views; | |
| 15 | 14 | use WPDeveloper\BetterDocs\Core\BaseAPI; |
| 16 | 15 | use WPDeveloper\BetterDocs\Core\Install; |
| 16 | +use WPDeveloper\BetterDocs\Core\KBMigration; | |
| 17 | +use WPDeveloper\BetterDocs\Core\Query; | |
| 17 | 18 | use WPDeveloper\BetterDocs\Core\Request; |
| 18 | 19 | use WPDeveloper\BetterDocs\Core\Rewrite; |
| 20 | +use WPDeveloper\BetterDocs\Core\Roles; | |
| 19 | 21 | use WPDeveloper\BetterDocs\Core\Scripts; |
| 20 | -use WPDeveloper\BetterDocs\Utils\Helper; | |
| 21 | 22 | use WPDeveloper\BetterDocs\Core\Settings; |
| 22 | -use WPDeveloper\BetterDocs\Core\KBMigration; | |
| 23 | -use WPDeveloper\BetterDocs\Utils\Enqueue; | |
| 23 | +use WPDeveloper\BetterDocs\Core\ShortcodeFactory; | |
| 24 | +use WPDeveloper\BetterDocs\Core\WriteWithAI; | |
| 25 | +use WPDeveloper\BetterDocs\Dependencies\DI\Container; | |
| 26 | +use WPDeveloper\BetterDocs\Dependencies\DI\ContainerBuilder; | |
| 24 | 27 | use WPDeveloper\BetterDocs\Editors\Editor; |
| 25 | -use WPDeveloper\BetterDocs\Utils\Database; | |
| 26 | -use WPDeveloper\BetterDocs\Admin\Analytics; | |
| 27 | -use WPDeveloper\BetterDocs\Admin\ReportEmail; | |
| 28 | 28 | use WPDeveloper\BetterDocs\FrontEnd\FrontEnd; |
| 29 | -use WPDeveloper\BetterDocs\Core\ShortcodeFactory; | |
| 30 | 29 | use WPDeveloper\BetterDocs\FrontEnd\TemplateTags; |
| 31 | -use WPDeveloper\BetterDocs\Admin\Customizer\Customizer; | |
| 32 | -use WPDeveloper\BetterDocs\Dependencies\DI\ContainerBuilder; | |
| 30 | +use WPDeveloper\BetterDocs\Modules\StyleHandler as ModulesStyleHandler; | |
| 31 | +use WPDeveloper\BetterDocs\Utils\Database; | |
| 32 | +use WPDeveloper\BetterDocs\Utils\Enqueue; | |
| 33 | +use WPDeveloper\BetterDocs\Utils\Helper; | |
| 34 | +use WPDeveloper\BetterDocs\Utils\Views; | |
| 33 | 35 | |
| 34 | 36 | final class Plugin { |
| 35 | - private static $_instance = null; | |
| 36 | - /** | |
| 37 | - * Assets manager | |
| 38 | - * | |
| 39 | - * @var Enqueue | |
| 40 | - */ | |
| 41 | - public $assets; | |
| 42 | - /** | |
| 43 | - * View manager | |
| 44 | - * | |
| 45 | - * @var Views | |
| 46 | - */ | |
| 47 | - public $views; | |
| 48 | - /** | |
| 49 | - * Container Manager | |
| 50 | - * | |
| 51 | - * @var Container | |
| 52 | - */ | |
| 53 | - public $container; | |
| 54 | - /** | |
| 55 | - * Editor Manager | |
| 56 | - * @var Editor | |
| 57 | - */ | |
| 58 | - public $editor; | |
| 59 | - /** | |
| 60 | - * Helper class | |
| 61 | - * @var Helper | |
| 62 | - */ | |
| 63 | - public $helper; | |
| 64 | - /** | |
| 65 | - * KBMigration class | |
| 66 | - * @var KBMigration | |
| 67 | - */ | |
| 68 | - public $kbmigration; | |
| 69 | - /** | |
| 70 | - * KBMigration class | |
| 71 | - * @var Admin | |
| 72 | - */ | |
| 73 | - public $admin; | |
| 74 | - /** | |
| 75 | - * Helper class | |
| 76 | - * @var Database | |
| 77 | - */ | |
| 78 | - public $database; | |
| 79 | - /** | |
| 80 | - * Helper class | |
| 81 | - * @var Settings | |
| 82 | - */ | |
| 83 | - public $settings; | |
| 84 | - /** | |
| 85 | - * Helper class | |
| 86 | - * @var TemplateTags | |
| 87 | - */ | |
| 88 | - public $template_helper; | |
| 89 | - /** | |
| 90 | - * Customizer class | |
| 91 | - * @var Customizer | |
| 92 | - */ | |
| 93 | - public $customizer; | |
| 94 | - /** | |
| 95 | - * Query class | |
| 96 | - * @var Query | |
| 97 | - */ | |
| 98 | - public $query; | |
| 99 | - /** | |
| 100 | - * Rewrite Class | |
| 101 | - * @var Rewrite | |
| 102 | - */ | |
| 103 | - public $rewrite; | |
| 104 | - /** | |
| 105 | - * Request Class | |
| 106 | - * @var Request | |
| 107 | - */ | |
| 108 | - public $request; | |
| 109 | - /** | |
| 110 | - * Analytics Class | |
| 111 | - * @var Analytics | |
| 112 | - */ | |
| 113 | - public $analytics; | |
| 114 | - /** | |
| 115 | - * Plugin Version | |
| 116 | - * @var string | |
| 117 | - */ | |
| 118 | - public $version = '3.3.4'; | |
| 37 | + private static $_instance = null; | |
| 38 | + /** | |
| 39 | + * Assets manager | |
| 40 | + * | |
| 41 | + * @var Enqueue | |
| 42 | + */ | |
| 43 | + public $assets; | |
| 44 | + /** | |
| 45 | + * View manager | |
| 46 | + * | |
| 47 | + * @var Views | |
| 48 | + */ | |
| 49 | + public $views; | |
| 50 | + /** | |
| 51 | + * Container Manager | |
| 52 | + * | |
| 53 | + * @var Container | |
| 54 | + */ | |
| 55 | + public $container; | |
| 56 | + /** | |
| 57 | + * Editor Manager | |
| 58 | + * @var Editor | |
| 59 | + */ | |
| 60 | + public $editor; | |
| 61 | + /** | |
| 62 | + * Helper class | |
| 63 | + * @var Helper | |
| 64 | + */ | |
| 65 | + public $helper; | |
| 66 | + /** | |
| 67 | + * KBMigration class | |
| 68 | + * @var KBMigration | |
| 69 | + */ | |
| 70 | + public $kbmigration; | |
| 71 | + /** | |
| 72 | + * KBMigration class | |
| 73 | + * @var Admin | |
| 74 | + */ | |
| 75 | + public $admin; | |
| 76 | + /** | |
| 77 | + * Helper class | |
| 78 | + * @var Database | |
| 79 | + */ | |
| 80 | + public $database; | |
| 81 | + /** | |
| 82 | + * Helper class | |
| 83 | + * @var Settings | |
| 84 | + */ | |
| 85 | + public $settings; | |
| 86 | + /** | |
| 87 | + * Helper class | |
| 88 | + * @var TemplateTags | |
| 89 | + */ | |
| 90 | + public $template_helper; | |
| 91 | + /** | |
| 92 | + * Customizer class | |
| 93 | + * @var Customizer | |
| 94 | + */ | |
| 95 | + public $customizer; | |
| 96 | + /** | |
| 97 | + * Query class | |
| 98 | + * @var Query | |
| 99 | + */ | |
| 100 | + public $query; | |
| 101 | + /** | |
| 102 | + * Rewrite Class | |
| 103 | + * @var Rewrite | |
| 104 | + */ | |
| 105 | + public $rewrite; | |
| 106 | + /** | |
| 107 | + * Request Class | |
| 108 | + * @var Request | |
| 109 | + */ | |
| 110 | + public $request; | |
| 111 | + /** | |
| 112 | + * Analytics Class | |
| 113 | + * @var Analytics | |
| 114 | + */ | |
| 115 | + public $analytics; | |
| 116 | + /** | |
| 117 | + * Plugin Version | |
| 118 | + * @var string | |
| 119 | + */ | |
| 120 | + public $version = '3.8.9'; | |
| 119 | 121 | |
| 120 | - /** | |
| 121 | - * WriteWithAI Class | |
| 122 | - * @var string | |
| 123 | - */ | |
| 124 | - public $ai_autowrtie; | |
| 122 | + /** | |
| 123 | + * WriteWithAI Class | |
| 124 | + * @var string | |
| 125 | + */ | |
| 126 | + public $ai_autowrtie; | |
| 127 | + public $backgroundProccessor; | |
| 125 | 128 | |
| 126 | - /** | |
| 127 | - * Plugin DB Version | |
| 128 | - * @var string | |
| 129 | - */ | |
| 130 | - public $db_version = '1.0.1'; | |
| 129 | + /** | |
| 130 | + * Plugin DB Version | |
| 131 | + * @var string | |
| 132 | + */ | |
| 133 | + public $db_version = '1.0.1'; | |
| 131 | 134 | |
| 132 | - public function __construct() { | |
| 133 | - $this->define_constants(); | |
| 135 | + public function __construct() { | |
| 136 | + $this->define_constants(); | |
| 134 | 137 | |
| 135 | - do_action( 'betterdocs_init_before' ); | |
| 136 | - $this->setup_container(); | |
| 137 | - /** | |
| 138 | - * Register activation and deactivation hooks | |
| 139 | - * and version updates check | |
| 140 | - */ | |
| 141 | - $this->container->get( Install::class ); | |
| 138 | + do_action( 'betterdocs_init_before' ); | |
| 142 | 139 | |
| 143 | - $this->initialize(); | |
| 140 | + $this->setup_container(); | |
| 141 | + /** | |
| 142 | + * Register activation and deactivation hooks | |
| 143 | + * and version updates check | |
| 144 | + */ | |
| 145 | + $this->container->get( Install::class ); | |
| 144 | 146 | |
| 145 | - add_action( 'init', [ $this, 'init' ], 0 ); | |
| 147 | + add_action( 'init', [ $this, 'initialize' ], 0 ); | |
| 146 | 148 | |
| 147 | - /** | |
| 148 | - * For admin only | |
| 149 | - */ | |
| 150 | - add_action( 'admin_init', [ $this, 'admin_init' ], 0 ); | |
| 149 | + /** | |
| 150 | + * Initialize API | |
| 151 | + */ | |
| 152 | + add_action( 'rest_api_init', [ $this, 'api_initialization' ] ); | |
| 151 | 153 | |
| 152 | - /** | |
| 153 | - * For AJAX only | |
| 154 | - */ | |
| 155 | - $this->ajax(); | |
| 156 | - } | |
| 154 | + /** | |
| 155 | + * For admin only | |
| 156 | + */ | |
| 157 | + add_action( 'admin_init', [ $this, 'admin_init' ], 0 ); | |
| 157 | 158 | |
| 158 | - private function define_constants() { | |
| 159 | - $this->define( 'BETTERDOCS_VERSION', $this->version ); | |
| 160 | - $this->define( 'BETTERDOCS_DB_VERSION', $this->db_version ); | |
| 161 | - $this->define( 'BETTERDOCS_ABSPATH', dirname( BETTERDOCS_PLUGIN_FILE ) . '/' ); | |
| 162 | - $this->define( 'BETTERDOCS_ABSURL', plugin_dir_url( BETTERDOCS_PLUGIN_FILE ) ); | |
| 163 | - $this->define( 'BETTERDOCS_PLUGIN_BASENAME', plugin_basename( BETTERDOCS_PLUGIN_FILE ) ); | |
| 164 | - $this->define( 'BETTERDOCS_BLOCKS_DIRECTORY', BETTERDOCS_ABSPATH . 'assets/blocks/' ); | |
| 165 | - $this->define( 'BETTERDOCS_ROOT_DIR_PATH', plugin_dir_path( BETTERDOCS_PLUGIN_FILE ) ); | |
| 166 | - $this->define( 'BETTERDOCS_FSE_TEMPLATES_PATH', BETTERDOCS_ROOT_DIR_PATH . 'views/templates/fse' ); | |
| 159 | + /** | |
| 160 | + * For AJAX only | |
| 161 | + */ | |
| 162 | + $this->ajax(); | |
| 167 | 163 | |
| 168 | - /** | |
| 169 | - * Third Party Constants | |
| 170 | - * @since 2.5.0 | |
| 171 | - * | |
| 172 | - * WPML compatibility with Polylang | |
| 173 | - */ | |
| 174 | - if ( Helper::is_plugin_active( 'polylang/polylang.php' ) ) { | |
| 175 | - define( 'PLL_WPML_COMPAT', false ); | |
| 176 | - } | |
| 177 | - } | |
| 164 | + /** | |
| 165 | + * Style Handler For Parsing and Saving Styles as file. | |
| 166 | + */ | |
| 167 | + ModulesStyleHandler::init(); | |
| 168 | + } | |
| 178 | 169 | |
| 179 | - /** | |
| 180 | - * Define constant if not already set. | |
| 181 | - * | |
| 182 | - * @param string $name Constant name. | |
| 183 | - * @param string|bool $value Constant value. | |
| 184 | - */ | |
| 185 | - private function define( $name, $value ) { | |
| 186 | - if ( ! defined( $name ) ) { | |
| 187 | - define( $name, $value ); | |
| 188 | - } | |
| 189 | - } | |
| 170 | + private function define_constants() { | |
| 171 | + $this->define( 'BETTERDOCS_VERSION', $this->version ); | |
| 172 | + $this->define( 'BETTERDOCS_DB_VERSION', $this->db_version ); | |
| 173 | + $this->define( 'BETTERDOCS_ABSPATH', dirname( BETTERDOCS_PLUGIN_FILE ) . '/' ); | |
| 174 | + $this->define( 'BETTERDOCS_ABSURL', plugin_dir_url( BETTERDOCS_PLUGIN_FILE ) ); | |
| 175 | + $this->define( 'BETTERDOCS_PLUGIN_BASENAME', plugin_basename( BETTERDOCS_PLUGIN_FILE ) ); | |
| 176 | + $this->define( 'BETTERDOCS_BLOCKS_DIRECTORY', BETTERDOCS_ABSPATH . 'assets/blocks/' ); | |
| 177 | + $this->define( 'BETTERDOCS_ROOT_DIR_PATH', plugin_dir_path( BETTERDOCS_PLUGIN_FILE ) ); | |
| 178 | + $this->define( 'BETTERDOCS_FSE_TEMPLATES_PATH', BETTERDOCS_ROOT_DIR_PATH . 'views/templates/fse' ); | |
| 190 | 179 | |
| 191 | - public function setup_container() { | |
| 192 | - $config_array = require_once BETTERDOCS_ABSPATH . 'includes/config.php'; | |
| 193 | - $config = apply_filters( 'betterdocs_container_config', $config_array ); | |
| 194 | - $builder = new ContainerBuilder(); | |
| 180 | + /** | |
| 181 | + * Third Party Constants | |
| 182 | + * @since 2.5.0 | |
| 183 | + * | |
| 184 | + * WPML compatibility with Polylang | |
| 185 | + */ | |
| 186 | + if ( Helper::is_plugin_active( 'polylang/polylang.php' ) ) { | |
| 187 | + define( 'PLL_WPML_COMPAT', false ); | |
| 188 | + } | |
| 189 | + } | |
| 195 | 190 | |
| 196 | - $builder->addDefinitions( $config ); | |
| 197 | - $this->container = $builder->build(); | |
| 198 | - } | |
| 191 | + /** | |
| 192 | + * Define constant if not already set. | |
| 193 | + * | |
| 194 | + * @param string $name Constant name. | |
| 195 | + * @param string|bool $value Constant value. | |
| 196 | + */ | |
| 197 | + private function define( $name, $value ) { | |
| 198 | + if ( ! defined( $name ) ) { | |
| 199 | + define( $name, $value ); | |
| 200 | + } | |
| 201 | + } | |
| 199 | 202 | |
| 200 | - public function initialize() { | |
| 201 | - $this->container->get( Scripts::class ); | |
| 202 | - $this->rewrite = $this->container->get( Rewrite::class ); | |
| 203 | - $this->request = $this->container->get( Request::class ); | |
| 204 | - $this->query = $this->container->get( Query::class ); | |
| 203 | + public function setup_container() { | |
| 204 | + $config_array = require_once BETTERDOCS_ABSPATH . 'includes/config.php'; | |
| 205 | + $config = apply_filters( 'betterdocs_container_config', $config_array ); | |
| 206 | + $builder = new ContainerBuilder(); | |
| 205 | 207 | |
| 206 | - $this->rewrite->init(); | |
| 207 | - $this->request->init(); | |
| 208 | + $builder->addDefinitions( $config ); | |
| 209 | + $this->container = $builder->build(); | |
| 210 | + } | |
| 208 | 211 | |
| 209 | - $this->assets = $this->container->get( Enqueue::class ); | |
| 210 | - $this->views = $this->container->get( Views::class ); | |
| 211 | - $this->helper = $this->container->get( Helper::class ); | |
| 212 | - $this->kbmigration = $this->container->get( KBMigration::class ); | |
| 213 | - $this->admin = $this->container->get( Admin::class ); | |
| 214 | - $this->database = $this->container->get( Database::class ); | |
| 215 | - $this->settings = $this->container->get( Settings::class ); | |
| 216 | - $this->analytics = $this->container->get( Analytics::class ); | |
| 212 | + public function initialize() { | |
| 217 | 213 | |
| 218 | - $this->template_helper = $this->container->get( TemplateTags::class ); | |
| 219 | - $this->customizer = $this->container->get( Customizer::class ); | |
| 220 | - $this->editor = $this->container->get( Editor::class ); | |
| 221 | - $this->ai_autowrtie = $this->container->get( WriteWithAI::class ); | |
| 214 | + /** | |
| 215 | + * Setup localization. | |
| 216 | + */ | |
| 217 | + $this->load_plugin_textdomain(); | |
| 222 | 218 | |
| 223 | - /** | |
| 224 | - * Initialize all editors. | |
| 225 | - * Elementor, Gutenberg/BlockEditor | |
| 226 | - */ | |
| 227 | - add_action( 'init', [ $this->editor, 'init' ] ); | |
| 219 | + $this->container->get( Scripts::class ); | |
| 220 | + $this->rewrite = $this->container->get( Rewrite::class ); | |
| 221 | + $this->request = $this->container->get( Request::class ); | |
| 222 | + $this->query = $this->container->get( Query::class ); | |
| 228 | 223 | |
| 229 | - /** | |
| 230 | - * Initialize API | |
| 231 | - */ | |
| 232 | - add_action( 'rest_api_init', [ $this, 'api_initialization' ] ); | |
| 233 | - } | |
| 224 | + // Initialize background process | |
| 225 | + $this->backgroundProccessor = $this->container->get( HelpScoutMigration::class ); | |
| 234 | 226 | |
| 235 | - /** | |
| 236 | - * Initialize the BetterDocs Plugin | |
| 237 | - * | |
| 238 | - * @return void | |
| 239 | - * @since 2.5.0 | |
| 240 | - */ | |
| 241 | - public function init() { | |
| 242 | - /** | |
| 243 | - * Setup localization. | |
| 244 | - */ | |
| 245 | - $this->load_plugin_textdomain(); | |
| 227 | + $this->rewrite->init(); | |
| 228 | + $this->request->init(); | |
| 246 | 229 | |
| 247 | - $this->container->get( Admin::class ); | |
| 248 | - $this->container->get( Roles::class ); | |
| 249 | - $this->container->get( ReportEmail::class ); | |
| 230 | + $this->assets = $this->container->get( Enqueue::class ); | |
| 231 | + $this->views = $this->container->get( Views::class ); | |
| 232 | + $this->helper = $this->container->get( Helper::class ); | |
| 233 | + $this->kbmigration = $this->container->get( KBMigration::class ); | |
| 234 | + $this->admin = $this->container->get( Admin::class ); | |
| 235 | + $this->database = $this->container->get( Database::class ); | |
| 236 | + $this->settings = $this->container->get( Settings::class ); | |
| 237 | + $this->analytics = $this->container->get( Analytics::class ); | |
| 250 | 238 | |
| 251 | - /** | |
| 252 | - * Initialize Shortcode | |
| 253 | - * Make sure you have listed out all shortcode in shortcode factory. | |
| 254 | - */ | |
| 255 | - $this->container->get( ShortcodeFactory::class )->init(); | |
| 239 | + $this->template_helper = $this->container->get( TemplateTags::class ); | |
| 240 | + $this->customizer = $this->container->get( Customizer::class ); | |
| 241 | + $this->editor = $this->container->get( Editor::class ); | |
| 242 | + $this->ai_autowrtie = $this->container->get( WriteWithAI::class ); | |
| 256 | 243 | |
| 257 | - $this->container->get( FrontEnd::class ); | |
| 244 | + $this->container->get( Admin::class ); | |
| 245 | + $this->container->get( Roles::class ); | |
| 246 | + $this->container->get( ReportEmail::class ); | |
| 258 | 247 | |
| 259 | - do_action( 'betterdocs_init' ); | |
| 260 | - } | |
| 248 | + /** | |
| 249 | + * Initialize Shortcode | |
| 250 | + * Make sure you have listed out all shortcode in shortcode factory. | |
| 251 | + */ | |
| 252 | + $this->container->get( ShortcodeFactory::class )->init(); | |
| 261 | 253 | |
| 262 | - /** | |
| 263 | - * Load plugins textdomain `betterdocs` into actions. | |
| 264 | - * @return void | |
| 265 | - */ | |
| 266 | - public function load_plugin_textdomain( $textdomain = 'betterdocs', $plugin_file = BETTERDOCS_PLUGIN_FILE ) { | |
| 267 | - $locale = determine_locale(); | |
| 254 | + $this->container->get( FrontEnd::class ); | |
| 268 | 255 | |
| 269 | - /** | |
| 270 | - * Filter to adjust the BetterDocs locale to use for translations. | |
| 271 | - */ | |
| 272 | - $locale = apply_filters( 'plugin_locale', $locale, $textdomain ); | |
| 256 | + do_action( 'betterdocs_init' ); | |
| 273 | 257 | |
| 274 | - unload_textdomain( $textdomain ); | |
| 275 | - load_textdomain( $textdomain, WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' ); | |
| 276 | - load_plugin_textdomain( $textdomain, false, plugin_basename( dirname( $plugin_file ) ) . '/languages' ); | |
| 277 | - } | |
| 258 | + $this->editor->init(); | |
| 259 | + } | |
| 278 | 260 | |
| 279 | - /** | |
| 280 | - * For AJAX Only | |
| 281 | - * @return void | |
| 282 | - */ | |
| 283 | - public function ajax() { | |
| 284 | - } | |
| 261 | + /** | |
| 262 | + * Load plugins textdomain `betterdocs` into actions. | |
| 263 | + * @return void | |
| 264 | + */ | |
| 265 | + public function load_plugin_textdomain( $textdomain = 'betterdocs', $plugin_file = BETTERDOCS_PLUGIN_FILE ) { | |
| 266 | + $locale = determine_locale(); | |
| 285 | 267 | |
| 286 | - /** | |
| 287 | - * Create a plugin instance. | |
| 288 | - * | |
| 289 | - * @param mixed ...$args | |
| 290 | - * | |
| 291 | - * @return static | |
| 292 | - * | |
| 293 | - * @suppress PHP0441 | |
| 294 | - * @since 2.5.0 | |
| 295 | - */ | |
| 296 | - public static function get_instance() { | |
| 297 | - if ( static::$_instance == null ) { | |
| 298 | - static::$_instance = new self(); | |
| 268 | + /** | |
| 269 | + * Filter to adjust the BetterDocs locale to use for translations. | |
| 270 | + */ | |
| 271 | + $locale = apply_filters( 'plugin_locale', $locale, $textdomain ); | |
| 299 | 272 | |
| 300 | - do_action( 'betterdocs_loaded' ); | |
| 301 | - } | |
| 273 | + if ( file_exists( WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' ) ) { | |
| 274 | + unload_textdomain( $textdomain ); | |
| 275 | + load_textdomain( $textdomain, WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' ); | |
| 276 | + } | |
| 302 | 277 | |
| 303 | - return static::$_instance; | |
| 304 | - } | |
| 278 | + load_plugin_textdomain( $textdomain, false, plugin_basename( dirname( $plugin_file ) ) . '/languages' ); | |
| 279 | + } | |
| 305 | 280 | |
| 306 | - /** | |
| 307 | - * Hooked with `admin_init` action. | |
| 308 | - * @return void | |
| 309 | - */ | |
| 310 | - public function admin_init() { | |
| 311 | - /** | |
| 312 | - * Maybe Redirect | |
| 313 | - * for setup related settings. | |
| 314 | - */ | |
| 315 | - $this->maybe_redirect(); | |
| 316 | - } | |
| 281 | + /** | |
| 282 | + * For AJAX Only | |
| 283 | + * @return void | |
| 284 | + */ | |
| 285 | + public function ajax() { | |
| 286 | + } | |
| 317 | 287 | |
| 318 | - /** | |
| 319 | - * Summary of maybe_redirect | |
| 320 | - * @return void | |
| 321 | - */ | |
| 322 | - public function maybe_redirect() { | |
| 323 | - // Bail if no activation transient is set. | |
| 324 | - if ( ! $this->database->get_transient( 'betterdocs_maybe_redirect' ) ) { | |
| 325 | - return; | |
| 326 | - } | |
| 288 | + /** | |
| 289 | + * Create a plugin instance. | |
| 290 | + * | |
| 291 | + * @param mixed ...$args | |
| 292 | + * | |
| 293 | + * @return static | |
| 294 | + * | |
| 295 | + * @suppress PHP0441 | |
| 296 | + * @since 2.5.0 | |
| 297 | + */ | |
| 298 | + public static function get_instance() { | |
| 299 | + if ( self::$_instance == null ) { | |
| 300 | + self::$_instance = new self(); | |
| 327 | 301 | |
| 328 | - // Delete the activation transient. | |
| 329 | - $this->database->delete_transient( 'betterdocs_maybe_redirect' ); | |
| 302 | + do_action( 'betterdocs_loaded' ); | |
| 303 | + } | |
| 330 | 304 | |
| 331 | - if ( ! is_multisite() ) { | |
| 332 | - $betterdocs_settings = get_option('betterdocs_settings'); | |
| 333 | - if ( $betterdocs_settings) { | |
| 334 | - wp_safe_redirect( add_query_arg( [ 'page' => 'betterdocs-settings' ], admin_url( 'admin.php' ) ) ); | |
| 335 | - } else { | |
| 336 | - wp_safe_redirect( add_query_arg( [ 'page' => 'betterdocs-setup' ], admin_url( 'admin.php' ) ) ); | |
| 337 | - } | |
| 338 | - } | |
| 339 | - } | |
| 305 | + return self::$_instance; | |
| 306 | + } | |
| 340 | 307 | |
| 341 | - /** | |
| 342 | - * Is Pro Plugin Is Installed? | |
| 343 | - * @return bool | |
| 344 | - */ | |
| 345 | - public function is_pro_installed() { | |
| 346 | - return $this->helper->get_plugins( 'betterdocs-pro/betterdocs-pro.php' ); | |
| 347 | - } | |
| 308 | + /** | |
| 309 | + * Hooked with `admin_init` action. | |
| 310 | + * @return void | |
| 311 | + */ | |
| 312 | + public function admin_init() { | |
| 313 | + /** | |
| 314 | + * Maybe Redirect | |
| 315 | + * for setup related settings. | |
| 316 | + */ | |
| 317 | + $this->maybe_redirect(); | |
| 318 | + } | |
| 348 | 319 | |
| 349 | - /** | |
| 350 | - * Is Pro Plugin Is Active? | |
| 351 | - * @return bool | |
| 352 | - */ | |
| 353 | - public function is_pro_active() { | |
| 354 | - return $this->helper->is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' ); | |
| 355 | - } | |
| 320 | + /** | |
| 321 | + * Summary of maybe_redirect | |
| 322 | + * @return void | |
| 323 | + */ | |
| 324 | + public function maybe_redirect() { | |
| 325 | + // Bail if no activation transient is set. | |
| 326 | + if ( ! $this->database->get_transient( 'betterdocs_maybe_redirect' ) ) { | |
| 327 | + return; | |
| 328 | + } | |
| 356 | 329 | |
| 357 | - /** | |
| 358 | - * Get all the API initialized. | |
| 359 | - * @return void | |
| 360 | - */ | |
| 361 | - public function api_initialization() { | |
| 362 | - $_api_classes = scandir( __DIR__ . DIRECTORY_SEPARATOR . 'REST' ); | |
| 330 | + // Delete the activation transient. | |
| 331 | + $this->database->delete_transient( 'betterdocs_maybe_redirect' ); | |
| 363 | 332 | |
| 364 | - if ( ! empty( $_api_classes ) && is_array( $_api_classes ) ) { | |
| 365 | - foreach ( $_api_classes as $class ) { | |
| 366 | - if ( $class == '.' || $class == '..' || strpos( $class, '.' ) === 0) { | |
| 367 | - continue; | |
| 368 | - } | |
| 333 | + if ( ! is_multisite() ) { | |
| 334 | + $betterdocs_settings = get_option( 'betterdocs_settings' ); | |
| 335 | + if ( $betterdocs_settings ) { | |
| 336 | + wp_safe_redirect( add_query_arg( [ 'page' => 'betterdocs-settings' ], admin_url( 'admin.php' ) ) ); | |
| 337 | + } else { | |
| 338 | + wp_safe_redirect( add_query_arg( [ 'page' => 'betterdocs-setup' ], admin_url( 'admin.php' ) ) ); | |
| 339 | + } | |
| 340 | + } | |
| 341 | + } | |
| 369 | 342 | |
| 370 | - $classname = basename( $class, '.php' ); | |
| 371 | - $classname = '\\' . __NAMESPACE__ . "\\REST\\$classname"; | |
| 372 | - $_api_class = $this->container->get( $classname ); | |
| 343 | + /** | |
| 344 | + * Is Pro Plugin Is Installed? | |
| 345 | + * @return bool | |
| 346 | + */ | |
| 347 | + public function is_pro_installed() { | |
| 348 | + return $this->helper->get_plugins( 'betterdocs-pro/betterdocs-pro.php' ); | |
| 349 | + } | |
| 373 | 350 | |
| 374 | - if ( $_api_class instanceof BaseAPI ) { | |
| 375 | - $_api_class->register(); | |
| 376 | - } | |
| 377 | - } | |
| 378 | - } | |
| 379 | - } | |
| 351 | + /** | |
| 352 | + * Is Pro Plugin Is Active? | |
| 353 | + * @return bool | |
| 354 | + */ | |
| 355 | + public function pro_file() { | |
| 356 | + return WP_PLUGIN_DIR . '/betterdocs-pro/betterdocs-pro.php'; | |
| 357 | + } | |
| 358 | + | |
| 359 | + public function is_pro_active() { | |
| 360 | + if ( file_exists( $this->pro_file() ) ) { | |
| 361 | + return $this->helper->is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' ); | |
| 362 | + } | |
| 363 | + | |
| 364 | + return false; | |
| 365 | + } | |
| 366 | + | |
| 367 | + public function pro_version() { | |
| 368 | + if ( ! $this->is_pro_active() ) { | |
| 369 | + return false; | |
| 370 | + } | |
| 371 | + | |
| 372 | + if ( ! function_exists( 'get_plugin_data' ) ) { | |
| 373 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 374 | + } | |
| 375 | + | |
| 376 | + $plugin_data = get_plugin_data( $this->pro_file() ); | |
| 377 | + | |
| 378 | + return $plugin_data['Version']; | |
| 379 | + } | |
| 380 | + | |
| 381 | + /** | |
| 382 | + * Get all the API initialized. | |
| 383 | + * @return void | |
| 384 | + */ | |
| 385 | + public function api_initialization() { | |
| 386 | + $_api_classes = scandir( __DIR__ . DIRECTORY_SEPARATOR . 'REST' ); | |
| 387 | + | |
| 388 | + if ( ! empty( $_api_classes ) && is_array( $_api_classes ) ) { | |
| 389 | + foreach ( $_api_classes as $class ) { | |
| 390 | + if ( $class == '.' || $class == '..' || strpos( $class, '.' ) === 0 ) { | |
| 391 | + continue; | |
| 392 | + } | |
| 393 | + | |
| 394 | + $classname = basename( $class, '.php' ); | |
| 395 | + $classname = '\\' . __NAMESPACE__ . "\\REST\\$classname"; | |
| 396 | + $_api_class = $this->container->get( $classname ); | |
| 397 | + | |
| 398 | + if ( $_api_class instanceof BaseAPI ) { | |
| 399 | + $_api_class->register(); | |
| 400 | + } | |
| 401 | + } | |
| 402 | + } | |
| 403 | + } | |
| 404 | + | |
| 405 | + public function is_betterdocs_screen( $hook, $admin_check = true ): bool { | |
| 406 | + $screens = [ | |
| 407 | + 'betterdocs_page_betterdocs-settings', | |
| 408 | + 'toplevel_page_betterdocs-admin', | |
| 409 | + 'betterdocs_page_betterdocs-analytics', | |
| 410 | + 'betterdocs_page_betterdocs-faq', | |
| 411 | + 'betterdocs_page_betterdocs-glossaries', | |
| 412 | + 'betterdocs_page_betterdocs-ai-chatbot', | |
| 413 | + | |
| 414 | + ]; | |
| 415 | + | |
| 416 | + if ( $admin_check ) { | |
| 417 | + if ( in_array( $hook, $screens ) ) { | |
| 418 | + return true; | |
| 419 | + } | |
| 420 | + | |
| 421 | + return false; | |
| 422 | + } | |
| 423 | + | |
| 424 | + return false; | |
| 425 | + } | |
| 426 | + | |
| 427 | + public function get_betterdocs_screen() { | |
| 428 | + $registered_screens = [ | |
| 429 | + 'toplevel_page_betterdocs-admin', | |
| 430 | + 'betterdocs_page_betterdocs-settings', | |
| 431 | + 'betterdocs_page_betterdocs-analytics', | |
| 432 | + 'betterdocs_page_betterdocs-faq', | |
| 433 | + 'betterdocs_page_betterdocs-glossaries', | |
| 434 | + 'betterdocs_page_betterdocs-ai-chatbot', | |
| 435 | + | |
| 436 | + ]; | |
| 437 | + | |
| 438 | + $current_screen_id = get_current_screen() != null ? get_current_screen()->id : ''; | |
| 439 | + | |
| 440 | + if ( in_array( $current_screen_id, $registered_screens ) ) { | |
| 441 | + return $current_screen_id; | |
| 442 | + } | |
| 443 | + | |
| 444 | + return false; | |
| 445 | + } | |
| 380 | 446 | } |