Skip to content

Instantly share code, notes, and snippets.

@cyberwani
cyberwani / .htaccess
Created August 10, 2018 09:39
Block the HTTRACK using HTACCESS files
Options All -Indexes
# Ultimate htaccess Blacklist 2 from Perishable Press
# Deny domain access to spammers and other scumbags
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ADSARobot|ah-ha|almaden|aktuelles|Anarchie|amzn_assoc|ASPSeek|ASSORT|ATHENS|Atomz|attach|attache|autoemailspider|BackWeb|Bandit|BatchFTP|bdfetch|big.brother|BlackWidow|bmclient|Boston\ Project|BravoBrian\ SpiderEngine\ MarcoPolo|Bot\ mailto:craftbot@yahoo.com|Buddy|Bullseye|bumblebee|capture|CherryPicker|ChinaClaw|CICC|clipping|Collector|Copier|Crescent|Crescent\ Internet\ ToolPak|Custo|cyberalert|DA$|Deweb|diagem|Digger|Digimarc|DIIbot|DISCo|DISCo\ Pump|DISCoFinder|Download\ Demon|Download\ Wonder|Downloader|Drip|DSurf15a|DTS.Agent|EasyDL|eCatch|ecollector|efp@gmx\.net|Email\ Extractor|EirGrabber|email|EmailCollector|EmailSiphon|EmailWolf|Express\ WebPictures|ExtractorPro|EyeNetIE|FavOrg|fastlwspider|Favorites\ Sweeper|Fetch|FEZhead|FileHound|FlashGet\ WebWasher|FlickBot|fluffy|FrontPage|GalaxyBot|Generic|Getleft|GetRight|
@cyberwani
cyberwani / polylang-shortcode.php
Created October 11, 2017 08:15
Shortcode to display content based on current language.
<?php
if( ! function_exists('polylang_content_func') ){
function polylang_content_func( $atts, $content = "" ) {
$atts = shortcode_atts( array(
'lang' => '',
), $atts );
extract($atts);
@cyberwani
cyberwani / wordpress-upload-base64.php
Created September 13, 2019 10:19
Upload a base64 string as image to the WordPress media library
<?php
/**
* Save the image on the server.
*/
function save_image( $base64_img, $title ) {
// Upload dir.
$upload_dir = wp_upload_dir();
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
<?php
// Load source and mask
$source = imagecreatefrompng( '1.png' );
$mask = imagecreatefrompng( '2.png' );
// Apply mask to source
imagealphamask( $source, $mask );
// Output
header( "Content-type: image/png");
imagepng( $source );
<?php
/**
* Plugin Name: Ratcache
* Description: An advanced caching plugin that uses an external object cache to store full pages.
* Author: Christopher Davis
* Author URI: http://christopherdavis.me
* Version: 0.1
*
* Place this file in your `wp-content` directory and add
* `define('WP_CACHE', true)` to your wp config file.
@cyberwani
cyberwani / wp-youtube-lazyload.php
Last active August 25, 2023 15:29
WordPress YouTube Lazy Load
<?php
/*
* Convert all YouTube embeds (embed shortcode and autoembed)
*
* */
function youtube_lazyload_oembed_html( $html, $url, $attr, $post_id ) {
$oembed = _wp_oembed_get_object();
// $oembed_provider = $oembed->get_provider( $url, $attr );
// $oembed_html = $oembed->get_html( $url, $attr );
$oembed_data = $oembed->get_data( $url, $attr );
@cyberwani
cyberwani / is_localhost
Created February 10, 2020 17:57 — forked from troutacular/is_localhost
PHP - Check if localhost
// Check if we are in a local environment
function is_localhost() {
// set the array for testing the local environment
$whitelist = array( '127.0.0.1', '::1' );
// check if the server is in the array
if ( in_array( $_SERVER['REMOTE_ADDR'], $whitelist ) ) {
@cyberwani
cyberwani / is_rest.php
Created March 30, 2023 17:38 — forked from matzeeable/is_rest.php
Checks if the current request is a WP REST API request.
<?php
if ( !function_exists( 'is_rest' ) ) {
/**
* Checks if the current request is a WP REST API request.
*
* Case #1: After WP_REST_Request initialisation
* Case #2: Support "plain" permalink settings and check if `rest_route` starts with `/`
* Case #3: It can happen that WP_Rewrite is not yet initialized,
* so do this (wp-settings.php)
@cyberwani
cyberwani / .gitlab-ci.yml
Created March 30, 2023 17:09 — forked from swashata/.gitlab-ci.yml
Deploy WordPress Plugin with GitLab CI/CD
# Our base image
image: registry.gitlab.com/wpquark/docker-containers/php-node:2.0.0-php-7.3-node-12.13.0
# Select what we should cache
cache:
key: "$CI_COMMIT_REF_SLUG-$CI_JOB_NAME"
paths:
- .yarn-cache
- .composer-cache
@cyberwani
cyberwani / SimpleICS.class.php
Created March 27, 2023 09:27 — forked from amattu2/SimpleICS.class.php
A simple ICS (iCalendar) event generator class.
<?php
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the