khaihihi
This commit is contained in:
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
/**
|
||||
* Connect existing WooCommerce pages to WooCommerce Admin.
|
||||
*
|
||||
* @package Woocommerce Admin
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\PageController;
|
||||
|
||||
/**
|
||||
* Returns core WC pages to connect to WC-Admin.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wc_admin_get_core_pages_to_connect() {
|
||||
$all_reports = WC_Admin_Reports::get_reports();
|
||||
$report_tabs = array();
|
||||
|
||||
foreach ( $all_reports as $report_id => $report_data ) {
|
||||
$report_tabs[ $report_id ] = $report_data['title'];
|
||||
}
|
||||
|
||||
return array(
|
||||
'wc-addons' => array(
|
||||
'title' => __( 'Extensions', 'woocommerce-admin' ),
|
||||
'tabs' => array(),
|
||||
),
|
||||
'wc-reports' => array(
|
||||
'title' => __( 'Reports', 'woocommerce-admin' ),
|
||||
'tabs' => $report_tabs,
|
||||
),
|
||||
'wc-settings' => array(
|
||||
'title' => __( 'Settings', 'woocommerce-admin' ),
|
||||
'tabs' => apply_filters( 'woocommerce_settings_tabs_array', array() ),
|
||||
),
|
||||
'wc-status' => array(
|
||||
'title' => __( 'Status', 'woocommerce-admin' ),
|
||||
'tabs' => apply_filters(
|
||||
'woocommerce_admin_status_tabs',
|
||||
array(
|
||||
'status' => __( 'System status', 'woocommerce-admin' ),
|
||||
'tools' => __( 'Tools', 'woocommerce-admin' ),
|
||||
'logs' => __( 'Logs', 'woocommerce-admin' ),
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter breadcrumbs for core pages that aren't explicitly connected.
|
||||
*
|
||||
* @param array $breadcrumbs Breadcrumb pieces.
|
||||
* @return array Filtered breadcrumb pieces.
|
||||
*/
|
||||
function wc_admin_filter_core_page_breadcrumbs( $breadcrumbs ) {
|
||||
$screen_id = PageController::get_instance()->get_current_screen_id();
|
||||
$pages_to_connect = wc_admin_get_core_pages_to_connect();
|
||||
|
||||
foreach ( $pages_to_connect as $page_id => $page_data ) {
|
||||
if ( preg_match( "/^woocommerce_page_{$page_id}\-/", $screen_id ) ) {
|
||||
if ( empty( $page_data['tabs'] ) ) {
|
||||
$new_breadcrumbs = array( $page_data['title'] );
|
||||
} else {
|
||||
$new_breadcrumbs = array(
|
||||
array(
|
||||
add_query_arg( 'page', $page_id, 'admin.php' ),
|
||||
$page_data['title'],
|
||||
),
|
||||
);
|
||||
|
||||
if ( isset( $_GET['tab'] ) ) {
|
||||
$current_tab = wc_clean( wp_unslash( $_GET['tab'] ) );
|
||||
} else {
|
||||
$current_tab = key( $page_data['tabs'] );
|
||||
}
|
||||
|
||||
$new_breadcrumbs[] = $page_data['tabs'][ $current_tab ];
|
||||
}
|
||||
|
||||
return $new_breadcrumbs;
|
||||
}
|
||||
}
|
||||
|
||||
return $breadcrumbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the WC-Admin header bar on all WooCommerce core pages.
|
||||
*
|
||||
* @param bool $is_connected Whether the current page is connected.
|
||||
* @param bool $current_page The current page, if connected.
|
||||
* @return bool Whether to connect the page.
|
||||
*/
|
||||
function wc_admin_connect_core_pages( $is_connected, $current_page ) {
|
||||
if ( false === $is_connected && false === $current_page ) {
|
||||
$screen_id = PageController::get_instance()->get_current_screen_id();
|
||||
$pages_to_connect = wc_admin_get_core_pages_to_connect();
|
||||
|
||||
foreach ( $pages_to_connect as $page_id => $page_data ) {
|
||||
if ( preg_match( "/^woocommerce_page_{$page_id}\-/", $screen_id ) ) {
|
||||
add_filter( 'woocommerce_navigation_get_breadcrumbs', 'wc_admin_filter_core_page_breadcrumbs' );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $is_connected;
|
||||
}
|
||||
|
||||
add_filter( 'woocommerce_navigation_is_connected_page', 'wc_admin_connect_core_pages', 10, 2 );
|
||||
|
||||
$posttype_list_base = 'edit.php';
|
||||
|
||||
// WooCommerce > Orders.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-orders',
|
||||
'screen_id' => 'edit-shop_order',
|
||||
'title' => __( 'Orders', 'woocommerce-admin' ),
|
||||
'path' => add_query_arg( 'post_type', 'shop_order', $posttype_list_base ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Orders > Add New.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-add-order',
|
||||
'parent' => 'woocommerce-orders',
|
||||
'screen_id' => 'shop_order-add',
|
||||
'title' => __( 'Add New', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Orders > Edit Order.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-edit-order',
|
||||
'parent' => 'woocommerce-orders',
|
||||
'screen_id' => 'shop_order',
|
||||
'title' => __( 'Edit Order', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Coupons.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-coupons',
|
||||
'screen_id' => 'edit-shop_coupon',
|
||||
'title' => __( 'Coupons', 'woocommerce-admin' ),
|
||||
'path' => add_query_arg( 'post_type', 'shop_coupon', $posttype_list_base ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Coupons > Add New.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-add-coupon',
|
||||
'parent' => 'woocommerce-coupons',
|
||||
'screen_id' => 'shop_coupon-add',
|
||||
'title' => __( 'Add New', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Coupons > Edit Coupon.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-edit-coupon',
|
||||
'parent' => 'woocommerce-coupons',
|
||||
'screen_id' => 'shop_coupon',
|
||||
'title' => __( 'Edit Coupon', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-products',
|
||||
'screen_id' => 'edit-product',
|
||||
'title' => __( 'Products', 'woocommerce-admin' ),
|
||||
'path' => add_query_arg( 'post_type', 'product', $posttype_list_base ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Add New.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-add-product',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'product-add',
|
||||
'title' => __( 'Add New', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Edit Order.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-edit-product',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'product',
|
||||
'title' => __( 'Edit Product', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Import Products.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-import-products',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'product_page_product_importer',
|
||||
'title' => __( 'Import Products', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Export Products.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-export-products',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'product_page_product_exporter',
|
||||
'title' => __( 'Export Products', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Product categories.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-product-categories',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'edit-product_cat',
|
||||
'title' => __( 'Product categories', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Edit category.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-product-edit-category',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'product_cat',
|
||||
'title' => __( 'Edit category', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Product tags.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-product-tags',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'edit-product_tag',
|
||||
'title' => __( 'Product tags', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Edit tag.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-product-edit-tag',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'product_tag',
|
||||
'title' => __( 'Edit tag', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Attributes.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-product-attributes',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'product_page_product_attributes',
|
||||
'title' => __( 'Attributes', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
|
||||
// WooCommerce > Products > Edit attribute.
|
||||
wc_admin_connect_page(
|
||||
array(
|
||||
'id' => 'woocommerce-product-edit-attribute',
|
||||
'parent' => 'woocommerce-products',
|
||||
'screen_id' => 'product_page_product_attribute-edit',
|
||||
'title' => __( 'Edit attribute', 'woocommerce-admin' ),
|
||||
)
|
||||
);
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Core Functions
|
||||
*
|
||||
* Holds core functions for wc-admin.
|
||||
*
|
||||
* @package WC_Admin\Functions
|
||||
*/
|
||||
|
||||
use \Automattic\WooCommerce\Admin\Loader;
|
||||
|
||||
/**
|
||||
* Format a number using the decimal and thousands separator settings in WooCommerce.
|
||||
*
|
||||
* @param mixed $number Number to be formatted.
|
||||
* @return string
|
||||
*/
|
||||
function wc_admin_number_format( $number ) {
|
||||
$currency_settings = Loader::get_currency_settings();
|
||||
return number_format(
|
||||
$number,
|
||||
0,
|
||||
$currency_settings['decimalSeparator'],
|
||||
$currency_settings['thousandSeparator']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a URL to relative path inside WooCommerce admin with
|
||||
* the provided query parameters.
|
||||
*
|
||||
* @param string $path Relative path of the desired page.
|
||||
* @param array $query Query parameters to append to the path.
|
||||
*
|
||||
* @return string Fully qualified URL pointing to the desired path.
|
||||
*/
|
||||
function wc_admin_url( $path = null, $query = array() ) {
|
||||
if ( ! empty( $query ) ) {
|
||||
$query_string = http_build_query( $query );
|
||||
$path = $path ? '&path=' . $path . '&' . $query_string : '';
|
||||
}
|
||||
|
||||
return admin_url( 'admin.php?page=wc-admin' . $path, dirname( __FILE__ ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Record an event using Tracks.
|
||||
*
|
||||
* @internal WooCommerce core only includes Tracks in admin, not the REST API, so we need to include it.
|
||||
* @param string $event_name Event name for tracks.
|
||||
* @param array $properties Properties to pass along with event.
|
||||
*/
|
||||
function wc_admin_record_tracks_event( $event_name, $properties = array() ) {
|
||||
if ( ! class_exists( 'WC_Tracks' ) ) {
|
||||
if ( ! defined( 'WC_ABSPATH' ) || ! file_exists( WC_ABSPATH . 'includes/tracks/class-wc-tracks.php' ) ) {
|
||||
return;
|
||||
}
|
||||
include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks.php';
|
||||
include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks-event.php';
|
||||
include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks-client.php';
|
||||
include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks-footer-pixel.php';
|
||||
include_once WC_ABSPATH . 'includes/tracks/class-wc-site-tracking.php';
|
||||
}
|
||||
|
||||
WC_Tracks::record_event( $event_name, $properties );
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin report export download
|
||||
*
|
||||
* @package WooCommerce/Admin/Templates/Emails/HTML
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/*
|
||||
* @hooked WC_Emails::email_header() Output the email header
|
||||
*/
|
||||
do_action( 'woocommerce_email_header', $email_heading, $email );
|
||||
|
||||
?>
|
||||
<a href="<?php echo esc_url( $download_url ); ?>">
|
||||
<?php echo esc_html( sprintf( __( 'Download your %s Report', 'woocommerce-admin' ), $report_name ) ); ?>
|
||||
</a>
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @hooked WC_Emails::email_footer() Output the email footer
|
||||
*/
|
||||
do_action( 'woocommerce_email_footer', $email );
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin report export download email (plain text)
|
||||
*
|
||||
* @package WooCommerce/Admin/Templates/Emails/HTML
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
|
||||
echo esc_html( wp_strip_all_tags( $email_heading ) );
|
||||
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
|
||||
|
||||
/* translators: %1$s: report name, %2$s: download URL */
|
||||
echo sprintf( __( 'Download your %1$s Report: %2$s', 'woocommerce-admin' ), $report_name, $download_url );
|
||||
|
||||
echo "\n\n----------------------------------------\n\n";
|
||||
|
||||
echo wp_kses_post( apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) ) );
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// WARNING: Do not directly edit this file.
|
||||
// This file is auto-generated as part of the build process and things may break.
|
||||
if ( ! function_exists( 'wc_admin_get_feature_config' ) ) {
|
||||
function wc_admin_get_feature_config() {
|
||||
return array(
|
||||
'activity-panels' => true,
|
||||
'analytics' => true,
|
||||
'analytics-dashboard' => true,
|
||||
'analytics-dashboard/customizable' => true,
|
||||
'devdocs' => false,
|
||||
'onboarding' => true,
|
||||
'store-alerts' => true,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Convenience functions for PageController.
|
||||
*
|
||||
* @package Woocommerce Admin
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\PageController;
|
||||
|
||||
/**
|
||||
* Connect an existing page to WooCommerce Admin.
|
||||
* Passthrough to PageController::connect_page().
|
||||
*
|
||||
* @param array $options Options for PageController::connect_page().
|
||||
*/
|
||||
function wc_admin_connect_page( $options ) {
|
||||
$controller = PageController::get_instance();
|
||||
$controller->connect_page( $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register JS-powered WooCommerce Admin Page.
|
||||
* Passthrough to PageController::register_page().
|
||||
*
|
||||
* @param array $options Options for PageController::register_page().
|
||||
*/
|
||||
function wc_admin_register_page( $options ) {
|
||||
$controller = PageController::get_instance();
|
||||
$controller->register_page( $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this page connected to WooCommerce Admin?
|
||||
* Passthrough to PageController::is_connected_page().
|
||||
*
|
||||
* @return boolean True if the page is connected to WooCommerce Admin.
|
||||
*/
|
||||
function wc_admin_is_connected_page() {
|
||||
$controller = PageController::get_instance();
|
||||
return $controller->is_connected_page();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a WooCommerce Admin Page?
|
||||
* Passthrough to PageController::is_registered_page().
|
||||
*
|
||||
* @return boolean True if the page is a WooCommerce Admin page.
|
||||
*/
|
||||
function wc_admin_is_registered_page() {
|
||||
$controller = PageController::get_instance();
|
||||
return $controller->is_registered_page();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get breadcrumbs for WooCommerce Admin Page navigation.
|
||||
* Passthrough to PageController::get_breadcrumbs().
|
||||
*
|
||||
* @return array Navigation pieces (breadcrumbs).
|
||||
*/
|
||||
function wc_admin_get_breadcrumbs() {
|
||||
$controller = PageController::get_instance();
|
||||
return $controller->get_breadcrumbs();
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* WooCommerce Admin Updates
|
||||
*
|
||||
* Functions for updating data, used by the background updater.
|
||||
*
|
||||
* @package WooCommerce/Admin
|
||||
*/
|
||||
|
||||
use \Automattic\WooCommerce\Admin\Install as Installer;
|
||||
|
||||
/**
|
||||
* Update order stats `status` index length.
|
||||
* See: https://github.com/woocommerce/woocommerce-admin/issues/2969.
|
||||
*/
|
||||
function wc_admin_update_0201_order_status_index() {
|
||||
global $wpdb;
|
||||
|
||||
// Max DB index length. See wp_get_db_schema().
|
||||
$max_index_length = 191;
|
||||
|
||||
$index = $wpdb->get_row( "SHOW INDEX FROM {$wpdb->prefix}wc_order_stats WHERE key_name = 'status'" );
|
||||
|
||||
if ( property_exists( $index, 'Sub_part' ) ) {
|
||||
// The index was created with the right length. Time to bail.
|
||||
if ( $max_index_length === $index->Sub_part ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to drop the index so it can be recreated.
|
||||
$wpdb->query( "DROP INDEX `status` ON {$wpdb->prefix}wc_order_stats" );
|
||||
}
|
||||
|
||||
// Recreate the status index with a max length.
|
||||
$wpdb->query( $wpdb->prepare( "ALTER TABLE {$wpdb->prefix}wc_order_stats ADD INDEX status (status(%d))", $max_index_length ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update DB Version.
|
||||
*/
|
||||
function wc_admin_update_0201_db_version() {
|
||||
Installer::update_db_version( '0.20.1' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename "gross_total" to "total_sales".
|
||||
* See: https://github.com/woocommerce/woocommerce-admin/issues/3175
|
||||
*/
|
||||
function wc_admin_update_0230_rename_gross_total() {
|
||||
global $wpdb;
|
||||
|
||||
// We first need to drop the new `total_sales` column, since dbDelta() will have created it.
|
||||
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wc_order_stats DROP COLUMN `total_sales`" );
|
||||
// Then we can rename the existing `gross_total` column.
|
||||
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wc_order_stats CHANGE COLUMN `gross_total` `total_sales` double DEFAULT 0 NOT NULL" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update DB Version.
|
||||
*/
|
||||
function wc_admin_update_0230_db_version() {
|
||||
Installer::update_db_version( '0.23.0' );
|
||||
}
|
||||
Reference in New Issue
Block a user