Skip to content

Instantly share code, notes, and snippets.

@stephenharris
stephenharris / is-descendent-of.php
Created May 29, 2013 23:26
Check if current page is a descendant of the specified one.
<?php
/**
* Is the current page a descendent of page identified by the path (not slug).
* A page is not a descendent of itself!
* @link http://wordpress.stackexchange.com/questions/101213/does-is-child-exist-in-wp-3-5-1
* @param string $page_path The path of the page, e.g. mypage/mysubpage
* @return boolean True if current page is a descednent of specified $page_path. False otherwise.
*/
function is_descendent_of( $page_path ){
@hissy
hissy / gist:7352933
Created November 7, 2013 11:07
[WordPress] Add file to media library programmatically
<?php
$file = '/path/to/file.png';
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $parent_post_id,
@fer-ri
fer-ri / Spinner.php
Last active December 16, 2019 06:09
PHP Spinner Updated – Spin articles for SEO Taken from http://www.paul-norman.co.uk/2010/09/php-spinner-updated-spin-articles-for-seo/ All credit goes to him
<?php
class Spinner
{
# Detects whether to use the nested or flat version of the spinner (costs some speed)
public static function detect($text, $seedPageName = true, $openingConstruct = '{{', $closingConstruct = '}}', $separator = '|')
{
if(preg_match('~'.$openingConstruct.'(?:(?!'.$closingConstruct.').)*'.$openingConstruct.'~s', $text))
{
return self::nested($text, $seedPageName, $openingConstruct, $closingConstruct, $separator);
@wpmark
wpmark / wp-toplevel-admnin-menu.php
Last active December 12, 2019 19:05
Add a WordPress Admin Top Level Menu
<?php
function wpmark_add_toplevel_menu() {
/* add a new menu item */
add_menu_page(
'My Admin Menu', // page title
'My Admin Menu', // menu title
'edit_posts', // capability
'wpmark_admin_menu', // menu slug
'wpmark_admin_menu_content', // callback function
@wpmark
wpmark / wp-admin-menu-hierarchy-correction.php
Created November 19, 2014 17:19
WordPress Admin Menu Hierarchy Correction
<?php
function wpmark_menu_hierarchy_correction( $parent_file ) {
global $current_screen;
/* get the base of the current screen */
$screenbase = $current_screen->base;
/* if this is the edit.php base */
if( $screenbase == 'edit' ) {
@yesvods
yesvods / gist:51af798dd1e7058625f4
Created August 15, 2015 11:13
Merge Arrays in one with ES6 Array spread
const arr1 = [1,2,3]
const arr2 = [4,5,6]
const arr3 = [...arr1, ...arr2] //arr3 ==> [1,2,3,4,5,6]
@lury
lury / spintax.php
Last active December 16, 2019 05:59 — forked from MarkLL/spintax.php
<?PHP
/**
* Spintax - A helper class to process Spintax strings.
* @name Spintax
* @author Jason Davis - https://www.codedevelopr.com/
* Tutorial: https://www.codedevelopr.com/articles/php-spintax-class/
* Modified by Mark Larsen:
* Added ability so that a fixed output can be returned.
*/
class Spintax
@fer-ri
fer-ri / Example.php
Created January 19, 2016 06:14
Spinner PHP Class With Seed
<?php
$string = '{{The|A}} {{quick|speedy|fast}} {{brown|black|red}} {{fox|wolf}} {{jumped|bounded|hopped|skipped}} over the {{lazy|tired}} {{dog|hound}}';
echo '<p>';
for($i = 1; $i <= 5; $i++)
{
echo Spinner::detect($string, false).'<br />';
// or Spinner::flat($string, false).'<br />';
@ControlledChaos
ControlledChaos / README.md
Last active June 22, 2023 07:47
Change the default WordPress post name to News and replace the Dashicon.

Change Default Posts to News

WordPress Snippet

@yaodong
yaodong / gist:f5b785c5b17337ce1b9a
Created February 11, 2016 23:15
things cloud requests
login
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Authorization: Password pppppwwwwdddd" -H "Accept-Language: en-us" --compressed https://cloud.culturedcode.com/version/1/account/user%40exmaple.com
get key
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Authorization: Password pppppwwwwdddd" -H "Accept-Language: en-us" --compressed https://cloud.culturedcode.com/version/1/account/user%40exmaple.com/own-history-keys
get index
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Accept-Language: en-us" --compressed https: