Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Plugin Name: No Spam Registration with JavaScript
* Plugin URI: http://blog.samelh.com
* Description: Prevents spam registration on your WordPress blog/website by adding a necessary form field with JavaScript on document load
* Author: Samuel Elh
* Author URI: http://samelh.com
* Version: 0.1
*/
<?php
/**
* Plugin Name: Restrict mail TLD registration
* Plugin URI: http://samelh.com
* Description: Allow/disallow user registration for email TLD
* Author: Samuel Elh
* Author URI: http://samelh.com
* Version: 0.1
*/
@elhardoum
elhardoum / WordPress Transients - Helper Class.php
Created August 28, 2016 14:19
WordPress Transients - Helper Class - for handling WordPress Transients and caching data and keeping things simple as they should
<?php
/**
* WordPress Transients - Helper Class
*
* Makes it easier to store transients and call them and all in like 4 lines of code
* Helps you save large amounts of data (arrays) without the confusing proccess of
* chunking data into batches, and joining later upon getting all the data and also
* deleting all of these batches correctly. This class does it all for you.
*
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = (percentComplete.toFixed(2) * 100);
// add a progress bar container
if ( $('#upload-progress',container).length == 0 ) {
$(container).append('<div id="upload-progress" style="background: rgba(255, 186, 186, 0.32); width: 0; overflow: hidden; padding: 4px;"></div>');
}
@elhardoum
elhardoum / modifier.relative_date.php
Last active October 25, 2016 00:11 — forked from dodyw/modifier.relative_date.php
Smarty relative date ... (time) agoSave to plugins folderUsage: <%$date|relative_date%>
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: modifier
* Name: relative_date
* Version: 1.1
* Date: November 28, 2008
* Author: Chris Wheeler <[email protected]>
<?php
if ( defined('BM_CUSTOM_LOAD') && isset($BM_Loader) && method_exists($BM_Loader, "init") ) {
if ( true /* my custom preferences */ ) {
$BM_Loader->init();
}
}
<?php
/** @link https://samelh.com/blog/2016/12/22/add-custom-fields-bbpress-profile/ **/
// add field to bbP profile edit
add_action( "bbp_user_edit_after_contact", "se_add_city_field" );
function se_add_city_field() {
// a random selection of cities
$cities = array( "Seoul", "Mexico City", "Amsterdam", "Mumbai", "Agadir", "Egypt" );
// selected city, if any
<?php
/**
* @link https://github.com/bainternet/PHP-Hooks
*/
function hooks() {
global $hooks;
if ( !isset($hooks) || !($hooks instanceof \Hooks) ) {
$hooks = new \Hooks;
@elhardoum
elhardoum / hashScrollFix.js
Last active April 29, 2017 13:16
Adjust scroll when you have a fixed menu and a hash URL
var hashScrollFix = function() {
var hash = location.hash
, menu = $('.main-navi.fixed') // your fixed menu selector
, itm;
// I added menu.position().top >= 0 because I fade my menu to above viewport
// with a negative top position
if ( menu.is(':visible') && menu.position().top >= 0 ) {
itm = $(hash);
@elhardoum
elhardoum / AmIFromContinent.php
Last active May 5, 2017 23:55
Check if current user is from certain continent
<?php
/**
* Get client IP
*/
function whatismyip() {
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];