Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@dgoze
dgoze / custom-queries.php
Created March 31, 2019 01:35 — forked from carlodaniele/custom-queries.php
An example plugin showing how to add custom query vars, rewrite tags and rewrite rules to WordPress
<?php
/**
* @package Custom_queries
* @version 1.0
*/
/*
Plugin Name: Custom queries
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin
Author: Carlo Daniele
@dgoze
dgoze / strip-hidden-ascii-chars.php
Last active September 12, 2019 23:08 — forked from tommcfarlin/strip-hidden-ascii-chars.php
A simple regex for stripping out everything *except* alphanumeric characters.
<?php
// Replace anything that is not an 'a-z', 'A-Z', or '0-9' from the given $value
$value = preg_replace( "/[^a-zA-Z0-9\s]/", "", $value );
/*
* Read the comments below to see some of the available functions WordPress provides for evaluating the validity of the characters in the input string.
* /
<?php
// Register Post Type
add_action('init', 'hwk_post_type_exemple', 0);
function hwk_post_type_exemple(){
register_post_type('exemple', array(
'hierarchical' => false, // true | false. See 'post_row_actions' & 'page_row_actions' filters
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
<?php
add_filter('sanitize_file_name', 'hwk_sanitize_file_name');
function hwk_sanitize_file_name($input){
$path = pathinfo($input);
$extension = (isset($path['extension']) && !empty($path['extension'])) ? $path['extension'] : '';
$file = (!empty($extension)) ? preg_replace('/.' . $extension . '$/', '', $input) : $input;
return sanitize_title(str_replace('_', '-', $file)) . ((!empty($extension)) ? '.' . $extension : '');
}
@dgoze
dgoze / post_to_slack.php
Created November 2, 2019 04:30 — forked from ntwb/post_to_slack.php
post_to_slack.php
<?php
/**
* Post a message to Slack from WordPress
*
* @param string $message the message to be sent to Slack
* @param string $channel the #channel to send the message to (or @user for a DM)
* @param string $username the username for this bot eg : WordPress bot
* @param string $icon_emoji the icon emoji name for this bot eg :monkey:
*
@dgoze
dgoze / acf_modifications.php
Created November 5, 2019 23:42 — forked from courtneymyers/acf_modifications.php
Reduces initial height of Advanced Custom Fields WYSIWYG fields to 100px, and enables autoresizing of WYSIWYG field, as text is entered. Best practice would be to include this function in a site-specific plugin.
<?php
/*
* -----------------------------------------------------------------------------
* Advanced Custom Fields Modifications
* -----------------------------------------------------------------------------
*/
function PREFIX_apply_acf_modifications() {
?>
<style>
@dgoze
dgoze / km-remove-slug-from-custom-post-type.php
Created May 6, 2020 04:24 — forked from kellenmace/km-remove-slug-from-custom-post-type.php
Remove Slug from Custom Post Type URL in WordPress
<?php
/**
* Plugin Name: Remove Slug from Custom Post Type
* Description: Remove slug from custom post type URLs.
* Version: 0.1.0
* Author: Kellen Mace
* Author URI: https://kellenmace.com/
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
<?php
/*
Plugin Name: Disable plugins when doing local dev
Description: If the WP_LOCAL_DEV constant is true, disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
@dgoze
dgoze / show-meta-data-in-admin-list.php
Created May 6, 2020 15:23 — forked from ashokmhrj/show-meta-data-in-admin-list.php
Showing feature image in admin post listing
/**
* WordPress
* Showing feature image in admin post listing
*/
add_filter('manage_posts_columns' , 'ask_custom_columns');
/*add_filter('manage_{post-type-slug}_posts_columns' , 'ask_custom_columns');*/
function ask_custom_columns( $columns ) {
$columns = array(
@dgoze
dgoze / acf-sync-user-and-cpt-bidirectional-relationship.php
Created May 6, 2020 15:28 — forked from codytooker/acf-sync-user-and-cpt-bidirectional-relationship.php
Modified version of the bidirectional relationship function to help facilitate users to cpt relationships
<?php
/*
* This code is modified from the original here
* https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-reciprocal-relationship.php
*
* Some comments may not be useful anymore since the modifications
*/