Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save l00f00/b19d98de5b7d3ce7b5af7bb7d11eeefd to your computer and use it in GitHub Desktop.
Save l00f00/b19d98de5b7d3ce7b5af7bb7d11eeefd to your computer and use it in GitHub Desktop.
A custom component that encodes an email address, how-to-write-a-custom-oxygen-element-using-a-code-snippet
//CREDITS https://wpcodebox.com/how-to-write-a-custom-oxygen-element-using-a-code-snippet/
<?php
add_action('plugins_loaded', function() {
class EncodeEmail extends OxyEl {
function init() {
}
function afterInit() {
$this->removeApplyParamsButton();
}
function name() {
return 'Obfuscated Email';
}
function slug() {
return "obfuscated-email";
}
function icon() {
return CT_FW_URI . '/toolbar/UI/oxygen-icons/add-icons/loginform.svg';
}
function controls() {
$email_control = $this->addOptionControl(
array(
"type" => 'textfield',
"name" => 'Enter Email',
"slug" => 'email'
)
);
$email_control->rebuildElementOnChange();
}
function render($options, $defaults, $content) {
?>
<?php echo $this->encode_email_address($options['email']); ?>
<?php
}
/**
* Encode an email address to display on your website
*/
function encode_email_address( $email ) {
$output = '';
for ($i = 0; $i < strlen($email); $i++)
{
$output .= '&#'.ord($email[$i]).';';
}
$output = $output;
return $output;
}
}
new EncodeEmail();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment