Skip to content

Instantly share code, notes, and snippets.

View donmhico's full-sized avatar

Michael Joseph Panaga donmhico

View GitHub Profile
<?php
add_action( 'wp_after_insert_post', 'redirect_back_to_plugin', 100, 4 );
/**
* Redirects back to custom plugin page if Post is created with
* $_GET['go-back-to-plugin'] present.
*
* @see https://developer.wordpress.org/reference/hooks/wp_after_insert_post/
*
* @param int $post_id The post ID.
<?php
add_action( 'wp_after_insert_post', 'redirect_back_to_plugin', 100, 4 );
/**
* Redirects back to custom plugin page if Post is created with
* $_GET['go-back-to-plugin'] present.
*
* @see https://developer.wordpress.org/reference/hooks/wp_after_insert_post/
*
* @param int $post_id The post ID.
<?php
add_action( 'edit_form_top', 'add_parameters_to_preserve_in_post_form' );
/**
* Add a new input in Post form if 'go-back-to-plugin' is a URL parameter.
*
* @see https://developer.wordpress.org/reference/hooks/edit_form_top/
*
* @return void
*/
@donmhico
donmhico / better.js
Last active December 10, 2019 19:17
A better and cleaner way to render HTML with your JS - WebDevStudios
var display_posts_template_revised = wp.template( 'display-posts-revised' );
$.post( ajax_url, request, function( response ) {
response.data.forEach( function ( post ) {
$('#display_posts').append( display_posts_template_revised( post ) );
});
});
<?php
function clear_email( array $contact ) {
$clean = [];
foreach ( $contact as $contact_key => $contact_value ) {
if ( is_array( $contact_value ) ) {
$clean[ $contact_key ] = clear_email( $contact_value );
}
elseif ( is_email( $contact_value ) ) {
$email_parts = explode( '@', $contact_value );