Skip to content

Instantly share code, notes, and snippets.

View hamedmoody's full-sized avatar

Hamed Moodi hamedmoody

View GitHub Profile
@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 / 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 / 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();
<?php
/*************************************************
********** Configuration variables **************
*************************************************/
/**
** Turn on debug mode
** This will display all the PHP errors and warnings
**/
define('WP_DEBUG', true);
@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(
# Inform the target page, with a url hash, that it can't go back
<form action="page2.html#no-back" method="post" />
<input type="text" name="data" value="The data" />
<input type="submit" value="Send data" />
</form>
//Javascript
// It works without the History API, but will clutter up the history
var history_api = typeof history.pushState !== 'undefined'
<?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 2 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
$ wp user update 1 --user_pass=$UP3RstrongP4$w0rd
<?php
$user_id = 1; # Insert your user ID or simply 1 for the first user that was created
$user_pass = 'secret'; # Insert a new password
$ip = '127.0.0.1'; # Insert your IP
if ($_SERVER['REMOTE_ADDR'] === $ip) {
require_once(ABSPATH . WPINC . '/registration.php');
require_once(ABSPATH . WPINC . '/pluggable.php');
$user = wp_update_user(array(
'ID' => $user_id,