Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Updating knowledgebase...

Luis CasperBraske

🤓
Updating knowledgebase...
View GitHub Profile
@CasperBraske
CasperBraske / wp_menu_items_to_links.sql
Last active Aug 29, 2015
Change WordPress' nav menu items into custom links
View wp_menu_items_to_links.sql
@CasperBraske
CasperBraske / Dummy.Csharp.example.cs
Last active Nov 29, 2019
Example of well formatted code
View Dummy.Csharp.example.cs
using System;
namespace FacebookGroup {
public class Example(){
public Exemple(){
Console.WriteLine("hej på dig");
}
}
}
@CasperBraske
CasperBraske / changing-form-fields-after-user-log-in.php
Last active Aug 25, 2017
Since WordPress uses difrerent templates for both logged and not logged-in users, I ended up having to use some other hooks other than the default filter.
View changing-form-fields-after-user-log-in.php
<?php
function alter_comment_form_fields($fields){
$commenter = wp_get_current_commenter();
$fields['author'] = '<p class="comment-form-input comment-form-author"><label for="author">' . __( 'This is a fancy label', 'your-text-domain' ) . '</label><input id="author" required name="author" type="text" placeholder="Seu nome" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" aria-required="true" /></p>';
return $fields;
}
@CasperBraske
CasperBraske / MyTax-meta-class.php
Created Jul 17, 2016
Add Google Maps meta field to taxonomy using bainternet/Tax-Meta-Class
View MyTax-meta-class.php
<?php
include_once dirname(__FILE__)."/Tax-meta-class/Tax-meta-class.php";
class MyTax_Meta_Class extends Tax_Meta_Class {
public function load_scripts_styles(){
parent::load_scripts_styles();
// enqueue only in the right place
if(isset($_REQUEST['taxonomy'])) {
//script must have been registered previously (priority of at least 10)
@CasperBraske
CasperBraske / list.html
Last active Aug 25, 2017
One-liner last-child style remover.
View list.html
<style>
ul {
list-style:none;
}
li {
display: inline-block;
padding: 5px;
}
</style>
@CasperBraske
CasperBraske / a2dissite.sh
Last active Aug 25, 2017
Apache 2's a2ensite and a2dissite for non-Deb based distros. Source (slightly modified): Apache virtual hosting in CentOS http://www.tecmint.com/apache-virtual-hosting-in-centos/
View a2dissite.sh
#!/bin/bash
avail=/etc/httpd/sites-enabled/$1.conf
enabled=/etc/httpd/sites-enabled
site=`ls /etc/httpd/sites-enabled/`
if [ "$#" != "1" ]; then
echo "Use script: a2dissite virtual_site"
echo -e "\nAvailable virtual hosts: \n$site"
exit 0
else
@CasperBraske
CasperBraske / ApplicationContext.cs
Created May 26, 2017
Friendship workflow using Entity Framework
View ApplicationContext.cs
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace Test.Models {
public DbSet<Friendship> Friendships { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
/* USER */
modelBuilder.Entity<User>().HasMany(u => u.Friends).WithMany();
@CasperBraske
CasperBraske / .bashrc
Created May 26, 2017
My .bashrc setup.
View .bashrc
source /opt/wp-completion.bash
export DEV=/var/www/html
export EDITOR=subl
export PS1="\[$(tput bold)\]\[\033[38;5;58m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\[$(tput sgr0)\]\[\033[38;5;58m\]\H\[$(tput sgr0)\]\[$(tput sgr0)\]\[\033[38;5;15m\] [\t] \w \\$\n> \[$(tput sgr0)\]"
# function to set terminal title
function set-title() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
@CasperBraske
CasperBraske / toggle.js
Last active Dec 9, 2017
A bookmarklet to quickly toggle admin bar in WordPress .
View toggle.js
javascript: (function() {
var htmlStyle = document.documentElement.style;
var adminBarStyle = document.getElementById('wpadminbar').style;
if(undefined == window.hasAdminBar){
window.hasAdminBar = true;
}
var cssText, display;
@CasperBraske
CasperBraske / loop.php
Created Mar 8, 2018
Adding taxonomy filtering to a loop
View loop.php
<?php
$args = array(
'post_type' => 'cardapio',
'posts_per_page' => 999,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'cardapio_category',
'field' => 'term_id',