* @link https://www.fireplugins.com * @copyright Copyright © 2021 FirePlugins All Rights Reserved * @license GNU GPLv3 or later */ namespace FireBox\Core\Shortcodes; if (!defined('ABSPATH')) { exit; // Exit if accessed directly. } class Shortcodes { /** * A list of shortcodes. * * To run shortcode: [loginForm]. i.e. [fboxLoginForm] * * @var array. */ private $shortcodes = [ 'LoginForm', 'NavigationMenu' ]; /** * Shortcodes prefix * * @var string */ private $prefix = 'fbox'; public function __construct() { $this->addShortcodes(); } /** * Adds all shortcodes * * @return void */ private function addShortcodes() { // redirect shortcodes foreach ($this->shortcodes as $shortcode) { $shortcode = $this->prefix . $shortcode; $method = $shortcode . 'ShortcodeHandler'; // make sure callback exists if (!method_exists($this, $method)) { continue; } // add shortcode add_shortcode($shortcode, [$this, $method]); } } /** * Create a shortcode [fboxLoginShortcode] to print the WP Login Form * * @return void */ public function fboxLoginFormShortcodeHandler($atts) { if (is_user_logged_in()) { $factory = new \FPFramework\Base\Factory(); $user = $factory->getUser(); $firstname = $user->user_firstname; $lastname = $user->user_lastname; $sep = empty($lastname) ? '' : ' '; $name = $firstname . $sep . $lastname; $name = empty($name) ? $user->user_login : $name; $str = '

' . fpframework()->_('FPF_HI') . ' ' . esc_attr($name) . ',

' . fpframework()->_('FPF_LOG_OUT') . '

'; return $str; } $show_forgot_password_link = isset($atts['show_forgot_link']) && $atts['show_forgot_link']; $args = [ 'echo' => false, 'remember' => true, 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'form_id' => 'fboxLogin', 'id_username' => 'user_login', 'id_password' => 'user_pass', 'id_remember' => 'rememberme', 'id_submit' => 'wp-submit', 'label_username' => firebox()->_('FB_USERNAME_OR_EMAIL_ADDRESS'), 'label_password' => fpframework()->_('FPF_PASSWORD'), 'label_remember' => fpframework()->_('FPF_REMEMBER_ME'), 'label_log_in' => fpframework()->_('FPF_LOG_IN'), 'value_username' => '', 'value_remember' => false ]; $forgot_password_link = $show_forgot_password_link ? '
' . fpframework()->_('FPF_FORGOT_YOUR_PASSWORD') . '
' : ''; // load CSS wp_enqueue_style( 'firebox-login-shortcode', FBOX_MEDIA_PUBLIC_URL . 'css/shortcodes/login.css', [], FBOX_VERSION, false ); return wp_login_form($args) . $forgot_password_link; } /** * Create a shortcode [fboxNavigationMenu] to print the navigation menu * * @return void */ public function fboxNavigationMenuShortcodeHandler($atts, $content = null) { extract(shortcode_atts( [ 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'depth' => 0, 'walker' => '', 'theme_location' => '' ], $atts) ); return wp_nav_menu( [ 'menu' => $menu, 'container' => $container, 'container_class' => $container_class, 'container_id' => $container_id, 'menu_class' => $menu_class, 'menu_id' => $menu_id, 'echo' => false, 'fallback_cb' => $fallback_cb, 'before' => $before, 'after' => $after, 'link_before' => $link_before, 'link_after' => $link_after, 'depth' => $depth, 'walker' => $walker, 'theme_location' => $theme_location ] ); } }