From a4665068c6ecf870cccd9a3b09233c3c53830fe4 Mon Sep 17 00:00:00 2001 From: Ishita Jagtap <143935560+ishitaj34@users.noreply.github.com> Date: Fri, 21 Aug 2026 16:34:54 +0530 Subject: [PATCH 1/4] add: Premium_Only_Function_Check class and register check --- .../Premium_Only_Function_Check.php | 91 +++++++++++++++++++ includes/Checker/Default_Check_Repository.php | 2 + 2 files changed, 93 insertions(+) create mode 100644 includes/Checker/Checks/Plugin_Repo/Premium_Only_Function_Check.php diff --git a/includes/Checker/Checks/Plugin_Repo/Premium_Only_Function_Check.php b/includes/Checker/Checks/Plugin_Repo/Premium_Only_Function_Check.php new file mode 100644 index 000000000..84623f0e8 --- /dev/null +++ b/includes/Checker/Checks/Plugin_Repo/Premium_Only_Function_Check.php @@ -0,0 +1,91 @@ +add_result_error_for_file( + $result, + __( 'Function declarations ending in __premium_only look like premium/pro-only code and should not be included in a WordPress.org plugin.', 'plugin-check' ), + 'premium_only_function_found', + $match['file'], + $match['line'], + $match['column'], + 'https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/' + ); + } + } + } + + /** + * Gets the description for the check. + * + * Every check must have a short description explaining what the check does. + * + * @since 1.2.0 + * + * @return string Description. + */ + public function get_description(): string { + return __( 'Detects function declarations ending in __premium_only.', 'plugin-check' ); + } + + /** + * Gets the documentation URL for the check. + * + * Every check must have a URL with further information about the check. + * + * @since 1.2.0 + * + * @return string The documentation URL. + */ + public function get_documentation_url(): string { + return __( 'https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/', 'plugin-check' ); + } +} diff --git a/includes/Checker/Default_Check_Repository.php b/includes/Checker/Default_Check_Repository.php index d4d5c548d..3c335614e 100644 --- a/includes/Checker/Default_Check_Repository.php +++ b/includes/Checker/Default_Check_Repository.php @@ -14,6 +14,7 @@ */ class Default_Check_Repository extends Empty_Check_Repository { + /** * True if the class was fully initialized. * @@ -105,6 +106,7 @@ private function register_default_checks() { 'external_admin_menu_links' => new Checks\Plugin_Repo\External_Admin_Menu_Links_Check(), 'wp_functions_compatibility' => new Checks\Plugin_Repo\WP_Functions_Compatibility_Check(), 'ai_provider' => new Checks\General\AI_Provider_Check(), + 'premium_only_function' => new Checks\Plugin_Repo\Premium_Only_Function_Check(), ) ); From 507a7a9405528b20b1fb7a0eb63734dfa6587885 Mon Sep 17 00:00:00 2001 From: Ishita Jagtap <143935560+ishitaj34@users.noreply.github.com> Date: Fri, 21 Aug 2026 16:36:24 +0530 Subject: [PATCH 2/4] add: unit tests and fixtures --- .../load.php | 19 ++++++++ .../load.php | 19 ++++++++ .../Premium_Only_Function_Check_Tests.php | 45 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-premium-only-function-with-errors/load.php create mode 100644 tests/phpunit/testdata/plugins/test-plugin-premium-only-function-without-errors/load.php create mode 100644 tests/phpunit/tests/Checker/Checks/Premium_Only_Function_Check_Tests.php diff --git a/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-with-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-with-errors/load.php new file mode 100644 index 000000000..1976c5762 --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-with-errors/load.php @@ -0,0 +1,19 @@ +
Premium-only test notice.
'; +} diff --git a/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-without-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-without-errors/load.php new file mode 100644 index 000000000..f745f8a77 --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-without-errors/load.php @@ -0,0 +1,19 @@ +Standard test notice.
'; +} diff --git a/tests/phpunit/tests/Checker/Checks/Premium_Only_Function_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Premium_Only_Function_Check_Tests.php new file mode 100644 index 000000000..aa11654b8 --- /dev/null +++ b/tests/phpunit/tests/Checker/Checks/Premium_Only_Function_Check_Tests.php @@ -0,0 +1,45 @@ +run( $check_result ); + + $errors = $check_result->get_errors(); + + $this->assertNotEmpty( $errors ); + $this->assertArrayHasKey( 'load.php', $errors ); + $this->assertEquals( 2, $check_result->get_error_count() ); + + $this->assertArrayHasKey( 13, $errors['load.php'] ); + $this->assertArrayHasKey( 17, $errors['load.php'] ); + $this->assertEquals( 'premium_only_function_found', $errors['load.php'][13][1][0]['code'] ); + $this->assertEquals( 'premium_only_function_found', $errors['load.php'][17][1][0]['code'] ); + } + + public function test_run_without_errors() { + $check = new Premium_Only_Function_Check(); + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-premium-only-function-without-errors/load.php' ); + $check_result = new Check_Result( $check_context ); + + $check->run( $check_result ); + + $errors = $check_result->get_errors(); + + $this->assertEmpty( $errors ); + $this->assertEquals( 0, $check_result->get_error_count() ); + } +} From 0ac90a8040795a0a7ed385c03287d38d9c5ec984 Mon Sep 17 00:00:00 2001 From: Ishita Jagtap <143935560+ishitaj34@users.noreply.github.com> Date: Fri, 21 Aug 2026 18:57:24 +0530 Subject: [PATCH 3/4] chore: update version --- .../Checks/Plugin_Repo/Premium_Only_Function_Check.php | 10 +++++----- .../load.php | 1 - .../load.php | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/Checker/Checks/Plugin_Repo/Premium_Only_Function_Check.php b/includes/Checker/Checks/Plugin_Repo/Premium_Only_Function_Check.php index 84623f0e8..08bdf319d 100644 --- a/includes/Checker/Checks/Plugin_Repo/Premium_Only_Function_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Premium_Only_Function_Check.php @@ -16,7 +16,7 @@ /** * Check to detect functions ending in __premium_only. * - * @since 1.2.0 + * @since x.x.x */ class Premium_Only_Function_Check extends Abstract_File_Check { @@ -28,7 +28,7 @@ class Premium_Only_Function_Check extends Abstract_File_Check { * * Every check must have at least one category. * - * @since 1.2.0 + * @since x.x.x * * @return array The categories for the check. */ @@ -39,7 +39,7 @@ public function get_categories() { /** * Amends the given result by running the check on the given list of files. * - * @since 1.2.0 + * @since x.x.x * * @param Check_Result $result The check result to amend. * @param array $files List of absolute file paths. @@ -68,7 +68,7 @@ protected function check_files( Check_Result $result, array $files ) { * * Every check must have a short description explaining what the check does. * - * @since 1.2.0 + * @since x.x.x * * @return string Description. */ @@ -81,7 +81,7 @@ public function get_description(): string { * * Every check must have a URL with further information about the check. * - * @since 1.2.0 + * @since x.x.x * * @return string The documentation URL. */ diff --git a/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-with-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-with-errors/load.php index 1976c5762..ff1d13a2f 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-with-errors/load.php +++ b/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-with-errors/load.php @@ -2,7 +2,6 @@ /** * Plugin Name: Premium Only Function Test * Description: Test plugin containing functions named with the __premium_only suffix. - * Author: Monzur Alam * Version: 1.0.0 */ diff --git a/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-without-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-without-errors/load.php index f745f8a77..58209ef5a 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-without-errors/load.php +++ b/tests/phpunit/testdata/plugins/test-plugin-premium-only-function-without-errors/load.php @@ -2,7 +2,6 @@ /** * Plugin Name: Premium Only Function Clean Test * Description: Test plugin containing standard functions without __premium_only suffix. - * Author: Monzur Alam * Version: 1.0.0 */ From 953af9c0f1aef512f57ea30b35b71d6bb91ddf3d Mon Sep 17 00:00:00 2001 From: Ishita Jagtap <143935560+ishitaj34@users.noreply.github.com> Date: Fri, 21 Aug 2026 23:54:40 +0530 Subject: [PATCH 4/4] refactor: add stricter assertions --- .../Checks/Premium_Only_Function_Check_Tests.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/tests/Checker/Checks/Premium_Only_Function_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Premium_Only_Function_Check_Tests.php index aa11654b8..b4abe9aef 100644 --- a/tests/phpunit/tests/Checker/Checks/Premium_Only_Function_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Premium_Only_Function_Check_Tests.php @@ -22,12 +22,12 @@ public function test_run_with_errors() { $this->assertNotEmpty( $errors ); $this->assertArrayHasKey( 'load.php', $errors ); - $this->assertEquals( 2, $check_result->get_error_count() ); + $this->assertSame( 2, $check_result->get_error_count() ); - $this->assertArrayHasKey( 13, $errors['load.php'] ); - $this->assertArrayHasKey( 17, $errors['load.php'] ); - $this->assertEquals( 'premium_only_function_found', $errors['load.php'][13][1][0]['code'] ); - $this->assertEquals( 'premium_only_function_found', $errors['load.php'][17][1][0]['code'] ); + $this->assertArrayHasKey( 12, $errors['load.php'] ); + $this->assertArrayHasKey( 16, $errors['load.php'] ); + $this->assertSame( 'premium_only_function_found', $errors['load.php'][12][1][0]['code'] ); + $this->assertSame( 'premium_only_function_found', $errors['load.php'][16][1][0]['code'] ); } public function test_run_without_errors() { @@ -40,6 +40,6 @@ public function test_run_without_errors() { $errors = $check_result->get_errors(); $this->assertEmpty( $errors ); - $this->assertEquals( 0, $check_result->get_error_count() ); + $this->assertSame( 0, $check_result->get_error_count() ); } }