Skip to content

Instantly share code, notes, and snippets.

@soderlind
soderlind / get-ip.php
Last active July 12, 2021 09:14
PHP, Get IP behind trusted proxy
<?php
/**
* Inspired by https://raw.githubusercontent.com/zendframework/zend-http/master/src/PhpEnvironment/RemoteAddress.php
*/
//PHP 5.6
function get_ip( $trusted_proxies = [] ) {
if ( ! empty( $trusted_proxies ) && isset( $_SERVER['REMOTE_ADDR'] ) && ! in_array( $_SERVER['REMOTE_ADDR'], $trusted_proxies ) ) {
if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
@wplit
wplit / style.css
Last active February 14, 2022 07:23
Allow tabbing across the sub menu items in Oxygen Menu (for keyboard user)
/* Allows focus on sub menu items by tabbing menu
------------------------------------------------ */
.oxy-nav-menu:not(.oxy-nav-menu-open) .menu-item .sub-menu {
right: 5000px;
visibility: visible;
}
.oxy-nav-menu:not(.oxy-nav-menu-open).menu-item .sub-menu .sub-menu {
right: auto;
@mkg20001
mkg20001 / generate-nginx-cloudflare-allow.sh
Last active April 17, 2025 16:21
A script to generate a config to allow or additionally allow cloudflare addresses for a specific domain
#!/bin/bash
set -e
cf_ips() {
echo "# https://www.cloudflare.com/ips"
for type in v4 v6; do
echo "# IP$type"
curl -sL "https://www.cloudflare.com/ips-$type/" | sed "s|^|allow |g" | sed "s|\$|;|g"
@hnq90
hnq90 / functions.php
Created January 11, 2018 16:52 — forked from yoren/functions.php
Parent Post From Another Post Type And A New URL Structure In WordPress
<?php
// Flush rewrite rules after switch theme
function my_rewrite_flush() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_rewrite_flush' );
// A little help so we can get the stylesheet from parent theme
// Remove line 10-19 if this is not a child theme
function my_enqueue_styles() {
@holmberd
holmberd / php-pools.md
Last active April 16, 2025 07:11
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log
@JTruax
JTruax / wp-snippets.php
Last active June 29, 2023 17:54
WordPress Function Snippets
<!--------------------------------------------------------
SNIPPETS INDEX
-- 01 - Enqueue Google Fonts
-- 02 - Make jQuery load from Google Library
-- 03 - Customize excerpt length and read more characters
-- 04 - Enable Pagination Links
-- 05 - Replace WP login logo with custom
-- 06 - Displays a custom Dashboard Widget
-- 07 - Allow different file formats in Media Library
-- 08 - Turn Off Your Self-referring Pingbacks
@habibimroncn
habibimroncn / pll.md
Last active March 1, 2025 00:03
Get Current language on Polylang Plugin for Wordpress.

Reference for language code : Language Code

<?php 
$currLang = get_bloginfo('language');
if($currLang == "id-ID"){ // Replace condition with your language code.
	echo 'Bahasa Indonesia';
} else {
	echo 'up to you'
}
?&gt;
@amboutwe
amboutwe / yoast_seo_json_remove.php
Last active July 23, 2021 08:08
Remove all JSON output by Yoast SEO
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Remove all JSON output by Yoast SEO
* Credit: Yoast development team
* Documentation: https://developer.yoast.com/schema-documentation/api/
* Last Tested: Apr 16 2019 using Yoast SEO 11.0 on WordPress 5.1.1
*/
add_filter( 'wpseo_json_ld_output', '__return_false' );
@derekshirk
derekshirk / acf-inline-svg.php
Created July 20, 2016 22:14
Output Inline SVGs from ACF image field
<?php
/* ————————————————————————— */
/* ACF Inline SVGs
/* ————————————————————————— */
$repeater = 'repeater_field_name'
if ( have_rows( $repeater ) ): ?>
<section class="content-main">
<div class="container"> <?php
@c3mdigital
c3mdigital / cacheable-ajax.php
Last active November 13, 2024 05:32
Example of how to cache fronted ajax requests in WordPress. This will allow you to use ajax and page caching like varnish or redis. Where ajax requests would normally not be cached using the built in wp_ajax_action method.
<?php
add_filter( 'rewrite_rules_array', 'cache_frontend_ajax_rules' );
/**
* Rewrite rules filter to add rules for front end ajax calls
*
* @param array $rewrite_rules
*
* @return array
*/