Skip to content

Instantly share code, notes, and snippets.

View thomasgriffin's full-sized avatar
👋

Thomas Griffin thomasgriffin

👋
View GitHub Profile
<?php
/*
* Completely untested, but may work. :-)
*/
function tgm_quick_write_file() {
$url = wp_nonce_url( 'YOUR NONCIFIED URL HERE (if you are using a post mechanism to write the file' );
$method = ''; // WP_Filesystem will populate this automatically
if ( false === ( $creds = request_filesystem_credentials( $url, $method, false, false, null ) ) )
<?php
/**
* Factory method for creating a new image filter object instance. The image param must
* be a valid directory path to the image.
*
* @since 1.0.0
*
* @param int $id The image attachment ID
* @param string $image The real path to the image being filtered
* @param string $filter The type of filter to be applied to the image
<?php
add_action( 'wp_login', array( $this, 'update_creds' ), 10, 2 );
public function update_creds( $login, $user ) {
// Do your stuff here
}
<?php
add_action( 'wp_login', 'update_some_random_option' );
function update_some_random_option() {
update_option( 'my_test_option', 'I have been saved!' );
}
add_action( 'admin_notices', 'check_some_random_option' );
function check_some_random_option() {
<?php
/** Add nonce to wp_localize_script */
wp_localize_script( 'qvote-ajax', 'QVoteAJAX', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'vote_nonce' ) ) );
/** Pass nonce in Ajax request */
var data = {
action: 'qvote_count',
postid: postid,
vtype: vtype,
count: count,
<?php
add_action( 'tgmsp_before_slider_output', 'tgm_unregister_soliloquy_style' );
function tgm_unregister_soliloquy_style( $id ) {
// If you only want to do it for a particular slider, use the $id param to test against a slider in particular
wp_dequeue_script( 'soliloquy-style' );
}
/**
* Prevents unnatural scaling when shifting viewport modes on iPhone/iPod/iPad.
*
* When shifting from portrait to landscape mode on an iPad, some responsive
* CSS will cause the landscape view to be scaled upon switch. This bit of JS
* prevents that by first ensuring that we have the responsive meta tag enabled,
* setting the initials scales back to the original load state, and then re-enabling
* resizing once the user makes their first gesture on the screen.
*/
if ( navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i) ) {
<!--[if IE]>
<script type="text/javascript">
jQuery(document).ready(function($){
$(".flex-container").each(function(i, el){
$(el).hover(function(){
$(this).addClass("flex-hover");
}, function(){
$(this).removeClass("flex-hover");
});
});
<?php
add_action( 'wp_enqueue_scripts', 'my_custom_callback_function' );
function my_custom_callback_function() {
wp_register_script('scrollbar', get_template_directory_uri() .'/jquery.mCustomScrollbar.js', '3.1.4', '1.0.0', true);
wp_enqueue_script('scrollbar');
}
<?php
$xml = simplexml_load_file( 'path/to/my/file.xml' );
/** To list out all of the attributes and their values, loop through each child node and output it */
foreach ( $xml->children() as $node )
echo $node->getName() . ': ' . $node;