Skip to content

Instantly share code, notes, and snippets.

View sericgoran's full-sized avatar

Goran Šerić sericgoran

View GitHub Profile
<?php
define('WP_CACHE', 1); // Added by WP Rocket
/**
* The base configuration for WordPress, modified to work in both server and
* local development environments with WP Engine.
*
* The WP Engine configuration adheres to the well-known 12-Factor App principles
* of "Store config in the environment" (https://12factor.net/config) and
* "Dev/Prod Parity" (https://12factor.net/dev-prod-parity). This means you should
* use the same files and test environments on laptops as well as servers, and
@sericgoran
sericgoran / html-nds-advanced-search-results.php
Created May 6, 2024 18:35 — forked from nuancedesignstudio/html-nds-advanced-search-results.php
Creating a dynamic tax_query based on the taxonomy terms selected by the user in the search filters
<?php
$get_form_input = filter_input( INPUT_POST, $this->plugin_name , FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
$user_selected_video_taxonomies = isset( $get_form_input['video_taxonomies'] ) ? wp_unslash( $get_form_input['video_taxonomies'] ) : array();
$tax_query = array();
// create a dynamic tax_query if the user selected taxonomy terms in the search filters.
foreach ( $user_selected_video_taxonomies as $taxonomy_slug => $taxonomy_terms ) {
if ( ! empty( $user_selected_video_taxonomies[ $taxonomy_slug ] ) ) {
// tax_query takes an array of arrays.
@sericgoran
sericgoran / acf_parse_and_find_blocks.php
Created April 10, 2024 13:23 — forked from blonestar/acf_parse_and_find_blocks.php
Wordpress - ACF find and parse blocks (nested, inner blocks as well)
<?php
/**
* ACF parse and find all blocks with a given name
* @return: block Array(), blocks Array() or false
* @author: Bojan
* v0.1
* @usage: find_blocks('acf/adtheme-accordion');
* @usage: find_blocks('acf/adtheme-accordion', $post_id);
* TODO: refactor using modern recursive function
@sericgoran
sericgoran / get-script-promise.js
Created March 11, 2024 07:53 — forked from james2doyle/get-script-promise.js
Async load a script in the page and run it. Uses promises
// this function will work cross-browser for loading scripts asynchronously
function loadScript(src) {
return new Promise(function(resolve, reject) {
const s = document.createElement('script');
let r = false;
s.type = 'text/javascript';
s.src = src;
s.async = true;
s.onerror = function(err) {
reject(err, s);
@sericgoran
sericgoran / gf_dynamic.js
Created February 20, 2024 06:57 — forked from gicolek/gf_dynamic.js
Gravity Forms dynamic reload
<script type="text/javascript">
// let's make call to the global gwrf variable visible after enabling Gravity Forms
window.gwrf;
(function ($) {
gwrf = function (args) {
// prototype arguments, created when we instantiate it
this.formId = args.formId;
this.spinnerUrl = args.spinnerUrl;
@sericgoran
sericgoran / wp_kses_post_tags.php
Created September 15, 2023 05:23 — forked from bjorn2404/wp_kses_post_tags.php
WordPress allow iFrames with wp_kses_post filter
<?php
/**
* Add iFrame to allowed wp_kses_post tags
*
* @param array $tags Allowed tags, attributes, and/or entities.
* @param string $context Context to judge allowed tags by. Allowed values are 'post'.
*
* @return array
*/
@sericgoran
sericgoran / gist:a0071127ca837058891402cbc212a0bf
Created February 13, 2021 06:14 — forked from stuntbox/gist:4557917
Slightly smarter filtering to remove hard-coded width and height attributes from *all* images in WordPress (post thumbnails, images inserted into posts, and gravatars). Handy for responsive designs. Add the code below to the functions.php file in your theme's folder (/wp-content/themes/theme-name/ ). Remember to rename the function as needed to …
/**
* Filter out hard-coded width, height attributes on all images in WordPress.
* https://gist.github.com/4557917
*
* This version applies the function as a filter to the_content rather than send_to_editor.
* Changes made by filtering send_to_editor will be lost if you update the image or associated post
* and you will slowly lose your grip on sanity if you don't know to keep an eye out for it.
* the_content applies to the content of a post after it is retrieved from the database and is "theme-safe".
* (i.e., Your changes will not be stored permanently or impact the HTML output in other themes.)
*
@sericgoran
sericgoran / country_is_in_europe.php
Created February 11, 2021 15:14 — forked from Pamps/country_is_in_europe.php
Returns if a country is in Europe, in PHP
<?php
// Returns if a country is in Europe
// Pass in country name or code e.g. 'Spain' or 'ES'.
function country_is_in_europe( $country ) {
// Our list of countries
$countries = array(
'AT' => 'Austria',
'BE' => 'Belgium',
@sericgoran
sericgoran / .gitlab-ci.yml
Created February 11, 2021 15:13 — forked from Pamps/.gitlab-ci.yml
My default GitLab CI FTP deploy for WordPress sites, works well on SiteGround, SpeedyDot and others
deploy:
script:
- apt-get update -qq && apt-get install -y -qq lftp
- lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rnv ./ public_html/ --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
only:
- master
@sericgoran
sericgoran / add-admin-user-to-wordpress.php
Created February 11, 2021 15:13 — forked from Pamps/add-admin-user-to-wordpress.php
Add WordPress admin user via functions.php
<?php
// Add admin user
add_action( 'init', function () {
$username = 'admin';
$password = 'password';
$email_address = 'webmaster@mydomain.com';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );