Skip to content

Instantly share code, notes, and snippets.

@milesstewart88
milesstewart88 / WordPress - Plugin basename
Created November 11, 2014 10:24
Gets the plugin basename everytime without having to add a path.
function get_plugin_basepath() {
$path = explode("/", plugin_dir_path(__FILE__));
$basePath = explode("/", plugin_basename(__FILE__));
$pathKey = array_search($basePath[0], $path);
$newArray = array_slice(array_filter($path), 0, $pathKey);
$fullBasePath = implode("/", $newArray);
return "/" . $fullBasePath;
<?php
echo "Im about to pull the data.. Muh ... Shut your mouth";
function pullTheData( $url, $county) {
$page = file_get_contents($url);
$doc = new DOMDocument();
$doc->loadHTML($page);
<?php
/**
* I'll write a function for this shortly
*
* */
join(DIRECTORY_SEPARATOR,array( public_path(), "content", "source_files", "_translator", $new_name) );
@milesstewart88
milesstewart88 / Symfony 2 - Remove Cache & Logs
Last active January 3, 2016 19:59
Quickly remove the cache and logs
rm -rf app/cache/*
rm -rf app/logs/*
@milesstewart88
milesstewart88 / WordPress - Before Page Load
Created January 19, 2014 06:57
Action that runs before page is loaded
add_action( 'wp', 'the_function_name' );
@milesstewart88
milesstewart88 / PHP - Arrays - Sort Multi Dimensional
Last active December 21, 2015 13:19
Sort a multi-dimensional array by a value - Just use the value's keys
function compare_distance($a,$b)
{
if($a["details"]["distance"] == $b["details"]["distance"]) return 0;
return ($a["details"]["distance"] > $b["details"]["distance"]) ? 1 : -1;
}
usort($the_array, 'compare_distance');
// Company Logo Image field
$att = my_update_attachment('user_photo', $post_id);
update_field('{field_key}', $att['attach_id'], $post_id);
/*
*
* Upload Image to ACF Field
* From Frontend
*
*/
//functions.php on theme folder
function my_update_attachment($f,$pid,$t='',$c='') {
add_action( 'admin_init', 'redirect_non_admin_users' );
/**
* Redirect non-admin users to home page
*
* This function is attached to the 'admin_init' action hook.
*/
function redirect_non_admin_users() {
if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
wp_redirect( home_url() );
exit;