I have this piece of function in my functions.php file:
function user_content_replace($content) {
$sentences_per_paragraph = 3; // settings
$pattern = '~(?<=[.?!…])\s+~'; // some punctuation and trailing space(s)
$sentences_array = preg_split($pattern, $content, -1, PREG_SPLIT_NO_EMPTY); // get sentences into array
$sentences_count = count($sentences_array); // count sentences
$output=""; // new content init
// see PHP modulus
for($i = 0; $i < $sentences_count; $i++) {
if($i%$sentences_per_paragraph == 0 && $i == 0) { //divisible by settings and is first
$output .= "<p>" . $sentences_array[$i] . ' '; // add paragraph and the first sentence
} elseif($i%$sentences_per_paragraph == 0 && $i > 0) { //divisible by settings and not first
$output .= "</p><p>" . $sentences_array[$i] . ' '; // close and open paragraph, add the first sentence
} else {
$output .= $sentences_array[$i] . ' '; // concatenate other sentences
}
}
$output .= "</p>"; // close the last paragraph
echo $output;
}
add_filter('the_content','user_content_replace', 99);
This is just simple new-line random function on content (posts). Now my question is: Is there any way to restrict execution of this code on specific date range or to the range, for example:
Between date1 and date2 execute function, else – nothing (do not apply function on posts newer then date2) or simplier solution – just with one date:
All posts till date1 – execute function, else – do nothing.