AlkantarClanX12
| Current Path : /www/capitalgmcbuickregina_830/public/wp-content/themes/lbx-egypt/ |
| Current File : /www/capitalgmcbuickregina_830/public/wp-content/themes/lbx-egypt/functions.php |
<?php
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our theme. We will simply require it into the script here so that we
| don't have to worry about manually loading any of our classes later on.
|
*/
if (!file_exists($composer = __DIR__ . '/vendor/autoload.php')) {
wp_die(__('Error locating autoloader. Please run <code>composer install</code>.', 'sage'));
}
require $composer;
/*
|--------------------------------------------------------------------------
| Register The Bootloader
|--------------------------------------------------------------------------
|
| The first thing we will do is schedule a new Acorn application container
| to boot when WordPress is finished loading the theme. The application
| serves as the "glue" for all the components of Laravel and is
| the IoC container for the system binding all of the various parts.
|
*/
try {
\Roots\bootloader();
} catch (Throwable $e) {
wp_die(
__('You need to install Acorn to use this theme.', 'sage'),
'',
[
'link_url' => 'https://docs.roots.io/acorn/2.x/installation/',
'link_text' => __('Acorn Docs: Installation', 'sage'),
]
);
}
/*
|--------------------------------------------------------------------------
| Register Sage Theme Files
|--------------------------------------------------------------------------
|
| Out of the box, Sage ships with categorically named theme files
| containing common functionality and setup to be bootstrapped with your
| theme. Simply add (or remove) files from the array below to change what
| is registered alongside Sage.
|
*/
collect(['wrappers', 'helpers', 'setup', 'filters', 'admin'])
->each(function ($file) {
if (!locate_template($file = "app/{$file}.php", true, true)) {
wp_die(
/* translators: %s is replaced with the relative file path */
sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file)
);
}
});
/*
|--------------------------------------------------------------------------
| Enable Sage Theme Support
|--------------------------------------------------------------------------
|
| Once our theme files are registered and available for use, we are almost
| ready to boot our application. But first, we need to signal to Acorn
| that we will need to initialize the necessary service providers built in
| for Sage when booting.
|
*/
add_theme_support('sage');
require(__DIR__ . '/update.php');
function register_my_menus()
{
if (function_exists('pll_the_languages')) {
if (!(has_nav_menu('footer-menu')) || !(has_nav_menu('side-menu'))) {
register_nav_menus(
array(
'footer-menu' => __('Footer Menu'),
'side-menu' => __('Side Menu'),
'mobile-menu' => __('Mobile Menu')
)
);
}
} else {
if (
!(has_nav_menu('primary_navigation___fr')) || !(has_nav_menu('footer-menu')) || !(has_nav_menu('footer-menu___fr'))
|| !(has_nav_menu('side-menu')) || !(has_nav_menu('side-menu___fr'))
) {
register_nav_menus(
array(
'primary_navigation___fr' => __('Primary Navigation FR'),
'footer-menu' => __('Footer Menu'),
'footer-menu___fr' => __('Footer Menu FR'),
'side-menu' => __('Side Menu'),
'side-menu___fr' => __('Side Menu FR'),
'mobile-menu' => __('Mobile Menu'),
'mobile-menu___fr' => __('Mobile Menu FR')
)
);
}
}
}
add_action('after_setup_theme', 'register_my_menus');
function error_500_page()
{
include_once(get_template_directory() . "/resources/views/errors/500.blade.php");
}
add_action('wp_die_handler', 'error_500_page');
/* IN PROGRESS, DONT TOUCH IT */
/* function mi_shortcode_html() {
ob_start(); ?>
<div>
<h1>Título</h1>
<p>Contenido del shortcode HTML</p>
</div>
<?php
return ob_get_clean();
}
add_shortcode('mi_shortcode', 'mi_shortcode_html'); */
/*
|--------------------------------------------------------------------------
| disallow_myme_types
|--------------------------------------------------------------------------
| Jun-01-23
| This function disables video format files of the allowed file mime_types
|
*/
function disallow_mime_types($mime_types)
{
unset($mime_types['mp4']);
unset($mime_types['mov']);
unset($mime_types['wmv']);
unset($mime_types['avi']);
unset($mime_types['avchd']);
unset($mime_types['flv']);
unset($mime_types['f4v']);
unset($mime_types['swf']);
unset($mime_types['mkv']);
unset($mime_types['webm']);
return $mime_types;
}
add_filter('upload_mimes', 'disallow_mime_types');
/*
|--------------------------------------------------------------------------
| limit_upload_size_and_dimensions
|--------------------------------------------------------------------------
| Jun-01-23
| This function limits the size of the files to be uploaded. If the file
| is an image, restricts the dimensions of the image when it is uploaded
|
*/
function limit_upload_size_and_dimensions($file)
{
$file['error'] = "";
// check valid size of file
$file_size_limit = 5120; // 5MB in KB
$current_size = filesize($file['tmp_name']);
if ($current_size > $file_size_limit * 1024) {
$file['error'] = sprintf(__('ERROR: File size limit is %d MB.'), ($file_size_limit / 1024));
return $file;
}
// check valid image dimensions
return $file;
}
add_filter('wp_handle_upload_prefilter', 'limit_upload_size_and_dimensions');
/*
|--------------------------------------------------------------------------
| rewrite_max_upload_size_message
|--------------------------------------------------------------------------
| Jun-01-23
| With this script, which is injected into the wordpress administrator,
| the message that tells the user what the maximum weight allowed per file
| is rewritten
|
*/
function rewrite_max_upload_size_message()
{
?>
<script>
window.onload = function() {
const collection = document.getElementsByClassName("max-upload-size");
for (let i = 0; i < collection.length; i++) {
collection[i].innerHTML = "Maximum upload file size: 5 MB.";
}
}
</script>
<?php
}
add_action('admin_footer', 'rewrite_max_upload_size_message');
/*
|--------------------------------------------------------------------------
| LBX_is_plugin_activated
|--------------------------------------------------------------------------
| Nov-20-23
| This function checks if a WordPress plugin is currently active.
| It takes either the plugin name or the main .php file as an argument.
|
| @param string $plugin The name or main file of the plugin to check.
| @return bool True if the plugin is active, false otherwise.
|
*/
function LBX_is_plugin_activated($plugin)
{
// Convert both the plugin name and plugin names in the active plugins list to lowercase
$lowercase_plugin = strtolower($plugin);
// Get the list of active plugins
$active_plugins = get_option('active_plugins');
// Get information about all installed plugins
$all_plugins = get_plugins();
// Iterate through the list of active plugins and compare with the lowercase plugin name or main .php file
foreach ($active_plugins as $plugin_basename) {
$plugin_info = $all_plugins[$plugin_basename];
// Convert the plugin name to lowercase for comparison
$lowercase_plugin_name = strtolower($plugin_info['Name']);
// Check by lowercase plugin name or main .php file
if ($lowercase_plugin_name === $lowercase_plugin || strtolower($plugin_basename) === $lowercase_plugin) {
return true;
}
}
return false;
}
/*
|--------------------------------------------------------------------------
| get_form_details_by_modal_name
|--------------------------------------------------------------------------
| Jul-28-24
| This function retrieves details of a custom Ninja Form based on the modal name.
| It searches for a form title matching the provided modal name and returns
| information about the form, such as its ID and title.
|
| @param string $modalName The name of the modal to retrieve form details for.
| @return array An array containing the form ID, form title, and a boolean indicating
| whether the custom form was found or not.
|
*/
function get_form_details_by_modal_name($modalName)
{
$form_name_title = str_replace('-', ' ', $modalName);
// Obtener los formularios personalizados de Ninja Forms
$forms = Ninja_Forms()->form()->get_forms();
$custom_form_found = false;
$form_id = null;
$form_title = '';
foreach ($forms as $form) {
$fn = $form->get_setting('title');
if (str_replace('-', ' ', $modalName) == strtolower($fn)) {
$form_id = $form->get_id();
$form_title = $fn;
$custom_form_found = true;
break;
}
}
if (!$custom_form_found) {
$form_title = 'Form not found.';
}
return [
'form_id' => $form_id,
'form_title' => $form_title,
'custom_form_found' => $custom_form_found,
];
}
// Add support for custom line height controls.
add_theme_support('custom-line-height');
function enqueue_block_editor_assets()
{
wp_enqueue_script(
'sage-contact-us-card',
get_template_directory_uri() . '/resources/scripts/editor.js', // Ajusta la ruta a tu archivo JS
array('wp-blocks', 'wp-element', 'wp-editor'),
filemtime(get_template_directory() . '/resources/scripts/editor.js')
);
wp_localize_script(
'sage-contact-us-card',
'sageThemeData',
array(
'themeUri' => get_template_directory_uri(),
)
);
wp_enqueue_script(
'leadbox-shortcodes-document-panel',
get_template_directory_uri() . '/resources/scripts/leadbox-shortcodes-document-panel.js',
array('wp-plugins', 'wp-edit-post', 'wp-element', 'wp-components', 'wp-data'),
null,
true
);
}
add_action('enqueue_block_editor_assets', 'enqueue_block_editor_assets');
function sales_phone_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['sale_phone']) && !empty($contact['sale_phone'])) {
$sale_phone = '<a href="tel:' . $contact['sale_phone'] . '" class="font-bold lbx-sales-phone-shortcode LBX-click-to-call">' . format_phone($contact['sale_phone']) . '</a>';
}
return $sale_phone;
}
add_shortcode('lbx_sales_phone', 'sales_phone_data');
function service_phone_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['service_phone']) && !empty($contact['service_phone'])) {
$service_phone = '<a href="tel:' . $contact['service_phone'] . '" class="font-bold lbx-service-phone-shortcode LBX-click-to-call">' . format_phone($contact['service_phone']) . '</a>';
}
return $service_phone;
}
add_shortcode('lbx_service_phone', 'service_phone_data');
function parts_phone_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['parts_phone']) && !empty($contact['parts_phone'])) {
$parts_phone = '<a href="tel:' . $contact['parts_phone'] . '" class="font-bold lbx-parts-phone-shortcode LBX-click-to-call">' . format_phone($contact['parts_phone']) . '</a>';
}
return $parts_phone;
}
add_shortcode('lbx_parts_phone', 'parts_phone_data');
function bodyshop_phone_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['body_shop']) && !empty($contact['body_shop'])) {
$bodyshop_phone = '<a href="tel:' . $contact['body_shop'] . '" class="font-bold lbx-bodyshop-phone-shortcode LBX-click-to-call">' . format_phone($contact['body_shop']) . '</a>';
}
return $bodyshop_phone;
}
add_shortcode('lbx_bodyshop_phone', 'bodyshop_phone_data');
function collision_phone_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['collision_phone']) && !empty($contact['collision_phone'])) {
$collision_phone = '<a href="tel:' . $contact['collision_phone'] . '" class="font-bold lbx-collision-phone-shortcode LBX-click-to-call">' . format_phone($contact['collision_phone']) . '</a>';
}
return $collision_phone;
}
add_shortcode('lbx_collision_phone', 'collision_phone_data');
function accessories_phone_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['accessories_phone']) && !empty($contact['accessories_phone'])) {
$accessories_phone = '<a href="tel:' . $contact['accessories_phone'] . '" class="font-bold lbx-accessories-phone-shortcode LBX-click-to-call">' . format_phone($contact['accessories_phone']) . '</a>';
}
return $accessories_phone;
}
add_shortcode('lbx_accessories_phone', 'accessories_phone_data');
function fax_phone_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['fax']) && !empty($contact['fax'])) {
$fax_phone = '<a href="tel:' . $contact['fax'] . '" class="font-bold lbx-fax-phone-shortcode LBX-click-to-call">' . format_phone($contact['fax']) . '</a>';
}
return $fax_phone;
}
add_shortcode('lbx_fax_phone', 'fax_phone_data');
function sms_phone_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['sms']) && !empty($contact['sms'])) {
$sms_phone = '<a href="tel:' . $contact['sms'] . '" class="font-bold lbx-sms-phone-shortcode LBX-click-to-call">' . format_phone($contact['sms']) . '</a>';
}
return $sms_phone;
}
add_shortcode('lbx_sms_phone', 'sms_phone_data');
function primary_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['primary_email']) && !empty($contact['primary_email'])) {
$primary_email = '<a href="mailto:' . $contact['primary_email'] . '" class="font-bold lbx-primary-email-shortcode LBX-click-to-email">' . $contact['primary_email'] . '</a>';
}
return $primary_email;
}
add_shortcode('lbx_primary_email', 'primary_email_data');
function secondary_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['secondary_email']) && !empty($contact['secondary_email'])) {
$secondary_email = '<a href="mailto:' . $contact['secondary_email'] . '" class="font-bold lbx-secondary-email-shortcode LBX-click-to-email">' . $contact['secondary_email'] . '</a>';
}
return $secondary_email;
}
add_shortcode('lbx_secondary_email', 'secondary_email_data');
function sales_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['sales_email']) && !empty($contact['sales_email'])) {
$sales_email = '<a href="mailto:' . $contact['sales_email'] . '" class="font-bold lbx-sales-email-shortcode LBX-click-to-email">' . $contact['sales_email'] . '</a>';
}
return $sales_email;
}
add_shortcode('lbx_sales_email', 'sales_email_data');
function service_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['service_email']) && !empty($contact['service_email'])) {
$service_email = '<a href="mailto:' . $contact['service_email'] . '" class="font-bold lbx-service-email-shortcode LBX-click-to-email">' . $contact['service_email'] . '</a>';
}
return $service_email;
}
add_shortcode('lbx_service_email', 'service_email_data');
function parts_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['parts_email']) && !empty($contact['parts_email'])) {
$parts_email = '<a href="mailto:' . $contact['parts_email'] . '" class="font-bold lbx-parts-email-shortcode LBX-click-to-email">' . $contact['parts_email'] . '</a>';
}
return $parts_email;
}
add_shortcode('lbx_parts_email', 'parts_email_data');
function accessories_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['accessories_email']) && !empty($contact['accessories_email'])) {
$accessories_email = '<a href="mailto:' . $contact['accessories_email'] . '" class="font-bold lbx-accessories-email-shortcode LBX-click-to-email">' . $contact['accessories_email'] . '</a>';
}
return $accessories_email;
}
add_shortcode('lbx_accessories_email', 'accessories_email_data');
function collision_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['collision_email']) && !empty($contact['collision_email'])) {
$collision_email = '<a href="mailto:' . $contact['collision_email'] . '" class="font-bold lbx-collision-email-shortcode LBX-click-to-email">' . $contact['collision_email'] . '</a>';
}
return $collision_email;
}
add_shortcode('lbx_collision_email', 'collision_email_data');
function bodyshop_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['bodyshop_email']) && !empty($contact['bodyshop_email'])) {
$bodyshop_email = '<a href="mailto:' . $contact['bodyshop_email'] . '" class="font-bold lbx-bodyshop-email-shortcode LBX-click-to-email">' . $contact['bodyshop_email'] . '</a>';
}
return $bodyshop_email;
}
add_shortcode('lbx_bodyshop_email', 'bodyshop_email_data');
function additional1_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['additional1_email']) && !empty($contact['additional1_email'])) {
$additional1_email = '<a href="mailto:' . $contact['additional1_email'] . '" class="font-bold lbx-additional1-email-shortcode LBX-click-to-email">' . $contact['additional1_email'] . '</a>';
}
return $additional1_email;
}
add_shortcode('lbx_additional1_email', 'additional1_email_data');
function additional2_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['additional2_email']) && !empty($contact['additional2_email'])) {
$additional2_email = '<a href="mailto:' . $contact['additional2_email'] . '" class="font-bold lbx-additional2-email-shortcode LBX-click-to-email">' . $contact['additional2_email'] . '</a>';
}
return $additional2_email;
}
add_shortcode('lbx_additional2_email', 'additional2_email_data');
function additional3_email_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['additional3_email']) && !empty($contact['additional3_email'])) {
$additional3_email = '<a href="mailto:' . $contact['additional3_email'] . '" class="font-bold lbx-additional3-email-shortcode LBX-click-to-email">' . $contact['additional3_email'] . '</a>';
}
return $additional3_email;
}
add_shortcode('lbx_additional3_email', 'additional3_email_data');
function dealer_address_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['address_url_map']) && !empty($contact['address_url_map'])) {
$dealer_address = '<a target="_blank" href="' . $contact['address_url_map'] . '" class="font-bold lbx-dealer-address-shortcode LBX-click-to-email">' .
(isset($contact['address_line_1']) && !empty($contact['address_line_1']) ? $contact['address_line_1'] : '') .
(isset($contact['address_line_2']) && !empty($contact['address_line_2']) ? ' ' . $contact['address_line_2'] . ', ' : ', ') .
(isset($contact['address_city']) && !empty($contact['address_city']) ? $contact['address_city'] . ', ' : '') .
(isset($contact['address_province']) && !empty($contact['address_province']) ? $contact['address_province'] . ' ' : '') .
(isset($contact['address_postal_code']) && !empty($contact['address_postal_code']) ? $contact['address_postal_code'] : '') . '</a>';
}
return $dealer_address;
}
add_shortcode('lbx_dealer_address', 'dealer_address_data');
function dealer_city_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['address_url_map']) && !empty($contact['address_url_map'])) {
$dealer_city = (isset($contact['address_city']) && !empty($contact['address_city']) ? $contact['address_city'] . ', ' : '');
}
return $dealer_city;
}
add_shortcode('lbx_dealer_city', 'dealer_city_data');
function dealer_name_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['dealer_name']) && !empty($contact['dealer_name'])) {
if (isset($contact) && !empty($contact) && isset($contact['dealer_url']) && !empty($contact['dealer_url'])) {
$dealer_address = '<a href="' . $contact['dealer_url'] . '" class="font-bold lbx-dealer-name-shortcode">' . $contact['dealer_name'] . '</a>';
} else
$dealer_address = '<span class="font-bold lbx-dealer-name-shortcode">' . $contact['dealer_name'] . '</span>';
}
return $dealer_address;
}
add_shortcode('lbx_dealer_name', 'dealer_name_data');
function dealer_name_withoutlink_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['dealer_name']) && !empty($contact['dealer_name'])) {
$dealer_address = '<span class="lbx-dealer-name-shortcode">' . $contact['dealer_name'] . '</span>';
}
return $dealer_address;
}
add_shortcode('lbx_dealer_name_withoutlink', 'dealer_name_withoutlink_data');
function dealer_url_data()
{
$contact = get_option('dealer-settings-contact-options');
if (isset($contact) && !empty($contact) && isset($contact['dealer_url']) && !empty($contact['dealer_url'])) {
$dealer_address = '<a href="' . $contact['dealer_url'] . '" class="font-bold lbx-dealer-url-shortcode">' . $contact['dealer_url'] . '</a>';
}
return $dealer_address;
}
add_shortcode('lbx_dealer_url', 'dealer_url_data');
function dealer_manufacturer_data()
{
$dealer_manufacturer = '';
$lbsettings = get_option('leadbox-settings');
if (isset($lbsettings) && !empty($lbsettings) && isset($lbsettings["manufacturer"]) && !empty($lbsettings["manufacturer"])) {
$dealer_manufacturer = trim($lbsettings["manufacturer"]);
}
return $dealer_manufacturer;
}
add_shortcode('lbx_dealer_manufacturer', 'dealer_manufacturer_data');
function dealer_brands_seo_data()
{
$dealer_brands = '';
$lbsettings = get_option('leadbox-settings');
if (isset($lbsettings) && !empty($lbsettings) && isset($lbsettings["manufacturer"]) && !empty($lbsettings["manufacturer"])) {
$dealer_brands = trim($lbsettings["manufacturer"]);
if (isset($lbsettings) && !empty($lbsettings) && isset($lbsettings["other_brands"]) && !empty($lbsettings["other_brands"])) {
$dealer_brands = $dealer_brands . ',' . $lbsettings["other_brands"];
}
}
return $dealer_brands;
}
add_shortcode('lbx_dealer_brands_seo', 'dealer_brands_seo_data');
function dealer_brands_offers_data()
{
$dealer_brands = '';
$lbsettings = get_option('leadbox-settings');
if (isset($lbsettings) && !empty($lbsettings) && isset($lbsettings["manufacturer"]) && !empty($lbsettings["manufacturer"])) {
$dealer_brands = trim($lbsettings["manufacturer"]);
if (isset($lbsettings) && !empty($lbsettings) && isset($lbsettings["all_brands"]) && !empty($lbsettings["all_brands"])) {
$dealer_brands = $dealer_brands . ',' . $lbsettings["all_brands"];
}
}
return $dealer_brands;
}
add_shortcode('lbx_dealer_brands_offers', 'dealer_brands_offers_data');
function dealer_models_data()
{
$dealer_models = '';
$lbsettings = get_option('leadbox-settings');
if (isset($lbsettings) && !empty($lbsettings) && isset($lbsettings["oem_models"]) && !empty($lbsettings["oem_models"])) {
$dealer_models = trim($lbsettings["oem_models"]);
}
return $dealer_models;
}
add_shortcode('lbx_dealer_models', 'dealer_models_data');
function force_show_screen_options_css()
{
$screen = get_current_screen();
if ($screen->id === 'nav-menus') {
echo '<style type="text/css">
#screen-options-link-wrap {
display: block !important;
visibility: visible !important;
}
</style>';
}
}
add_action('admin_head', 'force_show_screen_options_css');
function show_contact_widget()
{
return isset(GENIUS['contact-widget']) &&
isset(GENIUS['contact-widget']['version']) &&
GENIUS['contact-widget']['version'] > 0;
}