Randomizing content from the database

The stars are in alignment—we have custom content in the database, we have a widget that displays content, and choosing the random content all depends on a single function: ContentRotator::get_random_content() . Let's update that function, so it pulls our content from the database:

static function get_random_content(){ $separator = get_option('content_rotation_content_separator'); $content_block = get_option('content_rotation_content_block'); // Ensure that the user has entered valid settings if ( empty($content_block) ) { return ''; } elseif (empty($separator)) { return $content_block; } // Get an array of non-empty chunks $content_array = explode($separator, $content_block); $sanitized_array = array(); foreach ...

Get WordPress 3 Plugin Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.