Created
July 17, 2026 14:25
-
-
Save Crocoblock/2af1fa5ab01fbefb6001428b714ccd0c to your computer and use it in GitHub Desktop.
URL contains macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action( 'jet-engine/register-macros', function() { | |
| class URL_Contains extends \Jet_Engine_Base_Macros { | |
| public function macros_tag() { | |
| return 'url_contains'; | |
| } | |
| public function macros_name() { | |
| return 'URL Contains'; | |
| } | |
| public function macros_args() { | |
| return array( | |
| 'needle' => array( | |
| 'label' => 'Text to search', | |
| 'type' => 'text', | |
| 'default' => '', | |
| ), | |
| ); | |
| } | |
| public function macros_callback( $args = array() ) { | |
| $needle = ! empty( $args['needle'] ) ? $args['needle'] : ''; | |
| if ( empty( $needle ) ) { | |
| return 0; | |
| } | |
| $request_uri = $_SERVER['REQUEST_URI'] ?? ''; | |
| return strpos( $request_uri, $needle ) !== false ? 1 : 0; | |
| } | |
| } | |
| new URL_Contains(); | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment