ajayver

Untitled

Jun 9th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.10 KB | None | 0 0
  1. add_action( 'after_setup_theme', 'child_theme_setup', 20 );
  2.  
  3. function child_theme_setup() {
  4.     remove_shortcode( 'vc_actionbox' );
  5.     add_shortcode( 'vc_actionbox', 'my_actionbox' );
  6. }
  7.  
  8.  
  9. function my_actionbox ($attributes, $content)
  10. {
  11.     $attributes = shortcode_atts(
  12.         array(
  13.             'type' => 'grey',
  14.             'controls' => 'right',
  15.             'title' => 'ActionBox title',
  16.             'title_size' => 'h2',
  17.             'message' => '',
  18.             'button1' => '',
  19.             'link1' => '',
  20.             'style1' => 'default',
  21.             'size1' => '',
  22.             'button2' => '',
  23.             'link2' => '',
  24.             'style2' => 'default',
  25.             'size2' => '',
  26.             'animate' => '',
  27.             'target1' => '',
  28.             'target2' => '',
  29.         ), $attributes);
  30.  
  31.     $animate_class = ($attributes['animate'] != '')?' animate_'.$attributes['animate']:'';
  32.  
  33.     $controls_position_class = ($attributes['controls'] != 'bottom')?' at_right':'';
  34.     $actionbox_controls_position_class = ($attributes['controls'] != 'bottom')?' controls_aside':'';
  35.  
  36.  
  37.     $output =   '<div class="w-actionbox color_'.$attributes['type'].$actionbox_controls_position_class.$animate_class.'">'.
  38.         '<div class="w-actionbox-h">'.
  39.         '<div class="w-actionbox-text">';
  40.     if ($attributes['title'] != '')
  41.     {
  42.         $output .=          '<h3>'.html_entity_decode($attributes['title']).'</h3>';
  43.     }
  44.     if ($attributes['message'] != '')
  45.     {
  46.         $output .=          '<p>'.html_entity_decode($attributes['message']).'</p>';
  47.     }
  48.  
  49.  
  50.     $output .=          '</div>'.
  51.         '<div class="w-actionbox-controls'.$controls_position_class.'">';
  52.  
  53.     if ($attributes['button1'] != '' AND $attributes['link1'] != '')
  54.     {
  55.         $colour_class = ($attributes['style1'] != '')?' type_'.$attributes['style1']:'';
  56.         $size_class = ($attributes['size1'] != '')?' size_'.$attributes['size1']:'';
  57.         $output .=          '<a class="w-actionbox-button g-btn'.$size_class.$colour_class.'" href="'.$attributes['link1'].'"';
  58.         if ($attributes['target1'] != '') {
  59.             $output .= ' target="'.$attributes['target1'].'"';
  60.         }
  61.         $output .= '><span>'.$attributes['button1'].'</span></a>';
  62.     }
  63.  
  64.     if ($attributes['button2'] != '' AND $attributes['link2'] != '')
  65.     {
  66.         $colour_class = ($attributes['style2'] != '')?' type_'.$attributes['style2']:'';
  67.         $size_class = ($attributes['size2'] != '')?' size_'.$attributes['size2']:'';
  68.         $output .=          '<a class="w-actionbox-button g-btn'.$size_class.$colour_class.'" href="'.$attributes['link2'].'"';
  69.         if ($attributes['target2'] != '') {
  70.             $output .= ' target="'.$attributes['target2'].'"';
  71.         }
  72.         $output .= '><span>'.$attributes['button2'].'</span></a>';
  73.     }
  74.  
  75.     $output .=          '</div>'.
  76.         '</div>'.
  77.         '</div>';
  78.     return $output;
  79. }
  80.  
  81. add_action('init', function()
  82. {
  83.     $shortcode_vc_actionbox_tmp = WPBMap::getShortCode('vc_actionbox');
  84.  
  85.     $target_arr = array(__("Same tab", "js_composer") => "", __("New tab", "js_composer") => "_blank");
  86.  
  87.     $shortcode_vc_actionbox_tmp['params'] = array(
  88.         array(
  89.             "type" => "dropdown",
  90.             "heading" => __("ActionBox Color", "js_composer"),
  91.             "param_name" => "type",
  92.             "value" => array(__('Primary Color', "js_composer") => "primary", __('Alternate Color', "js_composer") => "alternate",),
  93.             "description" => ''
  94.         ),
  95.         array(
  96.             "type" => "dropdown",
  97.             "heading" => __("Buttons Position", "js_composer"),
  98.             "param_name" => "controls",
  99.             "value" => array(__('Right', "js_composer") => "right", __('Bottom', "js_composer") => "bottom",),
  100.             "description" => '',
  101.         ),
  102.         array(
  103.             "type" => "textfield",
  104.             "heading" => __("ActionBox Title", "js_composer"),
  105.             "param_name" => "title",
  106.             "holder" => "div",
  107.             "value" => __("This is ActionBox", "js_composer"),
  108.             "description" => ''
  109.         ),
  110.         array(
  111.             "type" => "textarea",
  112.             "heading" => __("ActionBox Text", "js_composer"),
  113.             "param_name" => "message",
  114.             "value" => '',
  115.             "description" => ''
  116.         ),
  117.         array(
  118.             "type" => "textfield",
  119.             "heading" => __("Button 1 Label", "js_composer"),
  120.             "param_name" => "button1",
  121.             "value" => "",
  122.             "description" => ''
  123.         ),
  124.         array(
  125.             "type" => "textfield",
  126.             "heading" => __("Button 1 Link", "js_composer"),
  127.             "param_name" => "link1",
  128.             "value" => "",
  129.             "description" => ''
  130.         ),
  131.         array(
  132.             "type" => "dropdown",
  133.             "heading" => __("Button 1 Color", "js_composer"),
  134.             "param_name" => "style1",
  135.             "value" => array(__("Default (theme color)", "js_composer") => "default", __("Primary (theme color)", "js_composer") => "primary", __("Secondary (theme color)", "js_composer") => "secondary", __("Outlined with Transparent Background", "js_composer") => "outline", __("Pink", "js_composer") => "pink", __("Blue", "js_composer") => "blue", __("Green", "js_composer") => "green", __("Yellow", "js_composer") => "yellow", __("Purple", "js_composer") => "purple", __("Red", "js_composer") => "red", __("Lime", "js_composer") => "lime", __("Navy", "js_composer") => "navy", __("Cream", "js_composer") => "cream", __("Brown", "js_composer") => "brown", __("Midnight", "js_composer") => "midnight", __("Teal", "js_composer") => "teal"),
  136.             "description" => '',
  137.         ),
  138.         array(
  139.             "type" => "dropdown",
  140.             "heading" => __("Button 1 Size", "js_composer"),
  141.             "param_name" => "size1",
  142.             "value" => array(__("Normal", "js_composer") => "", __("Small", "js_composer") => "small", __("Big", "js_composer") => "big"),
  143.  
  144.         ),
  145.         array(
  146.             "type" => "dropdown",
  147.             "heading" => __("Button 1 Target", "js_composer"),
  148.             "param_name" => "target1",
  149.             "value" => $target_arr,
  150.         ),
  151.         array(
  152.             "type" => "textfield",
  153.             "heading" => __("Button 2 Label", "js_composer"),
  154.             "param_name" => "button2",
  155.             "value" => "",
  156.             "description" => ''
  157.         ),
  158.         array(
  159.             "type" => "textfield",
  160.             "heading" => __("Button 2 Link", "js_composer"),
  161.             "param_name" => "link2",
  162.             "value" => "",
  163.             "description" => ''
  164.         ),
  165.         array(
  166.             "type" => "dropdown",
  167.             "heading" => __("Button 2 Color", "js_composer"),
  168.             "param_name" => "style2",
  169.             "value" => array(__("Default (theme color)", "js_composer") => "default", __("Primary (theme color)", "js_composer") => "primary", __("Secondary (theme color)", "js_composer") => "secondary", __("Outlined with Transparent Background", "js_composer") => "outline", __("Pink", "js_composer") => "pink", __("Blue", "js_composer") => "blue", __("Green", "js_composer") => "green", __("Yellow", "js_composer") => "yellow", __("Purple", "js_composer") => "purple", __("Red", "js_composer") => "red", __("Lime", "js_composer") => "lime", __("Navy", "js_composer") => "navy", __("Cream", "js_composer") => "cream", __("Brown", "js_composer") => "brown", __("Midnight", "js_composer") => "midnight", __("Teal", "js_composer") => "teal"),
  170.             "description" => '',
  171.         ),
  172.         array(
  173.             "type" => "dropdown",
  174.             "heading" => __("Button 2 Size", "js_composer"),
  175.             "param_name" => "size2",
  176.             "value" => array(__("Normal", "js_composer") => "", __("Small", "js_composer") => "small", __("Big", "js_composer") => "big"),
  177.  
  178.         ),
  179.         array(
  180.             "type" => "dropdown",
  181.             "heading" => __("Button 2 Target", "js_composer"),
  182.             "param_name" => "target2",
  183.             "value" => $target_arr,
  184.         ),
  185.     );
  186.  
  187.     unset($shortcode_vc_actionbox_tmp['base']);
  188.  
  189.     vc_map_update('vc_actionbox', $shortcode_vc_actionbox_tmp);
  190. }, 100);
Advertisement
Add Comment
Please, Sign In to add comment