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 ($content_array as $chunk) { $chunk = trim($chunk); if (!empty($chunk)) { $sanitized_array[] = $chunk; } } $chunk_cnt = count($sanitized_array); ...