rjtucker
Forum Replies Created
-
Okay I think I finally figured it out. It seems to boil down to two things:
1. Remembering to copy from Text View in the WordPress editor (not from Visual View).
2. Avoiding the use of constants like PHP_EOL which the [insert_php] method supported but apparently the snippet method does not (yet) support.
Alex, please add support for constants like PHP_EOL to the snippet method.
Following these two points I have managed to get https://dailyprayer.ca/scripture-readings working with the snippet method. I have disabled the test page that I mentioned earlier.
Thanks.
Regards,
JimPS – I know others have said it before, but this feels like it belongs in the category of “If it ain’t broke, don’t fix it!” From my perspective there’s little if anything gained by migrating to the snippet method. The main reason I’ve done it is because eventually you’re going to remove support for the [insert_php] method. At the very least, the snippet method is the one you’ll be improving and developing in the future, so I don’t want to get stuck on the old version. Other than that I fail to see the practical benefits of the snippet method. Indeed, stubbing my toe on these conversion and compatibility gotchas seems like pain for no discernible gain. Even so, I appreciate your plugin and I thank you for it.
- This reply was modified 6 years, 4 months ago by rjtucker.
Hello, Alex.
Thank you very much for your message.
1. Yes, the result you showed is the result I got after I converted the code into a snippet.
2. I carefully copied your code into the snippet, but it did not change the result.
I’ve created https://dailyprayer.ca/scripture-readings-test so I don’t mess up the real page while troubleshooting this.
Here are the contents of https://dailyprayer.ca/scripture-readings-test:
<img class="alignnone size-full wp-image-1119" src="https://dailyprayer.ca/wp-content/uploads/2015/07/oybo1.png" alt="oybo" width="152" height="170" /> [wbcr_php_snippet id="2745"]
Here are the contents of snippet ID 2745 that I copied and pasted from your suggestion here on this web page:
date_default_timezone_set('America/Vancouver'); // Create the hyperlink to today's readings on the OYBO site $handle = fopen("https://oneyearbibleonline.com/daily-oyb/?version=ESVUK&nltdt=" . date('md'), "r"); if( $handle ) { $srchstrg_pre = 'openweeklylink\(\''; $srchstrg_post = "\'\)"; // Read line by line while( ($line = fgets($handle)) !== false ) { $line = htmlspecialchars($line); if( preg_match('/' . $srchstrg_pre . '.+' . $srchstrg_post . '/', $line, $match, PREG_OFFSET_CAPTURE) ) { $line = $match[0][0]; $line = substr($line, strlen($srchstrg_pre) - 1); $line = substr($line, 0, strlen($line) - strlen($srchstrg_post) + 2); echo "Open the " . date('F j') . " Readings in the ESV Anglicized Translation" . PHP_EOL . PHP_EOL; // Now stop reading the file for any more links break; } } // Close the feed fclose($handle); } else { // error opening the file. } // Display today's readings as text references $handle = fopen("https://oneyearbibleonline.com/daily-oyb/?version=ESVUK&nltdt=" . date('md'), "r"); $srchstrg_pre = "One Year Bible Readings"; if( $handle ) { // Read line by line while( ($line = fgets($handle)) !== false ) { $line = htmlspecialchars($line); if( preg_match('/' . $srchstrg_pre . '/', $line, $match, PREG_OFFSET_CAPTURE) ) { $srchstrg_pre = "<strong>.*<\/strong>"; if( preg_match('/' . $srchstrg_pre . '/', $line, $match, PREG_OFFSET_CAPTURE) ) { echo "" . substr($match[0][0], 14, strlen($match[0][0]) - 29) . "" . PHP_EOL; } $srchstrg_pre = "<br \/>.*<br \/>"; if( preg_match('/' . $srchstrg_pre . '/', $line, $match, PREG_OFFSET_CAPTURE) ) { $line = $match[0][0]; $srchstrg_pre = "<br \/>"; while( preg_match('/' . $srchstrg_pre . '/', $line, $match, PREG_OFFSET_CAPTURE) ) { if( $match[0][1] > 0 ) { echo substr($line, 0, $match[0][1]) . PHP_EOL; } $line = substr($line, $match[0][1] + 12); } echo PHP_EOL; } // Now stop reading the file break; } } // Close the feed fclose($handle); } else { // error opening the file. } // Create the general links to the OYBO site and podcast echo "For other dates or translations, check the "; echo "One Year Bible site." . PHP_EOL . PHP_EOL; echo "Listen to the One Year Bible "; echo "podcast.";
I don’t know what you changed. It looks the same to me.
Please advise.
Thanks.
Regards,
Jim