PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.1.1
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.1.1
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Core / Shortcodes / Shortcodes.php

Shortcodes.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 1.1.1, at Inc/Core/Shortcodes/Shortcodes.php

181 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 1.1.1 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2022 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Shortcodes;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Shortcodes
20 {
21 /**
22 * A list of shortcodes.
23 *
24 * To run shortcode: [loginForm]. i.e. [fboxLoginForm]
25 *
26 * @var array.
27 */
28 private $shortcodes = [
29 'LoginForm',
30 'NavigationMenu'
31 ];
32
33 /**
34 * Shortcodes prefix
35 *
36 * @var string
37 */
38 private $prefix = 'fbox';
39
40 public function __construct()
41 {
42 $this->addShortcodes();
43 }
44
45 /**
46 * Adds all shortcodes
47 *
48 * @return void
49 */
50 private function addShortcodes()
51 {
52 // redirect shortcodes
53 foreach ($this->shortcodes as $shortcode)
54 {
55 $shortcode = $this->prefix . $shortcode;
56
57 $method = $shortcode . 'ShortcodeHandler';
58
59 // make sure callback exists
60 if (!method_exists($this, $method))
61 {
62 continue;
63 }
64
65 // add shortcode
66 add_shortcode($shortcode, [$this, $method]);
67 }
68 }
69
70 /**
71 * Create a shortcode [fboxLoginForm] to print the WP Login Form
72 *
73 * @return void
74 */
75 public function fboxLoginFormShortcodeHandler($atts)
76 {
77 if (is_user_logged_in())
78 {
79 $factory = new \FPFramework\Base\Factory();
80 $user = $factory->getUser();
81
82 $firstname = $user->user_firstname;
83 $lastname = $user->user_lastname;
84
85 $sep = empty($lastname) ? '' : ' ';
86
87 $name = $firstname . $sep . $lastname;
88 $name = empty($name) ? $user->user_login : $name;
89
90 $str = '<p>' . fpframework()->_('FPF_HI') . ' ' . esc_attr($name) . ',</p><p><a href="' . wp_logout_url() . '" class="fb-btn fb-btn-primary fb-fullwidth">' . fpframework()->_('FPF_LOG_OUT') . '</a></p>';
91 return $str;
92 }
93
94 $show_forgot_password_link = isset($atts['show_forgot_link']) && $atts['show_forgot_link'];
95 $redirect = isset($atts['redirect']) ? $atts['redirect'] : (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
96
97 $args = [
98 'echo' => false,
99 'remember' => true,
100 /**
101 * We can only redirect to local URLs due to WP using wp_safe_redirect.
102 * To redirect to external URLs, users need to hook on allowed_redirect_hosts and add their external URL hosts.
103 * Hook doc: https://developer.wordpress.org/reference/hooks/allowed_redirect_hosts/
104 */
105 'redirect' => $redirect,
106 'form_id' => 'fboxLogin',
107 'id_username' => 'user_login',
108 'id_password' => 'user_pass',
109 'id_remember' => 'rememberme',
110 'id_submit' => 'wp-submit',
111 'label_username' => firebox()->_('FB_USERNAME_OR_EMAIL_ADDRESS'),
112 'label_password' => fpframework()->_('FPF_PASSWORD'),
113 'label_remember' => fpframework()->_('FPF_REMEMBER_ME'),
114 'label_log_in' => fpframework()->_('FPF_LOG_IN'),
115 'value_username' => '',
116 'value_remember' => false
117 ];
118
119 $forgot_password_link = $show_forgot_password_link ? '<div class="form-actions"><a href="' . wp_lostpassword_url() . '">' . fpframework()->_('FPF_FORGOT_YOUR_PASSWORD') . '</a></div>' : '';
120
121 // load CSS
122 wp_enqueue_style(
123 'firebox-login-shortcode',
124 FBOX_MEDIA_PUBLIC_URL . 'css/shortcodes/login.css',
125 [],
126 FBOX_VERSION,
127 false
128 );
129
130 return wp_login_form($args) . $forgot_password_link;
131 }
132
133 /**
134 * Create a shortcode [fboxNavigationMenu] to print the navigation menu
135 *
136 * @return void
137 */
138 public function fboxNavigationMenuShortcodeHandler($atts, $content = null)
139 {
140 extract(shortcode_atts(
141 [
142 'menu' => '',
143 'container' => 'div',
144 'container_class' => '',
145 'container_id' => '',
146 'menu_class' => 'menu',
147 'menu_id' => '',
148 'echo' => true,
149 'fallback_cb' => 'wp_page_menu',
150 'before' => '',
151 'after' => '',
152 'link_before' => '',
153 'link_after' => '',
154 'depth' => 0,
155 'walker' => '',
156 'theme_location' => ''
157 ], $atts)
158 );
159
160
161 return wp_nav_menu(
162 [
163 'menu' => $menu,
164 'container' => $container,
165 'container_class' => $container_class,
166 'container_id' => $container_id,
167 'menu_class' => $menu_class,
168 'menu_id' => $menu_id,
169 'echo' => false,
170 'fallback_cb' => $fallback_cb,
171 'before' => $before,
172 'after' => $after,
173 'link_before' => $link_before,
174 'link_after' => $link_after,
175 'depth' => $depth,
176 'walker' => $walker,
177 'theme_location' => $theme_location
178 ]
179 );
180 }
181 }