クラス
Master
ソース ソース
ファイル: src/Master.php
class Master
{
const REACT_DOM_NODE = 'wcexwl_react_app';
/**
* REST Routes object
*
* @var Routes\Rest
*/
public $restRoutes;
/**
* Error store object
*
* @var Error\Store
*/
public $estore;
/**
* Instantiates classes. Registers hooks. etc
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
*/
public function init() {
add_action('usces_after_cart_instant', function () {
$this->restRoutes = new Routes\Rest($this);
$this->restRoutes->dispatcher->listen();
}, 11);
Config\Permalink::init();
Views\Snackbar\Snackbar::init();
(new Routes\Redirect($this))->init();
$this->estore = new Error\Store();
$this->estore->populate();
Views\LoginPage::init();
Views\Header::init();
if (Config\Options::useReact()) {
(new React\CartPage\CartPage($this))->init();
(new React\ItemPage\ItemPage($this))->init();
(new React\WishlistPage\WishlistPage($this))->init();
} else {
(new Views\CartPage\CartPage($this))->init();
(new Views\ItemPage\ItemPage($this))->init();
(new Views\WishlistPage\WishlistPage($this))->init();
}
$cptmc = new CptmClient(
'AWW001',
WCEXWL_VERSION,
WCEXWL_PLUGIN_FILE,
'https://api.aivec.co.jp/cptmp/v1/getProvidersList/AWW001'
);
$cptmc->init();
(new SettingsPage($cptmc, 'WCEX Wishlist'))->createProviderSelectSettingsPage();
// global functions
require_once(__DIR__ . '/api-functions.php');
require_once(__DIR__ . '/template-functions.php');
// the following is for deprecated functionality
require_once(__DIR__ . '/Deprecated/filters.php');
require_once(__DIR__ . '/Deprecated/functions.php');
}
/**
* Returns wishlist table name
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @global \wpdb $wpdb
* @return string
*/
public static function getWishlistTableName() {
global $wpdb;
return $wpdb->prefix . 'wishlist';
}
/**
* Returns theme configuration
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return array
*/
public static function getThemeConfig() {
return Theme::themeConfig('wcexwl');
}
/**
* Enqueues client SDK js file
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
*/
public function loadClientSdk() {
$assetsmap = include(WCEXWL_PLUGIN_DIR . '/dist/js/client-sdk.asset.php');
wp_enqueue_script(
'wcexwl-client-sdk',
WCEXWL_PLUGIN_URL . '/dist/js/client-sdk.js',
$assetsmap['dependencies'],
$assetsmap['version'],
false
);
wp_localize_script('wcexwl-client-sdk', 'wlsdk', $this->getScriptInjectionVariables());
}
/**
* Returns array of filterable text/css/display values
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return array
*/
public static function getFilterableValues() {
$theme = self::getThemeConfig();
/**
* Filters the default batch button text displayed on both cart and wishlist pages
*
* @important
* @param string $text button text
*/
$batchButtonText = apply_filters('wcexwl_filter_batch_button_text', __('GO!', 'wcexwl'));
return [
/**
* Filters the default primary button class
*
* Primary buttons are used for the 'Add to ...' buttons and batch buttons on the cart and
* wishlist page
*
* @important
* @param string $class class name
*/
'btnprimary' => apply_filters('wcexwl_filter_primary_button_class', $theme['btnprimary']),
/**
* Filters the default secondary button class
*
* The secondary button is used for the 'Add to Wishlist' button on the item page
*
* @important
* @param string $class class name
*/
'btnsecondary' => apply_filters('wcexwl_filter_secondary_button_class', $theme['btnsecondary']),
/**
* Filters the 'Add to Cart' text displayed in the batch dropdown select menu on the wishlist page
*
* @important
* @param string $text select text
*/
'toCartSelectText' => apply_filters('wcexwl_filter_wlpage_dropdown_to_cart_text', __('To Cart', 'wcexwl')),
/**
* Filters the 'Add to Wishlist' text displayed in the batch dropdown select menu on the cart page
*
* @important
* @param string $text select text
*/
'toWishlistSelectText' => apply_filters('wcexwl_filter_cart_dropdown_to_wishlist_text', __('To Wishlist', 'wcexwl')),
/**
* Filters the 'Delete' text displayed in the batch dropdown select menu on the cart page and wishlist page
*
* @important
* @param string $text select text
*/
'deleteSelectText' => apply_filters('wcexwl_filter_batch_dropdown_delete_items_text', __('delete', 'wcexwl')),
/**
* Filters the '-- Select --' text displayed in the batch dropdown select menu on the cart page and
* wishlist page
*
* @important
* @param string $text select text
*/
'selectText' => apply_filters('wcexwl_filter_batch_dropdown_select_text', __('select', 'wcexwl')),
/**
* Filters the default batch button text displayed on the wishlist page
*
* @important
* @param string $text button text
*/
'wishlistBatchButtonText' => apply_filters('wcexwl_filter_wishlist_batch_button_text', $batchButtonText),
/**
* Filters the default batch button text displayed on the cart page
*
* @important
* @param string $text button text
*/
'cartBatchButtonText' => apply_filters('wcexwl_filter_cart_batch_button_text', $batchButtonText),
/**
* Filters the 'Items were added' text displayed in the snackbar alert
*
* @important
* @param string $text
*/
'itemsAddedText' => apply_filters('wcexwl_filter_snackbar_items_added_text', __('Item(s) were added.', 'wcexwl')),
/**
* Filters the 'Items Deleted' text displayed in the snackbar alert
*
* @important
* @param string $text
*/
'itemsDeletedText' => apply_filters('wcexwl_filter_snackbar_items_deleted_text', __('Items Deleted', 'wcexwl')),
/**
* Filters the 'See Cart' URL text displayed in the snackbar alert
*
* @important
* @param string $text
*/
'toCartUrlText' => apply_filters('wcexwl_filter_snackbar_to_cart_url_text', __('See Cart', 'wcexwl')),
/**
* Filters the 'See List' URL text displayed in the snackbar alert
*
* @important
* @param string $text
*/
'toWishlistUrlText' => apply_filters('wcexwl_filter_snackbar_to_wishlist_url_text', __('See List', 'wcexwl')),
/**
* Filters the HEX color of the success icon displayed in the snackbar alert
*
* RGB css values are also valid
*
* @important
* @param string $hexcolor
*/
'sbSuccessIconColor' => apply_filters('wcexwl_filter_snackbar_success_icon_color', '#33da3a'),
/**
* Filters the 'Please select an option.' text displayed in the snackbar alert
*
* @important
* @param string $text
*/
'batchNoActionText' => apply_filters('wcexwl_filter_batch_action_none_selected_text', __('Please select an option.', 'wcexwl')),
/**
* Filters the 'Please select an option.' text displayed in the snackbar alert on the wishlist page
*
* @important
* @param string $text
*/
'wtocNoneCheckedText' => apply_filters('wcexwl_filter_to_cart_none_checked_text', __('Please check at least one item to add to your cart.', 'wcexwl')),
/**
* Filters the 'Please select an option.' text displayed in the snackbar alert on the cart page
*
* @important
* @param string $text
*/
'ctowNoneCheckedText' => apply_filters('wcexwl_filter_to_wishlist_none_checked_text', __('Please check at least one item to add to your wishlist.', 'wcexwl')),
/**
* Filters the 'Please check at least one item to delete.' text displayed in the snackbar alert
*
* @important
* @param string $text
*/
'deleteNoneCheckedText' => apply_filters('wcexwl_filter_delete_items_none_checked_text', __('Please check at least one item to delete.', 'wcexwl')),
/**
* Filters the 'Your wishlist is currently empty.' text displayed on the wishlist page when no
* items exist in the wishlist
*
* @important
* @param string $text
*/
'emptyWishlistMessage' => apply_filters('wcexwl_filter_empty_wishlist_message', __('Your wishlist is currently empty.', 'wcexwl')),
/**
* Filters the 'Add To Wishlist' button text displayed on the item page
*
* @important
* @param string $text button text
*/
'addToWishlistButtonText' => apply_filters('wcexwl_filter_item_page_wishlist_button_text', __('Add To Wishlist', 'wcexwl')),
/**
* Filters the message shown to a user who tries to add an item to their wishlist while logged out
*
* @important
* @param string $text
*/
'loginRequiredMessage' => apply_filters('wcexwl_filter_login_required_message', __('You must be logged in to add items to a wishlist.', 'wcexwl')),
];
}
/**
* Returns list of variables to be injected into any script
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return array
*/
public function getScriptInjectionVariables() {
return array_merge(
$this->restRoutes->getScriptInjectionVariables(),
$this->estore->getScriptInjectionVariables(),
self::getFilterableValues(),
[
'reactDomNode' => self::REACT_DOM_NODE,
'wishlistPageUrl' => WCEXWL_PAGE_URL,
'loginUrl' => USCES_MEMBER_URL,
'cartUrl' => USCES_CART_URL,
'addRawItemOnLoginKey' => Routes\Redirect::REDIRECT_KEY_ADD_TO_WISHLIST,
'addSerializedItemOnLoginKey' => Routes\Redirect::REDIRECT_KEY_ADD_TO_WISHLIST_BY_SERIAL,
]
);
}
}
- getFilterableValues — Returns array of filterable text/css/display values
- getScriptInjectionVariables — Returns list of variables to be injected into any script
- getThemeConfig — Returns theme configuration
- getWishlistTableName — Returns wishlist table name
- init — Instantiates classes. Registers hooks. etc
- loadClientSdk — Enqueues client SDK js file