Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: Shortcode Stopping Next Shortcode on Page

Discussion in 'Misc WordPress Requests' started by itpcjames, Mar 19, 2018.

  1. itpcjames

    Guest

    Reply To: Shortcode Stopping Next Shortcode on Page, by itpcjames

    Yes, these were written by myself.

    As for the back to back, it is only being affected by the [business-hours] shortcode. Using a [business-phone] or [business-address] back to back, the issue is not there.

    Here’s the supplied code:

    function j3afb_ga_click($gacategory = 'None Set', $gaaction = 'None Set', $galabel = 'None Set', $gainteraction = false) {
    if($gainteraction) {
    $interaction = ", 'nonInteraction: 1'";
    }
    return "ga('itpcga.send', 'event', '".$gacategory."', '".$gaaction."', '".$galabel."'".$interaction.");";
    }

    function j3afb_build_phone($phonenum, $phonestyle, $class, $gacode, $pwrap = false, $nolink = false) {
    switch(strtolower($phonestyle)) {
    case 'dot':
    case 'dots':
    case 'period':
    case 'periods':
    $phoneareastart = '';
    $phoneareaend = '.';
    $phonedivider = '.';
    break;
    case 'hyphen':
    case 'hyphens':
    case 'dash':
    case 'dashes':
    $phoneareastart = '';
    $phoneareaend = '-';
    $phonedivider = '-';
    break;
    case 'normal':
    default:
    $phoneareastart = '(';
    $phoneareaend = ') ';
    $phonedivider = '-';
    break;
    }
    if(strlen(preg_replace('/[^0-9]/','',$phonenum)) == 7)
    $phoneformat = preg_replace("/([0-9]{3})([0-9]{4})/", "$1".$phonedivider."$2", preg_replace('/[^0-9]/','',$phonenum));
    else if(strlen(preg_replace('/[^0-9]/','',$phonenum)) == 10)
    $phoneformat = preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", $phoneareastart."$1".$phoneareaend."$2".$phonedivider."$3", preg_replace('/[^0-9]/','',$phonenum));
    else
    $phoneformat = $phonenum;

    $phonelink = '<a href="tel:'.preg_replace('/[^0-9]/','',$phonenum).'" class="phonelink" onclick="'.$gacode.'">';

    return ($pwrap ? '<p class="phonewrap '.$class.'">' : '<span class="phonewrap '.$class.'">').($nolink ? '<span class="phonelink">' : $phonelink).$phoneformat.($nolink ? '</span>' : '</a>').($pwrap ? '</p>' : '</span>');
    }

    function j3afb_build_address($businessname = '', $addressstreet, $addresssuite = '', $addresscity, $addressstate, $addresscode, $class, $nosuite = false, $nocity = false, $nostate = false, $nozip = false, $pwrap = false, $nolink = false, $breaks = '', $streetbreak = '', $suitebreak = '' ) {
    if(isset($businessname) && $businessname != '') {
    $labelset = true;
    }
    if(isset($addresssuite) && $addresssuite != '') {
    $suiteset = true;
    }

    if (isset($breaks) && $breaks != '') {
    $stdiv = $breaks;
    $sudiv = $breaks;
    } else {
    $stdiv = '<br />';
    $sudiv = '<br />';
    }
    if(isset($streetbreak) && $streetbreak != '') {
    $stdiv = $streetbreak;
    }
    if(isset($suitebreak) && $suitebreak != '') {
    $sudiv = $suitebreak;
    }

    $streetdivider = '<span class="addressstreetbreak">'.$stdiv.'</span>';
    $suitedivider = '<span class="addresssuitebreak">'.$sudiv.'</span>';

    $fulladdress = '<span class="streetwrap">'.$addressstreet.'</span>'.do_shortcode($streetdivider).($suiteset ? ($nosuite ? '' : '<span class="suitewrap">'.$addresssuite.'</span>'.do_shortcode($suitedivider)):'').($nocity ? '' : '<span class="citywrap">'.$addresscity.',</span> ').($nostate ? '' : '<span class="statewrap">'.$addressstate.'</span>').($nozip ? '' : ' '.'<span class="postalcodewrap">'.$addresscode.'</span>');

    $linkcode = '<a href="http://maps.google.com/?q='.($labelset ? $businessname.' ' : '').$addressstreet.', '.$addresscity.', '.$addressstate.', '.$addresscode.'" class="addresslink" onclick="'.$gacode.'" target="_blank">';

    return ($pwrap ? '<p class="addresswrap '.$class.'">' : '<span class="addresswrap '.$class.'">').($nolink ? '<span class="addresslink">' : $linkcode).$fulladdress.($nolink ? '</span>' : '</a>').($pwrap ? '</p>' : '</span>');
    }

    function j3afb_business_phone($atts) {
    extract(shortcode_atts(
    array( 'name' => '', 'phone' => '', 'style' => '', 'class' => '', 'gacategory' => 'call', 'gaaction' => 'call', 'galabel' => 'Site Default', 'ganoninteraction' => false, 'pwrap' => false, 'nolink' => false,), $atts )
    );

    $content = '';
    $phonenum = '';
    $businessname = '';
    $businessphonelabel = '';
    $gacode = '';

    if( !function_exists('acf_add_options_page') ) {
    return;
    }

    if(isset($style) && $style <> '') {
    $phonestyle = $style;
    } else {
    $phonestyle = get_field('business-phone-style', 'option');
    }

    $gacode = j3afb_ga_click($gacategory, $gaaction, $galabel, $ganoninteraction);

    if(have_rows('business', 'option')) {
    while(have_rows('business', 'option')) : the_row();
    $businessname = get_sub_field('business-name', 'option');
    if((strtolower($businessname) == strtolower($name)) || (isset($name) && $name == '')){
    if(have_rows('business-phones', 'option')) {
    while(have_rows('business-phones', 'option')) : the_row();
    $businessphonelabel = get_sub_field('business-phone-label', 'option');
    $phonenum = get_sub_field('business-phone-number', 'option');
    if((strtolower($businessphonelabel) == strtolower($phone)) || (isset($phone) && $phone == '')) {
    $content = j3afb_build_phone($phonenum, $phonestyle, $class, $gacode, $pwrap, $nolink);
    break;
    }
    endwhile;
    }
    }
    endwhile;
    }
    return $content;
    }

    function j3afb_business_address($atts) {
    extract(shortcode_atts(
    array( 'name' => '', 'address' => '', 'class' => '', 'gacategory' => 'directions', 'gaaction' => 'directions', 'galabel' => 'Site Default', 'ganoninteraction' => false, 'nosuite' => false, 'nocity' => false, 'nostate' => false, 'nozip' => false, 'pwrap' => false, 'nolink' => false, 'breaks' => '', 'streetbreak' => '', 'suitebreak' => ''), $atts )
    );
    $content = '';
    $businessname = '';
    $addressstreet = '';
    $addresssuite = '';
    $addresscity = '';
    $addressstate = '';
    $addresscode = '';

    if( !function_exists('acf_add_options_page') ) {
    return;
    }

    $gacode = j3afb_ga_click($gacategory, $gaaction, $galabel, $ganoninteraction);

    if(have_rows('business', 'option')) {
    while(have_rows('business', 'option')) : the_row();
    $businessname = get_sub_field('business-name', 'option');
    if((strtolower($businessname) == strtolower($name)) || (isset($name) && $name == '')){
    if(have_rows('business-address', 'option')) {
    while(have_rows('business-address', 'option')) : the_row();
    $businessaddresslabel = get_sub_field('business-address-label', 'option');
    $addressstreet = get_sub_field('business-address-street', 'option');
    $addresssuite = get_sub_field('business-address-street2', 'option');
    $addresscity = get_sub_field('business-address-city', 'option');
    if(get_sub_field('business-address-country', 'option') == 'Canada') {
    $addressstate = get_sub_field('business-address-province', 'option');
    } else {
    $addressstate = get_sub_field('business-address-state', 'option');
    }
    $addresscode = get_sub_field('business-address-postal-code', 'option');
    if((strtolower($businessaddresslabel) == strtolower($address)) || (isset($address) && $address == '')) {
    $content = j3afb_build_address($businessname, $addressstreet, $addresssuite, $addresscity, $addressstate, $addresscode, $class, $nosuite, $nocity, $nostate, $nozip, $pwrap, $nolink, $breaks, $streetbreak, $suitebreak);
    break;
    }
    endwhile;
    }
    }
    endwhile;
    }
    return $content;
    }

    function j3afb_build_day_hours($skipday = false, $dayopen = false, $day, $opentime, $closetime, $specialnote = '', $dayseperator = ':', $hourseperator = '-') {
    $info = '';
    $note = '';

    if($skipday && !$dayopen) {
    return;
    }

    if(isset($specialnote) && $specialnote != '') {
    $note = '<span class="noteseperator"><br /></span><span class="specialnote">'.$specialnote.'</span>';
    }

    $info = '<p class="businesshours">';
    $info .= '<span class="daylabel">'.$day.'</span><span class="dayseperator">'.$dayseperator.'</span> ';

    if(!$dayopen) {
    $info .= '<span class="hourentry"><span class="dayclosed">Closed</span></span>';
    } else {
    $info .= '<span class="hourentry"><span class="dayopen">';
    $info .= '<span class="houropen">'.$opentime.'</span> ';
    $info .= '<span class="hourseperator">'.$hourseperator.'</span> ';
    $info .= '<span class="hourclose">'.$closetime.'</span>';
    $info .= '</span></span>';
    $info .= $note;
    }

    $info .= '</p>';

    return $info;
    }

    function j3afb_business_hours($atts) {
    $attr = shortcode_atts(array(
    'name' => '',
    'style' => '',
    'grouping' => '',
    'dayseperator' => ':',
    'hourseperator' => '-',
    'skipclosed' => false
    ), $atts );

    if( !function_exists('acf_add_options_page') ) {
    return;
    }

    $content = '';
    $daylabels = array(
    'monday' => array('full' => 'Monday', 'short' => 'Mon', 'abbr' => 'M'),
    'tuesday' => array('full' => 'Tuesday', 'short' => 'Tues', 'abbr' => 'T'),
    'wednesday' => array('full' => 'Wednesday', 'short' => 'Wed', 'abbr' => 'W'),
    'thursday' => array('full' => 'Thursday', 'short' => 'Thurs', 'abbr' => 'Th'),
    'friday' => array('full' => 'Friday', 'short' => 'Fri', 'abbr' => 'F'),
    'saturday' => array('full' => 'Saturday', 'short' => 'Sat', 'abbr' => 'Sa'),
    'sunday' => array('full' => 'Sunday', 'short' => 'Sun', 'abbr' => 'Su')
    );

    if(have_rows('business', 'option')) {
    while(have_rows('business', 'option')) : the_row();
    $businessname = get_sub_field('business-name', 'option');
    if((strtolower($businessname) == strtolower($attr['name'])) || (isset($attr['name']) && $attr['name'] == '')) {
    if(isset($attr['style']) && $attr['style'] == ''){
    $attr['style'] = get_sub_field('day_name_style', 'option');
    }
    if(isset($attr['grouping']) && $attr['grouping'] == ''){
    $attr['grouping'] = get_sub_field('day_group_style', 'option');
    }
    if(isset($attr['skipclosed']) && $attr['skipclosed'] == ''){
    $attr['skipclosed'] = get_sub_field('skip_closed_days', 'option');
    }
    $content = '';

    $daysinfo = array(
    'monday' => get_sub_field('hours_mon'),
    'tuesday' => get_sub_field('hours_tues'),
    'wednesday' => get_sub_field('hours_wed'),
    'thursday' => get_sub_field('hours_thurs'),
    'friday' => get_sub_field('hours_fri'),
    'saturday' => get_sub_field('hours_sat'),
    'sunday' => get_sub_field('hours_sun')
    );
    $dayset = array(
    'monday' => false,
    'tuesday' => false,
    'wednesday' => false,
    'thursday' => false,
    'friday' => false,
    'saturday' => false,
    'sunday' => false
    );
    $daynames = array_keys($daysinfo);

    if($attr['grouping'] == 'span') {
    for($i=0;$i<count($daysinfo);$i++) {
    $currentday = '';
    if(!$dayset[$daynames[$i]]) {
    $daylabel = $daylabels[$daynames[$i]][strtolower($attr['style'])];
    for($y=$i+1;$y<count($daysinfo);$y++){
    if($daysinfo[$daynames[$y]]['hours_open'] && $daysinfo[$daynames[$i]]['hours_open_time'] === $daysinfo[$daynames[$y]]['hours_open_time'] && $daysinfo[$daynames[$i]]['hours_close_time'] === $daysinfo[$daynames[$y]]['hours_close_time']) {
    $currentday = $daylabels[$daynames[$y]][strtolower($attr['style'])];
    $dayset[$daynames[$y]] = true;
    } else {
    break;
    }
    }
    if(isset($currentday) && $currentday != '') {
    $daylabel .= ' - '.$currentday;
    }
    $dayset[$daynames[$i]] = true;
    $content .= j3afb_build_day_hours($attr['skipclosed'],$daysinfo[$daynames[$i]]['hours_open'],$daylabel,$daysinfo[$daynames[$i]]['hours_open_time'],$daysinfo[$daynames[$i]]['hours_close_time'],$daysinfo[$daynames[$i]]['hours_note'],$attr['dayseperator'],$attr['hourseperator']);
    }
    }
    } else if($attr['grouping'] == 'group') {
    for($i=0;$i<count($daysinfo);$i++) {
    if(!$dayset[$daynames[$i]]) {
    $daylabel = $daylabels[$daynames[$i]][$attr['style']];
    for($y=$i+1;$y<count($daysinfo);$y++){
    if($daysinfo[$daynames[$y]]['hours_open'] && $daysinfo[$daynames[$i]]['hours_open_time'] === $daysinfo[$daynames[$y]]['hours_open_time'] && $daysinfo[$daynames[$i]]['hours_close_time'] === $daysinfo[$daynames[$y]]['hours_close_time']) {
    $dayset[$daynames[$y]] = true;
    $daylabel .= ', '.$daylabels[$daynames[$y]][$attr['style']];
    }
    }
    $dayset[$daynames[$i]] = true;
    $content .= j3afb_build_day_hours($attr['skipclosed'],$daysinfo[$daynames[$i]]['hours_open'],$daylabel,$daysinfo[$daynames[$i]]['hours_open_time'],$daysinfo[$daynames[$i]]['hours_close_time'],$daysinfo[$daynames[$i]]['hours_note'],$attr['dayseperator'],$attr['hourseperator']);
    }
    }
    } else {
    foreach($daysinfo as $dayname => $values) {
    $content .= j3afb_build_day_hours($attr['skipclosed'],$values['hours_open'],$daylabels[$dayname][strtolower($attr['style'])],$values['hours_open_time'],$values['hours_close_time'],$values['hours_note'],$attr['dayseperator'],$attr['hourseperator']);
    }
    }
    break;
    }
    endwhile;
    }
    return $content;
    }

    add_shortcode('clinic-phone', 'j3afb_business_phone');
    add_shortcode('business-phone', 'j3afb_business_phone');

    add_shortcode('clinic-address', 'j3afb_business_address');
    add_shortcode('business-address', 'j3afb_business_address');

    add_shortcode('clinic-hours', 'j3afb_business_hours');
    add_shortcode('business-hours', 'j3afb_business_hours');

    Reply To: Shortcode Stopping Next Shortcode on Page
     
    #1

Share This Page

Monarch Social Sharing Plugin