Passed
Pull Request — master (#7)
by Joseph
02:29
created

Shortcodes::lostPasswordLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 9.6666
1
<?php
2
/**
3
 * This file is part of the Subway WordPress Plugin Package.
4
 *
5
 * (c) Joseph Gabito <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 * 
10
 * PHP Version 5.4
11
 * 
12
 * @category Subway\Shortcodes
13
 * @package  Subway\Shortcodes
14
 * @author   Joseph G. <[email protected]>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @version  GIT:github.com/codehaiku/subway
17
 * @link     github.com/codehaiku/subway The Plugin Repository
18
 */
19
20
namespace Subway;
21
22
if (! defined('ABSPATH') ) {
23
    return;
24
}
25
26
/**
27
 * Registers Plugin Shortcodes
28
 *
29
 * @category Subway\Shortcodes
30
 * @package  Subway
31
 * @author   Joseph G. <[email protected]>
32
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
33
 * @link     github.com/codehaiku/subway The Plugin Repository
34
 * @since    1.0  
35
 */
36
final class Shortcodes
37
{
38
39
    /**
40
     * Class Constructor.
41
     *
42
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
43
     */
44
    private function __construct() 
45
    {
46
        
47
        add_action('init', array( $this, 'register'));
48
        
49
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
50
51
    }
52
53
    /**
54
     * Instantiate our class.
55
     * 
56
     * @return mixed The instance of this class.
57
     */
58
    public static function instance() 
59
    {
60
        
61
        static $instance = null;
62
63
        if (null === $instance ) {
64
65
            $instance = new Shortcodes();
66
67
        }
68
69
        return $instance;
70
71
    }
72
73
    /**
74
     * Instantiate our class.
75
     * 
76
     * @return void
77
     */
78
    public function register() 
79
    {
80
81
        add_shortcode('subway_login', array( $this, 'loginForm' ));
82
83
        add_action('login_form_middle', array( $this, 'loginFormAction' ), 10, 2);
84
85
        add_action('login_form_middle', array( $this, 'lostPasswordLink' ), 10, 2);
86
87
        return;
88
89
    }
90
91
    /**
92
     * Displays the login form
93
     * 
94
     * @return void
95
     */
96
    public function loginForm() 
97
    {
98
        
99
        $atts = array();
100
101
        echo $this->renderTemplate($atts, 'login-form.php');
102
103
        return;
104
    }
105
106
    /**
107
     * Include the specific plugin file if there is no template file.
108
     * 
109
     * @param mixed  $atts The shortcode attribute.
110
     * @param string $file The shortcode template file.
111
     * 
112
     * @return string The html template content.
113
     */
114
    protected function renderTemplate( $atts, $file = '' ) 
115
    {
116
117
        ob_start();
118
119
        if (empty($file) ) {
120
            
121
            return;
122
123
        }
124
125
        $template = SUBWAY_DIR_PATH . 'templates/'.$file;
126
127
        if (file_exists($template) ) {
128
129
            $theme_template = locate_template(array('gears/shortcodes/'.$file ));
130
131
            if ($theme_template) {
132
133
                   $template = $theme_template;
134
135
            }
136
137
            include $template;
138
139
        } else {
140
141
            echo sprintf(
142
                esc_html_e(
143
                    'Subway Error: Unable to find template file in: %1s', 'subway'
144
                ), 
145
                $template
146
            );
147
148
        }
149
150
        return ob_get_clean();
151
    }
152
153
    /**
154
     * The action for our login form.
155
     * 
156
     * @param string $__content The current filtered contents.
157
     * 
158
     * @return string            The content of our login form action.
159
     */
160
    public function loginFormAction( $__content ) 
161
    {
162
163
        ob_start();
164
        
165
        do_action('login_form');
166
        
167
        return $__content . ob_get_clean();
168
169
    }
170
171
     /**
172
     * The action for our 'lost password' link.
173
     * 
174
     * @param string $content The current filtered contents.
175
     * 
176
     * @return string          The content of our lost password link.
177
     */
178
    public function lostPasswordLink( $content ) 
179
    {
180
        
181
        return $content . $this->renderTemplate(
182
            array(), 
183
            'login-form-lost-password.php'
184
        );
185
186
    }
187
188
}
189
190
$subway_shortcode = Shortcodes::instance();
191