Advertisement
Guest User

Untitled

a guest
May 27th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class Cool_Shortcode_Name {
  5. static $add_script;
  6.  
  7. static function init() {
  8. add_shortcode('cool_shortcode_name', array(__CLASS__, 'handle_shortcode'));
  9.  
  10. add_action('init', array(__CLASS__, 'register_script'));
  11.  
  12. add_action('wp_footer', array(__CLASS__, 'print_script'));
  13.  
  14. add_action('wp_footer', array(__CLASS__, 'internal_script') );
  15. }
  16.  
  17. static function handle_shortcode($raw_atts) {
  18. self::$add_script = true;
  19.  
  20. $atts = shortcode_atts( array(
  21. 'argument' => 'default',
  22. ), $raw_atts, 'cool_shortcode_name' );
  23.  
  24.  
  25.  
  26. ob_start();
  27. ?>
  28.  
  29. <div>
  30. Template!
  31. </div>
  32.  
  33. <?php
  34. $content = ob_get_clean();
  35.  
  36. return $content;
  37. }
  38.  
  39. static function register_script() {
  40. //wp_register_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(), '4.1.0', 'screen' );
  41. //wp_register_script('imagesloaded', '//cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.0.4/jquery.imagesloaded.js', array('jquery'), '3.0.4', true);
  42. }
  43.  
  44. static function print_script() {
  45. if ( ! self::$add_script )
  46. return;
  47. //wp_print_styles('font-awesome');
  48. //wp_print_scripts('imagesloaded');
  49. }
  50.  
  51. static function internal_script() {
  52. if ( ! self::$add_script )
  53. return;
  54. ?>
  55.  
  56. <script type="text/javascript">
  57. // Javascript goes here
  58. </script>
  59.  
  60. <style>
  61.  
  62. /* CSS Goes Here */
  63.  
  64. </style>
  65. <?php
  66. }
  67. }
  68.  
  69. Cool_Shortcode_Name::init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement