Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Modified Company Address shortcode to automatically include <ul> ta… #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions CleanBuild/functions/acf/acf-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ function company_reg_func( $atts ){
// COMPANY OPENING HOURS SHORTCODE
function company_opening_hours_func( $atts ){
$a = shortcode_atts( array(
'container' => 'false',
'container' => false,
), $atts );
$container = esc_attr($a['container']);
$html = '';
if($container == 'true') {
if($container === true) {
$html .= '<div class="opening-hours">';
}
while ( have_rows('company_opening_hours','company') ) : the_row();
$html .= '<p>'. get_sub_field('time') .'</p>';
endwhile;
if($container == 'true') {
if($container === true) {
$html .= '</div>';
}

Expand All @@ -38,9 +38,9 @@ function company_opening_hours_func( $atts ){
// EMAIL ADDRESS SHORTCODE
function company_email_address_func( $atts ){
$a = shortcode_atts( array(
'link' => 'false',
'link' => false,
'row' => '1',
'quick-link' => 'false',
'quick-link' => false,
), $atts );

$link = esc_attr($a['link']);
Expand All @@ -55,10 +55,10 @@ function company_email_address_func( $atts ){
$email = antispambot(get_sub_field('email_address'), 0);

if($row == $counter) {
if($quick == 'true') {
if($quick === true) {
$html .= '<a href="mailto:' . $email . '?subject='. $company .' (Website enquiry)" class="email-link">'. $email .'</a>';
} else {
if ($link == 'true'){
if ($link === true){
$html .= 'mailto:' . $email . '?subject='. $company .' (Website enquiry)';
} else {
$html .= $email;
Expand All @@ -75,9 +75,9 @@ function company_email_address_func( $atts ){
// PHONE NUMBER SHORTCODE
function company_phone_number_func( $atts ){
$a = shortcode_atts( array(
'link' => 'false',
'link' => false,
'row' => '1',
'quick-link' => 'false',
'quick-link' => false,
), $atts );

$link = esc_attr($a['link']);
Expand All @@ -100,10 +100,10 @@ function company_phone_number_func( $atts ){
}

if($row == $counter) {
if($quick == 'true') {
if($quick === true) {
$html .= '<a href="tel:' . $number_link . '" class="phone-link">'. $number .'</a>';
} else {
if ($link == 'true'){
if ($link === true){
$html .= 'tel:' . $number_link;
} else {
$html .= $number;
Expand All @@ -114,7 +114,7 @@ function company_phone_number_func( $atts ){

return $html;

if ($link == 'true'){
if ($link === true){
return $number_link;
} else {
return $number;
Expand All @@ -134,30 +134,52 @@ function company_fax_number_func( $atts ){
function company_address_func( $atts ){
$a = shortcode_atts( array(
'row' => '1',
'include-name' => 'false',
'container' => 'false',
'include-name' => false,
'container' => true,
'list' => true,
'line-break' => false,
), $atts );

$row = esc_attr($a['row']);
$name = esc_attr($a['include-name']);
$container = esc_attr($a['container']);
$list = esc_attr($a['list']);
$linebreak = esc_attr($a['line-break');
$counter = 0;
$html = '';
if($container == 'true') {
if($container === true) {
$html .= '<ul class="address-list">';
}
while ( have_rows('company_address', 'company') ) : the_row();
$counter++;
if($row == $counter) {
if($name == 'true') {
$html .= '<li class="address-item address-name">' . get_field('company_name', 'company') . '</li>';
if($name === true) {
if ($list === true) {
$html .= '<li class="address-item address-name">';
}
$html .= get_field('company_name', 'company');
if ($list === false && $linebreak === true) {
$html .= '<br />';
}
if ($list === true) {
$html .= '</li>';
}
}
while ( have_rows('address') ) : the_row();
$html .= '<li class="address-item">' . get_sub_field('address_line') . '</li>';
if ($list === true) {
$html .= '<li class="address-item address-name">';
}
$html .= get_sub_field('address_line');
if ($list === false && $linebreak === true) {
$html .= '<br />';
}
if ($list === true) {
$html .= '</li>';
}
endwhile;
}
endwhile;
if($container == 'true') {
if($container === 'true') {
$html .= '</ul>';
}

Expand All @@ -170,11 +192,11 @@ function company_address_func( $atts ){
// SOCIAL LINKS SHORTCODE
function company_social_func( $atts ){
$a = shortcode_atts( array(
'container' => 'false',
'container' => false,
), $atts );
$container = esc_attr($a['container']);
$html = '';
if($container == 'true') {
if($container === true) {
$html .= '<div class="social-links">';
}
while ( have_rows('social_links','company') ) : the_row();
Expand All @@ -189,7 +211,7 @@ function company_social_func( $atts ){
$html .= '<a href="'. $link .'" rel="nofollow" target="_blank">' . $icon . '</a>';
}
endwhile;
if($container == 'true') {
if($container === true) {
$html .= '</div>';
}

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ __Shortcodes__
- [Company Opening Hours](#company-opening-hours)

### Company Address
Returns the __Company Address__ field. It returns each row in to a separate ```li``` tag.
Returns the __Company Address__ field. By default it returns each row in to a separate ```li``` tag surrounded by a ```ul``` with the class of ```address-list```.
```php
<?php echo do_shortcode('[address]'); ?>
```
Expand All @@ -44,7 +44,9 @@ Option | Type | Default | Description
--- | --- | --- | ---
row | int | 1 | Selects which repeater row phone number will be returned
include-name | boolean | false | Will return the company name as the first ``` li ```
container | boolean | false | Will wrap the returned list items in a ```ul``` with the class of ```address-list```
container | boolean | true | Wraps the returned list items in a ```ul``` with the class of ```address-list```
list | boolean | true | Wraps each list item in a ```li``` tag
line-break | boolean | false | Will add a ```br /``` tag after the list item (applies when list option is false)

### Company Email Address
Returns the __Company Email Address__ field in plaintext.
Expand Down