LittleDemon WebShell


Linux webm001.cluster123.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
Path : /home/lapjouc/www/wp-content/themes/laap/
File Upload :
Command :
Current File : /home/lapjouc/www/wp-content/themes/laap/functions.php

<?php

/**
 * laap functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package laap
 */

if (!defined('_S_VERSION')) {
	// Replace the version number of the theme on each release.
	define('_S_VERSION', '1.0.0');
}

/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function laap_setup()
{
	/*
		* Make theme available for translation.
		* Translations can be filed in the /languages/ directory.
		* If you're building a theme based on laap, use a find and replace
		* to change 'laap' to the name of your theme in all the template files.
		*/
	load_theme_textdomain('laap', get_template_directory() . '/languages');

	// Add default posts and comments RSS feed links to head.
	add_theme_support('automatic-feed-links');

	/*
		* Let WordPress manage the document title.
		* By adding theme support, we declare that this theme does not use a
		* hard-coded <title> tag in the document head, and expect WordPress to
		* provide it for us.
		*/
	add_theme_support('title-tag');

	/*
		* Enable support for Post Thumbnails on posts and pages.
		*
		* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		*/
	add_theme_support('post-thumbnails');

	// This theme uses wp_nav_menu() in one location.
	register_nav_menus(
		array(
			'menu-1' => esc_html__('Primary', 'laap'),
		)
	);

	/*
		* Switch default core markup for search form, comment form, and comments
		* to output valid HTML5.
		*/
	add_theme_support(
		'html5',
		array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
			'style',
			'script',
		)
	);

	// Set up the WordPress core custom background feature.
	add_theme_support(
		'custom-background',
		apply_filters(
			'laap_custom_background_args',
			array(
				'default-color' => 'ffffff',
				'default-image' => '',
			)
		)
	);

	// Add theme support for selective refresh for widgets.
	add_theme_support('customize-selective-refresh-widgets');

	/**
	 * Add support for core custom logo.
	 *
	 * @link https://codex.wordpress.org/Theme_Logo
	 */
	add_theme_support(
		'custom-logo',
		array(
			'height'      => 250,
			'width'       => 250,
			'flex-width'  => true,
			'flex-height' => true,
		)
	);
}
add_action('after_setup_theme', 'laap_setup');

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function laap_content_width()
{
	$GLOBALS['content_width'] = apply_filters('laap_content_width', 640);
}
add_action('after_setup_theme', 'laap_content_width', 0);

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function laap_widgets_init()
{
	register_sidebar(
		array(
			'name'          => esc_html__('Sidebar', 'laap'),
			'id'            => 'sidebar-1',
			'description'   => esc_html__('Add widgets here.', 'laap'),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
	register_sidebar(
		array(
			'name'          => esc_html__('Sidebar-pages', 'laap'),
			'id'            => 'sidebar-2',
			'description'   => esc_html__('Add widgets here.', 'laap'),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__('header', 'laap'),
			'id'            => 'header-widgets',
			'description'   => esc_html__('Add widgets here.', 'laap'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
	register_sidebar(
		array(
			'name'          => esc_html__('footer', 'laap'),
			'id'            => 'footer-widgets',
			'description'   => esc_html__('Add widgets here.', 'laap'),
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
}
add_action('widgets_init', 'laap_widgets_init');

/**
 * Enqueue scripts and styles.
 */
function laap_scripts()
{
	wp_enqueue_style('laap-style', get_stylesheet_uri(), array(), _S_VERSION);
	wp_style_add_data('laap-style', 'rtl', 'replace');

	//wp_enqueue_script( 'laap-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true );

	wp_enqueue_script('jquery.min', get_template_directory_uri() . '/js/jquery.min.js', array(), false);

	wp_enqueue_script('tiny-slider', get_template_directory_uri() . '/js/tiny-slider.js', array(), true);

	wp_enqueue_script('app', get_template_directory_uri() . '/js/app.js', array(), '', true);


	if (is_singular() && comments_open() && get_option('thread_comments')) {
		wp_enqueue_script('comment-reply');
	}
}
add_action('wp_enqueue_scripts', 'laap_scripts');

/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/template-functions.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';

/**
 * Load Jetpack compatibility file.
 */
if (defined('JETPACK__VERSION')) {
	require get_template_directory() . '/inc/jetpack.php';
}

/**
 * Load WooCommerce compatibility file.
 */


if (class_exists('WooCommerce')) {
	require get_template_directory() . '/inc/woocommerce.php';
}


function register_category_block()
{
	if (function_exists('acf_register_block_type')) {
		acf_register_block_type(array(
			'name'              => 'category-block',
			'title'             => __('Category Block'),
			'description'       => __('A custom block to display a category with posts.'),
			'render_template'   => 'template-parts/blocks/category-block.php',
			'category'          => 'formatting',
			'icon'              => 'admin-comments',
			'keywords'          => array('category', 'posts'),
			'supports'          => array('align' => false),
		));
	}
}
add_action('acf/init', 'register_category_block');

/* SHORTCODE SOMMAIRE */

function journal_edition_posts_shortcode()
{
	global $post;
	ob_start();

	// Get the current post's categories
	$categories = get_the_category($post->ID);
	if (empty($categories)) {
		return '<p>No categories found for this post.</p>';
	}

	// Find the first category that matches the 'lap-*' pattern
	$category_id = null;
	foreach ($categories as $category) {
		if (preg_match('/^n\d+$/', $category->slug)) {
			$category_id = $category->term_id;
			break;
		}
	}

	if (!$category_id) {
		return reblex_display_block(212);
	}

	// Query for posts in the same journal edition
	$args = array(
		'cat' => $category_id,
		'posts_per_page' => -1,
		'orderby' => 'date',
		'order' => 'ASC',
	);

	$journal_query = new WP_Query($args);

	if ($journal_query->have_posts()) :
?>
		<div class="sommaireSB">
			<?php
			// Separate posts into 'A la Une', 'Edito', and other posts
			$a_la_une_post = null;
			$a_la_une_cat = category_description($category_id);
			$edito_post = null;
			$other_posts = array();

			while ($journal_query->have_posts()) : $journal_query->the_post();
				global $post; // Make sure to use the global $post variable
				if (has_category('a-la-une', $post)) {
					$a_la_une_post = $post;
				} elseif (has_category('edito', $post)) {
					$edito_post = $post;
				} else {
					$other_posts[] = $post;
				}
			endwhile;

			// Display 'Edito' post
			if ($edito_post) :
			?>
				<div class="edito-post">
					<h2> <a class="edito" href="<?php echo get_permalink($edito_post); ?>"><?php _e('Edito', 'your-theme'); ?></a></h2>
					<!-- <a href="<--?php echo get_permalink($edito_post); ?>"><--?php echo get_the_title($edito_post); ?></a>-->
				</div>
			<?php
			endif;

			// Display 'A la Une' post
			 if ($a_la_une_post) : 
			?>
				<div class="a-la-une-post">
					<h2><?php _e('À la Une', 'your-theme'); ?></h2>
					<?php echo $a_la_une_cat; ?>
				</div>
			<?php 
			endif; 


			// Display other posts
			if (!empty($other_posts)) :
			?>
				<h2 class="sommaire">Sommaire</h2>

				<ul class="other-posts">
					<?php foreach ($other_posts as $post) : setup_postdata($post); ?>
						<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
					<?php endforeach;
					wp_reset_postdata(); ?>
				</ul>
			<?php
			endif;
			?>
		</div>
	<?php
	else :
		echo '<p>No posts found in this category.</p>';
	endif;

	wp_reset_postdata();

	return ob_get_clean();
}
add_shortcode('journal_edition_posts', 'journal_edition_posts_shortcode');

// CONNEXION

function show_loggedin_function($atts)
{

	global $current_user, $user_login;
	get_currentuserinfo();
	add_filter('widget_text', 'do_shortcode');

	if ($user_login)

		return '<a class="wp-block-buttons btnNav connexion" href="' . get_permalink(wc_get_page_id('myaccount')) . ' ">Mon compte</a>';
	else
		return '<a class="wp-block-buttons btnNav connexion" href="' . get_permalink(wc_get_page_id('myaccount')) . ' ">Se connecter</a>';
}

add_shortcode('show_loggedin_as', 'show_loggedin_function');

/*
add_action('login_enqueue_scripts', 'custom_login_page_redirect');
function custom_login_page_redirect()
{
	wp_redirect(site_url('/mon-compte-lap/'));
	exit();
}
*/

function my_login_logo()
{ ?>
	<style type="text/css">
		#login h1 a,
		.login h1 a {
			background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/logo-laap.svg);
			height: 143px;
			width: 162px;
			background-size: contain;
			background-repeat: no-repeat;
			padding-bottom: 30px;
		}
	</style>
<?php }
add_action('login_enqueue_scripts', 'my_login_logo');

/* NAV secondaire pages */

function liste_pages_meme_niveau_shortcode() {
    global $post;

    // Obtenir l'ID de la page parente
    $parent_id = $post->post_parent ? $post->post_parent : $post->ID;

    // Récupérer les pages enfants
    $pages_enfants = get_pages(array(
        'child_of' => $parent_id,
        'parent'   => $parent_id,
        'sort_column' => 'menu_order'
    ));

    // Commencer la sortie du menu
    $output = '';

    // Vérifier s'il y a des pages enfants
    if (!empty($pages_enfants)) {
        // Ajouter le lien de la page parente en tant que titre
        $page_parente = get_post($parent_id);
        $output .= '<div class="sidebarWidgets"><h2><a href="' . get_permalink($page_parente->ID) . '">' . get_the_title($page_parente->ID) . '</a></h2>';
        
        $output .= '<ul>';

        foreach ($pages_enfants as $page) {
            $active_class = ($page->ID == $post->ID) ? ' class="active"' : '';
            $output .= '<li' . $active_class . '><a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a></li>';
        }

        $output .= '</ul></div>';
    }

    return $output;
}

// Ajouter le shortcode
add_shortcode('liste_pages_niveau', 'liste_pages_meme_niveau_shortcode');


add_theme_support( 'woocommerce', array(
    'thumbnail_image_width' => 512,
    'gallery_thumbnail_image_width' => 320,
    'single_image_width' => 768,
) );

add_filter( 'woocommerce_get_image_size_single', function( $size ) {
	return array(
	  'width'  => 768,
	  'height' => 1024,
	  'crop'   => 0,
	);
  } );

  add_filter( 'woocommerce_get_image_size_thumbnail', function( $size ) {
	return array(
	  'width'  => 512,
	  'height' => 683,
	  'crop'   => 0,
	);
  } );

  add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) {
	return array(
	  'width'  => 512,
	  'height' => 683,
	  'crop'   => 0,
	);
  } );


  add_filter( 'get_the_archive_title_prefix', '__return_empty_string' );



	







LittleDemon - FACEBOOK
[ KELUAR ]