Skip to content

Instantly share code, notes, and snippets.

View daviddarke's full-sized avatar
🚀

David Darke daviddarke

🚀
View GitHub Profile
@vxnick
vxnick / gist:380904
Created April 27, 2010 15:52
Array of country codes (ISO 3166-1 alpha-2) and corresponding names
<?php
$countries = array
(
'AF' => 'Afghanistan',
'AX' => 'Aland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
@iturgeon
iturgeon / Vagrantfile
Created November 29, 2012 19:45
Chef and Vagrant setup to easily create databases as needed
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
# pass json_attribs to chef
chef.json = {
@leepowers
leepowers / gist:5267871
Created March 29, 2013 00:17
Wordpress `paginate_links_array` - get an array of objects that can be used to generate a custom HTML structure for pagination. Use this if you want the functionality of `paginate_links` without HTML being generated.
<?php
/**
* Modification of `paginate_links()` Wordpress built-in function.
* Returns an array of objects describing links instead of generating HTML for links.
* @param array $args Same as `paginate_links()` arguments array. Exceptions: `classes` mapping for CSS classes; `type` is ignored
* @return array Returns an array of objects representing links that can be used to generate HTML
*/
function paginate_links_array($args = '') {
$defaults = array(
@carlosleopoldo
carlosleopoldo / delete-orphans-usermeta.sql
Last active June 16, 2023 13:23
Delete all orphans user meta in WordPress
DELETE FROM wp_usermeta
WHERE NOT EXISTS (
SELECT * FROM wp_users
WHERE wp_usermeta.user_id = wp_users.ID
)
@murdaugh
murdaugh / copy post to blog function
Created October 3, 2013 20:11
Copies a post (as well as its associated meta data) from one wordpress blog to another on the same network.
<?php
function copy_post_to_blog($post_id, $target_blog_id) {
$post = get_post($post_id, ARRAY_A); // get the original post
$meta = get_post_meta($post_id);
$post['ID'] = ''; // empty id field, to tell wordpress that this will be a new post
switch_to_blog($target_blog_id); // switch to target blog
$inserted_post_id = wp_insert_post($post); // insert the post
foreach($meta as $key=>$value) {
update_post_meta($inserted_post_id,$key,$value[0]);
}
@guillaumemolter
guillaumemolter / snippet.php
Created November 11, 2015 16:13
Disable WordPress default routes and endpoints REST API V2 - Correct way
<?php
remove_action( 'rest_api_init', 'create_initial_rest_routes', 0 );
@Nihisil
Nihisil / jail.local
Last active September 5, 2023 06:20
Send notifications to the Slack from fail2ban
...
action_with_slack_notification = %(banaction)s[name=%(__name__)s, port="%(port)$
slack[name=%(__name__)s]
action = %(action_with_slack_notification)s
...
@macbookandrew
macbookandrew / functions.php
Created June 21, 2016 19:13
Prevent YouTube embedded videos from showing related videos at the end
/* Prevent YouTube Related Content on oEmbed-ed videos */
add_filter( 'oembed_result', 'prevent_featured_youtube_videos' );
function prevent_featured_youtube_videos( $embed ) {
return str_replace( '?feature=oembed', '?feature=oembed&rel=0', $embed );
}