Content.php
8 years ago
Interface.php
8 years ago
Login.php
8 years ago
LoginRedirect.php
8 years ago
LoginRedirect.php
85 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 | * |
| 37 | * @param type $args |
| 38 | * @param type $content |
| 39 | */ |
| 40 | public function __construct($args, $content) { |
| 41 | $this->args = $args; |
| 42 | $this->content = $content; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Process shortcode |
| 47 | * |
| 48 | */ |
| 49 | public function run() { |
| 50 | $redirect = AAM_Core_Request::server('REQUEST_URI'); |
| 51 | $class = (isset($this->args['class']) ? $this->args['class'] : ''); |
| 52 | |
| 53 | if (isset($this->args['callback'])) { |
| 54 | $button = call_user_func($this->args['callback'], $this); |
| 55 | } else { |
| 56 | $url = add_query_arg( |
| 57 | 'reason', |
| 58 | 'access-denied', |
| 59 | wp_login_url($redirect) |
| 60 | ); |
| 61 | |
| 62 | $button = '<a href="' . $url . '" '; |
| 63 | $button .= 'class="' . $class . '">' . $this->content . '</a>'; |
| 64 | } |
| 65 | |
| 66 | return $button; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * |
| 71 | * @return type |
| 72 | */ |
| 73 | public function getArgs() { |
| 74 | return $this->args; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * |
| 79 | * @return type |
| 80 | */ |
| 81 | public function getContent() { |
| 82 | return $this->content; |
| 83 | } |
| 84 | |
| 85 | } |