Skip to content

Instantly share code, notes, and snippets.

@mariusvetrici
mariusvetrici / filter_po_files.sh
Created July 2, 2015 10:36
Filter PO files - remove translated or untranslated messages
msgattrib --translated woocommerce-subscriptions-ro_RO.po -o woocommerce-subscriptions-ro_RO_ONLY_TRANSLATED.po
@mariusvetrici
mariusvetrici / translate_plugin_from_child_theme.php
Created July 2, 2015 10:21
Translate Plugin From Child Theme - ever needed to translate some strings from a plugin so as to be able to further upgrade the main plugin without loosing your translations?
<?php
add_action( 'after_setup_theme', 'load_custom_translations');
function load_custom_translations(){
load_child_theme_textdomain( 'woocommerce-bookings', get_stylesheet_directory() . '/translations' );
load_child_theme_textdomain( 'woocommerce-social-login', get_stylesheet_directory() . '/translations' );
}
add_filter( 'load_textdomain_mofile', 'filter_custom_translation_paths', 10, 2);
/**
* Update the path for loading custom translations for plugins
@mariusvetrici
mariusvetrici / add-html-comment-using-role.php
Created June 17, 2015 12:44
Add html comments using newly created user role
<?php
$role = add_role( 'new_role', 'My new role' );
// Add all your needed roles here and then, don't forget:
$role->add_cap( 'unfiltered_html' );
@mariusvetrici
mariusvetrici / Vagrantfile.rb
Created May 29, 2015 08:00
Vagrant file with NFS sharing - x100 times faster
# -*- mode: ruby -*-
# vi: set ft=ruby :
vagrant_dir = File.expand_path(File.dirname(__FILE__))
Vagrant.configure("2") do |config|
# Store the current version of Vagrant for use in conditionals when dealing
# with possible backward compatible issues.
vagrant_version = Vagrant::VERSION.sub(/^v/, '')
@mariusvetrici
mariusvetrici / Filter Custom Posts by Author in WP-ADmin.php
Last active February 1, 2024 05:37
Need to filter your Custom Post Types (WordPress) by Author in WPAdmin? Here's a handy way to do it by adding a new drop down for filtering
<?php
add_action( 'restrict_manage_posts', 'admin_posts_filter_restrict_manage_posts_by_author' );
/**
* Create the drop down
*
* @return void
*/
function admin_posts_filter_restrict_manage_posts_by_author(){
if (isset($_GET['post_type']) && 'task' == $_GET['post_type']){
wp_dropdown_users( array(
@mariusvetrici
mariusvetrici / gist:986fa6d350d4b6ebfcaa
Created May 8, 2015 10:27
Mandrill template for WordPress comment
<div mc:edit="author_name"></div>
<div mc:edit="comment_content"></div>
Reply to your task using the link below:
<div mc:edit="task_link"></div>
@mariusvetrici
mariusvetrici / replace-comment-notification-email-with-mandrill-template.php
Last active August 29, 2015 14:20
WordPress - Replace comment notification email with Mandrill template
<?php
define( 'ABC_NEW_COMMENT_EMAIL_MARKER', '|||abcNewComment||' );
add_filter( "comment_notification_text", "abc_comment_notification_text", 10, 2 );
/**
* Filter for changing the content of the email notification sent upon new comment.
*
* This function replaces the original comment email with a prefix + the comment_id.
* Later it will be extracted and inserted into Mandrill template as variables by abc_replace_mandrill_template.
*
@mariusvetrici
mariusvetrici / 0_reuse_code.js
Last active August 29, 2015 14:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mariusvetrici
mariusvetrici / gist:3e33bc3919d8b8fb3c8a
Last active August 29, 2015 14:17
Test if Flexslider loaded - or test if any element finished loading without AJAX events
// In my case, I had to wait for the Flexslider to load. The slider was added by the theme, not by my code, so I could not subscribe to the start callback event
jQuery("document").ready(function() {
waitForSlider();
});
function waitForSlider() {
// Test if slider is visible, i.e. loaded
if (jQuery(".wooslider-next").is(":visible")) {
// Do your stuff here. Slider is loaded
}
@mariusvetrici
mariusvetrici / sync_acf_field_with_post_author
Created February 9, 2015 17:45
Synchronize / connect WordPress Post Author field with Advanced Custom Fields (ACF) user field
<?php
function mve_save_task_post_hook($post_id, $post, $update) {
if ($post->post_type != 'task') {
return;
}
// If ACF Customer != Post author, update it
$old_post_author = sanitize_text_field($_REQUEST['post_author']);
$new_post_author = sanitize_text_field($_REQUEST['post_author_override']);
if (isset($new_post_author) &&