Created
February 10, 2025 22:47
-
-
Save VictorPietro/0f6becb375a306c03caf4ab8178cfb35 to your computer and use it in GitHub Desktop.
Jet Engine - Add Current Website 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 | |
/** | |
* Note! | |
* Register macros on jet-engine/register-macros action only, | |
* as the base macro class \Jet_Engine_Base_Macros is not available before that action; | |
* after it - all macros are registered already | |
*/ | |
add_action( 'jet-engine/register-macros', function(){ | |
/** | |
* Current_Website_URL class. | |
* Adds macro, that returns the current website URL. | |
* | |
* Has methods (all JetEngine macros classes should have those): | |
* macros_tag() - sets macros tag | |
* macros_name() - sets human-readable macros name for UI | |
* macros_callback() - function that returns needed value | |
*/ | |
class Current_Website_URL extends \Jet_Engine_Base_Macros { | |
/** | |
* Macros tag - this macro will look like %current_website_url% if typed manually | |
*/ | |
public function macros_tag() { | |
return 'current_website_url'; | |
} | |
/** | |
* Macros name in UI | |
*/ | |
public function macros_name() { | |
return 'Current website URL'; | |
} | |
/** | |
* Macros callback - gets the current website URL | |
*/ | |
public function macros_callback( $args = array() ) { | |
return home_url(); | |
} | |
} | |
/** | |
* Create instances of Current_User_Prop and Current_Website_URL to add the macros | |
*/ | |
new Current_Website_URL(); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment