Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. /**
  3. * Class: Example Module
  4. *
  5. * @package projectname
  6. * @subpackage modules
  7. */
  8.  
  9. /**
  10. * Example Module
  11. */
  12. class Example_Module {
  13.  
  14. /**
  15. * Construct
  16. *
  17. * @param bool|string $style_uri (Optional) Specify stylesheet URI.
  18. */
  19. public function __construct( $style_uri = false ) {
  20. $this->styles( $style_uri );
  21. }
  22.  
  23. /**
  24. * Hero
  25. *
  26. * @param array $args Arguments.
  27. */
  28. public function hero( $args = array() ) {
  29. $defaults = array(
  30. 'heading' => 'Et eaque et suscipit et voluptate.',
  31. 'content' => 'Placeat sunt deleniti. Sed eum aut neque laboriosam repellendus quaerat.',
  32. );
  33.  
  34. $args = wp_parse_args( $args, $defaults );
  35.  
  36. ob_start();
  37. ?>
  38. <div class="hero">
  39. <h1 class="hero__heading"><?php echo esc_html( $args['heading'] ); ?></h1>
  40. <div class="hero__content">
  41. <?php echo wp_kses_post( $args['content'] ); ?>
  42. </div>
  43. </div>
  44. <?php
  45. echo wp_kses_post( ob_get_clean() );
  46. }
  47.  
  48. /**
  49. * Styles
  50. *
  51. * @param bool|string $style_uri External stylesheet.
  52. */
  53. private function styles( $style_uri = false ) {
  54. ob_start();
  55. ?>
  56. <style>
  57. .hero {
  58. background: #ddd;
  59. padding: 2em 6em;
  60. }
  61.  
  62. .hero__heading {
  63. font-size: 2em;
  64. }
  65.  
  66. .hero__content {
  67. max-width: 600px;
  68. }
  69. </style>
  70. <?php
  71. wp_register_style( 'case-study', $style_uri, array(), '1.0.0' );
  72. wp_enqueue_style( 'case-study' );
  73. wp_add_inline_style( 'case-study', ob_get_clean() );
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement