Skip to content

Instantly share code, notes, and snippets.

@dinolatoga
dinolatoga / gist:6004917
Last active January 21, 2021 07:34
Programmatically Create Pages/Posts in WordPress. Personally modified to work properly. Source: http://advent.squareonemd.co.uk/programmatically-create-a-wordpress-page-post-or-custom-post-type/
<?php
// Helper Functions
/**
* Programmatically creates a WordPress post based on the incoming parameters.
*
* Note: This function may need some additional work if you're dealing with non-English languages.
*
* @param string $title The title of the page as presented to the users
* @param string $slug The slug used to access the page via the URL
function add_admin_menu_separator($position) {
global $menu;
$index = 0;
foreach($menu as $offset => $section) {
if (substr($section[2],0,9)=='separator')
$index++;
if ($offset>=$position) {
$menu[$position] = array('','read',"separator{$index}",'','wp-menu-separator');
break;
}
@dinolatoga
dinolatoga / gist:6025880
Created July 18, 2013 00:51
Add admin separator to admin menu
add_action( 'admin_init', 'add_sep' );
function add_sep() {
if ( ! is_admin() )
return false;
global $menu;
$sep = $menu[4]; // that's the default separator
$pos = 6; // change it for the desired position
$menu = array_merge(
@dinolatoga
dinolatoga / related-posts.php
Last active December 20, 2015 04:09 — forked from jtallant/jt-related-posts.php
Get WordPress Related Posts by tags if available and category if not
@dinolatoga
dinolatoga / sort-array.php
Created April 2, 2014 03:18
Move Arrays on top or bottom
function move_to_top(&$array, $key) {
$temp = array($key => $array[$key]);
unset($array[$key]);
$array = $temp + $array;
}
function move_to_bottom(&$array, $key) {
$value = $array[$key];
unset($array[$key]);
$array[$key] = $value;
@dinolatoga
dinolatoga / gist:181db2c972028c15506a
Last active August 29, 2015 14:06
Get current php version of server
<?php
echo 'Current PHP version: ' . phpversion();
echo phpversion('tidy'); // if the extension isn't enabled
@dinolatoga
dinolatoga / relatedposts.php
Last active December 1, 2015 08:52
Display Related Posts (WordPress)
@dinolatoga
dinolatoga / Create ISO image from folder
Created July 14, 2015 00:40
Create an ISO image on OSX from the command line without the use of any additional tools. Source: https://matt.berther.io/2008/12/14/creating-iso-images-from-a-folder-in-osx/
hdiutil makehybrid -o ~/Desktop/image.iso ~/path/to/folder/to/be/converted -iso -joliet
@dinolatoga
dinolatoga / update.php
Created September 8, 2015 07:22
WordPress migration update domain name
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
@dinolatoga
dinolatoga / gist:0aa34115f921ef3939c5
Created September 18, 2015 12:56 — forked from remyperona/gist:13348dbcd2bbb0d9406f
WordPress customizer custom tinymce control
class Text_Editor_Custom_Control extends WP_Customize_Control
{
public $type = 'textarea';
/**
** Render the content on the theme customizer page
*/
public function render_content() { ?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php