get( 'TextDomain' ); $active_theme = andrina_get_raw_option( 'template' ); // return apply_filters( 'andrina_is_preview', ( $active_theme != strtolower( $theme_name ) && !is_child_theme())); return apply_filters( 'andrina_is_preview', ( $active_theme == strtolower( $theme_name ))); } // Get Raw Options function andrina_get_raw_option( $opt_name ) { $alloptions = wp_cache_get( 'alloptions', 'options' ); $alloptions = maybe_unserialize( $alloptions ); return isset( $alloptions[ $opt_name ] ) ? maybe_unserialize( $alloptions[ $opt_name ] ) : false; } // Random Images function andrina_get_preview_img_src( $i = 0 ) { // prevent infinite loop if ( 10 == $i ) { return ''; } $path = get_template_directory() . '/assets/images/'; // Build or re-build the global dem img array if ( ! isset( $GLOBALS['andrina_preview_images'] ) || empty( $GLOBALS['andrina_preview_images'] ) ) { $imgs = array( 'img1.png', 'img2.png', 'img3.png', 'img4.png', 'img5.png', 'img6.png', 'img7.png', 'img8.png', 'img9.png', 'img10.png' ); $candidates = array(); foreach ( $imgs as $img ) { $candidates[] = $img; } $GLOBALS['andrina_preview_images'] = $candidates; } $candidates = $GLOBALS['andrina_preview_images']; // get a random image name $rand_key = array_rand( $candidates ); $img_name = $candidates[$rand_key]; // if file does not exists, reset the global and recursively call it again if ( ! file_exists( $path . $img_name ) ) { unset( $GLOBALS['andrina_preview_images'] ); $i++; return andrina_get_preview_img_src( $i ); } // unset all sizes of the img found and update the global $new_candidates = $candidates; foreach ( $candidates as $_key => $_img ) { if ( substr( $_img, 0, strlen( "{$img_name}" ) ) === "{$img_name}" ) { unset($new_candidates[$_key]); } } $GLOBALS['andrina_preview_images'] = $new_candidates; return get_template_directory_uri() . '/assets/images/' . $img_name; } /** * Filter thumbnail image * * @param string $input Post thumbnail. */ function andrina_preview_thumbnail( $input ) { if ( empty( $input ) && andrina_is_preview() ) { $placeholder = andrina_get_preview_img_src(); return ''; } return $input; } add_filter( 'post_thumbnail_html', 'andrina_preview_thumbnail' );