Technical Library / Open Source

Joomla Snippets

Searchable collection of production-ready code recipes for template overrides, modules, plugins, and Joomla! 3 to 6 APIs.

100 Snippets
12 Categories
J3 to J6 Compatibility
Showing 8 of 8 snippets
PHP J6 J5 J3 Helper / API
Users, ACL and Security

Get the Logged-In User with $app->getIdentity() (Replaces JFactory::getUser)

Reads ID, name, email, groups and guest status of the active user using the native Joomla 5 and 6 Identity API.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$user = Factory::getApplication()->getIdentity();
// ...
71 243 2 versions
PHP J6 J5 J3 Component
Users, ACL and Security

Check Granular ACL Permissions with $user->authorise()

Validates core.create, core.edit, core.edit.own and core.delete permissions at component, category or item asset level.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$user    = Factory::getApplication()->getIdentity();
// ...
42 158 2 versions
PHP J6 J5 J3 Component
Users, ACL and Security

Protect Forms and AJAX Endpoints Against CSRF with Session::checkToken()

Renders HTMLHelper::_('form.token') in forms and verifies the session token inside controllers with Session::checkToken().

<?php

declare(strict_types=1);

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session;
// ...
56 189 2 versions
PHP J6 J5 J3 Component
Users, ACL and Security

Read and Sanitize Request Input with $app->getInput() (GET, POST, JSON)

Replaces raw $_GET/$_POST and deprecated $app->input with strongly filtered $app->getInput() accessors.

<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$input   = Factory::getApplication()->getInput();
// ...
49 175 2 versions
PHP J6 J5 J3 Helper / API
Users, ACL and Security

Generate Clean URL-Safe Slugs with ApplicationHelper::stringURLSafe()

Transliterates accented characters and strips symbols into clean SEF-ready aliases honoring Joomla global settings.

<?php

declare(strict_types=1);

use Joomla\CMS\Application\ApplicationHelper;

$title = 'Configuração Avançada de Joomla! 6';
// ...
30 112 2 versions
.htaccess J6 J5 J4 Template
Users, ACL and Security

Force HTTPS, Block Sensitive Files and Harden Headers in .htaccess

Production Apache rules for Joomla: permanent HTTPS redirect, blocking .git/.env/backups and adding baseline security headers.

# Força HTTPS mantendo o domínio canônico
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Bloqueia acesso direto a arquivos sensíveis (.git, .env, backups SQL/ZIP)
RewriteRule ^\.git - [F,L]
// ...
67 221
.htaccess J6 J5 J4 Template
Users, ACL and Security

Enable Browser Caching (Expires) and Gzip Compression in .htaccess

Sets long-lived browser cache headers for WebP/AVIF images, WOFF2 fonts and versioned CSS/JS plus Gzip compression for fast PageSpeed scores.

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/avif "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
// ...
57 191
.htaccess J6 J5 J4 J3 Template
Users, ACL and Security

Write Clean 301 Redirects Without Breaking Joomla SEF Routing

Uses mod_rewrite RewriteRule [R=301,L] above the Joomla Core SEF block so old URLs redirect cleanly without index.php artifacts.

# Redirecionamentos 301 personalizados (posicione ANTES do bloco Joomla Core SEF)
RewriteRule ^pagina-antiga/?$ /pt/nova-pagina [R=301,L]
RewriteRule ^blog-antigo/(.*)$ /pt/blog/$1 [R=301,L]

# Remove barra final duplicada (exceto diretórios reais e /administrator)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/administrator/
// ...
42 146
Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.