| 1 |
<?php |
| 2 |
/** |
| 3 |
* Whols Admin. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Whols; |
| 9 |
|
| 10 |
/** |
| 11 |
* Admin class. |
| 12 |
*/ |
| 13 |
class Admin { |
| 14 |
public $version = WHOLS_VERSION; |
| 15 |
|
| 16 |
/** |
| 17 |
* Admin constructor. |
| 18 |
* |
| 19 |
* @since 1.0.0 |
| 20 |
*/ |
| 21 |
public function __construct() { |
| 22 |
// Debug mode |
| 23 |
if( defined( 'WP_DEBUG' ) && WP_DEBUG ){ |
| 24 |
$this->version = time(); |
| 25 |
} |
| 26 |
|
| 27 |
// Fixed textdomain loading early issue |
| 28 |
add_action( 'init', function() { |
| 29 |
new Admin\Wholesaler_Request_Metabox(); |
| 30 |
new Admin\Role_Cat_Metabox(); |
| 31 |
new Admin\Product_Category_Metabox(); |
| 32 |
}, -1 ); |
| 33 |
|
| 34 |
new Admin\Custom_Taxonomies(); |
| 35 |
new Admin\Product_Metabox(); |
| 36 |
new Admin\User_Metabox(); |
| 37 |
new Admin\Role_Manager(); |
| 38 |
new Admin\Custom_Columns(); |
| 39 |
new Admin\Install_Manager(); |
| 40 |
new Admin\Product_Quick_Edit_Fields(); |
| 41 |
new Admin\Polylang_Integration(); |
| 42 |
|
| 43 |
// Bind admin page link to the plugin action link. |
| 44 |
add_filter( 'plugin_action_links_whols/whols.php', array($this, 'action_links_add'), 10, 4 ); |
| 45 |
|
| 46 |
// Admin assets hook into action. |
| 47 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); |
| 48 |
|
| 49 |
// Add page states to the page list table |
| 50 |
add_filter('display_post_states', array( $this, 'filter_post_states' ), 10, 2); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Action link add. |
| 55 |
* |
| 56 |
* @since 1.0.0 |
| 57 |
*/ |
| 58 |
function action_links_add( $actions, $plugin_file, $plugin_data, $context ){ |
| 59 |
|
| 60 |
$settings_page_link = sprintf( |
| 61 |
/* |
| 62 |
* translators: |
| 63 |
* 1: Settings label |
| 64 |
*/ |
| 65 |
'<a href="'. esc_url( get_admin_url() . 'admin.php?page=whols-admin' ) .'">%1$s</a>', |
| 66 |
esc_html__( 'Settings', 'whols' ) |
| 67 |
); |
| 68 |
|
| 69 |
array_unshift( $actions, $settings_page_link ); |
| 70 |
|
| 71 |
return $actions; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Enqueue admin assets. |
| 76 |
* |
| 77 |
* @since 1.0.0 |
| 78 |
*/ |
| 79 |
public function enqueue_admin_assets( $hook_suffix ) { |
| 80 |
$current_screen = get_current_screen(); |
| 81 |
|
| 82 |
if ( |
| 83 |
$current_screen->post_type == 'whols_user_request' || |
| 84 |
$current_screen->base == 'toplevel_page_whols-admin' || |
| 85 |
$current_screen->base == 'whols_page_whols-welcome' || |
| 86 |
$current_screen->post_type == 'product' || |
| 87 |
'user-edit' == $current_screen->base || |
| 88 |
$current_screen->taxonomy == 'whols_role_cat' |
| 89 |
) { |
| 90 |
wp_enqueue_style( 'vex', WHOLS_ASSETS . '/css/vex.css', null, $this->version ); |
| 91 |
wp_enqueue_style( 'vex-theme-plain', WHOLS_ASSETS . '/css/vex-theme-plain.css', null, $this->version ); |
| 92 |
wp_enqueue_style( 'whols-admin', WHOLS_ASSETS . '/css/admin.css', null, $this->version ); |
| 93 |
wp_enqueue_script( 'vex', WHOLS_ASSETS . '/js/vex.combined.min.js', array('jquery'), $this->version ); |
| 94 |
wp_enqueue_script( 'whols-admin', WHOLS_ASSETS . '/js/admin.js', array('jquery'), $this->version ); |
| 95 |
|
| 96 |
// inline js for the settings submenu |
| 97 |
$is_whols_setting = isset( $_GET['page'] ) ? sanitize_text_field($_GET['page']) : ''; |
| 98 |
$is_whols_setting = $is_whols_setting == 'whols-admin' ? 1 : 0; |
| 99 |
wp_add_inline_script( 'whols-admin', 'var whols_is_settings_page = '. esc_js( $is_whols_setting ) .';'); |
| 100 |
} |
| 101 |
|
| 102 |
$css = '#adminmenu li a[href="admin.php?page=whols-welcome"]{display: none;}'; |
| 103 |
wp_add_inline_style('common', $css); |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* It adds a "Whols Registration Page" state to the page that is set as the registration page. |
| 108 |
* |
| 109 |
* @param post_states (array) An array of post display states. |
| 110 |
* @param post The post object. |
| 111 |
*/ |
| 112 |
public function filter_post_states( $post_states, $post ){ |
| 113 |
if( has_shortcode( $post->post_content, 'whols_registration_form') || |
| 114 |
(whols_get_option('registration_page') && $post->ID == whols_get_option('registration_page')) |
| 115 |
){ |
| 116 |
$post_states['whols_registration_page'] = __('Whols Registration Page', 'whols'); |
| 117 |
} |
| 118 |
|
| 119 |
return $post_states; |
| 120 |
} |
| 121 |
} |