Skip to content

Instantly share code, notes, and snippets.

View pietromalerba's full-sized avatar

Pietro Malerba pietromalerba

  • M3
  • Civitanova Marche (MC) - Italy
View GitHub Profile
@pietromalerba
pietromalerba / Json-api-ACF.php
Created May 29, 2014 19:00 — forked from diegochavez/Json-api-ACF.php
Wordpres json ACF
add_filter('json_api_encode', 'json_api_encode_acf');
function json_api_encode_acf($response)
{
if (isset($response['posts'])) {
foreach ($response['posts'] as $post) {
json_api_add_acf($post); // Add specs to each post
}
}
@pietromalerba
pietromalerba / remove.php
Last active August 29, 2015 14:06 — forked from craigmdennis/remove.php
Remove menu for specific users
<?php
add_action( 'admin_menu', 'remove_menus' );
function remove_menus() {
global $menu;
global $submenu;
// echo '<pre>';
// print_r($menu);
jQuery.ajax({
url: '/wp-admin/admin-ajax.php',
type: 'GET',//POST, JSON, XML
dataType: 'html',
data: ({
action: 'MY_AJAX_FUNCTION',
state: state,
}),
success: function(data){
if (data){
jQuery(function($) {
$('form[data-async]').live('submit', function(event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
<?php
class MyJS {
public function __construct() {
add_action( 'wp_enqueue_scripts', array( &$this, 'addScripts' ) );
}
public function addScripts() {
// jQuery
@pietromalerba
pietromalerba / functions.php
Last active August 29, 2015 14:08 — forked from kloon/functions.php
Woocommerce filter price
<?php
// Add save percent next to sale item prices.
add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );
function woocommerce_custom_sales_price( $price, $product ) {
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
return $price . sprintf( __(' Save %s', 'woocommerce' ), $percentage . '%' );
}
?>
<?php
global $wpdb;
// Insert the original post
$original = wp_insert_post($array, true);
// Insert the translated post
$translated = wp_insert_post($array, true);
// Make some updates to both translations
<?php
/**
* Add the custom attribute "Special Promotion" to a product.
*/
add_filter( 'dfrpswc_product_attributes', 'mycode_add_promo_attribute', 20, 5 );
function mycode_add_promo_attribute( $attributes, $post, $product, $set, $action ) {
if ( isset( $product['promo'] ) ) {
$attr = 'Special Promotion';
if ( !isset( $attributes[sanitize_title( $attr )] ) ) {
<?php
/**
* Add color attribute.
*
* The attribute "Color" with a slug of "color" must already exist here:
* WordPress Admin Area > Products > Attributes.
*/
add_filter( 'dfrpswc_filter_attribute_value', 'mycode_add_color_attribute', 20, 6 );
function mycode_add_color_attribute( $value, $attribute, $post, $product, $set, $action ) {
@pietromalerba
pietromalerba / wordpress-adminbar-modal.php
Last active June 30, 2019 00:53 — forked from MrMaz/ab-modal.php
Wordpress admin bar modal box
<?php
/**
* Setup admin bar item which opens URL in a thickbox window
*
* @param WP_Admin_Bar $wp_admin_bar
*/
function admin_bar_menu_modal_window( $wp_admin_bar )
{
// add "tools" node