Rewrite functions.php for 2.0.0
- Prefix every function with sswt_. - Add sswt_setup() with text domain and theme supports. - Register the header-menu location on init (slug unchanged). - Enqueue style.css with the theme version. - Replace the locale dependent title prefix with the private/protected title format filters. - Guard is_bbpress() with function_exists(). - Make the bbPress profile redirect toggleable via a filter. - Turn the logout helper into sswt_logout_link(). - Make the mail from address and name filterable.
This commit is contained in:
1 parent
4db3682d09
commit
3e772c5547
1 file changed
+133
-41
+133
-41
@@ -1,54 +1,146 @@
|
|||||||
<?php
|
<?php
|
||||||
function register_my_menu() {
|
/**
|
||||||
register_nav_menu("header-menu", __( "Header Menu" ));
|
* Theme setup and helpers.
|
||||||
|
*
|
||||||
|
* @package Super_Simple_WP_Theme
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register theme supports and load the theme text domain.
|
||||||
|
*/
|
||||||
|
function sswt_setup() {
|
||||||
|
load_theme_textdomain( 'super-simple-wp-theme', get_template_directory() . '/languages' );
|
||||||
|
|
||||||
|
add_theme_support( 'title-tag' );
|
||||||
|
add_theme_support( 'post-thumbnails' );
|
||||||
|
add_theme_support( 'automatic-feed-links' );
|
||||||
|
add_theme_support( 'responsive-embeds' );
|
||||||
|
add_theme_support( 'customize-selective-refresh-widgets' );
|
||||||
|
add_theme_support( 'align-wide' );
|
||||||
|
add_theme_support(
|
||||||
|
'html5',
|
||||||
|
array(
|
||||||
|
'search-form',
|
||||||
|
'comment-form',
|
||||||
|
'comment-list',
|
||||||
|
'gallery',
|
||||||
|
'caption',
|
||||||
|
'style',
|
||||||
|
'script',
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
add_action( "init", "register_my_menu" );
|
add_action( 'after_setup_theme', 'sswt_setup' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the theme nav menu location.
|
||||||
|
*
|
||||||
|
* The "header-menu" slug must stay unchanged: the existing menu assignment is
|
||||||
|
* stored against it.
|
||||||
|
*/
|
||||||
|
function sswt_register_menus() {
|
||||||
|
register_nav_menu( 'header-menu', __( 'Header Menu', 'super-simple-wp-theme' ) );
|
||||||
|
}
|
||||||
|
add_action( 'init', 'sswt_register_menus' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue the theme stylesheet.
|
||||||
|
*/
|
||||||
|
function sswt_enqueue_assets() {
|
||||||
|
wp_enqueue_style(
|
||||||
|
'sswt-style',
|
||||||
|
get_stylesheet_uri(),
|
||||||
|
array(),
|
||||||
|
wp_get_theme()->get( 'Version' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action( 'wp_enqueue_scripts', 'sswt_enqueue_assets' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop the "Private:" and "Protected:" prefixes from post titles.
|
||||||
|
*
|
||||||
|
* Uses the core filters instead of a locale dependent str_replace().
|
||||||
|
*
|
||||||
|
* @param string $format Title format.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function sswt_title_format( $format ) {
|
||||||
|
return '%s';
|
||||||
|
}
|
||||||
|
add_filter( 'private_title_format', 'sswt_title_format' );
|
||||||
|
add_filter( 'protected_title_format', 'sswt_title_format' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send anonymous visitors to the login screen when they open a bbPress page.
|
||||||
|
*/
|
||||||
|
function sswt_redirect_to_login() {
|
||||||
|
if ( ! function_exists( 'is_bbpress' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Vidaresend til innlogging viss ein ikkje er innlogga på forumet
|
|
||||||
function redirect_to_login_if_not_logged_in() {
|
|
||||||
if ( is_bbpress() && ! is_user_logged_in() ) {
|
if ( is_bbpress() && ! is_user_logged_in() ) {
|
||||||
wp_redirect(wp_login_url(get_permalink()));
|
wp_safe_redirect( wp_login_url( get_permalink() ) );
|
||||||
exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('template_redirect', 'redirect_to_login_if_not_logged_in');
|
|
||||||
|
|
||||||
|
|
||||||
// Ikkje vis profilsida
|
|
||||||
function remove_bbpress_profile_page() {
|
|
||||||
if (function_exists('bbp_is_single_user')) {
|
|
||||||
if (bbp_is_single_user()) {
|
|
||||||
//wp_redirect(home_url()); // Omdirigerer til hjemmesiden
|
|
||||||
wp_redirect(home_url('forums/')); // Omdirigerer til hjemmesiden
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
add_action( 'template_redirect', 'sswt_redirect_to_login' );
|
||||||
//add_action('template_redirect', 'remove_bbpress_profile_page');
|
|
||||||
|
|
||||||
|
/**
|
||||||
function remove_private_title_prefix($title) {
|
* Redirect the bbPress single user profile to the forum root.
|
||||||
// Fjern "Privat:" fra tittelen
|
*
|
||||||
$title = str_replace('Privat: ', '', $title);
|
* Disabled by default. Enable it with:
|
||||||
return $title;
|
* add_filter( 'sswt_redirect_bbpress_profile', '__return_true' );
|
||||||
}
|
*/
|
||||||
add_filter('the_title', 'remove_private_title_prefix');
|
function sswt_redirect_bbpress_profile() {
|
||||||
|
if ( ! apply_filters( 'sswt_redirect_bbpress_profile', false ) ) {
|
||||||
|
return;
|
||||||
// Logg-ut-knapp
|
|
||||||
function add_logout_button() {
|
|
||||||
if (is_user_logged_in()) {
|
|
||||||
echo '<a href="' . wp_logout_url(home_url()) . '">Logg ut</a>';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change default WordPress email address
|
if ( function_exists( 'bbp_is_single_user' ) && bbp_is_single_user() ) {
|
||||||
add_filter('wp_mail_from', 'new_mail_from');
|
wp_safe_redirect( home_url( 'forums/' ) );
|
||||||
add_filter('wp_mail_from_name', 'new_mail_from_name');
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'template_redirect', 'sswt_redirect_bbpress_profile' );
|
||||||
|
|
||||||
function new_mail_from($old) { return 'info@taubaneforeningen.no'; }
|
/**
|
||||||
|
* Print a logout link for the current user.
|
||||||
|
*
|
||||||
|
* Prints nothing for anonymous visitors, so the #logout container keeps the
|
||||||
|
* same markup as before.
|
||||||
|
*/
|
||||||
|
function sswt_logout_link() {
|
||||||
|
if ( ! is_user_logged_in() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function new_mail_from_name($old) { return 'Norske Tau- og Kabelbaners Forening'; }
|
printf(
|
||||||
//end: Change default WordPress email address
|
'<a href="%s">%s</a>',
|
||||||
?>
|
esc_url( wp_logout_url( home_url() ) ),
|
||||||
|
esc_html__( 'Logg ut', 'super-simple-wp-theme' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the default "from" address used by wp_mail().
|
||||||
|
*
|
||||||
|
* @param string $email Default address.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function sswt_mail_from( $email ) {
|
||||||
|
return apply_filters( 'sswt_mail_from', 'info@taubaneforeningen.no' );
|
||||||
|
}
|
||||||
|
add_filter( 'wp_mail_from', 'sswt_mail_from' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the default "from" name used by wp_mail().
|
||||||
|
*
|
||||||
|
* @param string $name Default name.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function sswt_mail_from_name( $name ) {
|
||||||
|
return apply_filters( 'sswt_mail_from_name', 'Norske Tau- og Kabelbaners Forening' );
|
||||||
|
}
|
||||||
|
add_filter( 'wp_mail_from_name', 'sswt_mail_from_name' );
|
||||||
Reference in new issue
Block a user