This file contains hidden or 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
// Remove empty paragraphs | |
function filter_woocommerce_short_description2( $post_post_excerpt ) { | |
$post_post_excerpt = str_replace("<p></p>","",$post_post_excerpt); | |
$post_post_excerpt = str_replace("<p> </p>","",$post_post_excerpt); | |
return $post_post_excerpt; | |
}; | |
add_filter('woocommerce_short_description', 'filter_woocommerce_short_description2', 10, 1); |
This file contains hidden or 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 empty_content($str) { | |
return trim(str_replace(' ','',strip_tags($str))) == ''; | |
} |
This file contains hidden or 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
// https://stackoverflow.com/questions/4356289/php-random-string-generator | |
function generateRandomString($length = 10) { | |
return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length); | |
} | |
echo generateRandomString(); // OR: generateRandomString(24) |
This file contains hidden or 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
/* | |
* Filters the $order->get_items() method results to order all line items by | |
* product name | |
*/ | |
add_filter( 'woocommerce_order_get_items', function( $items, $order ) { | |
uasort( $items, | |
function( $a, $b ) { | |
return strnatcmp( $a['name'], $b['name'] ); | |
} |
This file contains hidden or 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
if (is_admin()){ | |
if ( !get_option('db_last_auto_cnl') || (get_option('db_last_auto_cnl') < time()- 86400) ) { | |
global $wpdb; | |
$del= $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'"); | |
$del= $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'"); | |
$del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_rss%'"); | |
$del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_rss_%'"); | |
$del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_feed_%'"); | |
$del= $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_feed_%'"); | |
//if you want, you can uncomment these too |
This file contains hidden or 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 getLastPathSegment($url) { | |
$path = parse_url($url, PHP_URL_PATH); // to get the path from a whole URL | |
$pathTrimmed = trim($path, '/'); // normalise with no leading or trailing slash | |
$pathTokens = explode('/', $pathTrimmed); // get segments delimited by a slash | |
if (substr($path, -1) !== '/') { | |
array_pop($pathTokens); | |
} | |
return end($pathTokens); // get the last segment | |
} |
This file contains hidden or 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_action('add_attachment', function($postId) { | |
// get the attachment post object | |
$attachment = get_post($postId); | |
// get the slug for the attachment | |
$slug = $attachment->post_name; | |
// update the post data of the attachment with an edited slug | |
wp_update_post(array( | |
'ID' => $postId, | |
'post_name' => 'media-'.$slug, //adds a prefix | |
//'post_name' => $slug.'-photo', //adds a suffix |
This file contains hidden or 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
/** | |
* Recursively sort an array of taxonomy terms hierarchically. Child categories will be | |
* placed under a 'children' member of their parent term. | |
* @param Array $cats taxonomy term objects to sort | |
* @param integer $parentId the current parent ID to put them in | |
*/ | |
function sort_terms_hierarchicaly(Array $cats, $parentId = 0) | |
{ | |
$into = []; | |
foreach ($cats as $i => $cat) { |
This file contains hidden or 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_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' ); | |
function display_price_in_variation_option_name( $term ) { | |
global $wpdb, $product; | |
if ( empty( $term ) ) return $term; | |
if ( empty( $product->id ) ) return $term; | |
$id = $product->get_id(); |
This file contains hidden or 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
// wp_get_object_terms() always queries the database | |
/* If you’re looping over WP_Query results, you should prefer get_the_terms() instead. | |
It’s pretty much the same for most use cases, but it uses the object cache, | |
which by default gets populated with the terms for the posts matching your query — unless you specifically | |
set update_post_term_cache as false when instantiating WP_Query. | |
*/ | |
// Get terms for post | |
if ( ! function_exists( 'storefront_post_terms' ) ) { | |
function storefront_post_terms(){ |
NewerOlder