diff --git a/classes/class-connector.php b/classes/class-connector.php index 863d9a6f8..066baf9e3 100644 --- a/classes/class-connector.php +++ b/classes/class-connector.php @@ -110,7 +110,7 @@ public function unregister() { */ public function callback() { $action = current_filter(); - $callback = array( $this, 'callback_' . preg_replace( '/[^a-z0-9_\-]/', '_', $action ) ); + $callback = array( $this, 'callback_' . preg_replace( '/[^a-z0-9_]/', '_', $action ) ); // For the sake of testing, trigger an action with the name of the callback. if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) { diff --git a/tests/tests/test-class-connector.php b/tests/tests/test-class-connector.php index c9342359d..15df3b5f7 100644 --- a/tests/tests/test-class-connector.php +++ b/tests/tests/test-class-connector.php @@ -27,6 +27,7 @@ public function setUp(): void { */ public $actions = array( 'simulate_fault', + 'hyphenated-action', ); /** @@ -69,6 +70,17 @@ public function callback_simulate_fault() { // This is used to check if this callback method actually ran do_action( 'wp_stream_test_child_callback_simulate_fault' ); } + + /** + * Log the hyphenated action callback. + * + * @action hyphenated-action + * + * @return void + */ + public function callback_hyphenated_action() { + do_action( 'wp_stream_test_child_callback_hyphenated_action' ); + } }; $this->assertNotEmpty( $this->connector ); @@ -111,6 +123,17 @@ public function test_callback() { $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'child_callback_' . $action ) ); } + public function test_callback_hyphenated() { + global $wp_current_filter; + $action = $this->connector->actions[1]; + $wp_current_filter[] = $action; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + + $this->connector->callback(); + + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_hyphenated_action' ) ); + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'child_callback_hyphenated_action' ) ); + } + public function test_action_links() { $current_links = array( 'IMDB' => '',