Login.php
83 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_Login 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 | * "label" => Login button label |
| 36 | * "callback" => callback function that returns the login button |
| 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 | $label = (isset($this->args['label']) ? $this->args['label'] : 'Login'); |
| 54 | |
| 55 | if (isset($this->args['callback'])) { |
| 56 | $button = call_user_func($this->args['callback'], $this); |
| 57 | } else { |
| 58 | $url = wp_login_url($redirect); |
| 59 | |
| 60 | $button = '<a href="' . $url . '" '; |
| 61 | $button .= 'class="' . $class . '">' . $label . '</a>'; |
| 62 | } |
| 63 | |
| 64 | return $button; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * |
| 69 | * @return type |
| 70 | */ |
| 71 | public function getArgs() { |
| 72 | return $this->args; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * |
| 77 | * @return type |
| 78 | */ |
| 79 | public function getContent() { |
| 80 | return $this->content; |
| 81 | } |
| 82 | |
| 83 | } |