Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.52 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Loads the custom Tailor element(s).
  5. */
  6. function hb_tailor_load_custom_element() {
  7. /**
  8. * Creates a Full Width Section.
  9. */
  10.  
  11. if ( class_exists( 'Tailor_Element' ) && ! class_exists( 'Tailor_Full_Width_Section_Element' ) ) {
  12. /**
  13. * Tailor custom wrapper element class.
  14. */
  15. class Tailor_Full_Width_Section_Element extends Tailor_Element {
  16. /**
  17. * Registers element settings, sections and controls.
  18. *
  19. * @access protected
  20. */
  21. protected function register_controls() {
  22.  
  23. $this->add_section( 'general', array(
  24. 'title' => __( 'General' ),
  25. 'priority' => 10,
  26. ) );
  27. $this->add_section( 'colors', array(
  28. 'title' => __( 'Colors' ),
  29. 'priority' => 30,
  30. ) );
  31. $this->add_section( 'attributes', array(
  32. 'title' => __( 'Attributes' ),
  33. 'priority' => 40,
  34. ) );
  35. $priority = 0;
  36. // Add as many custom settings as you like..
  37. $this->add_setting( 'title', array(
  38. 'sanitize_callback' => 'tailor_sanitize_text',
  39. 'default' => 'Full Width Section',
  40. ) );
  41. $this->add_control( 'title', array(
  42. 'label' => __( 'Full Width Section' ),
  43. 'type' => 'text',
  44. 'section' => 'general',
  45. 'priority' => $priority += 10,
  46. ) );
  47. $this->add_setting( 'description', array(
  48. 'sanitize_callback' => 'tailor_sanitize_text',
  49. ) );
  50. $this->add_control( 'description', array(
  51. 'label' => __( 'A section for heros and other elements that need to be full width' ),
  52. 'type' => 'text',
  53. 'section' => 'general',
  54. 'priority' => $priority += 10,
  55. ) );
  56.  
  57. // See the custom content element for an example of how to use/modify standard control types
  58. $general_control_types = array();
  59. $general_control_arguments = array();
  60. tailor_control_presets( $this, $general_control_types, $general_control_arguments, $priority );
  61. // Standard color settings..
  62. $priority = 0;
  63. $color_control_types = array(
  64. 'color',
  65. 'link_color',
  66. 'heading_color',
  67. 'background_color',
  68. 'border_color',
  69. );
  70. $color_control_arguments = array();
  71. tailor_control_presets( $this, $color_control_types, $color_control_arguments, $priority );
  72. // Standard attribute settings..
  73. $priority = 0;
  74. $attribute_control_types = array(
  75. 'class',
  76. 'padding',
  77. 'margin',
  78. 'border_style',
  79. 'border_width',
  80. 'border_radius',
  81. 'shadow',
  82. 'background_image',
  83. 'background_repeat',
  84. 'background_position',
  85. 'background_size',
  86. );
  87. $attribute_control_arguments = array();
  88. tailor_control_presets( $this, $attribute_control_types, $attribute_control_arguments, $priority );
  89. }
  90. /**
  91. * Returns custom CSS rules for the element.
  92. *
  93. * @param $atts
  94. * @return array
  95. */
  96. public function generate_css( $atts ) {
  97. $css_rules = array();
  98. $excluded_control_types = array();
  99. // Just generate the default setting CSS
  100. $css_rules = tailor_css_presets( $css_rules, $atts, $excluded_control_types );
  101. return $css_rules;
  102. }
  103. }
  104. }
  105. }
  106.  
  107. add_action( 'tailor_load_elements', 'hb_tailor_load_custom_element', 20 );
  108.  
  109. /**
  110. * Registers your custom element.
  111. */
  112. function hb_tailor_register_custom_element( $element_manager ) {
  113.  
  114. // Wrapper element contain one or more content elements
  115. $element_manager->add_element( 'full_width_section_element', array(
  116. 'label' => __( 'Full Width Section' ),
  117. 'description' => __( 'A section for heros and other elements that need to be full width' ),
  118. 'type' => 'wrapper',
  119. //'badge' => __( 'Custom', 'text-domain' ), // Optional
  120. 'child_container' => '.tailor-full-width-section__content', // Optional selector for childViewContainer
  121. ) );
  122.  
  123. }
  124. add_action( 'tailor_register_elements', 'hb_tailor_register_custom_element' );
  125.  
  126. if ( ! function_exists( 'hb_tailor_shortcode_full_width_section_wrapper_element' ) ) {
  127. /**
  128. * Defines the shortcode rendering function for the custom wrapper element.
  129. *
  130. * @param array $atts
  131. * @param string $content
  132. * @param string $tag
  133. * @return string
  134. */
  135.  
  136. function hb_tailor_shortcode_full_width_section_wrapper_element( $atts, $content = null, $tag ) {
  137. /**
  138. * Filter the default shortcode attributes.
  139. *
  140. * @param array
  141. */
  142. $default_atts = apply_filters( 'tailor_shortcode_default_atts_' . $tag, array() );
  143. $atts = shortcode_atts( $default_atts, $atts, $tag );
  144. $html_atts = array(
  145. 'id' => empty( $atts['id'] ) ? null : $atts['id'],
  146. 'class' => explode( ' ', "tailor-element tailor-full-width-section {$atts['class']}" ),
  147. 'data' => array(),
  148. );
  149.  
  150. // Do something with the element settings
  151. $content = '';
  152. if ( ! empty( $atts['title'] ) ) {
  153. $content .= '<h2>' . esc_attr( $atts['title'] ) . '</h2>';
  154. }
  155. if ( ! empty( $atts['description'] ) ) {
  156. $content .= '<p>' . esc_attr( $atts['description'] ) . '</p>';
  157. }
  158.  
  159. /**
  160. * Filter the HTML attributes for the element.
  161. *
  162. * @param array $html_attributes
  163. * @param array $atts
  164. * @param string $tag
  165. */
  166. $html_atts = apply_filters( 'tailor_shortcode_html_attributes', $html_atts, $atts, $tag );
  167. $html_atts['class'] = implode( ' ', (array) $html_atts['class'] );
  168. $html_atts = tailor_get_attributes( $html_atts );
  169. $outer_html = "<div {$html_atts}>%s</div>";
  170. $inner_html = '<div class="tailor-full-width-section__content">%s</div>';
  171. $html = sprintf( $outer_html, sprintf( $inner_html, $content ) );
  172. /**
  173. * Filter the HTML for the element.
  174. *
  175. * @param string $html
  176. * @param string $outer_html
  177. * @param string $inner_html
  178. * @param string $html_atts
  179. * @param array $atts
  180. * @param string $content
  181. * @param string $tag
  182. */
  183. $html = apply_filters( 'tailor_shortcode_html', $html, $outer_html, $inner_html, $html_atts, $atts, $content, $tag );
  184. return $html;
  185. }
  186. add_shortcode( 'full_width_section_element', 'hb_tailor_shortcode_full_width_section_wrapper_element' );
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement