Skip to content

Instantly share code, notes, and snippets.

View hamedmoody's full-sized avatar

Hamed Moodi hamedmoody

View GitHub Profile
@hamedmoody
hamedmoody / nav-menu-item-custom-fields.php
Created May 27, 2018 10:53 — forked from kucrut/nav-menu-item-custom-fields.php
Proof of concept for how to add new fields to nav_menu_item posts in the WordPress menu editor.
<?php
/**
* Proof of concept for how to add new fields to nav_menu_item posts in the WordPress menu editor.
* @author Weston Ruter (@westonruter), X-Team
*/
add_action( 'init', array( 'XTeam_Nav_Menu_Item_Custom_Fields', 'setup' ) );
class XTeam_Nav_Menu_Item_Custom_Fields {
static $options = array(
<?php
/*************************************************
********** Configuration variables **************
*************************************************/
/**
** Turn on debug mode
** This will display all the PHP errors and warnings
**/
define('WP_DEBUG', true);
@hamedmoody
hamedmoody / use-media-upload-in-wordpress-frontend.php
Created January 1, 2018 15:37
Use media upload in wordpress frontend.
<form method="post" action="#" enctype="multipart/form-data" >
<input type="file" name="featured_image">
</form>
<?php
function insert_attachment($file_handler,$post_id,$setthumb='false') {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
@hamedmoody
hamedmoody / delete-orphans-usermeta.sql
Last active November 10, 2017 17:06
Delete all orphans user meta in WordPress Raw
DELETE FROM wp_usermeta
WHERE NOT EXISTS (
SELECT * FROM wp_users
WHERE wp_usermeta.user_id = wp_users.ID
)
DELETE FROM wp_postmeta
WHERE NOT EXISTS (
SELECT * FROM wp_posts
WHERE wp_postmeta.post_id = wp_posts.ID
@hamedmoody
hamedmoody / list-table-example.php
Created September 13, 2017 12:25
Custom AJAX List Table Example WordPress plugin fork implementing AJAX loading
<?php
/**
* Custom AJAX List Table Example
*
* Custom AJAX List Table Example is a WordPress Plugin example of WP_List_Table
* AJAX implementation. It is a fork of Matt Van Andel's Custom List Table Example
* plugin.
*
* Plugin Name: Custom AJAX List Table Example
* Plugin URI: https://github.com/Askelon/Custom-AJAX-List-Table-Example
@hamedmoody
hamedmoody / wp-bootstrap-navwalker.php
Created June 15, 2017 10:55
A custom WordPress nav walker class to fully implement the Bootstrap 3.0+ navigation style in a custom theme using the WordPress built in menu manager.
<?php
/**
* WP Bootstrap Navwalker
*
* @package WP-Bootstrap-Navwalker
*/
/*
* Class Name: WP_Bootstrap_Navwalker
* Plugin Name: WP Bootstrap Navwalker
* Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noodp, noydir" />
<link rel="dns-prefetch" href="//cdnjs.cloudflare.com">
<link rel="canonical" href="http://mysite.com/" />
<link rel="stylesheet" href="http://mysite.com/style.css" type="text/css" />
@hamedmoody
hamedmoody / Classloader.php
Created May 24, 2016 18:55 — forked from RoverWire/Classloader.php
Autoloader Class
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@hamedmoody
hamedmoody / github-oauth2-client.php
Created May 3, 2016 09:14
Simple PHP example of using Github's OAuth 2 API
<?php
define('OAUTH2_CLIENT_ID', '');
define('OAUTH2_CLIENT_SECRET', '');
$authorizeURL = 'https://github.com/login/oauth/authorize';
$tokenURL = 'https://github.com/login/oauth/access_token';
$apiURLBase = 'https://api.github.com/';
session_start();
@hamedmoody
hamedmoody / wpmail_exceptions.php
Created March 3, 2016 05:35 — forked from franz-josef-kaiser/wpmail_exceptions.php
WP Mail Error/Exception handling and SMTP settings
<?php
defined( 'ABSPATH' ) OR exit;
/**
* Plugin Name: (WCM) PHPMailer Exceptions & SMTP
* Description: WordPress by default returns <code>FALSE</code> instead of an <code>Exception</code>. This plugin fixes that.
*/
add_action( 'phpmailer_init', 'WCMphpmailerException' );
function WCMphpmailerException( $phpmailer )
{