advantage_Marketing

The Advantage advantage Marketing class.

Defined (1)

The class is defined in the following location(s).

/inc/widgets.php  
  1. class advantage_Marketing extends WP_Widget { 
  2. function __construct() { 
  3. WP_Widget::__construct( 
  4. 'widget_advantage_marketing',  
  5. __( '(advantage) Marketing', 'advantage' ),  
  6. array( 
  7. 'classname' => 'marketing',  
  8. 'description' => __( 'Display image, headline and action button', 'advantage' ),  
  9. ); 
  10. // Widget outputs 
  11. function widget( $args, $instance ) { 
  12. extract( $args, EXTR_SKIP ); 
  13. $instance = wp_parse_args($instance, $this->widget_defaults()); 
  14. extract( $instance, EXTR_SKIP ); 
  15. $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base);  
  16.  
  17. echo $before_widget;  
  18. if ( ! empty( $title ) ) { 
  19. echo $before_title; 
  20. echo $title; 
  21. echo $after_title; 
  22. }  
  23.  
  24. if ( ! empty( $image ) ) { 
  25. if ( ! empty( $action_url ) ) 
  26. echo '<a href="' . esc_url( $action_url ) . '">'; 
  27. echo wp_get_attachment_image( $image, advantage_thumbnail_size( $thumbnail ) ); 
  28. if ( ! empty( $action_url ) ) 
  29. echo '</a>';  
  30.  
  31. if ( ! empty( $headline ) ) 
  32. echo '<h2>' . esc_attr( $headline ) . '</h2>'; 
  33. if ( ! empty( $tagline ) ) 
  34. echo do_shortcode( $tagline ); 
  35. if ( ! empty( $action_url ) && ! empty( $action_label ) ) { 
  36. echo '<p><a href="' . esc_url( $action_url ); 
  37. echo '" class="action-label btn btn-' . esc_attr( $action_color ) . '">'; 
  38. echo esc_attr( $action_label ) . '</a></p>'; 
  39.  
  40. echo $after_widget; 
  41.  
  42. // Update options 
  43. function update( $new, $old ) { 
  44. $instance = $old; 
  45. $instance['title'] = strip_tags( $new['title'] ); 
  46. $instance['headline'] = wp_kses_stripslashes($new['headline']); 
  47. $instance['tagline'] = wp_kses_stripslashes($new['tagline']); 
  48. $instance['image'] = $new['image']; 
  49. $instance['thumbnail'] = $new['thumbnail']; 
  50. $instance['action_url'] = esc_url_raw($new['action_url']); 
  51. $instance['action_label'] = wp_kses_stripslashes($new['action_label']); 
  52.  
  53. $instance['action_color'] = wp_kses_stripslashes( $new['action_color'] ); 
  54.  
  55. return $instance; 
  56.  
  57. function widget_defaults() { 
  58. return array( 
  59. 'title' => '',  
  60. 'headline' => '',  
  61. 'tagline' => '',  
  62. 'image' => '',  
  63. 'action_url' => '',  
  64. 'action_label' => 'Learn More',  
  65. 'action_color' => 'primary',  
  66. 'thumbnail' => 'large',  
  67. ); 
  68.  
  69. // Display options 
  70. function form( $instance ) { 
  71. $instance = wp_parse_args( $instance, $this->widget_defaults() ); 
  72. advantage_widget_field( $this, array ( 'field' => 'title', 'label' => __( 'Title:', 'advantage' ) ), $instance['title'] ); 
  73. advantage_widget_field( $this, array ( 'field' => 'image', 'label' => __( 'Image:', 'advantage' ), 'type' => 'media' ), $instance['image'] ); 
  74. advantage_widget_field( $this, array ( 'field' => 'thumbnail', 'type' => 'select', 'label' => __( 'Image Size:', 'advantage' ), 'options' => advantage_thumbnail_array(), 'class' => '' ), $instance['thumbnail'] ); 
  75. if ( $instance['image'] ) 
  76. echo wp_get_attachment_image( $instance['image'], advantage_thumbnail_size( $instance['thumbnail'] ), false, array( 'class' => 'widget-image' ) ); 
  77. advantage_widget_field( $this, array ( 'field' => 'headline', 'label' => __( 'Headline:', 'advantage' ) ), $instance['headline'] ); 
  78. advantage_widget_field( $this, array ( 'field' => 'tagline', 'label' => __( 'Tagline:', 'advantage' ), 'type' => 'textarea' ), $instance['tagline'] ); 
  79. advantage_widget_field( $this, array ( 'field' => 'action_url', 'label' => __( 'Action URL:', 'advantage' ), 'type' => 'url' ), $instance['action_url'] ); 
  80. advantage_widget_field( $this, array ( 'field' => 'action_label', 'label' => __( 'Action Label:', 'advantage' ) ), $instance['action_label'] ); 
  81. advantage_widget_field( $this, array ( 'field' => 'action_color', 'type' => 'select', 'label' => __( 'Action Button: ', 'advantage' ),  
  82. 'options' => array ( 
  83. array( 'key' => 'primary',  
  84. 'name' => __( 'Primary', 'advantage' ) ),  
  85. array( 'key' => 'info',  
  86. 'name' => __( 'Info', 'advantage' ) ),  
  87. array( 'key' => 'warning',  
  88. 'name' => __( 'Warning', 'advantage' ) ),  
  89. array( 'key' => 'danger',  
  90. 'name' => __( 'Danger', 'advantage' ) ),  
  91. array( 'key' => 'success',  
  92. 'name' => __( 'Success', 'advantage' ) ),  
  93. array( 'key' => 'custom1',  
  94. 'name' => __( 'Custom 1', 'advantage' ) ),  
  95. array( 'key' => 'custom2',  
  96. 'name' => __( 'Custom 2', 'advantage' ) ),  
  97. ),  
  98. 'class' => '' ), $instance['action_color'] );