LoginRedirect.php
99 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | * |
| 9 | * @version 6.0.0 |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * AAM shortcode strategy for login button |
| 14 | * |
| 15 | * @package AAM |
| 16 | * @version 6.0.0 |
| 17 | */ |
| 18 | class AAM_Shortcode_Handler_LoginRedirect |
| 19 | implements AAM_Core_Contract_ShortcodeInterface |
| 20 | { |
| 21 | |
| 22 | /** |
| 23 | * Shortcode arguments |
| 24 | * |
| 25 | * @var array |
| 26 | * |
| 27 | * @access protected |
| 28 | * @version 6.0.0 |
| 29 | */ |
| 30 | protected $args; |
| 31 | |
| 32 | /** |
| 33 | * Wrapped by shortcode content |
| 34 | * |
| 35 | * @var string |
| 36 | * |
| 37 | * @access protected |
| 38 | * @version 6.0.0 |
| 39 | */ |
| 40 | protected $content; |
| 41 | |
| 42 | /** |
| 43 | * Initialize shortcode decorator |
| 44 | * |
| 45 | * Expecting attributes in $args are: |
| 46 | * "class" => CSS class for login button |
| 47 | * "callback" => callback function that returns the login button |
| 48 | * "label" => if stand-alone shortcode then defined text label will be used |
| 49 | * |
| 50 | * @param type $args |
| 51 | * @param type $content |
| 52 | * |
| 53 | * @return void |
| 54 | * |
| 55 | * @access public |
| 56 | * @version 6.0.0 |
| 57 | */ |
| 58 | public function __construct($args, $content) |
| 59 | { |
| 60 | $this->args = $args; |
| 61 | $this->content = $content; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Process the shortcode |
| 66 | * |
| 67 | * @return string |
| 68 | * |
| 69 | * @access public |
| 70 | * @version 6.0.0 |
| 71 | */ |
| 72 | public function run() |
| 73 | { |
| 74 | $redirect = AAM_Core_Request::server('REQUEST_URI'); |
| 75 | $class = (isset($this->args['class']) ? $this->args['class'] : ''); |
| 76 | |
| 77 | if (isset($this->args['callback'])) { |
| 78 | $button = call_user_func($this->args['callback'], $this); |
| 79 | } else { |
| 80 | $url = add_query_arg('reason', 'restricted', wp_login_url($redirect)); |
| 81 | |
| 82 | if (empty($this->content)) { |
| 83 | if (!empty($this->args['label'])) { |
| 84 | $label = $this->args['label']; |
| 85 | } else { |
| 86 | $label = __('Login to continue', AAM_KEY); |
| 87 | } |
| 88 | } else { |
| 89 | $label = $this->content; |
| 90 | } |
| 91 | |
| 92 | $button = '<a href="' . $url . '" '; |
| 93 | $button .= 'class="' . $class . '">' . $label . '</a>'; |
| 94 | } |
| 95 | |
| 96 | return $button; |
| 97 | } |
| 98 | |
| 99 | } |