diff --git a/functions.php b/functions.php
index 44c6a7b..a40be5d 100644
--- a/functions.php
+++ b/functions.php
@@ -1,54 +1,146 @@
get( 'Version' )
+ );
}
-//add_action('template_redirect', 'remove_bbpress_profile_page');
+add_action( 'wp_enqueue_scripts', 'sswt_enqueue_assets' );
-
-function remove_private_title_prefix($title) {
- // Fjern "Privat:" fra tittelen
- $title = str_replace('Privat: ', '', $title);
- return $title;
+/**
+ * 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('the_title', 'remove_private_title_prefix');
+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;
+ }
-// Logg-ut-knapp
-function add_logout_button() {
- if (is_user_logged_in()) {
- echo 'Logg ut';
- }
+ if ( is_bbpress() && ! is_user_logged_in() ) {
+ wp_safe_redirect( wp_login_url( get_permalink() ) );
+ exit;
+ }
+}
+add_action( 'template_redirect', 'sswt_redirect_to_login' );
+
+/**
+ * Redirect the bbPress single user profile to the forum root.
+ *
+ * Disabled by default. Enable it with:
+ * add_filter( 'sswt_redirect_bbpress_profile', '__return_true' );
+ */
+function sswt_redirect_bbpress_profile() {
+ if ( ! apply_filters( 'sswt_redirect_bbpress_profile', false ) ) {
+ return;
+ }
+
+ if ( function_exists( 'bbp_is_single_user' ) && bbp_is_single_user() ) {
+ wp_safe_redirect( home_url( 'forums/' ) );
+ exit;
+ }
+}
+add_action( 'template_redirect', 'sswt_redirect_bbpress_profile' );
+
+/**
+ * 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;
+ }
+
+ printf(
+ '%s',
+ esc_url( wp_logout_url( home_url() ) ),
+ esc_html__( 'Logg ut', 'super-simple-wp-theme' )
+ );
}
-// Change default WordPress email address
-add_filter('wp_mail_from', 'new_mail_from');
-add_filter('wp_mail_from_name', 'new_mail_from_name');
+/**
+ * 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' );
-function new_mail_from($old) { return 'info@taubaneforeningen.no'; }
-
-function new_mail_from_name($old) { return 'Norske Tau- og Kabelbaners Forening'; }
-//end: Change default WordPress email address
-?>
\ No newline at end of file
+/**
+ * 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' );