esc_html__( 'Sidebar Widget Area', 'throwback' ),
'id' => 'primary',
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '',
) );
}
add_theme_support( 'title-tag' );
add_theme_support( 'automatic-feed-links' );
function register_my_menu() {
register_nav_menu('header-menu',__( 'Header Menu', 'throwback' ));
}
add_action( 'init', 'register_my_menu' );
//
add_filter( 'wp_trim_excerpt', 'my_custom_excerpt', 10, 2 );
//$getexerpt = get_theme_mod( 'excerpt_length', 200 );
function my_custom_excerpt($text, $raw_excerpt) {
if( ! $raw_excerpt ) {
$content = apply_filters( 'the_content', get_the_content() );
$text = substr( $content, 0, strpos( $content, '' ) + 4 );
}
return $text;
}
function throwback_get_excerpt( $limit, $source = null ) {
( $source == 'content' ? ( $excerpt = get_the_content() ) : ( $excerpt = get_the_excerpt() ) );
$excerpt = preg_replace( ' (\[.*?\])', '', $excerpt );
$excerpt = strip_shortcodes( $excerpt );
$excerpt = strip_tags( $excerpt );
$excerpt = substr( $excerpt, 0, $limit );
$excerpt = substr( $excerpt, 0, strripos( $excerpt, ' ' ) );
$excerpt = trim( preg_replace( '/\s+/', ' ', $excerpt ) );
return $excerpt;
}
function throwback_sanitize_absint_array($theArray = null) {
foreach ($theArray as $i) {
$i = absint($i);
}
return $theArray;
}
function throwback_sanitize_number_absint( $number, $setting ) {
// Ensure $number is an absolute integer (whole number, zero or greater).
$number = absint( $number );
// If the input is an absolute integer, return it; otherwise, return the default
return ( $number ? $number : $setting->default );
}
function throwback_sanitize_checkbox($checked)
{
return ((isset($checked) && (true == $checked || 'on' == $checked)) ? true : false);
}
function throwback_sanitize_float( $input ) {
if ( ! $input ) {
return '0'; // '0' vs. 0 or false
}
return round( floatval( $input ), 2 ) . '';
}
function throwback_sanitize_font_body ( $theFont ) {
global $theFontsList;
if (!in_array($theFont, $theFontsList['all'])) {
$theFont = null;
}
return $theFont;
}
function throwback_sanitize_font_titles ( $theFont ) {
global $theFontsList;
if (!in_array($theFont, $theFontsList['all'])) {
$theFont = null;
}
return $theFont;
}
function zzthrowback_body_weights ($wp_customize) {
global $newFont;
$wp_customize->remove_control('body_font_weight');
$body_sizes[400] = 400;
$wp_customize->get_control('body_font_weight')->choices=$body_sizes;
}
add_action('customize_register','my_customize_register');
function my_customize_register( $wp_customize ) {
class throwback_Separator extends WP_Customize_Control {
public function render_content() {
?>
label ); ?>
label; ?>
label; ?>
add_panel( 'throwback_blog_settings',
array(
'priority' => 50,
'title' => __( 'throwback Settings', 'throwback' ),
'description' => __( 'Change theme settings', 'throwback' ),
//'capability' => 'edit_theme_options',
)
);
require get_theme_file_path( 'inc/author.php' );
require get_theme_file_path( 'inc/colors.php' );
require get_theme_file_path( 'inc/excerpt-options.php' );
require get_theme_file_path( 'inc/header-menu.php' );
require get_theme_file_path( 'inc/footer.php' );
require get_theme_file_path( 'inc/fonts.php' );
require get_theme_file_path( 'inc/font-sizes.php' );
}
function strposN($haystack, $needle, $num) {
// Find the Nth occurence of needle
return strpos($haystack, $needle, $num > 1 ?
strposN($haystack, $needle, $num-1)+strlen($needle):0);
};
// Various functions to set up custom Google fonts
function throwback_setup() {
add_editor_style( array( throwback_fonts_url() ) );
}
function throwback_enqueue() {
global $theFontsList;
wp_enqueue_style( 'throwback-fonts', throwback_fonts_url(), array(), null );
wp_enqueue_script ( 'throwback_font_js', get_template_directory_uri().'/inc/font.js?123', array('customize-controls'), false, true);
wp_add_inline_script( 'throwback_font_js', 'const theFont = ' . json_encode( $theFontsList ), 'before' );
}
//Enqueue styles and scripts for the Customizer pane.
function throwback_suggested_fonts() {
global $theFontsList;
$theSerif = $theFontsList['serif'];
$theSansSerif = $theFontsList['sansserif'];
$theDisplay = $theFontsList['display'];
return apply_filters( 'throwback_suggested_fonts', array(
'serif' => $theFontsList['serif'], 'throwback',
'sansserif' => $theFontsList['sansserif'], 'throwback',
'display' => $theFontsList['display'], 'throwback'
) );
}
function throwback_customize_pane_enqueue() {
global $theFontsList;
$fonts = throwback_suggested_fonts($theFontsList);
$fonts = array_merge( $fonts['serif'], $fonts['sansserif'], $fonts['display'] );
wp_enqueue_style( 'throwback-suggested-fonts',
throwback_fonts_url( $fonts ), array(), null );
}
function throwback_fonts_list( $fonts ) {
// Take arrays of font names, merge, and sort alphabetically.
// Used in font selection choices.
// $fonts = array_merge($fonts['serif'], $fonts['sansserif'], $fonts['display']);
asort($fonts);
$list = '';
}
function throwback_showFonts($theFontList) {
$theOut = "";
foreach ($theFontList as $theFont) {
$theOut .= '
' . esc_html( $theFont ) . '
';
}
$theOut .= "
";
return $theOut;
}
function throwback_get_googlefonts() {
$url="https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key=AIzaSyBtkkXcR7MLmyNRbPvj4cg1Bah8xLZAHhM";
$response = wp_remote_get($url, array('sslverify' => false ));
$response_code = wp_remote_retrieve_response_code($response);
$response = wp_remote_retrieve_body( $response);
return array($response_code, $response);
}
function throwback_query_googlefonts() {
$theFonts = throwback_get_googlefonts();
$response_code = $theFonts[0];
$response = $theFonts[1];
//$theFonts = [];
if( $response_code != 200 ) {
/* translators: Translated error should be as short as possible (15 chars max), displayed on Fonts Family panel in 2 columns, longer text may wrap badly. */
$theFonts['serif'][] = __( 'Unknown Error', 'throwback' );
$theFonts['sansserif'][] = "Unknown Error";
$theFonts['display'][] = "Unknown Error";
} else {
$json_fonts = json_decode($response, true);
// Put the decoded response back into theFonts so it can be encoded pack when passed to javascript
$theFonts[1] = $json_fonts;
$items = $json_fonts['items'];
$i = 0;
$fonts_sansserif = [];
$fonts_serif = [];
$fonts_display = [];
foreach ($items as $item) {
$theFonts['all'][] = $item['family'];
if ($item['category'] == 'serif') {
if (sizeof($fonts_serif) < 100) {
$fonts_serif[] = $item['family'];
}
} elseif ($item['category'] == 'sans-serif') {
if (sizeof($fonts_sansserif) < 100) {
$fonts_sansserif[] = $item['family'];
}
} elseif ($item['category'] == 'display') {
if (sizeof($fonts_display) < 100) {
$fonts_display[] = $item['family'];
}
}
$i++;
}
$theFonts['serif'] = $fonts_serif;
$theFonts['sansserif'] = $fonts_sansserif;
$theFonts['display'] = $fonts_display;
}
return($theFonts);
}
$theFontsList = throwback_query_googlefonts();
add_action( 'customize_controls_enqueue_scripts', 'throwback_customize_pane_enqueue' );
// Generate custom Google font URL
function throwback_fonts_url( $name_only = array() ) {
$fonts_url = '';
$query_args = array();
if ( empty( $name_only ) ) {
$defaults = throwback_default_fonts();
$font_families = array_merge( $defaults, get_theme_mod( 'google_fonts', $defaults ) );
}
else {
$font_families = array_unique( (array) $name_only );
$query_args['text'] = urlencode(
join( '', array_unique( str_split( join( '', $name_only ) ) ) )
);
}
$font_families = array_map( 'esc_attr', array_unique( array_filter( $font_families ) ) );
$new_families = array();
foreach ($font_families as $font) {
$new_families[] = $font.':400,400italic,700';
}
if ( ! empty( $font_families ) ) {
$query_args['family'] = urlencode( implode( '|', $new_families ) );
$query_args['display'] = 'fallback';
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( apply_filters( 'throwback_fonts_url', $fonts_url ) );
}
// Generate style rules for the fonts chosen.
function throwback_font_rules( $for_editor = false ) {
$defaults = throwback_default_fonts();
// Sanity check in case settings have been blanked out
$fonts = get_theme_mod('google_fonts');
if ($fonts['body'] == '' ) {
$fonts['body'] = $defaults['body'];
set_theme_mod('google_fonts', $fonts);
}
if ($fonts['titles'] == '' ) {
$fonts['titles'] = $defaults['titles'];
set_theme_mod('google_fonts', $fonts);
}
$font_families = array_merge( $defaults, get_theme_mod( 'google_fonts' ) );
$font_families = array_map( 'esc_attr', array_filter( $font_families ) );
$css = isset( $font_families['body'] ) ?
':root{--body_font_family: "' . $font_families['body'] . '", sans-serif;}'
: '';
$css .= isset( $font_families['titles'] ) ?
':root{--titles_font_family: "' . $font_families['titles'] . '", serif;}'
: '';
return apply_filters( 'throwback_font_rules', $css, $font_families, $for_editor );
}
function throwback_default_fonts() {
return apply_filters( 'throwback_default_fonts',
array( 'body' => 'Roboto Slab', 'titles' => 'Turret Road' ) );
}
// Generate style rules for the fonts chosen.
function throwback_color_rules() {
$css = ':root{--page_bg_color:' . get_theme_mod('page_bg_color', '#fff') . '; ';
$css .= '--header_bg_color:' . get_theme_mod('header_bg_color', '#036') . '; ';
$css .= '--header_txt_color:' . get_theme_mod('header_txt_color', '#fff') . '; ';
$css .= '--menu_bg_color:' . get_theme_mod('menu_bg_color', '#069') . '; ';
$css .= '--menu_txt_color:' . get_theme_mod('menu_txt_color', '#fff') . '; ';
$css .= '--entry_date_color:' . get_theme_mod('entry_date_color', '#666') . '; ';
$css .= '--entry_title_color:' . get_theme_mod('entry_title_color', '#000') . '; ';
$css .= '--body_txt_color:' . get_theme_mod('body_txt_color', '#000') . '; ';
$css .= '--border_color:' . get_theme_mod('border_color', '#ccc') . '; ';
$css .= '--side_title_color:' . get_theme_mod('side_title_color', '#000') . '; ';
$css .= '--reply_button_color:' . get_theme_mod('reply_button_color', '#37bdd3') . '; ';
$css .= '--reply_button_txt_color:' . get_theme_mod('reply_button_txt_color', '#fff') . '; ';
$css .= '--blockquote_left_border_color:' . get_theme_mod('blockquote_left_border_color', '#888') . '; ';
$css .= '--blockquote_background_color:' . get_theme_mod('blockquote_background_color', '#ddd') . '; ';
$css .= '--blockquote_text_color:' . get_theme_mod('blockquote_text_color', '#666') . '; ';
$css .= '--block_button_color:' . get_theme_mod('block_button_color', '#286eb5') . '; ';
$css .= '--block_button_txt_color:' . get_theme_mod('block_button_txt_color', '#fff') . '; ';
$css .= '--block_background_color:' . get_theme_mod('block_background_color', '#000') . '; ';
$css .= '--header_font_size:' . get_theme_mod('header_font_size', '24') . '; ';
$css .= '--header_letter_spacing:' . get_theme_mod('header_letter_spacing', '0') . '; ';
$css .= '--header_font_weight:' . get_theme_mod('header_font_weight', '400') . '; ';
$css .= '--menu_font_size:' . get_theme_mod('menu_font_size', '13') . '; ';
$css .= '--menu_line_height:' . get_theme_mod('menu_line_height', '29') . '; ';
$css .= '--title_font_size:' . get_theme_mod('title_font_size', '24') . '; ';
$css .= '--title_letter_spacing:' . get_theme_mod('title_letter_spacing', '0') . '; ';
$css .= '--title_font_weight:' . get_theme_mod('title_font_weight', '400') . '; ';
$css .= '--body_font_size:' . get_theme_mod('body_font_size', '13') . '; ';
$css .= '--body_letter_spacing:' . get_theme_mod('body_letter_spacing', '0') . '; ';
$css .= '--body_font_weight:' . get_theme_mod('body_font_weight', '400') . '; '; $css .= '}';
return $css;
}
// Generate the style rules for the dynamic options.
function throwback_dynamic_rules( $for_editor = false ) {
$css = throwback_font_rules( $for_editor );
$css .= throwback_color_rules();
return $css;
}
// Output the styles for the dynamic options.
function throwback_dynamic_style() {
$css = throwback_dynamic_rules();
if ( $css ) :
?>