This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Sample code for using WordPress as a REST API endpoint (vs AJAX Admin) | |
* Author: Pete Nelson @GunGeekATX | |
* | |
* 1) Create a page called API in WordPres | |
* 2) Create a file called page-api.php in your theme directory | |
* 3) Add code as-needed | |
* | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// some defaults | |
$start = new DateTime('2013-04-11'); | |
$end = new DateTime('2013-05-09'); | |
$current = new DateTime('2013-04-19'); | |
if (isset($_REQUEST['s'])) | |
$start = new DateTime($_REQUEST['s']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// via http://www.paulund.co.uk/change-the-enter-title-text-for-custom-post-types | |
// just saving it here for later reference | |
function change_default_title( $title ){ | |
$screen = get_current_screen(); | |
if ( $screen->post_type == 'product' ) { | |
return 'Enter New Product Here'; | |
} | |
} | |
add_filter( 'enter_title_here', 'change_default_title' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add to header.php prior to wp_head() | |
$custom_css_file = get_post_meta( get_the_id(), $key = 'custom-css-file', $single = true ); | |
if (false !== $custom_css_file && !empty($custom_css_file)) | |
wp_enqueue_style( get_the_id() . '-custom-css-file', get_template_directory_uri() . '/' . $custom_css_file, array(), $version_tag_here ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: GGA Twitter Card | |
Description: Adds Twitter card meta tags to the header | |
Author: @GunGeekATX | |
*/ | |
add_action('wp_head', 'gga_twitter_card_wp_head'); | |
function gga_twitter_card_wp_head() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$test_data = array(); | |
$test_data[] = new stdClass(); | |
$test_data[0]->field1 = 'hello'; | |
$test_data[0]->field2 = 'world'; | |
$test_data[0]->my_object = new stdClass(); | |
$test_data[0]->my_object->field3 = 'more hello world'; | |
wp_localize_script( 'gmec-intranet', 'test_data', $test_data ); | |
// outputs the following Javascript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: GGA Import Pages | |
Description: Quick plugin to bulk import a list of pages <a href="admin-ajax.php?action=gga_import_pages">[Import Now]</a> | |
*/ | |
add_action( 'wp_ajax_gga_import_pages', 'gga_import_pages' ); | |
function gga_import_pages() { | |
global $post; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// just using a file, could easily be replaced by some other storage method | |
if (isset($_REQUEST['new']) && $_REQUEST['new'] == '1') { | |
$ver = new stdClass(); | |
$ver->ver = time(); | |
file_put_contents('ver.json', json_encode($ver)); | |
} | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: GGA - AJAX Posts by Taxonomy | |
Author: Pete Nelson (@GunGeekATX) | |
Description: <a href="http://petenelson.com/wp-admin/admin-ajax.php?action=gga_posts_by_taxonomy&post_type=post&taxonomy=post_tag&term=android">Try it out</a> | |
Version: 1.0 | |
*/ | |
/* | |
http://petenelson.com/wp-admin/admin-ajax.php?action=gga_posts_by_taxonomy&post_type=post&taxonomy=post_tag&term=android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gga_set_featured_image_from_url($post_id, $url) { | |
$temp_file = download_url( $url ); | |
if (is_wp_error( $temp_file )) | |
return $temp_file; | |
$file_array['name'] = basename( $url ); | |
$file_array['tmp_name'] = $temp_file; | |
$sideloaded_id = media_handle_sideload( $file_array, $post_id ); |