Changeset 2088897
- Timestamp:
- 05/16/2019 07:35:38 AM (5 years ago)
- Location:
- log-out-shortcode/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
log-out-shortcode/trunk/log-out-shortcode.php
r1522833 r2088897 1 1 <?php 2 /* 2 /* 3 3 Plugin Name: Log Out Shortcode 4 4 Plugin URI: https://om4.com.au/plugins/log-out-shortcode/ 5 5 Description: Easily add a log out link to a post or page using a simple <code>[logout]</code> shortcode. 6 Version: 1.0. 56 Version: 1.0. 7 7 Author: OM4 8 8 Author URI: https://om4.com.au/plugins/ 9 9 Text Domain: log-out-shortcode 10 10 License: GPLv2 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 11 29 */ 12 30 13 /* 14 15 Copyright 2014-2016 OM4 (email: plugins@om4.com.au web: https://om4.com.au/) 16 17 This program is free software; you can redistribute it and/or modify 18 it under the terms of the GNU General Public License as published by 19 the Free Software Foundation; either version 2 of the License, or 20 (at your option) any later version. 21 22 This program is distributed in the hope that it will be useful, 23 but WITHOUT ANY WARRANTY; without even the implied warranty of 24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 GNU General Public License for more details. 26 27 You should have received a copy of the GNU General Public License 28 along with this program; if not, write to the Free Software 29 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 */ 31 32 function logout_shortcode( $atts, $content = null, $shortcode_name = null ) { 31 /** 32 * Create logout link 33 * 34 * @param array $atts The shortcode attributes. 35 * @param string $content The shortcode content (if any). 36 * @param string $shortcode_name Name of the shortcode. 37 * @return string 38 */ 39 function logout_shortcode( $atts, $content = '', $shortcode_name = '' ) { 33 40 $defaults = array( 34 'text' => __( 'Log out' ), // This is the default log out text from wp-includes/general-template.php35 'redirect' => '', // path/URL to redirect to after logging out36 41 42 43 'class' => 'logout', // CSS Class(es) to use in link. 37 44 ); 38 45 … … 43 50 $atts = shortcode_atts( $defaults, $atts ); 44 51 45 if ( 'logout_to_home' == $shortcode_name ) {52 if ( 'logout_to_home' == $shortcode_name ) { 46 53 $atts['redirect'] = 'home'; 47 } else if ( 'logout_to_current'== $shortcode_name ) {54 } else== $shortcode_name ) { 48 55 $atts['redirect'] = 'current'; 49 56 } 50 57 51 if ( 'home' == $atts['redirect'] ) {58 if ( 'home' == $atts['redirect'] ) { 52 59 $atts['redirect'] = home_url(); 53 } else if ( 'current'== $atts['redirect'] ) {60 } else== $atts['redirect'] ) { 54 61 $atts['redirect'] = get_the_permalink(); 55 62 } 56 63 57 64 $class_html = ''; 58 if ( '' != $atts['class'] ) {59 // Multiple classes are separated by a space 60 $classes = explode( ' ', $atts['class'] );61 $classes = array_map( 'sanitize_html_class', $classes );65 if ( '' != $atts['class'] ) { 66 // Multiple classes are separated by a space 67 $classes = explode( ' ', $atts['class'] ); 68 $classes = array_map( 'sanitize_html_class', $classes ); 62 69 $class_html = ' class="' . implode( $classes, ' ' ) . '"'; 63 70 } 64 71 65 return '<a href="' . esc_url( wp_logout_url( $atts['redirect'] ) ) . '"' . $class_html . '>' 72 return '<a href="' . esc_url( wp_logout_url( $atts['redirect'] ) ) . '"' . $class_html . '>' . esc_html( $atts['text'] ) . '</a>'; 66 73 67 74 } -
log-out-shortcode/trunk/readme.txt
r1682376 r2088897 3 3 Contributors: jamescollins 4 4 Requires at least: 3.9 5 Tested up to: 4.86 Stable tag: 1.0. 55 Tested up to: 6 Stable tag: 1.0. 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 63 63 == Changelog == 64 64 65 66 67 65 68 = 1.0.5 = 66 69 * Fix a bug that meant it was not possible to use specify multiple classes in the class="" attribute. Thanks to @hughc for the bug report.
Note: See TracChangeset
for help on using the changeset viewer.