Content.php
7 years ago
Interface.php
7 years ago
Login.php
7 years ago
LoginRedirect.php
7 years ago
LoginRedirect.php
92 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 | |
| 10 | /** |
| 11 | * AAM shortcode strategy for login button |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 15 | */ |
| 16 | class AAM_Shortcode_Strategy_LoginRedirect implements AAM_Shortcode_Strategy_Interface { |
| 17 | |
| 18 | /** |
| 19 | * |
| 20 | * @var type |
| 21 | */ |
| 22 | protected $args; |
| 23 | |
| 24 | /** |
| 25 | * |
| 26 | * @var type |
| 27 | */ |
| 28 | protected $content; |
| 29 | |
| 30 | /** |
| 31 | * Initialize shortcode decorator |
| 32 | * |
| 33 | * Expecting attributes in $args are: |
| 34 | * "class" => CSS class for login button |
| 35 | * "callback" => callback function that returns the login button |
| 36 | * "label" => if stand-alone shortcode then defined text label will be used |
| 37 | * |
| 38 | * @param type $args |
| 39 | * @param type $content |
| 40 | */ |
| 41 | public function __construct($args, $content) { |
| 42 | $this->args = $args; |
| 43 | $this->content = $content; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Process shortcode |
| 48 | * |
| 49 | */ |
| 50 | public function run() { |
| 51 | $redirect = AAM_Core_Request::server('REQUEST_URI'); |
| 52 | $class = (isset($this->args['class']) ? $this->args['class'] : ''); |
| 53 | |
| 54 | if (isset($this->args['callback'])) { |
| 55 | $button = call_user_func($this->args['callback'], $this); |
| 56 | } else { |
| 57 | $url = add_query_arg( |
| 58 | 'reason', |
| 59 | 'access-denied', |
| 60 | wp_login_url($redirect) |
| 61 | ); |
| 62 | |
| 63 | if (empty($this->content)) { |
| 64 | $label = (!empty($this->args['label']) ? $this->args['label'] : __('Login to continue', AAM_KEY)); |
| 65 | } else { |
| 66 | $label = $this->content; |
| 67 | } |
| 68 | |
| 69 | $button = '<a href="' . $url . '" '; |
| 70 | $button .= 'class="' . $class . '">' . $label . '</a>'; |
| 71 | } |
| 72 | |
| 73 | return $button; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * |
| 78 | * @return type |
| 79 | */ |
| 80 | public function getArgs() { |
| 81 | return $this->args; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * |
| 86 | * @return type |
| 87 | */ |
| 88 | public function getContent() { |
| 89 | return $this->content; |
| 90 | } |
| 91 | |
| 92 | } |