| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.9 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 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. [firebox.LoginForm] |
| 25 |
* |
| 26 |
* @var array. |
| 27 |
*/ |
| 28 |
private $shortcodes = [ |
| 29 |
'loginForm', |
| 30 |
'navigationMenu', |
| 31 |
'embed' |
| 32 |
]; |
| 33 |
|
| 34 |
/** |
| 35 |
* Shortcodes prefix |
| 36 |
* |
| 37 |
* @var string |
| 38 |
*/ |
| 39 |
private $prefix = 'firebox.'; |
| 40 |
|
| 41 |
public function __construct() |
| 42 |
{ |
| 43 |
$this->addShortcodes(); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Adds all shortcodes |
| 48 |
* |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
private function addShortcodes() |
| 52 |
{ |
| 53 |
// Backwards compatibility Start - We changed shortcode syntax in vesion 2.1.22 |
| 54 |
add_shortcode('fbox' . ucfirst($this->shortcodes[0]), [$this, 'LoginForm']); |
| 55 |
add_shortcode('fbox' . ucfirst($this->shortcodes[1]), [$this, 'NavigationMenu']); |
| 56 |
// Backwards compatibility end |
| 57 |
|
| 58 |
// redirect shortcodes |
| 59 |
foreach ($this->shortcodes as $shortcode) |
| 60 |
{ |
| 61 |
// add shortcode |
| 62 |
$callback = ucfirst($shortcode); |
| 63 |
$shortcode = $this->prefix . $shortcode; |
| 64 |
add_shortcode($shortcode, [$this, $callback]); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Create a shortcode [firebox.loginForm] to print the WP Login Form |
| 70 |
* |
| 71 |
* @param array $attributes |
| 72 |
* |
| 73 |
* @return void |
| 74 |
*/ |
| 75 |
public function LoginForm($attributes) |
| 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 |
global $wp; |
| 95 |
$currentUrl = add_query_arg((isset($_SERVER['QUERY_STRING']) ? sanitize_url(wp_unslash($_SERVER['QUERY_STRING'])) : ''), '', home_url( $wp->request ) ); |
| 96 |
|
| 97 |
$show_forgot_password_link = isset($attributes['show_forgot_link']) && $attributes['show_forgot_link']; |
| 98 |
$redirect = isset($attributes['redirect']) ? esc_url_raw($attributes['redirect']) : $currentUrl; |
| 99 |
|
| 100 |
$args = [ |
| 101 |
'echo' => false, |
| 102 |
'remember' => true, |
| 103 |
/** |
| 104 |
* We can only redirect to local URLs due to WP using wp_safe_redirect. |
| 105 |
* To redirect to external URLs, users need to hook on allowed_redirect_hosts and add their external URL hosts. |
| 106 |
* Hook doc: https://developer.wordpress.org/reference/hooks/allowed_redirect_hosts/ |
| 107 |
*/ |
| 108 |
'redirect' => $redirect, |
| 109 |
'form_id' => 'fboxLogin', |
| 110 |
'id_username' => 'user_login', |
| 111 |
'id_password' => 'user_pass', |
| 112 |
'id_remember' => 'rememberme', |
| 113 |
'id_submit' => 'wp-submit', |
| 114 |
'label_username' => firebox()->_('FB_USERNAME_OR_EMAIL_ADDRESS'), |
| 115 |
'label_password' => fpframework()->_('FPF_PASSWORD'), |
| 116 |
'label_remember' => fpframework()->_('FPF_REMEMBER_ME'), |
| 117 |
'label_log_in' => fpframework()->_('FPF_LOG_IN'), |
| 118 |
'value_username' => '', |
| 119 |
'value_remember' => false |
| 120 |
]; |
| 121 |
|
| 122 |
$forgot_password_link = $show_forgot_password_link ? '<div class="form-actions"><a href="' . wp_lostpassword_url() . '">' . fpframework()->_('FPF_FORGOT_YOUR_PASSWORD') . '</a></div>' : ''; |
| 123 |
|
| 124 |
// load CSS |
| 125 |
wp_enqueue_style( |
| 126 |
'firebox-login-shortcode', |
| 127 |
FBOX_MEDIA_PUBLIC_URL . 'css/shortcodes/login.css', |
| 128 |
[], |
| 129 |
FBOX_VERSION, |
| 130 |
false |
| 131 |
); |
| 132 |
|
| 133 |
return wp_login_form($args) . $forgot_password_link; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Create a shortcode [firebox.navigationMenu] to print the navigation menu |
| 138 |
* |
| 139 |
* @param array $attributes |
| 140 |
* @param string $content |
| 141 |
* |
| 142 |
* @return void |
| 143 |
*/ |
| 144 |
public function NavigationMenu($attributes, $content = null) |
| 145 |
{ |
| 146 |
$atts = shortcode_atts( |
| 147 |
[ |
| 148 |
'menu' => '', |
| 149 |
'container' => 'div', |
| 150 |
'container_class' => '', |
| 151 |
'container_id' => '', |
| 152 |
'menu_class' => 'menu', |
| 153 |
'menu_id' => '', |
| 154 |
'echo' => true, |
| 155 |
'fallback_cb' => 'wp_page_menu', |
| 156 |
'before' => '', |
| 157 |
'after' => '', |
| 158 |
'link_before' => '', |
| 159 |
'link_after' => '', |
| 160 |
'depth' => 0, |
| 161 |
'walker' => '', |
| 162 |
'theme_location' => '' |
| 163 |
], |
| 164 |
$attributes |
| 165 |
); |
| 166 |
|
| 167 |
return wp_nav_menu( |
| 168 |
[ |
| 169 |
'menu' => sanitize_text_field($atts['menu']), |
| 170 |
'container' => sanitize_text_field($atts['container']), |
| 171 |
'container_class' => sanitize_html_class($atts['container_class']), |
| 172 |
'container_id' => sanitize_html_class($atts['container_id']), |
| 173 |
'menu_class' => sanitize_html_class($atts['menu_class']), |
| 174 |
'menu_id' => sanitize_html_class($atts['menu_id']), |
| 175 |
'echo' => false, |
| 176 |
'fallback_cb' => sanitize_text_field($atts['fallback_cb']), |
| 177 |
'before' => wp_kses_post($atts['before']), |
| 178 |
'after' => wp_kses_post($atts['after']), |
| 179 |
'link_before' => wp_kses_post($atts['link_before']), |
| 180 |
'link_after' => wp_kses_post($atts['link_after']), |
| 181 |
'depth' => absint($atts['depth']), |
| 182 |
'walker' => sanitize_text_field($atts['walker']), |
| 183 |
'theme_location' => sanitize_text_field($atts['theme_location']) |
| 184 |
] |
| 185 |
); |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Create a shortcode [firebox.embed id="X"] to display a FireBox campaign with mode = Embed. |
| 190 |
* |
| 191 |
* @param array $attributes |
| 192 |
* @param string $content |
| 193 |
* |
| 194 |
* @return void |
| 195 |
*/ |
| 196 |
public function Embed($attributes, $content = null) |
| 197 |
{ |
| 198 |
$atts = shortcode_atts( |
| 199 |
[ |
| 200 |
'id' => '' |
| 201 |
], |
| 202 |
$attributes |
| 203 |
); |
| 204 |
|
| 205 |
if (!$atts['id']) |
| 206 |
{ |
| 207 |
return; |
| 208 |
} |
| 209 |
|
| 210 |
return \FireBox\Core\Helpers\Embed::renderCampaign(absint($atts['id'])); |
| 211 |
} |
| 212 |
} |