Created
April 20, 2016 17:27
-
-
Save Reedyseth/c7eaa9bb38a4e7ed704d35c4be612c55 to your computer and use it in GitHub Desktop.
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 | |
/* | |
Author: WP Sharks | |
Author URI: https://wpsharks.com | |
Version: 1.0 | |
Plugin Name: Alert Box Shortcode | |
Description: Provides an `[alert_box]` shortcode. | |
Plugin URI: https://wordpress.org/plugins/alert-box-shortcode/ | |
Text Domain: alert-box-shortcode | |
*/ | |
add_action('plugins_loaded', function () { | |
add_shortcode('alert_box', 'alert_box'); | |
}); | |
function alert_box($attr, $content, $shortcode) | |
{ | |
static $counter = 0; | |
$id = 'alert-box-'.$counter; | |
$short_code_content; | |
$attr = shortcode_atts( | |
[ | |
'border_width' => '1px', | |
'background_color' => '#ffe6e6', | |
'border_color' => '#ff8080', | |
'text_color' => '#000000', | |
'link_color' => '#b30000', | |
'link_hover_color' => '#4d0000', | |
'border_radius' => '.25em', | |
'padding' => '1em', | |
'style' => '' | |
], | |
$attr, | |
$shortcode | |
); | |
$css = ' | |
<style type="text/css"> | |
#'.$id.' { | |
border-width: '.$attr['border_width'].'; | |
background-color: '.$attr['background_color'].'; | |
border-radius: '.$attr['border_radius'].'; | |
padding: '.$attr['padding'].'; | |
color: '.$attr['text_color'].'; | |
} | |
#'.$id.' a { | |
color: '.$attr['link_color'].'; | |
} | |
#'.$id.' a:hover { | |
color: '.$attr['link_hover_color'].'; | |
} | |
</style> | |
'; | |
$counter++; | |
$style = ""; | |
if( isset( $attr[ 'style' ] ) ) | |
{ | |
$style = 'style="'.$attr[ 'style' ] . '"'; | |
} | |
$short_code_content = $css; // Styles from above. | |
$short_code_content .= '<div id="'.esc_attr($id).'" '. $style .'>'; | |
$short_code_content .= trim($content); | |
$short_code_content .= '</div>'; | |
return $short_code_content; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment