Skip to content

Instantly share code, notes, and snippets.

View jreviews's full-sized avatar

JReviews jreviews

View GitHub Profile
@jreviews
jreviews / dbdelta-patch-queries.php
Created June 10, 2024 14:48
WordPress dbDelta mu-plugin patch to avoid unnecessary queries
<?php
/**
* /wp-content/mu-plugins/dbdelta-patch-queries.php
* Patches queries before they are processed by dbDelta to ensure that it doesn't run unnecessary queries
* On some setups, not specifying TINYINT length always causes the query to run a delta,
* so forcing it to length 4 when it's not specified
*/
add_filter('dbdelta_queries', function($queries) {
$patterns = [
@jreviews
jreviews / mod_security.md
Created November 24, 2023 12:16
mod_security issues

The following was shared by a client having problems with uploads in JReviews not working:

Never disable all rules !! This could cause serious security issues!

The easiest way to disable individual mod_security rules if you are using cPanel is to install ConfigServer ModSecurity Control and use it to disable individual mod_security rules by ID or via a specific directory.

Otherwise you will need to review and edit specific Apache server files as follows: (Windows Web Server not addressed here)

The mod_security ID's I whitelisted for JReviews Joomla are:

@jreviews
jreviews / forseo_functions.md
Last active September 21, 2023 21:37
Disable 4SEO in JReviews Listings

JReviews has always had a strong focus in SEO and comes with functionality to add Schema.org markup, Open Graph and Twitter tags. It also allows using internal features like media and custom fields as part of this functionality which is something 3rd party solutions cannot do unless support is added specifically for them.

If you are using 4SEO for your site, it will add all these SEO features for core functionality and some 3rd party solutions. However, this creates a problem with duplication in JReviews listings. JReviews has it's own data and in some cases may do things differently. So in this case, the recommended solution is to disable the 4SEO tags in JReviews listings to avoid duplication.

This can be done programatically using 4SEO hooks

If you are not using hooks yet, you'll need to create the file at:

  • /libraries/weeblr/forseo_functions.php (when using Joomla)
@jreviews
jreviews / vivaz-hover-dropdowns.md
Last active July 25, 2023 11:42
Vivaz template - open dropdowns on hover
<script>
window.addEventListener('DOMContentLoaded', (event) => {

  // Iterate through each main link in the topbar navigation. 
  document.querySelectorAll('.mod-menu > li > a').forEach((mainLink) => {
    const mainLi = mainLink.closest('li'); // Find the closest parent 'li'.
    const mainDropdownElement = mainLi.querySelector('.dropdown-menu'); // Select the dropdown menu of the main link.

    // Execute if both the main link and associated dropdown menu exist.
@jreviews
jreviews / Zip.md
Last active March 13, 2023 22:25
Joomla Zip::extractNative replacement

The following method is a replacement for Joomla's unzip method to overcome a server's ulimit setting that prevents large packages from unzipping.

The original method can be found in following path. You can open the file and replace the extractNative function with the one below.

  • libraries/vendor/joomla/archive/src/Zip.php

The new function overcomes the server restrictions on the number of simultaneous open files because it doesn't try to extract based on the number of files in the zip archive that could cause issues with ulimit; instead, it extracts everything to a temporary folder using the extractTo method, which reduces the number of simultaneous open files.

Once extraction is completed, it loops over each file in the zip archive and moves files one by one from the temporary directory to the final destination. This approach has good performance because it solves the issue by reducing the maximum number of open files simultaneously, irrespective of the number of files in the zip archive.

@jreviews
jreviews / ga4-custom-report.md
Last active December 14, 2022 15:13
Generate GA4 custom report for specific path, event and timeframe using Google Analytics Data API

This code example uses Laravel's Http client.

You need to generate the private key from your service account in a Google Cloud Platform project. Then grant access to your GA4 property to the service account client email.

There are some instructions for doing that in the JReviews Dashboard Addon documentation, which is where the code below comes from.

function getAuthToken($clientEmail, $privateKey)
{          
      $base64URLEncode = function($data) {
@jreviews
jreviews / peepso-search-member-profiles.md
Last active September 14, 2022 18:20
PeepSo: Allow searching member profiles with multi-select fields

Within PeepSo fields it's only possible to enable single select lists as searchable. The following code uses PeepSo filters to allow you to include multi-select fields in the members search area by converting them to single select and including the selected value in the database query.

Create a peepso-search-member-profiles.php file in /wp-content/mu-plugins with the following code:

<?php

/**
 * Find the field IDs under PeepSo Manage Fields
 * Add the field IDs of multiple select fields you want to show for member search
@jreviews
jreviews / htmx-loading-states-extension.md
Last active April 1, 2024 22:22
htmx loading states extension

htmx loading states extension

The loading-states extension allows you to easily manage loading states while a request is in flight, including disabling elements, and adding and removing CSS classes.

Using the extension

Add the hx-ext="loading-states" attribute to the body tag or to any parent element containing your htmx attributes.

Add the following class to your stylesheet to make sure elements are hidden by default:

@jreviews
jreviews / listings-shortcode-word-match.md
Created October 28, 2021 20:45
Using match=words attribute in listings shortcode

All searches in JReviews use LIKE to retrieve results. To use an exact word match, it would be necessary to use REGEXP because there aren't any fulltext indexes.

The following filter allows adding the match=word attribute to the listings shortcode to perform a word match. Example usage:

[jreviews type="listings" custom_params="keywords=you" match="word" limit="3"]

The above will match "you", but not "yourself", "yours", etc.

@jreviews
jreviews / custom-parameter-active-events.md
Last active October 26, 2021 14:19
Using a custom parameter to filter results for active events

The filter hook below allows using a custom defined parameter events=active to automatically filter results shown in shortcodes and listings module to only show events that are currently active/open.

Add the code below to filter_functions.php in overrides, and then in your shortcode or listings module add events=open in the custom parameters attribute or setting respectively.

Clickfwd\Hook\Filter::add('pre_get_listings_listings_module_query', function($listingsRepository, $params) 
{
	$customParams = $params['params']['module']['custom_params'] ?? '';
	
	if (empty($customParams)) {