plugin_config = $plugin_config; } /** * Run system requirements check. * * @return bool */ public function evaluate_system(): bool { if ( $this->is_blocked() ) { return false; } $this->basename = basename( __DIR__ ); $mofile = plugin_dir_path(__FILE__) . 'lang/' . $this->get('text_domain') . '-' . get_locale() . '.mo'; load_textdomain($this->get('text_domain'), $mofile); $this->test_php(); $this->test_required_plugins(); $this->test_php_extensions(); return $this->result; } /** * Check PHP version. */ private function test_php(): void { if ( PHP_VERSION_ID < $this->get( 'min_php_int' ) ) { $this->fail_with_notice( sprintf( $this->t( 'PHP version is older than %s. This plugin requires a newer PHP version.' ), $this->get( 'min_php' ) ) ); } } /** * Check if required plugins are active. */ private function test_required_plugins(): void { $required_plugins = $this->get( 'required_plugins' ); if ( empty( $required_plugins ) ) { return; } include_once ABSPATH . 'wp-admin/includes/plugin.php'; foreach ( $required_plugins as $slug ) { $status = $this->test_plugin( $slug ); if ( self::TEST_PLUGIN_INSTALLED === $status ) { $this->fail_with_notice( sprintf( $this->t( "Required plugin '%s' is installed but not activated." ), $slug ) ); } if ( self::TEST_PLUGIN_NOT_INSTALLED === $status ) { $this->fail_with_notice( sprintf( $this->t( "Required plugin '%s' is not installed." ), $slug ) ); } } } /** * Check if required PHP extensions are loaded. */ private function test_php_extensions(): void { $required_extensions = $this->get( 'required_php_extensions' ); if ( empty( $required_extensions ) ) { return; } $missing = []; foreach ( $required_extensions as $ext ) { if ( false === extension_loaded( $ext ) ) { $missing[] = $ext; } } if ( ! empty( $missing ) ) { $this->fail_with_notice( sprintf( $this->t( 'Required PHP extensions missing: %s' ), implode( ', ', $missing ) ) ); } } /** * Add admin notice and set failure flag. * * @param string $message Message to display. */ private function fail_with_notice( string $message ): void { $this->result = false; add_action( 'admin_notices', function () use ( $message ) { printf( '
%s: %s