Skip to content

Instantly share code, notes, and snippets.

@waqasy
waqasy / opcache.ini
Created March 14, 2022 16:01 — forked from rohankhudedev/opcache.ini
Best Zend OpCache Settings / Tuning / Configurations
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
;opcache.enable_cli=1
; The OPcache shared memory storage size.
opcache.memory_consumption=512
@waqasy
waqasy / resize-original-upload.php
Created September 30, 2020 10:38 — forked from trepmal/resize-original-upload.php
resize new uploads to fit max dimensions
<?php
/*
Plugin Name: Resize Original Upload
*/
add_filter('wp_handle_upload', 'max_dims_for_new_uploads', 10, 2 );
function max_dims_for_new_uploads( $array, $context ) {
// $array = array( 'file' => $new_file, 'url' => $url, 'type' => $type )
// $context = 'upload' || 'sideload'
@waqasy
waqasy / jpegoptim.php
Created May 20, 2020 20:43 — forked from miya0001/jpegoptim.php
Optimizing images for WordPress with the jpegoptim
<?php
add_filter( 'wp_image_editors', function( $editors ) {
if ( ! class_exists( '_WP_Image_Editor_GD' ) ) {
class _WP_Image_Editor_GD extends WP_Image_Editor_GD {
protected function _save( $image, $filename = null, $mime_type = null ) {
$saved = parent::_save( $image, $filename, $mime_type );
if ( ! empty( $saved["mime-type"] ) && 'image/jpeg' == $saved["mime-type"] ) {
jpegoptim( $saved['path'] );
}
@waqasy
waqasy / wpcom-cdn.php
Created April 27, 2020 19:35 — forked from zacscott/wpcom-cdn.php
Use the WP.com Photon image CDN without installing JetPack
<?php
/**
* Plugin Name: Photon CDN
* Version: 1.1
* Description: Use the WP.com Photon image CDN without installing JetPack
* Author: Zachary Scott
*/
namespace zacscott;
@waqasy
waqasy / WP-HTML-Compression
Created December 21, 2018 05:44 — forked from sethbergman/WP-HTML-Compression
Minify HTML for WordPress without a Plugin - Add to function.php
<?php
class WP_HTML_Compression
{
// Settings
protected $compress_css = true;
protected $compress_js = true;
protected $info_comment = true;
protected $remove_comments = true;
// Variables
@waqasy
waqasy / gist:6811b52d74e42ac4921638dfca1fbd7d
Created December 11, 2018 07:11 — forked from lukaszklis/gist:1247306
WordPress: check if a current page has children, if so display them, if not display all pages on the same level as current page
<?php
// Your functions.php content
function has_children() {
global $post;
$pages = get_pages('child_of=' . $post->ID);
return count($pages);
@waqasy
waqasy / repeatable-fields-metabox.php
Created October 21, 2018 16:48 — forked from helen/repeatable-fields-metabox.php
Repeating Custom Fields in a Metabox
<?
/**
* Repeatable Custom Fields in a Metabox
* Author: Helen Hou-Sandi
*
* From a bespoke system, so currently not modular - will fix soon
* Note that this particular metadata is saved as one multidimensional array (serialized)
*/
function hhs_get_sample_options() {
<?php
$args = array(
'label' => '', // Text in Label
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post meta where id is the meta_key
'id' => '', // required
'name' => '', //name will set from id if empty
@waqasy
waqasy / wp-better-side-nav.php
Created October 7, 2018 19:41 — forked from MikeNGarrett/wp-better-side-nav.php
Instead of wp_list_pages where all children and grandchildren of the current page are listed out this method lists the parent page, siblings of the current page (in menu order) and when it gets to the current page it lists out the children.
<?php /* Not as simple as it sounds */ ?>
<div class="side-nav">
<div class="holder">
<ul>
<?php
if (isset($post->post_parent) && $post->post_parent > 0) {
$permalink = get_permalink($post->post_parent);
$parent_title = get_the_title($post->post_parent);
print('<li class="page_item page-parent"><a href="'.$permalink.'">'.$parent_title.'</a></li>');
$parent = $post->post_parent;
@waqasy
waqasy / php-UA.php
Created July 13, 2018 05:45 — forked from walkergv/php-UA.php
Simple Event Tracking with Measurement Protocol Using cURL and PHP (plus redirect)
<?
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www.google-analytics.com/collect?v=1&tid=[UA-XXXXXXXXX-1]&cid=[RANDOM_INTEGER_OR_GUID]&t=event&ec=[EVENT_CATEGORY]&ea=[EVENT_ACTION]&el=[EVENT_LABEL]',
CURLOPT_USERAGENT => 'Vanity-URL-Tracker',
));
$resp = curl_exec($curl);
curl_close($curl);
header("HTTP/1.1 301 Moved Permanently");