Skip to content

Instantly share code, notes, and snippets.

View apsolut's full-sized avatar
🎯
Focusing

Aleksandar Perisic apsolut

🎯
Focusing
View GitHub Profile
@mishterk
mishterk / wp-query-efficiency-args.php
Created June 24, 2021 23:33
Some handy considerations when running WP_Query to speed up the query depending on the requirements. This demonstrates using specific post ID's from ACF custom database tables in conjunction with some built in WP_Query args to save on internal queries.
<?php
$query = new WP_Query([
// Standard query args. Using post__in can be much faster. If searching ACF custom
// database tables data, plugin the found post IDs in here.
'post_type' => 'post',
'post__in' => [1,2,3], // array of post IDs
// Optional args to improve performance. Use these to cut down on internal
@morgyface
morgyface / acf_image_to_featured_image.php
Created April 8, 2020 19:54
WordPress | Set ACF image to be the WP feature image
@danieldogeanu
danieldogeanu / WampHTTPS.md
Last active April 13, 2024 20:38
How to enable HTTPS for WAMP Server.

After you've downloaded and installed WAMP Server, follow these steps:

  1. Generate SSL certificate using OpenSSL:
  • Add C:\wamp64\bin\apache\apache2.4.27\bin directory to the PATH so you can access openssl command from the command prompt (WAMP comes with its own version of OpenSSL already integrated, so you don't need to install it. You'll find it in this directory.).

    IMPORTANT: Please note that the path of your installation depends on your version of Apache! DO NOT copy and paste the paths presented in this gist as they will not match with yours!

  • Navigate to your user directory (C:\Users\%YOUR_USERNAME%\), create a new folder (.openssl), navigate to it with Powershell and run these commands:

    openssl genrsa -aes256 -out private.key 2048
    

openssl rsa -in private.key -out private.key

<?php
if(isset($_POST['login'])) {
if(!isset($_POST['g-recaptcha-response']) || empty($_POST['g-recaptcha-response'])) {
echo 'reCAPTHCA verification failed, please try again.';
} else {
$secret = 'google_secret_key';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@reecelucas
reecelucas / useScrollDirection.js
Last active September 8, 2021 20:07
React hook to detect scroll direction, based on the API of https://github.com/dollarshaveclub/scrolldir
const SCROLL_UP = "up";
const SCROLL_DOWN = "down";
const useScrollDirection = ({
initialDirection,
thresholdPixels,
off
} = {}) => {
const [scrollDir, setScrollDir] = useState(initialDirection);
@khromov
khromov / acf-nowhere-location-rule.php
Created October 2, 2017 17:36
"Nowhere" location rule for Advanced Custom Fields - never matches
<?php
/*
Plugin Name: Advanced Custom Fields: Nowhere location rules
Description: Adds a "Nowhere" location rule in ACF
*/
add_filter('acf/location/rule_types', function($rules) {
$rules['Extra']['nowhere'] = 'Nowhere';
@ollietreend
ollietreend / acf-php-to-json.php
Last active April 22, 2024 11:12
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
<?php
/**
* Plugin Name: Convert ACF PHP to JSON
* Description: Convert Advanced Custom Fields Pro configuration from PHP to JSON.
*/
namespace ConvertAcfPhpToJson;
/**
* Add submenu item under 'Custom Fields'
@felthy
felthy / custom-search-acf-wordpress.php
Last active April 19, 2021 15:11 — forked from fiskhandlarn/custom-search-acf-wordpress.php
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request. Updated to use wpdb prepare() and esc_like().
<?php
/*
##############################
########### Search ###########
##############################
Included are steps to help make this script easier for other to follow
All you have to do is add custom ACF post types into Step 1 and custom taxonomies into Step 10
[list_searcheable_acf list all the custom fields we want to include in our search query]
@return [array] [list of custom fields]
@AaronRutley
AaronRutley / ar_save_testimonials_to_content.php
Last active December 30, 2020 14:48
Save ACF Testimonials to post content
<?php // Save ACF Testimonials to post content
function ar_save_testimonials_to_content( $post_id ) {
// Only run this code if we're on a particilar post / page
if( $post_id === 1234 ) {
// Start an output buffer
ob_start();
// Loop over our testimonials
@kloon
kloon / fake-emails.php
Last active September 12, 2018 14:07
WooCommerce prohibit account creation with fake emails, ie sharklashers.com
<?php
/**
* Do not allow account creation with temp email addresses
* @param Object $validation_errors
* @param string $username
* @param string $email
* @return WP_Error
*/
function do_not_allow_temp_email_addresses( $validation_errors, $username, $email ) {
$prohibitied_domains = array(