woocommerce/admin/admin-init.php

499 lines
18 KiB
PHP
Raw Normal View History

2011-08-09 15:16:18 +00:00
<?php
/**
2011-08-10 17:11:11 +00:00
* WooCommerce Admin
2011-08-09 15:16:18 +00:00
*
2011-08-10 17:11:11 +00:00
* Main admin file which loads all settings panels and sets up admin menus.
2011-08-09 15:16:18 +00:00
*
2011-08-10 17:11:11 +00:00
* @author WooThemes
2011-08-09 15:16:18 +00:00
* @category Admin
2011-08-10 17:11:11 +00:00
* @package WooCommerce
2011-08-09 15:16:18 +00:00
*/
2011-08-10 17:11:11 +00:00
include_once( 'admin-install.php' );
2011-08-09 15:16:18 +00:00
2011-08-10 17:11:11 +00:00
function woocommerce_admin_init() {
include_once( 'admin-settings-forms.php' );
include_once( 'admin-settings.php' );
2011-08-10 17:11:11 +00:00
include_once( 'admin-attributes.php' );
include_once( 'admin-dashboard.php' );
include_once( 'admin-import.php' );
include_once( 'admin-post-types.php' );
include_once( 'admin-reports.php' );
2011-09-16 08:10:12 +00:00
include_once( 'admin-taxonomies.php' );
2011-08-10 17:11:11 +00:00
include_once( 'writepanels/writepanels-init.php' );
2011-08-09 15:16:18 +00:00
}
2011-08-10 17:11:11 +00:00
add_action('admin_init', 'woocommerce_admin_init');
2011-08-09 15:16:18 +00:00
2011-10-10 22:33:58 +00:00
/**
* Admin Menus
*
* Sets up the admin menus in wordpress.
*/
function woocommerce_admin_menu() {
global $menu, $woocommerce;
if ( current_user_can( 'manage_woocommerce' ) ) $menu[] = array( '', 'read', 'separator-woocommerce', '', 'wp-menu-separator woocommerce' );
2011-10-10 22:33:58 +00:00
2011-10-16 19:59:30 +00:00
add_menu_page(__('WooCommerce', 'woothemes'), __('WooCommerce', 'woothemes'), 'manage_woocommerce', 'woocommerce' , 'woocommerce_settings', $woocommerce->plugin_url() . '/assets/images/icons/menu_icons.png', 55);
2011-10-10 22:33:58 +00:00
add_submenu_page('woocommerce', __('General Settings', 'woothemes'), __('Settings', 'woothemes') , 'manage_woocommerce', 'woocommerce', 'woocommerce_settings');
add_submenu_page('woocommerce', __('Reports', 'woothemes'), __('Reports', 'woothemes') , 'manage_woocommerce', 'woocommerce_reports', 'woocommerce_reports');
add_submenu_page('edit.php?post_type=product', __('Attributes', 'woothemes'), __('Attributes', 'woothemes'), 'manage_categories', 'woocommerce_attributes', 'woocommerce_attributes');
2011-10-10 22:33:58 +00:00
$print_css_on = array( 'toplevel_page_woocommerce', 'woocommerce_page_woocommerce_reports', 'product_page_woocommerce_attributes', 'edit-tags.php', 'edit.php', 'index.php', 'post-new.php', 'post.php' );
foreach ($print_css_on as $page) add_action( 'admin_print_styles-'. $page, 'woocommerce_admin_css' );
}
add_action('admin_menu', 'woocommerce_admin_menu', 9);
2011-09-04 00:02:44 +00:00
/**
* Admin Scripts
*/
function woocommerce_admin_scripts() {
global $woocommerce;
2011-09-16 12:45:46 +00:00
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
2011-09-16 12:45:46 +00:00
// Register scripts
wp_register_script( 'woocommerce_admin', $woocommerce->plugin_url() . '/assets/js/admin/woocommerce_admin'.$suffix.'.js', array('jquery', 'jquery-ui-widget', 'jquery-ui-core'), '1.0' );
2011-10-12 10:39:30 +00:00
wp_register_script( 'jquery-ui-datepicker', $woocommerce->plugin_url() . '/assets/js/admin/ui-datepicker.js', array('jquery','jquery-ui-core'), '1.0' );
wp_register_script( 'woocommerce_writepanel', $woocommerce->plugin_url() . '/assets/js/admin/write-panels'.$suffix.'.js', array('jquery', 'jquery-ui-datepicker') );
// Get admin screen id
2011-09-16 12:45:46 +00:00
$screen = get_current_screen();
// WooCommerce admin pages
if (in_array( $screen->id, array( 'toplevel_page_woocommerce', 'woocommerce_page_woocommerce_reports', 'edit-shop_order', 'edit-shop_coupon', 'shop_coupon', 'shop_order', 'edit-product', 'product' ))) :
2011-10-12 10:39:30 +00:00
wp_enqueue_script( 'woocommerce_admin' );
2011-10-25 12:54:16 +00:00
wp_enqueue_script('farbtastic');
endif;
2011-10-07 19:27:10 +00:00
// Edit product category pages
if (in_array( $screen->id, array('edit-product_cat') )) :
2011-10-12 10:39:30 +00:00
wp_enqueue_script( 'media-upload' );
wp_enqueue_script( 'thickbox' );
endif;
// Product/Coupon/Orders
if (in_array( $screen->id, array( 'shop_coupon', 'shop_order', 'product' ))) :
global $post;
2011-10-12 10:39:30 +00:00
wp_enqueue_script( 'woocommerce_writepanel' );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'media-upload' );
wp_enqueue_script( 'thickbox' );
$woocommerce_witepanel_params = array(
'remove_item_notice' => __("Remove this item? If you have previously reduced this item's stock, or this order was submitted by a customer, will need to manually restore the item's stock.", 'woothemes'),
'cart_total' => __("Calc totals based on order items, discount amount, and shipping?", 'woothemes'),
'copy_billing' => __("Copy billing information to shipping information? This will remove any currently entered shipping information.", 'woothemes'),
'prices_include_tax' => get_option('woocommerce_prices_include_tax'),
'ID' => __('ID', 'woothemes'),
'item_name' => __('Item Name', 'woothemes'),
'quantity' => __('Quantity e.g. 2', 'woothemes'),
'cost_unit' => __('Cost per unit e.g. 2.99', 'woothemes'),
'tax_rate' => __('Tax Rate e.g. 20.0000', 'woothemes'),
'meta_name' => __('Meta Name', 'woothemes'),
'meta_value' => __('Meta Value', 'woothemes'),
'select_terms' => __('Select terms', 'woothemes'),
'plugin_url' => $woocommerce->plugin_url(),
'ajax_url' => admin_url('admin-ajax.php'),
'add_order_item_nonce' => wp_create_nonce("add-order-item"),
'upsell_crosssell_search_products_nonce' => wp_create_nonce("search-products"),
'calendar_image' => $woocommerce->plugin_url().'/assets/images/calendar.png',
'post_id' => $post->ID
2011-10-12 10:39:30 +00:00
);
wp_localize_script( 'woocommerce_writepanel', 'woocommerce_writepanel_params', $woocommerce_witepanel_params );
2011-10-07 19:27:10 +00:00
endif;
// Term ordering
if ($screen->id=='edit-product_cat' || strstr($screen->id, 'edit-pa_')) :
wp_register_script( 'woocommerce_term_ordering', $woocommerce->plugin_url() . '/assets/js/admin/term-ordering.js', array('jquery-ui-sortable') );
wp_enqueue_script( 'woocommerce_term_ordering' );
$taxonomy = (isset($_GET['taxonomy'])) ? $_GET['taxonomy'] : '';
$woocommerce_term_order_params = array(
'taxonomy' => $taxonomy
);
wp_localize_script( 'woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params );
endif;
2011-10-07 19:27:10 +00:00
// Reports pages
2011-09-16 12:45:46 +00:00
if ($screen->id=='woocommerce_page_woocommerce_reports') :
2011-10-12 10:39:30 +00:00
wp_enqueue_script( 'jquery-ui-datepicker' );
2011-09-16 12:45:46 +00:00
wp_enqueue_script( 'flot', $woocommerce->plugin_url() . '/assets/js/admin/jquery.flot'.$suffix.'.js', 'jquery', '1.0' );
wp_enqueue_script( 'flot-resize', $woocommerce->plugin_url() . '/assets/js/admin/jquery.flot.resize'.$suffix.'.js', array('jquery', 'flot'), '1.0' );
2011-09-16 12:45:46 +00:00
endif;
2011-09-04 00:02:44 +00:00
}
2011-10-12 10:39:30 +00:00
add_action('admin_enqueue_scripts', 'woocommerce_admin_scripts');
2011-09-04 00:02:44 +00:00
2011-08-09 15:16:18 +00:00
/**
2011-10-10 22:33:58 +00:00
* Queue admin CSS
2011-08-09 15:16:18 +00:00
*/
2011-10-10 22:33:58 +00:00
function woocommerce_admin_css() {
global $woocommerce, $typenow, $post;
if ($typenow=='post' && isset($_GET['post']) && !empty($_GET['post'])) $typenow = $post->post_type;
2011-08-09 15:16:18 +00:00
2011-10-10 22:33:58 +00:00
if ( $typenow=='' || $typenow=="product" || $typenow=="shop_order" || $typenow=="shop_coupon" ) :
wp_enqueue_style( 'thickbox' );
wp_enqueue_style( 'woocommerce_admin_styles', $woocommerce->plugin_url() . '/assets/css/admin.css' );
wp_enqueue_style( 'jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
endif;
2011-10-15 11:16:56 +00:00
2011-10-25 12:54:16 +00:00
wp_enqueue_style('farbtastic');
2011-10-15 11:16:56 +00:00
do_action('woocommerce_admin_css');
2011-08-09 15:16:18 +00:00
}
2011-10-10 22:33:58 +00:00
/**
* Order admin menus
*/
2011-08-10 17:11:11 +00:00
function woocommerce_admin_menu_order( $menu_order ) {
2011-08-09 15:16:18 +00:00
// Initialize our custom order array
2011-08-10 17:11:11 +00:00
$woocommerce_menu_order = array();
2011-08-09 15:16:18 +00:00
// Get the index of our custom separator
2011-08-10 17:11:11 +00:00
$woocommerce_separator = array_search( 'separator-woocommerce', $menu_order );
2011-09-08 10:03:02 +00:00
// Get index of product menu
$woocommerce_product = array_search( 'edit.php?post_type=product', $menu_order );
2011-08-09 15:16:18 +00:00
// Loop through menu order and do some rearranging
foreach ( $menu_order as $index => $item ) :
2011-08-10 17:11:11 +00:00
if ( ( ( 'woocommerce' ) == $item ) ) :
$woocommerce_menu_order[] = 'separator-woocommerce';
2011-09-08 10:03:02 +00:00
$woocommerce_menu_order[] = $item;
$woocommerce_menu_order[] = 'edit.php?post_type=product';
2011-08-10 17:11:11 +00:00
unset( $menu_order[$woocommerce_separator] );
2011-09-08 10:03:02 +00:00
unset( $menu_order[$woocommerce_product] );
elseif ( !in_array( $item, array( 'separator-woocommerce' ) ) ) :
2011-08-10 17:11:11 +00:00
$woocommerce_menu_order[] = $item;
2011-08-09 15:16:18 +00:00
endif;
endforeach;
// Return order
2011-08-10 17:11:11 +00:00
return $woocommerce_menu_order;
2011-08-09 15:16:18 +00:00
}
2011-10-10 22:33:58 +00:00
add_action('menu_order', 'woocommerce_admin_menu_order');
2011-08-09 15:16:18 +00:00
2011-08-10 17:11:11 +00:00
function woocommerce_admin_custom_menu_order() {
2011-10-26 13:11:20 +00:00
if ( !current_user_can( 'manage_woocommerce' ) ) return false;
2011-08-09 15:16:18 +00:00
return true;
}
2011-08-10 17:11:11 +00:00
add_action('custom_menu_order', 'woocommerce_admin_custom_menu_order');
2011-08-09 15:16:18 +00:00
/**
* Admin Head
*
2011-08-10 17:11:11 +00:00
* Outputs some styles in the admin <head> to show icons on the woocommerce admin pages
2011-08-09 15:16:18 +00:00
*/
2011-08-10 17:11:11 +00:00
function woocommerce_admin_head() {
2011-10-10 22:33:58 +00:00
global $woocommerce;
if ( !current_user_can( 'manage_woocommerce' ) ) return false;
2011-08-09 15:16:18 +00:00
?>
<style type="text/css">
2011-10-10 22:33:58 +00:00
#toplevel_page_woocommerce .wp-menu-image{background:url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/icons/menu_icons.png) no-repeat 0px -32px !important;}
#toplevel_page_woocommerce .wp-menu-image img{display:none;}
#toplevel_page_woocommerce:hover .wp-menu-image,#toplevel_page_woocommerce.wp-has-current-submenu .wp-menu-image{background:url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/icons/menu_icons.png) no-repeat 0px 0px !important;}
#menu-posts-product .wp-menu-image{background:url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/icons/menu_icons.png) no-repeat -35px -32px !important;}
#menu-posts-product:hover .wp-menu-image,#menu-posts-product.wp-has-current-submenu .wp-menu-image{background:url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/icons/menu_icons.png) no-repeat -35px 0px !important;}
#menu-posts-shop_order .wp-menu-image{background:url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/icons/menu_icons.png) no-repeat -70px -32px !important;}
#menu-posts-shop_order:hover .wp-menu-image,#menu-posts-shop_order.wp-has-current-submenu .wp-menu-image{background:url(<?php echo $woocommerce->plugin_url(); ?>/assets/images/icons/menu_icons.png) no-repeat -70px 0px !important;}
2011-08-09 15:16:18 +00:00
<?php if ( isset($_GET['taxonomy']) && $_GET['taxonomy']=='product_cat' ) : ?>
.icon32-posts-product { background-position: -243px -5px !important; }
<?php elseif ( isset($_GET['taxonomy']) && $_GET['taxonomy']=='product_tag' ) : ?>
.icon32-posts-product { background-position: -301px -5px !important; }
<?php endif; ?>
</style>
<?php
}
2011-08-10 17:11:11 +00:00
add_action('admin_head', 'woocommerce_admin_head');
2011-08-09 15:16:18 +00:00
/**
* Ajax request handling for categories ordering
*/
function woocommerce_term_ordering() {
2011-08-09 15:16:18 +00:00
global $wpdb;
$id = (int) $_POST['id'];
2011-08-09 15:16:18 +00:00
$next_id = isset($_POST['nextid']) && (int) $_POST['nextid'] ? (int) $_POST['nextid'] : null;
$taxonomy = isset($_POST['thetaxonomy']) ? esc_attr( $_POST['thetaxonomy'] ) : null;
$term = get_term_by('id', $id, $taxonomy);
2011-08-09 15:16:18 +00:00
if( !$id || !$term || !$taxonomy ) die(0);
2011-08-09 15:16:18 +00:00
woocommerce_order_terms( $term, $next_id, $taxonomy );
$children = get_terms($taxonomy, "child_of=$id&menu_order=ASC&hide_empty=0");
2011-08-09 15:16:18 +00:00
if( $term && sizeof($children) ) {
echo 'children';
die;
}
}
add_action('wp_ajax_woocommerce-term-ordering', 'woocommerce_term_ordering');
2011-08-22 14:42:36 +00:00
2011-08-28 11:38:29 +00:00
/**
* Duplicate a product action
*
* Based on 'Duplicate Post' (http://www.lopo.it/duplicate-post-plugin/) by Enrico Battocchi
*/
add_action('admin_action_duplicate_product', 'woocommerce_duplicate_product_action');
function woocommerce_duplicate_product_action() {
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'duplicate_post_save_as_new_page' == $_REQUEST['action'] ) ) ) {
wp_die(__('No product to duplicate has been supplied!', 'woothemes'));
}
// Get the original page
$id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
check_admin_referer( 'woocommerce-duplicate-product_' . $id );
2011-08-28 11:38:29 +00:00
$post = woocommerce_get_product_to_duplicate($id);
// Copy the page and insert it
if (isset($post) && $post!=null) {
$new_id = woocommerce_create_duplicate_from_product($post);
// If you have written a plugin which uses non-WP database tables to save
// information about a page you can hook this action to dupe that data.
do_action( 'woocommerce_duplicate_product', $new_id, $post );
// Redirect to the edit screen for the new draft page
wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_id ) );
exit;
} else {
wp_die(__('Product creation failed, could not find original product:', 'woothemes') . ' ' . $id);
}
}
/**
* Duplicate a product link on products list
*/
add_filter('post_row_actions', 'woocommerce_duplicate_product_link_row',10,2);
add_filter('page_row_actions', 'woocommerce_duplicate_product_link_row',10,2);
function woocommerce_duplicate_product_link_row($actions, $post) {
if (function_exists('duplicate_post_plugin_activation')) return $actions;
if (!current_user_can('manage_woocommerce')) return $actions;
2011-09-25 00:40:32 +00:00
if ($post->post_type!='product') return $actions;
$actions['duplicate'] = '<a href="' . wp_nonce_url( admin_url( 'admin.php?action=duplicate_product&amp;post=' . $post->ID ), 'woocommerce-duplicate-product_' . $post->ID ) . '" title="' . __("Make a duplicate from this product", 'woothemes')
2011-08-28 11:38:29 +00:00
. '" rel="permalink">' . __("Duplicate", 'woothemes') . '</a>';
return $actions;
}
/**
* Duplicate a product link on edit screen
*/
add_action( 'post_submitbox_start', 'woocommerce_duplicate_product_post_button' );
function woocommerce_duplicate_product_post_button() {
2011-09-25 00:40:32 +00:00
global $post;
2011-08-28 11:38:29 +00:00
if (function_exists('duplicate_post_plugin_activation')) return;
if (!current_user_can('manage_woocommerce')) return;
2011-09-25 00:40:32 +00:00
if ($post->post_type!='product') return;
2011-08-28 11:38:29 +00:00
if ( isset( $_GET['post'] ) ) :
$notifyUrl = wp_nonce_url( admin_url( "admin.php?action=duplicate_product&post=" . $_GET['post'] ), 'woocommerce-duplicate-product_' . $_GET['post'] );
2011-08-28 11:38:29 +00:00
?>
<div id="duplicate-action"><a class="submitduplicate duplication"
2011-09-21 06:50:40 +00:00
href="<?php echo esc_url( $notifyUrl ); ?>"><?php _e('Copy to a new draft', 'woothemes'); ?></a>
2011-08-28 11:38:29 +00:00
</div>
<?php
endif;
}
/**
* Get a product from the database
*/
function woocommerce_get_product_to_duplicate($id) {
global $wpdb;
$post = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID=$id");
if ($post->post_type == "revision"){
$id = $post->post_parent;
$post = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID=$id");
}
return $post[0];
}
/**
* Function to create the duplicate
*/
function woocommerce_create_duplicate_from_product($post, $parent = 0) {
global $wpdb;
$new_post_author = wp_get_current_user();
$new_post_date = current_time('mysql');
$new_post_date_gmt = get_gmt_from_date($new_post_date);
if ($parent>0) :
$post_parent = $parent;
$suffix = '';
$post_status = 'publish';
else :
$post_parent = $post->post_parent;
$post_status = 'draft';
$suffix = __(" (Copy)", 'woothemes');
endif;
$new_post_type = $post->post_type;
$post_content = str_replace("'", "''", $post->post_content);
$post_content_filtered = str_replace("'", "''", $post->post_content_filtered);
$post_excerpt = str_replace("'", "''", $post->post_excerpt);
$post_title = str_replace("'", "''", $post->post_title).$suffix;
$post_name = str_replace("'", "''", $post->post_name);
$comment_status = str_replace("'", "''", $post->comment_status);
$ping_status = str_replace("'", "''", $post->ping_status);
// Insert the new template in the post table
$wpdb->query(
"INSERT INTO $wpdb->posts
(post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt, post_status, post_type, comment_status, ping_status, post_password, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type)
VALUES
('$new_post_author->ID', '$new_post_date', '$new_post_date_gmt', '$post_content', '$post_content_filtered', '$post_title', '$post_excerpt', '$post_status', '$new_post_type', '$comment_status', '$ping_status', '$post->post_password', '$post->to_ping', '$post->pinged', '$new_post_date', '$new_post_date_gmt', '$post_parent', '$post->menu_order', '$post->post_mime_type')");
$new_post_id = $wpdb->insert_id;
// Copy the taxonomies
woocommerce_duplicate_post_taxonomies($post->ID, $new_post_id, $post->post_type);
// Copy the meta information
woocommerce_duplicate_post_meta($post->ID, $new_post_id);
// Copy the children (variations)
if ( $children_products =& get_children( 'post_parent='.$post->ID.'&post_type=product_variation' ) ) :
if ($children_products) foreach ($children_products as $child) :
woocommerce_create_duplicate_from_product(woocommerce_get_product_to_duplicate($child->ID), $new_post_id);
endforeach;
endif;
return $new_post_id;
}
/**
* Copy the taxonomies of a post to another post
*/
function woocommerce_duplicate_post_taxonomies($id, $new_id, $post_type) {
global $wpdb;
$taxonomies = get_object_taxonomies($post_type); //array("category", "post_tag");
foreach ($taxonomies as $taxonomy) {
$post_terms = wp_get_object_terms($id, $taxonomy);
for ($i=0; $i<count($post_terms); $i++) {
wp_set_object_terms($new_id, $post_terms[$i]->slug, $taxonomy, true);
}
}
}
/**
* Copy the meta information of a post to another post
*/
function woocommerce_duplicate_post_meta($id, $new_id) {
global $wpdb;
$post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$id");
if (count($post_meta_infos)!=0) {
$sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
foreach ($post_meta_infos as $meta_info) {
$meta_key = $meta_info->meta_key;
$meta_value = addslashes($meta_info->meta_value);
$sql_query_sel[]= "SELECT $new_id, '$meta_key', '$meta_value'";
}
$sql_query.= implode(" UNION ALL ", $sql_query_sel);
$wpdb->query($sql_query);
}
}
/**
* Deleting products sync
*
* Removes variations etc belonging to a deleted post
*/
add_action('delete_post', 'woocommerce_delete_product_sync', 10);
function woocommerce_delete_product_sync( $id ) {
if (!current_user_can('delete_posts')) return;
if ( $id > 0 ) :
if ( $children_products =& get_children( 'post_parent='.$id.'&post_type=product_variation' ) ) :
if ($children_products) :
2011-08-28 11:38:29 +00:00
foreach ($children_products as $child) :
wp_delete_post( $child->ID, true );
endforeach;
2011-08-28 11:38:29 +00:00
endif;
endif;
2011-08-28 11:38:29 +00:00
endif;
}
/**
* Directory for uploads
*
*/
add_filter('upload_dir', 'woocommerce_downloads_upload_dir');
function woocommerce_downloads_upload_dir( $pathdata ) {
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']) :
$args = wp_parse_args( $_SERVER['HTTP_REFERER'] );
extract( $args, EXTR_SKIP );
2011-11-14 13:57:12 +00:00
if (isset($from) && $from =='wc01') :
// Uploading a downloadable file
$subdir = '/woocommerce_uploads'.$pathdata['subdir'];
$pathdata['path'] = str_replace($pathdata['subdir'], $subdir, $pathdata['path']);
$pathdata['url'] = str_replace($pathdata['subdir'], $subdir, $pathdata['url']);
$pathdata['subdir'] = str_replace($pathdata['subdir'], $subdir, $pathdata['subdir']);
return $pathdata;
endif;
endif;
return $pathdata;
}