Plugin Directory

Changeset 3446538


Ignore:
Timestamp:
01/25/2026 01:16:33 PM (2 months ago)
Author:
sarangan112
Message:

Update plugin to version 1.0.0 with settings page and custom redirect support

Location:
redirect-to-homepage-after-logout/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • redirect-to-homepage-after-logout/trunk/readme.txt

    r3405518 r3446538  
    33Tags: logout, redirect, homepage, user, session
    44Requires at least: 5.0
    5 Tested up to: 6.9
    6 Stable tag: 0.1
     5Tested up to: 6.8
     6Stable tag: 1.0.0
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    3535== Changelog ==
    3636= 1.0.0 =
    37 * Initial release.
     37* Added Admin Settings Page.
     38* Added support for Custom URLs and Page Selection.
     39* Added Master Toggle to enable/disable functionality.
     40* Improved security with wp_safe_redirect for internal links.
    3841
    3942== Upgrade Notice ==
     
    4245
    4346== Credits ==
    44 Developed by Sarangan Thillaiampalam
     47Developed by Sarangan Thillayampalam
  • redirect-to-homepage-after-logout/trunk/redirect-homepage-logout.php

    r3384478 r3446538  
    11<?php
    22/*
    3 * Plugin Name: Redirect to Homepage After Logout
    4 * Description: This plugin simply redirect you to home of your WordPress site, instead of just back to the login page again.
    5 * Author: Sarangan Thillayampalam
    6 * Version: 0.1
    7 * Author URI: https://sarangan.dk
    8 * License: GPLv2 or later
    9 */
     3 * Plugin Name: Redirect to Homepage After Logout
     4 * Description: Redirects users to a custom URL, page, or homepage after they log out.
     5 * Author: Sarangan Thillayampalam
     6 * Version: 1.0
     7 * Author URI: https://sarangan.dk
     8 * License: GPLv2 or later
     9 */
    1010
    11  function wpc_auto_redirect_after_logout(){
    12   wp_redirect( home_url() );
    13   exit();
     11if ( ! defined( 'ABSPATH' ) ) {
     12    exit;
    1413}
    15 add_action('wp_logout','wpc_auto_redirect_after_logout');
    16 ?>
     14
     15/**
     16 * Register settings and admin menu
     17 */
     18function rhal_settings_init() {
     19    register_setting( 'rhal_settings_group', 'rhal_settings' );
     20
     21    add_settings_section(
     22        'rhal_main_section',
     23        __( 'Redirect Settings', 'redirect-to-homepage-after-logout' ),
     24        'rhal_section_callback',
     25        'rhal-settings-page'
     26    );
     27
     28    add_settings_field(
     29        'rhal_enable',
     30        __( 'Enable Redirect', 'redirect-to-homepage-after-logout' ),
     31        'rhal_enable_render',
     32        'rhal-settings-page',
     33        'rhal_main_section'
     34    );
     35
     36    add_settings_field(
     37        'rhal_type',
     38        __( 'Redirect To', 'redirect-to-homepage-after-logout' ),
     39        'rhal_type_render',
     40        'rhal-settings-page',
     41        'rhal_main_section'
     42    );
     43
     44    add_settings_field(
     45        'rhal_page_id',
     46        __( 'Select Page', 'redirect-to-homepage-after-logout' ),
     47        'rhal_page_render',
     48        'rhal-settings-page',
     49        'rhal_main_section'
     50    );
     51
     52    add_settings_field(
     53        'rhal_custom_url',
     54        __( 'Custom URL', 'redirect-to-homepage-after-logout' ),
     55        'rhal_url_render',
     56        'rhal-settings-page',
     57        'rhal_main_section'
     58    );
     59}
     60add_action( 'admin_init', 'rhal_settings_init' );
     61
     62function rhal_section_callback() {
     63    echo __( 'Configure where users should be sent after logging out.', 'redirect-to-homepage-after-logout' );
     64}
     65
     66function rhal_enable_render() {
     67    $options = get_option( 'rhal_settings' );
     68    // Default to '1' if the option doesn't exist yet (new install)
     69    $enabled = ( $options === false ) ? '1' : ( isset( $options['rhal_enable'] ) ? $options['rhal_enable'] : '0' );
     70    ?>
     71    <input type='checkbox' name='rhal_settings[rhal_enable]' <?php checked( $enabled, '1' ); ?> value='1'>
     72    <?php
     73}
     74
     75function rhal_type_render() {
     76    $options = get_option( 'rhal_settings' );
     77    $type = isset( $options['rhal_type'] ) ? $options['rhal_type'] : 'home';
     78    ?>
     79    <select name='rhal_settings[rhal_type]'>
     80        <option value='home' <?php selected( $type, 'home' ); ?>>Homepage</option>
     81        <option value='page' <?php selected( $type, 'page' ); ?>>A Specific Page</option>
     82        <option value='custom' <?php selected( $type, 'custom' ); ?>>Custom URL</option>
     83    </select>
     84    <?php
     85}
     86
     87function rhal_page_render() {
     88    $options = get_option( 'rhal_settings' );
     89    $page_id = isset( $options['rhal_page_id'] ) ? $options['rhal_page_id'] : 0;
     90    wp_dropdown_pages( array(
     91        'name'              => 'rhal_settings[rhal_page_id]',
     92        'selected'          => $page_id,
     93        'show_option_none'  => '-- Select Page --',
     94        'option_none_value' => '0',
     95    ) );
     96}
     97
     98function rhal_url_render() {
     99    $options = get_option( 'rhal_settings' );
     100    $url = isset( $options['rhal_custom_url'] ) ? $options['rhal_custom_url'] : '';
     101    ?>
     102    <input type='url' name='rhal_settings[rhal_custom_url]' value='<?php echo esc_url( $url ); ?>' class='regular-text' placeholder='https://example.com'>
     103    <?php
     104}
     105
     106/**
     107 * Add Admin Menu
     108 */
     109function rhal_add_admin_menu() {
     110    add_options_page(
     111        'Logout Redirect',
     112        'Logout Redirect',
     113        'manage_options',
     114        'logout-redirect',
     115        'rhal_options_page'
     116    );
     117}
     118add_action( 'admin_menu', 'rhal_add_admin_menu' );
     119
     120function rhal_options_page() {
     121    ?>
     122    <div class="wrap">
     123        <h1>Logout Redirect Settings</h1>
     124        <form action='options.php' method='post'>
     125            <?php
     126            settings_fields( 'rhal_settings_group' );
     127            do_settings_sections( 'rhal-settings-page' );
     128            submit_button();
     129            ?>
     130        </form>
     131    </div>
     132    <?php
     133}
     134
     135/**
     136 * Add Settings link to plugin page
     137 */
     138function rhal_add_settings_link( $links ) {
     139    $settings_link = '<a href="options-general.php?page=logout-redirect">' . __( 'Settings', 'redirect-to-homepage-after-logout' ) . '</a>';
     140    array_unshift( $links, $settings_link );
     141    return $links;
     142}
     143$plugin_file = plugin_basename( __FILE__ );
     144add_filter( "plugin_action_links_$plugin_file", 'rhal_add_settings_link' );
     145
     146/**
     147 * Perform Redirection
     148 */
     149function wpc_auto_redirect_after_logout() {
     150    $options = get_option( 'rhal_settings' );
     151
     152    // If no settings exist yet, default to enabled + homepage
     153    if ( $options === false ) {
     154        wp_safe_redirect( home_url() );
     155        exit();
     156    }
     157
     158    // Check if explicitly enabled
     159    if ( ! isset( $options['rhal_enable'] ) ) {
     160        return;
     161    }
     162
     163    $redirect_url = home_url(); // Default
     164    $type = isset( $options['rhal_type'] ) ? $options['rhal_type'] : 'home';
     165
     166    if ( $type === 'page' && ! empty( $options['rhal_page_id'] ) ) {
     167        $redirect_url = get_permalink( $options['rhal_page_id'] );
     168    } elseif ( $type === 'custom' && ! empty( $options['rhal_custom_url'] ) ) {
     169        $redirect_url = $options['rhal_custom_url'];
     170        // Use wp_redirect for custom URLs to allow external sites
     171        wp_redirect( $redirect_url );
     172        exit();
     173    }
     174
     175    // Default/Homepage/Page redirects use safe redirect
     176    wp_safe_redirect( $redirect_url );
     177    exit();
     178}
     179add_action( 'wp_logout', 'wpc_auto_redirect_after_logout' );
Note: See TracChangeset for help on using the changeset viewer.