Okay, finally I have recovered from the problem. Not much of an actual solution which I was looking for, but it would get the job done. So below is the problem and solution for the question. Hope it helps someone else.
The Problem:
I created a WordPress shortcode in which I was getting two things, an audio link and description for it. Both of these two parameters would contain three comma separated parameters. So it would be something like:
[shortcode audio="one, two, three" desc="one, two, three"]
To get multiple parameters in one variable I had to use explode()
so that it could be separated. Now if one of the desc by any chance contains a comma ,
then it was processed as different parameter. So the following created problems for me
[shortcode audio="one, two, three" desc="The text, The,text , The text"]
Notice the second parameter in desc variable. It contains an extra comma so that was processes as a separate parameter.
The Solution:
The solution was not the perfect one but it got the job done. What I did was I replaced the ',' delimiter as '*' so now my shortcode looks something like this:
[shortcode audio="one * two * three" desc="The text * The,text * The text"]
The Code:
function header_custom_box($atts) {
$atts = shortcode_atts( array( 'audio' => '', 'desc' => ''), $atts, 'header-custom-box' );
// Create Empty Arrays to store differnt mp3 links and descriptions.
$posts = array();
$audioArray = array();
$textArray = array();
$postCount = 3;
// Load the Parameters
$audioFiles = explode( "*", $atts['audio'] );
$descText = explode( "*", $atts['desc'] );
// Break if the parameters values are less than required.
if ( count($audioFiles) < $postCount || count($descText) < $postCount) {
echo "You need to provide atleast three links and descriptions. Please check the shortcode again!";
exit;
}
// Create audio with mp3 files in WordPress
foreach ($audioFiles as $audioFile) {
$attr = array(
'src' => trim($audioFile),
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
$audioArray[] = wp_audio_shortcode( $attr );
}
// Store the descriptions in $textArray array.
foreach ($descText as $desc) {
$textArray[] = trim($desc);
}
// Format the post in HTML and store them in $posts array.
$counter = 0;
$buf = '';
while ($counter < $postCount) {
$buf = '';
$buf .= '<div class="header-tab-box">';
$buf .= '<div class="audio-text"><h2>Your Daily Audio:</h2> <br/>';
$buf .= $textArray[$counter];
$buf .= '</div>';
$buf .= '<div class="audio-player">';
$buf .= $audioArray[$counter];
$buf .= '</div>';
$buf .= '</div>';
$posts[$counter] = $buf;
$counter++;
}
// Scheduling the returned posts.
$currentDay = date("D");
$postOne = $posts[0];
$postTwo = $posts[1];
$postThree = $posts[2];
if ($currentDay == "Sat" || $currentDay == "Sun" || $currentDay == "Mon" || $currentDay == "Tue") {
return $postOne;
} elseif ($currentDay == "Wed" || $currentDay == "Thu") {
return $postTwo;
} elseif ($currentDay == "Fri" ) {
return $postThree;
}
}
add_shortcode( 'header-custom-box', 'header_custom_box' );
Hope this helps!
Thanks all ..