diff --git a/CHANGELOG.md b/CHANGELOG.md index 035e1c9..c3213d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.5.0 +* Feat: Add `More Plugins` options page. + ## 1.4.3 * Tested up to WP 7.0. diff --git a/composer.json b/composer.json index 73fc6ce..729c282 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,9 @@ "email": "badasswpdev@gmail.com" } ], + "require": { + "badasswp/pluginate": "^1.0" + }, "require-dev": { "phpunit/phpunit": "^9.6", "mockery/mockery": "^1.6", @@ -40,4 +43,4 @@ "analyse": "vendor/bin/phpstan analyse --memory-limit=2048M", "coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-cobertura cobertura.xml && coveralls --repo-token=lo7lxZfU7gVcSJwU7oXEx6qPZW8F9p7wt --file=cobertura.xml" } -} \ No newline at end of file +} diff --git a/inc/Services/Admin.php b/inc/Services/Admin.php index 192f530..d05ad5f 100644 --- a/inc/Services/Admin.php +++ b/inc/Services/Admin.php @@ -13,7 +13,27 @@ use SqlToCpt\Abstracts\Service; use SqlToCpt\Interfaces\Kernel; +use Pluginate\Admin as Pluginate; + class Admin extends Service implements Kernel { + /** + * Pluginate instance. + * + * @since 1.5.0 + * + * @var Pluginate + */ + public Pluginate $pluginate; + + /** + * Admin constructor. + * + * @since 1.5.0 + */ + public function __construct() { + $this->pluginate = new Pluginate( 'sql-to-cpt' ); + } + /** * Bind to WP. * @@ -23,6 +43,7 @@ class Admin extends Service implements Kernel { */ public function register(): void { add_action( 'admin_menu', [ $this, 'register_admin_menu' ] ); + add_action( 'admin_init', [ $this->pluginate, 'init' ] ); } /** @@ -44,6 +65,15 @@ public function register_admin_menu(): void { 'dashicons-database', 90 ); + + add_submenu_page( + 'sql-to-cpt', + __( 'More Plugins', 'sql-to-cpt' ), + __( 'More Plugins', 'sql-to-cpt' ), + 'manage_options', + sprintf( '%s-more-plugins', 'sql-to-cpt' ), + [ $this, 'register_more_plugins' ] + ); } /** @@ -69,4 +99,33 @@ public function register_admin_page(): void { ] ); } + + /** + * Register More Plugins. + * + * This controls the display of the + * "More Plugins" submenu page. + * + * @since 1.5.0 + * + * @return void + */ + public function register_more_plugins(): void { + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + vprintf( + '
+

%s

+

%s

+ %s +
', + array_map( + '__', + [ + 'More Plugins', + 'Check out some other amazing plugin of ours...', + $this->pluginate->get_more_plugins(), + ] + ) + ); + } } diff --git a/tests/unit/php/Core/ContainerTest.php b/tests/unit/php/Core/ContainerTest.php index 4788b84..b67148b 100644 --- a/tests/unit/php/Core/ContainerTest.php +++ b/tests/unit/php/Core/ContainerTest.php @@ -23,6 +23,7 @@ * @covers \SqlToCpt\Services\Post::__construct * @covers \SqlToCpt\Core\Post::__construct * @covers \SqlToCpt\Services\Routes::__construct + * @covers \SqlToCpt\Services\Admin::__construct */ class ContainerTest extends TestCase { public Container $container; @@ -108,6 +109,16 @@ public function test_register() { ] ); + $admin = Service::$services[ Admin::class ]; + + WP_Mock::expectActionAdded( + 'admin_init', + [ + $admin->pluginate, + 'init', + ] + ); + WP_Mock::expectActionAdded( 'init', [ diff --git a/tests/unit/php/Services/AdminTest.php b/tests/unit/php/Services/AdminTest.php index a2b28a0..2686f5d 100644 --- a/tests/unit/php/Services/AdminTest.php +++ b/tests/unit/php/Services/AdminTest.php @@ -10,6 +10,7 @@ * @covers \SqlToCpt\Services\Admin::register * @covers \SqlToCpt\Services\Admin::register_admin_menu * @covers \SqlToCpt\Services\Admin::register_admin_page + * @covers \SqlToCpt\Services\Admin::__construct */ class AdminTest extends TestCase { public Admin $admin; @@ -26,6 +27,7 @@ public function tearDown(): void { public function test_register() { WP_Mock::expectActionAdded( 'admin_menu', [ $this->admin, 'register_admin_menu' ] ); + WP_Mock::expectActionAdded( 'admin_init', [ $this->admin->pluginate, 'init' ] ); $this->admin->register(); @@ -52,6 +54,21 @@ function ( $arg ) { ) ->andReturn( null ); + WP_Mock::userFunction( '__' ) + ->andReturnUsing( fn( $text, $domain ) => $text ); + + WP_Mock::userFunction( 'add_submenu_page' ) + ->once() + ->with( + 'sql-to-cpt', + 'More Plugins', + 'More Plugins', + 'manage_options', + 'sql-to-cpt-more-plugins', + [ $this->admin, 'register_more_plugins' ] + ) + ->andReturn( null ); + $this->admin->register_admin_menu(); $this->assertConditionsMet();