| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.5 Free | |
| 4 | + * @version 2.1.39 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2021 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2025 FirePlugins All Rights Reserved | |
| 9 | 9 | * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | namespace FireBox\Core\Shortcodes; |
| @@ -20,15 +20,16 @@ | ||
| 20 | 20 | { |
| 21 | 21 | /** |
| 22 | 22 | * A list of shortcodes. |
| 23 | 23 | * |
| 24 | - * To run shortcode: [loginForm]. i.e. [fboxLoginForm] | |
| 24 | + * To run shortcode: [loginForm]. i.e. [firebox.LoginForm] | |
| 25 | 25 | * |
| 26 | 26 | * @var array. |
| 27 | 27 | */ |
| 28 | 28 | private $shortcodes = [ |
| 29 | - 'LoginForm', | |
| 30 | - 'NavigationMenu' | |
| 29 | + 'loginForm', | |
| 30 | + 'navigationMenu', | |
| 31 | + 'embed' | |
| 31 | 32 | ]; |
| 32 | 33 | |
| 33 | 34 | /** |
| 34 | 35 | * Shortcodes prefix |
| @@ -34,9 +35,9 @@ | ||
| 34 | 35 | * Shortcodes prefix |
| 35 | 36 | * |
| 36 | 37 | * @var string |
| 37 | 38 | */ |
| 38 | - private $prefix = 'fbox'; | |
| 39 | + private $prefix = 'firebox.'; | |
| 39 | 40 | |
| 40 | 41 | public function __construct() |
| 41 | 42 | { |
| 42 | 43 | $this->addShortcodes(); |
| @@ -48,32 +49,31 @@ | ||
| 48 | 49 | * @return void |
| 49 | 50 | */ |
| 50 | 51 | private function addShortcodes() |
| 51 | 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 | + | |
| 52 | 58 | // redirect shortcodes |
| 53 | 59 | foreach ($this->shortcodes as $shortcode) |
| 54 | 60 | { |
| 61 | + // add shortcode | |
| 62 | + $callback = ucfirst($shortcode); | |
| 55 | 63 | $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]); | |
| 64 | + add_shortcode($shortcode, [$this, $callback]); | |
| 67 | 65 | } |
| 68 | 66 | } |
| 69 | 67 | |
| 70 | 68 | /** |
| 71 | - * Create a shortcode [fboxLoginShortcode] to print the WP Login Form | |
| 69 | + * Create a shortcode [firebox.loginForm] to print the WP Login Form | |
| 72 | 70 | * |
| 71 | + * @param array $attributes | |
| 72 | + * | |
| 73 | 73 | * @return void |
| 74 | 74 | */ |
| 75 | - public function fboxLoginFormShortcodeHandler($atts) | |
| 75 | + public function LoginForm($attributes) | |
| 76 | 76 | { |
| 77 | 77 | if (is_user_logged_in()) |
| 78 | 78 | { |
| 79 | 79 | $factory = new \FPFramework\Base\Factory(); |
| @@ -89,15 +89,24 @@ | ||
| 89 | 89 | |
| 90 | 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 | 91 | return $str; |
| 92 | 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 ) ); | |
| 93 | 96 | |
| 94 | - $show_forgot_password_link = isset($atts['show_forgot_link']) && $atts['show_forgot_link']; | |
| 97 | + $show_forgot_password_link = isset($attributes['show_forgot_link']) && $attributes['show_forgot_link']; | |
| 98 | + $redirect = isset($attributes['redirect']) ? $attributes['redirect'] : $currentUrl; | |
| 95 | 99 | |
| 96 | 100 | $args = [ |
| 97 | 101 | 'echo' => false, |
| 98 | 102 | 'remember' => true, |
| 99 | - 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], | |
| 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, | |
| 100 | 109 | 'form_id' => 'fboxLogin', |
| 101 | 110 | 'id_username' => 'user_login', |
| 102 | 111 | 'id_password' => 'user_pass', |
| 103 | 112 | 'id_remember' => 'rememberme', |
| @@ -124,15 +133,18 @@ | ||
| 124 | 133 | return wp_login_form($args) . $forgot_password_link; |
| 125 | 134 | } |
| 126 | 135 | |
| 127 | 136 | /** |
| 128 | - * Create a shortcode [fboxNavigationMenu] to print the navigation menu | |
| 137 | + * Create a shortcode [firebox.navigationMenu] to print the navigation menu | |
| 129 | 138 | * |
| 139 | + * @param array $attributes | |
| 140 | + * @param string $content | |
| 141 | + * | |
| 130 | 142 | * @return void |
| 131 | 143 | */ |
| 132 | - public function fboxNavigationMenuShortcodeHandler($atts, $content = null) | |
| 144 | + public function NavigationMenu($attributes, $content = null) | |
| 133 | 145 | { |
| 134 | - extract(shortcode_atts( | |
| 146 | + $atts = shortcode_atts( | |
| 135 | 147 | [ |
| 136 | 148 | 'menu' => '', |
| 137 | 149 | 'container' => 'div', |
| 138 | 150 | 'container_class' => '', |
| @@ -147,29 +159,54 @@ | ||
| 147 | 159 | 'link_after' => '', |
| 148 | 160 | 'depth' => 0, |
| 149 | 161 | 'walker' => '', |
| 150 | 162 | 'theme_location' => '' |
| 151 | - ], $atts) | |
| 163 | + ], | |
| 164 | + $attributes | |
| 152 | 165 | ); |
| 153 | 166 | |
| 154 | - | |
| 155 | 167 | return wp_nav_menu( |
| 156 | 168 | [ |
| 157 | - 'menu' => $menu, | |
| 158 | - 'container' => $container, | |
| 159 | - 'container_class' => $container_class, | |
| 160 | - 'container_id' => $container_id, | |
| 161 | - 'menu_class' => $menu_class, | |
| 162 | - 'menu_id' => $menu_id, | |
| 169 | + 'menu' => $atts['menu'], | |
| 170 | + 'container' => $atts['container'], | |
| 171 | + 'container_class' => $atts['container_class'], | |
| 172 | + 'container_id' => $atts['container_id'], | |
| 173 | + 'menu_class' => $atts['menu_class'], | |
| 174 | + 'menu_id' => $atts['menu_id'], | |
| 163 | 175 | 'echo' => false, |
| 164 | - 'fallback_cb' => $fallback_cb, | |
| 165 | - 'before' => $before, | |
| 166 | - 'after' => $after, | |
| 167 | - 'link_before' => $link_before, | |
| 168 | - 'link_after' => $link_after, | |
| 169 | - 'depth' => $depth, | |
| 170 | - 'walker' => $walker, | |
| 171 | - 'theme_location' => $theme_location | |
| 176 | + 'fallback_cb' => $atts['fallback_cb'], | |
| 177 | + 'before' => $atts['before'], | |
| 178 | + 'after' => $atts['after'], | |
| 179 | + 'link_before' => $atts['link_before'], | |
| 180 | + 'link_after' => $atts['link_after'], | |
| 181 | + 'depth' => $atts['depth'], | |
| 182 | + 'walker' => $atts['walker'], | |
| 183 | + 'theme_location' => $atts['theme_location'] | |
| 172 | 184 | ] |
| 173 | 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($atts['id']); | |
| 174 | 211 | } |
| 175 | 212 | } |