Refactor admin cl interface and handle product access with groups
This commit is contained in:
@@ -20,6 +20,20 @@ class Wiaas_Admin_CL_Packages {
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
add_action( 'admin_menu', array(__CLASS__, 'add_cl_packages_menu') );
|
||||
|
||||
add_action( 'admin_head', array( __CLASS__, 'menu_highlight' ) );
|
||||
|
||||
add_filter( 'manage_product_posts_columns', array( __CLASS__, 'define_list_table_products_columns' ), 999 );
|
||||
|
||||
add_filter( 'bulk_actions-edit-product', array( __CLASS__, 'define_list_table_products_bulk_actions' ), 999 );
|
||||
|
||||
add_filter( 'views_edit-product', array( __CLASS__, 'define_list_table_products_views' ), 999 );
|
||||
|
||||
add_filter( 'post_row_actions', array( __CLASS__, 'define_list_table_products_row_actions' ), 999, 2 );
|
||||
|
||||
add_filter( 'list_table_primary_column', array( __CLASS__, 'define_list_table_products_primary_column' ), 999, 2 );
|
||||
|
||||
add_action( 'manage_product_posts_custom_column', array( __CLASS__, 'render_list_table_products_columns' ), 10, 2 );
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
@@ -29,38 +43,33 @@ class Wiaas_Admin_CL_Packages {
|
||||
}
|
||||
|
||||
public static function add_cl_packages_menu() {
|
||||
add_menu_page(
|
||||
__( 'Products', 'wiaas' ),
|
||||
__( 'Products', 'wiaas' ),
|
||||
'manage_wiaas_cl_products',
|
||||
'wiaas-cl-packages',
|
||||
array(__CLASS__, 'output_list'),
|
||||
null,
|
||||
'55.5' );
|
||||
|
||||
add_submenu_page(
|
||||
null,
|
||||
'edit.php?post_type=product',
|
||||
__( 'Products', 'wiaas' ),
|
||||
null,
|
||||
'manage_wiaas_cl_products',
|
||||
'wiaas-cl-product',
|
||||
'wiaas-cl-package',
|
||||
array(__CLASS__, 'output_package')
|
||||
);
|
||||
}
|
||||
|
||||
public static function output_list() {
|
||||
public static function menu_highlight() {
|
||||
global $parent_file;
|
||||
|
||||
$packages_list = new Wiaas_Admin_CL_Packages_List();
|
||||
$screen = get_current_screen();
|
||||
|
||||
$packages_list->prepare_items();
|
||||
if ($screen->id === 'admin_page_wiaas-cl-product') {
|
||||
|
||||
require 'views/html-admin-cl-packages-page.php';
|
||||
error_log('set parent');
|
||||
|
||||
$parent_file = 'edit.php?post_type=product';
|
||||
}
|
||||
}
|
||||
|
||||
public static function output_package() {
|
||||
wp_enqueue_script( 'jquery-ui-tabs' );
|
||||
|
||||
$package_id = absint( $_GET['id'] );
|
||||
$package_id = absint( $_GET['cl_package_id'] );
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
@@ -126,6 +135,87 @@ class Wiaas_Admin_CL_Packages {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @section Customize display of list table products for commercial lead
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define columns for commercial lead view
|
||||
* @param array $columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_columns($columns) {
|
||||
$cl_columns = array();
|
||||
|
||||
$cl_columns['thumb'] = $columns['thumb'];
|
||||
$cl_columns['wiaas_cl_name'] = $columns['name'];
|
||||
$cl_columns['taxonomy-package_type'] = __('Type', 'wiaas');
|
||||
$cl_columns['taxonomy-package_status'] = __('Status', 'wiaas');
|
||||
$cl_columns['taxonomy-product_country'] = $columns['taxonomy-product_country'];
|
||||
$cl_columns['date'] = $columns['date'];
|
||||
|
||||
return $cl_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide list table products bulk actions for commercial lead view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_bulk_actions() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide list table products views for commercial lead view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_views() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show only ID in table products views for commercial lead view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_row_actions($actions, $post) {
|
||||
if ($post->post_type === 'product') {
|
||||
return array( 'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $post->ID ) );
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define custom primary column in list table products for commercial lead view
|
||||
*
|
||||
* @param $default
|
||||
* @param $screen_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function define_list_table_products_primary_column($default, $screen_id) {
|
||||
if ( 'edit-product' === $screen_id ) {
|
||||
return 'wiaas_cl_name';
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
public static function render_list_table_products_columns($column, $post_id) {
|
||||
if ($column === 'wiaas_cl_name') {
|
||||
|
||||
$package = wc_get_product($post_id);
|
||||
|
||||
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-cl-package&cl_package_id=' . absint( $package->get_id() ) );
|
||||
|
||||
echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) . '">' . esc_html( $package->get_title() ) . '</a></strong>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// PRIVATE HANDLERS
|
||||
|
||||
Reference in New Issue
Block a user