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