2011-12-12 16:34:56 +00:00
< ? php
/**
* WooCommerce Admin Hooks
*
2012-08-14 12:21:34 +00:00
* Action / filter hooks used for WooCommerce functions .
*
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin
* @ version 1.6 . 4
2011-12-12 16:34:56 +00:00
*/
2012-10-15 10:32:24 +00:00
if ( ! defined ( 'ABSPATH' ) ) exit ; // Exit if accessed directly
2013-08-06 10:41:20 +00:00
/**
* Grant downloadable file access to any newly added files on any existing
* orders for this product that have previously been granted downloadable file access
*
* @ access public
* @ param int $product_id product identifier
* @ param int $variation_id optional product variation identifier
* @ param array $file_paths newly set file paths
*/
function woocommerce_process_product_file_download_paths ( $product_id , $variation_id , $file_paths ) {
global $wpdb ;
if ( $variation_id )
$product_id = $variation_id ;
// determine whether any new files have been added
$existing_file_paths = apply_filters ( 'woocommerce_file_download_paths' , get_post_meta ( $product_id , '_file_paths' , true ), $product_id , null , null );
if ( ! $existing_file_paths ) $existing_file_paths = array ();
$new_download_ids = array_diff ( array_keys ( $file_paths ), array_keys ( $existing_file_paths ) );
if ( $new_download_ids ) {
// determine whether downloadable file access has been granted (either via the typical order completion, or via the admin ajax method)
$existing_permissions = $wpdb -> get_results ( $wpdb -> prepare ( " SELECT * from { $wpdb -> prefix } woocommerce_downloadable_product_permissions WHERE product_id = %d GROUP BY order_id " , $product_id ) );
foreach ( $existing_permissions as $existing_permission ) {
$order = new WC_Order ( $existing_permission -> order_id );
if ( $order -> id ) {
foreach ( $new_download_ids as $new_download_id ) {
// grant permission if it doesn't already exist
if ( ! $wpdb -> get_var ( $wpdb -> prepare ( " SELECT true FROM { $wpdb -> prefix } woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s " , $order -> id , $product_id , $new_download_id ) ) ) {
woocommerce_downloadable_file_permission ( $new_download_id , $product_id , $order );
}
}
}
}
}
}
add_action ( 'woocommerce_process_product_file_download_paths' , 'woocommerce_process_product_file_download_paths' , 10 , 3 );
2012-08-14 12:21:34 +00:00
/**
* Events
2012-08-14 14:13:08 +00:00
*
* @ see woocommerce_delete_post ()
2012-12-10 11:23:38 +00:00
* @ see woocommerce_trash_post ()
* @ see woocommerce_untrash_post ()
2012-08-14 14:13:08 +00:00
* @ see woocommerce_preview_emails ()
* @ see woocommerce_prevent_admin_access ()
2013-01-02 16:34:23 +00:00
* @ see woocommerce_check_download_folder_protection ()
2012-08-14 14:13:08 +00:00
* @ see woocommerce_ms_protect_download_rewite_rules ()
2012-08-14 12:21:34 +00:00
*/
2012-12-10 11:23:38 +00:00
add_action ( 'delete_post' , 'woocommerce_delete_post' );
add_action ( 'wp_trash_post' , 'woocommerce_trash_post' );
add_action ( 'untrash_post' , 'woocommerce_untrash_post' );
2011-12-12 16:34:56 +00:00
add_action ( 'admin_init' , 'woocommerce_preview_emails' );
add_action ( 'admin_init' , 'woocommerce_prevent_admin_access' );
2013-01-02 16:34:23 +00:00
add_action ( 'woocommerce_settings_saved' , 'woocommerce_check_download_folder_protection' );
2012-03-13 16:59:21 +00:00
add_filter ( 'mod_rewrite_rules' , 'woocommerce_ms_protect_download_rewite_rules' );
2011-12-12 16:34:56 +00:00
2012-08-14 12:21:34 +00:00
/**
* File uploads
2012-08-14 14:13:08 +00:00
*
* @ see woocommerce_downloads_upload_dir ()
* @ see woocommerce_media_upload_downloadable_product ()
2012-08-14 12:21:34 +00:00
*/
2011-12-12 16:34:56 +00:00
add_filter ( 'upload_dir' , 'woocommerce_downloads_upload_dir' );
add_action ( 'media_upload_downloadable_product' , 'woocommerce_media_upload_downloadable_product' );
2012-08-14 12:21:34 +00:00
/**
* Shortcode buttons
2012-08-14 14:13:08 +00:00
*
* @ see woocommerce_add_shortcode_button ()
* @ see woocommerce_refresh_mce ()
2012-08-14 12:21:34 +00:00
*/
2011-12-12 16:34:56 +00:00
add_action ( 'init' , 'woocommerce_add_shortcode_button' );
add_filter ( 'tiny_mce_version' , 'woocommerce_refresh_mce' );
2012-08-14 12:21:34 +00:00
/**
* Category / term ordering
2012-08-14 14:13:08 +00:00
*
* @ see woocommerce_create_term ()
* @ see woocommerce_delete_term ()
2012-08-14 12:21:34 +00:00
*/
2012-10-17 11:05:54 +00:00
add_action ( " create_term " , 'woocommerce_create_term' , 5 , 3 );
add_action ( " delete_term " , 'woocommerce_delete_term' , 5 );
2012-07-11 12:33:26 +00:00
2012-08-14 12:21:34 +00:00
/**
* Bulk editing
2012-08-14 14:13:08 +00:00
*
* @ see woocommerce_bulk_admin_footer ()
* @ see woocommerce_order_bulk_action ()
* @ see woocommerce_order_bulk_admin_notices ()
2012-08-14 12:21:34 +00:00
*/
2012-07-11 12:33:26 +00:00
add_action ( 'admin_footer' , 'woocommerce_bulk_admin_footer' , 10 );
add_action ( 'load-edit.php' , 'woocommerce_order_bulk_action' );
2013-03-10 14:33:27 +00:00
add_action ( 'admin_notices' , 'woocommerce_order_bulk_admin_notices' );
/**
* Mijireh Gateway
*/
add_action ( 'add_meta_boxes' , array ( 'WC_Gateway_Mijireh' , 'add_page_slurp_meta' ) );
add_action ( 'wp_ajax_page_slurp' , array ( 'WC_Gateway_Mijireh' , 'page_slurp' ) );