/** * Oslo functions and definitions * * @package Oslo */ define( 'OSLO_ASSET_VERSION', '1.0.2' ); /** * Set the content width based on the theme's design and stylesheet. */ if ( ! isset( $content_width ) ) { $content_width = 640; // pixels } if ( ! function_exists( 'oslo_setup' ) ) : /** * Sets up theme defaults and registers support for various WordPress features. * * Note that this function is hooked into the after_setup_theme hook, which * runs before the init hook. The init hook is too late for some features, such * as indicating support for post thumbnails. */ function oslo_setup() { /* * Make theme available for translation. * Translations can be filed in the /languages/ directory. */ load_theme_textdomain( 'oslo', get_template_directory() . '/languages' ); /* * Add default posts and comments RSS feed links to head. */ add_theme_support( 'automatic-feed-links' ); /* * Add admin bar support, but without adding its CSS callback, which conflicts with our sidebar. * * @link https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/admin-bar.php#L769 */ add_theme_support( 'admin-bar', array( 'callback' => '__return_false') ); /* * Enable support for Post Thumbnails on posts and pages. * * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails */ add_theme_support( 'post-thumbnails' ); /* * Enable custom header support. */ add_theme_support( 'custom-header', array( 'default-image' => '', 'random-default' => false, 'width' => 1200, 'height' => 1200, 'flex-height' => true, 'flex-width' => true, 'default-text-color' => 'FFFFFF', 'header-text' => true, 'uploads' => true, 'wp-head-callback' => '', 'admin-head-callback' => '', 'admin-preview-callback' => '', ) ); /* * Use HTML markup for some features. */ add_theme_support( 'html5' ); /* * Add a single nav menu. Used in sidebar.php */ register_nav_menus( array( 'primary' => __( 'Primary Menu', 'oslo' ), ) ); /* * Add editor styles. */ add_editor_style( 'css/editor.css' ); /* * Filter get_comment_date to return relative dates */ if ( ! is_admin() ) { add_filter( 'get_comment_date', 'oslo_comment_relative_date' ); } } endif; add_action( 'after_setup_theme', 'oslo_setup' ); /** * Register widget area and update sidebar with default widgets. */ function oslo_widgets_init() { register_sidebar( array( 'name' => __( 'Sidebar', 'oslo' ), 'id' => 'sidebar-1', 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'oslo_widgets_init' ); /** * Enqueue scripts and styles. */ function oslo_scripts() { // Main stylesheet wp_enqueue_style( 'oslo-style', get_stylesheet_uri(), array(), OSLO_ASSET_VERSION ); // Print stylesheet wp_enqueue_style( 'oslo-print', get_template_directory_uri() . '/css/print.css', array( 'oslo-style' ), OSLO_ASSET_VERSION, 'print' ); // Main script wp_enqueue_script( 'oslo-theme', get_template_directory_uri() . '/javascripts/theme.js', array( 'jquery' ), OSLO_ASSET_VERSION, true ); // Google web fonts // Translators: If there are characters in your language that are not supported // by any of the following fonts, translate this to 'off'. Do not translate into your own language. if ( 'off' !== _x( 'on', 'Webfonts: on or off', 'oslo' ) ) { wp_enqueue_style( 'oslo-webfonts', '//fonts.googleapis.com/css?family=Roboto:400,400italic,700,700italic,300|Droid+Serif:400,400italic,700,700italic', array( 'oslo-style' ) ); } // Social icon font if ( oslo_customize_has_social() ) { wp_enqueue_style( 'oslo-social', get_template_directory_uri() . '/css/oslo-social.css', array( 'oslo-style' ), OSLO_ASSET_VERSION ); } // Share menu translations if ( function_exists( 'sharing_display' ) ) { wp_localize_script( 'oslo-theme', '__PXU_ShareMenu', array( 'showMoreText' => __( 'Show more', 'oslo' ), 'showLessText' => __( 'Show less', 'oslo' ), ) ); } // WP comment reply script if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } add_action( 'wp_enqueue_scripts', 'oslo_scripts' ); if ( ! function_exists( 'oslo_is_wpcom' ) ) : /** * Whether or not the current environment is WordPress.com. * * @return bool */ function oslo_is_wpcom() { return ( defined( 'IS_WPCOM' ) && true === IS_WPCOM ); } endif; if ( ! function_exists( 'oslo_excerpt_more' ) ) : /** * Change excerpt cutoff text. */ function oslo_excerpt_more( $more ) { return '...'; } endif; add_filter('excerpt_more', 'oslo_excerpt_more'); if ( ! function_exists( 'oslo_relative_comment_date' ) ) : /** * Changes comments to use relative dates. * * @param string $date The original date string as created by `comment_date`. * @return string */ function oslo_comment_relative_date( $date ) { global $comment; $post_time = strtotime($comment->comment_date_gmt); $rel_time = time() - $post_time; if ( $rel_time < 1 ) { return __( 'just now', 'oslo' ); } $periods = array( 'year' => 60 * 60 * 24 * 30 * 12, 'month' => 60 * 60 * 24 * 30, 'week' => 60 * 60 * 24 * 7, 'day' => 60 * 60 * 24, 'hour' => 60 * 60, 'minute' => 60, 'second' => 1, ); foreach ( $periods as $denomination => $seconds ) { $delta = round( $rel_time / $seconds ); if ( $delta < 1) { continue; } else if ( $denomination == 'year' ) { return $date; } else if ( $denomination == 'month' ) { return sprintf( _n( '1 month ago', '%1$s months ago', $delta, 'oslo' ), $delta ); } else if ( $denomination == 'week' ) { return sprintf( _n( '1 week ago', '%1$s weeks ago', $delta, 'oslo' ), $delta ); } else if ( $denomination == 'day' ) { return sprintf( _n( '1 day ago', '%1$s days ago', $delta, 'oslo' ), $delta ); } else if ( $denomination == 'hour' ) { return sprintf( _n( '1 hour ago', '%1$s hours ago', $delta, 'oslo' ), $delta ); } else if ( $denomination == 'minute' ) { return sprintf( _n( '1 minute ago', '%1$s minutes ago', $delta, 'oslo' ), $delta ); } else if ( $denomination == 'second' ) { return sprintf( _n( '1 second ago', '%1$s seconds ago', $delta, 'oslo' ), $delta ); } } return $date; } endif; if ( ! function_exists( 'oslo_comment_form_defaults' ) ) : /** * Change the comment form defaults. * * The markup below is similar to WordPress defaults when theme support is added for HTML5, with a few minor * differences. The main thing is that instead of a form input label, the "placeholder" attribute is used. * * @param array $defaults The default values. * @return array The modified defaults. */ function oslo_comment_form_defaults( $defaults ) { // Comment form header $defaults['title_reply'] = _x( 'Leave a reply', 'plural noun', 'oslo' ); // Comment form notes $defaults['comment_notes_before'] = ''; $defaults['comment_notes_after'] = sprintf( '

%1$s

', __( 'Basic HTML is allowed. Your email address will not be published.', 'oslo' ) ); // Comment Author $comment_author = ( isset( $_POST['author'] ) ) ? trim( strip_tags( $_POST['author'] ) ) : null; $author_field = sprintf( '

', 'author', esc_attr__( 'Name', 'oslo' ), esc_attr( $comment_author ), 1 ); // Comment Author Email $comment_author_email = ( isset( $_POST['email'] ) ) ? trim( $_POST['email'] ) : null; $email_field = sprintf( '

', 'email', esc_attr__( 'Email', 'oslo' ), esc_attr( $comment_author_email ), 2 ); // Comment Author URL $comment_author_url = ( isset( $_POST['url'] ) ) ? trim( $_POST['url'] ) : null; $url_field = sprintf( '

', 'url', esc_attr__( 'Website', 'oslo' ), esc_attr( $comment_author_url ), 3 ); // Set the fields in the $defaults array $defaults['fields'] = array( 'author' => $author_field, 'email' => $email_field, 'url' => $url_field ); // Comment Form $defaults['comment_field'] = sprintf( '

', esc_attr__( 'Enter your comment here…', 'oslo' ) ); return $defaults; } endif; add_filter( 'comment_form_defaults', 'oslo_comment_form_defaults' ); if ( ! function_exists( 'oslo_the_content_more_link' ) ) : /** * Ensures that more links are always nested inside a paragraph. */ function oslo_the_content_more_link( $link ) { return '

' . $link . '

'; } endif; add_filter( 'the_content_more_link', 'oslo_the_content_more_link' ); /** * Custom template tags for this theme. */ require get_template_directory() . '/includes/template-tags.php'; /** * Custom functions that act independently of the theme templates. */ require get_template_directory() . '/includes/extras.php'; /** * Customizer additions. */ require get_template_directory() . '/includes/customizer.php'; /** * Load Jetpack compatibility file. */ require get_template_directory() . '/includes/jetpack.php'; /** * Editor customizations. */ require get_template_directory() . '/includes/editor.php'; /** * The Header for our theme. * * Displays all of the section, the #secondary content, and everything up till
* * @package Oslo */ ?>