Skip to content

Instantly share code, notes, and snippets.

@VictorPietro
Created February 10, 2025 22:47
Show Gist options
  • Save VictorPietro/0f6becb375a306c03caf4ab8178cfb35 to your computer and use it in GitHub Desktop.
Save VictorPietro/0f6becb375a306c03caf4ab8178cfb35 to your computer and use it in GitHub Desktop.
Jet Engine - Add Current Website Macro
<?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