-
-
Save Crocoblock/ae6ed393e1575c13cc4c40dc4d213740 to your computer and use it in GitHub Desktop.
JetEngine. Example of custom macros registration based on Jet_Engine_Base_Macros class
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! Always include mcros file only on 'jet-engine/register-macros' hook - before base class is not avaialable, | |
* after - all macros already registered and you can't insert a new one. | |
*/ | |
add_action( 'jet-engine/register-macros', function() { | |
require_once get_theme_file_path( 'macros.php' ); | |
new My_JE_Macros(); | |
} ); |
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 | |
/** | |
* Required methods: | |
* macros_tag() - here you need to set macros tag for JetEngine core | |
* macros_name() - here you need to set human-readable macros name for different UIs where macros are available | |
* macros_callback() - the main function of the macros. Returns the value | |
* macros_args() - Optional, arguments list for the macros. Arguments format is the same ad for Elementor controls | |
*/ | |
class My_JE_Macros extends Jet_Engine_Base_Macros { | |
/** | |
* Returns macros tag | |
* | |
* @return string | |
*/ | |
public function macros_tag() { | |
return 'my_macros'; | |
} | |
/** | |
* Returns macros name | |
* | |
* @return string | |
*/ | |
public function macros_name() { | |
return 'My Macros'; | |
} | |
/** | |
* Callback function to return macros value | |
* | |
* @return string | |
*/ | |
public function macros_callback( $args = array() ) { | |
var_dump( $args ); | |
return 'macros value'; | |
} | |
/** | |
* Optionally return custom macros attributes array | |
* | |
* @return array | |
*/ | |
public function macros_args() { | |
return array( | |
'arg_1' => array( | |
'label' => __( 'Arg 1', 'jet-engine' ), | |
'type' => 'text', | |
'default' => '', | |
), | |
'arg_2' => array( | |
'label' => __( 'Arg 2', 'jet-engine' ), | |
'type' => 'text', | |
'default' => '', | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment