class-yith-wcwl-admin-panel.php
1 year ago
class-yith-wcwl-admin.php
1 year ago
class-yith-wcwl-rendering-method-admin-handler.php
1 year ago
class-yith-wcwl-admin.php
198 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin init class |
| 4 | * |
| 5 | * @package YITH\Wishlist\Classes |
| 6 | * @author YITH <plugins@yithemes.com> |
| 7 | * @version 3.0.0 |
| 8 | */ |
| 9 | |
| 10 | if ( ! defined( 'YITH_WCWL' ) ) { |
| 11 | exit; |
| 12 | } // Exit if accessed directly |
| 13 | |
| 14 | if ( ! class_exists( 'YITH_WCWL_Admin' ) ) { |
| 15 | /** |
| 16 | * Initiator class. Create and populate admin views. |
| 17 | * |
| 18 | * @since 1.0.0 |
| 19 | */ |
| 20 | class YITH_WCWL_Admin extends YITH_WCWL_Admin_Legacy { |
| 21 | use YITH_WCWL_Extensible_Singleton_Trait; |
| 22 | |
| 23 | /** |
| 24 | * Plugin options |
| 25 | * |
| 26 | * @since 1.0.0 |
| 27 | * @var array |
| 28 | */ |
| 29 | public $options; |
| 30 | |
| 31 | /** |
| 32 | * Constructor of the class |
| 33 | * |
| 34 | * @since 2.0.0 |
| 35 | */ |
| 36 | public function __construct() { |
| 37 | YITH_WCWL_Admin_Panel::get_instance(); |
| 38 | YITH_WCWL_Rendering_Method_Admin_Handler::get_instance(); |
| 39 | |
| 40 | // init admin processing. |
| 41 | add_action( 'init', array( $this, 'init' ) ); |
| 42 | |
| 43 | // enqueue scripts. |
| 44 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), 20 ); |
| 45 | |
| 46 | // plugin panel options. |
| 47 | add_filter( 'yith_plugin_fw_panel_wc_extra_row_classes', array( $this, 'mark_options_disabled' ), 10, 23 ); |
| 48 | |
| 49 | // add plugin links. |
| 50 | add_filter( 'plugin_action_links_' . plugin_basename( YITH_WCWL_DIR . 'init.php' ), array( $this, 'action_links' ) ); |
| 51 | add_filter( 'yith_show_plugin_row_meta', array( $this, 'add_plugin_meta' ), 10, 5 ); |
| 52 | |
| 53 | // add a post display state for special WC pages. |
| 54 | add_filter( 'display_post_states', array( $this, 'add_display_post_states' ), 10, 2 ); |
| 55 | } |
| 56 | |
| 57 | /* === ADMIN GENERAL === */ |
| 58 | |
| 59 | /** |
| 60 | * Add a post display state for special WC pages in the page list table. |
| 61 | * |
| 62 | * @param array $post_states An array of post display states. |
| 63 | * @param WP_Post $post The current post object. |
| 64 | */ |
| 65 | public function add_display_post_states( $post_states, $post ) { |
| 66 | if ( (int) get_option( 'yith_wcwl_wishlist_page_id' ) === $post->ID ) { |
| 67 | $post_states[ 'yith_wcwl_page_for_wishlist' ] = __( 'Wishlist Page', 'yith-woocommerce-wishlist' ); |
| 68 | } |
| 69 | |
| 70 | return $post_states; |
| 71 | } |
| 72 | |
| 73 | /* === INITIALIZATION SECTION === */ |
| 74 | |
| 75 | /** |
| 76 | * Initiator method. Initiate properties. |
| 77 | * |
| 78 | * @return void |
| 79 | * @access private |
| 80 | * @since 1.0.0 |
| 81 | */ |
| 82 | public function init() { |
| 83 | $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'unminified/' : ''; |
| 84 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 85 | |
| 86 | wp_register_style( 'yith-wcwl-material-icons', 'https://fonts.googleapis.com/icon?family=Material+Icons', array(), '3.0.1' ); |
| 87 | wp_register_style( 'yith-wcwl-admin', YITH_WCWL_URL . 'assets/css/admin.css', array(), YITH_WCWL_VERSION ); |
| 88 | wp_register_script( 'yith-wcwl-admin', YITH_WCWL_URL . 'assets/js/' . $prefix . 'admin/yith-wcwl' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ), YITH_WCWL_VERSION, true ); |
| 89 | |
| 90 | |
| 91 | $icons = yith_wcwl_get_plugin_icons_list(); |
| 92 | wp_localize_script( |
| 93 | 'yith-wcwl-admin', |
| 94 | 'yith_wcwl_admin', |
| 95 | array( |
| 96 | 'plugin_icons' => array_combine( array_keys( $icons ), array_column( $icons, 'svg' ) ), |
| 97 | 'i18n' => array( |
| 98 | 'deleteWishlistConfirmModal' => array( |
| 99 | 'title' => _x( 'Confirm delete', '[Admin] Delete wishlist from panel confirmation modal', 'yith-woocommerce-wishlist' ), |
| 100 | //translators: %s is the name of the wishlist |
| 101 | 'message' => _x( 'Are you sure you want to delete %s?', '[Admin] Delete wishlist from panel confirmation modal', 'yith-woocommerce-wishlist' ), |
| 102 | 'confirmButton' => _x( 'Delete', '[Admin] Delete wishlist from panel confirmation modal', 'yith-woocommerce-wishlist' ), |
| 103 | ), |
| 104 | ), |
| 105 | ) |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Run the installation |
| 111 | * |
| 112 | * @return void |
| 113 | * @since 1.0.0 |
| 114 | * @depreacted since 4.0 |
| 115 | * @see YITH_WCWL_Install::maybe_install |
| 116 | */ |
| 117 | public function install() { |
| 118 | wc_deprecated_function( 'YITH_WCWL_Admin::install', '4.0.0', 'YITH_WCWL_Install::maybe_install' ); |
| 119 | yith_wcwl_install()->maybe_install(); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Adds plugin actions link |
| 124 | * |
| 125 | * @param mixed $links Available action links. |
| 126 | * @return array |
| 127 | */ |
| 128 | public function action_links( $links ) { |
| 129 | $links = yith_add_action_links( $links, 'yith_wcwl_panel', defined( 'YITH_WCWL_PREMIUM' ), YITH_WCWL_SLUG ); |
| 130 | return $links; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Adds plugin row meta |
| 135 | * |
| 136 | * @param array $new_row_meta_args Array of meta for current plugin. |
| 137 | * @param array $plugin_meta Not in use. |
| 138 | * @param string $plugin_file Current plugin iit file path. |
| 139 | * @param array $plugin_data Plugin info. |
| 140 | * @param string $status Plugin status. |
| 141 | * @param string $init_file Wishlist plugin init file. |
| 142 | * @return array |
| 143 | * @since 2.0.0 |
| 144 | */ |
| 145 | public function add_plugin_meta( $new_row_meta_args, $plugin_meta, $plugin_file, $plugin_data, $status, $init_file = 'YITH_WCWL_INIT' ) { |
| 146 | if ( ! defined( $init_file ) || constant( $init_file ) !== $plugin_file ) { |
| 147 | return $new_row_meta_args; |
| 148 | } |
| 149 | |
| 150 | $new_row_meta_args[ 'slug' ] = 'yith-woocommerce-wishlist'; |
| 151 | $new_row_meta_args[ 'is_premium' ] = defined( 'YITH_WCWL_PREMIUM' ); |
| 152 | $new_row_meta_args[ 'is_extended' ] = defined( 'YITH_WCWL_EXTENDED' ); |
| 153 | |
| 154 | return $new_row_meta_args; |
| 155 | } |
| 156 | |
| 157 | /* === WISHLIST SUBPANEL SECTION === */ |
| 158 | |
| 159 | /** |
| 160 | * Adds yith-disabled class |
| 161 | * Adds class to fields when required, and when disabled state cannot be achieved any other way (eg. by dependencies) |
| 162 | * |
| 163 | * @param array $classes Array of field extra classes. |
| 164 | * @param array $field Array of field data. |
| 165 | * |
| 166 | * @return array Filtered array of extra classes |
| 167 | */ |
| 168 | public function mark_options_disabled( $classes, $field ) { |
| 169 | if ( isset( $field[ 'id' ] ) && 'yith_wfbt_enable_integration' === $field[ 'id' ] && ! ( defined( 'YITH_WFBT' ) && YITH_WFBT ) ) { |
| 170 | $classes[] = 'yith-disabled'; |
| 171 | } |
| 172 | |
| 173 | return $classes; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Load admin style. |
| 178 | * |
| 179 | * @return void |
| 180 | * @since 1.0.0 |
| 181 | */ |
| 182 | public function enqueue() { |
| 183 | global $woocommerce, $pagenow; |
| 184 | |
| 185 | if ( 'admin.php' === $pagenow && isset( $_GET[ 'page' ] ) && 'yith_wcwl_panel' === $_GET[ 'page' ] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 186 | wp_enqueue_style( 'yith-wcwl-admin' ); |
| 187 | wp_enqueue_script( 'yith-wcwl-admin' ); |
| 188 | |
| 189 | if ( isset( $_GET[ 'tab' ], $_GET[ 'sub_tab' ] ) && 'dashboard' === $_GET[ 'tab' ] && 'dashboard-popular' === $_GET[ 'sub_tab' ] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 190 | wp_enqueue_style( 'yith-wcwl-material-icons' ); |
| 191 | wp_enqueue_editor(); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 |