クラス
MemberEditPage
Adds option to sync or unsync Amazon account with Welcart account
説明 説明
Syncing will allow a user to login to their Welcart account by logging in with their Amazon account. Unsyncing will disallow this feature.
By default, users who created their Welcart account via their Amazon account will have sync turned on, while users who created their Welcart account via the default signup page will have to manually sync their Amazon account. Again, this feature only works if the Welcart account email and Amazon account email are the same.
ファイル: src/Views/MemberEditPage/MemberEditPage.php
class MemberEditPage { const COMP_JS_SLUG = 'wcexaap-login-option-component'; /** * AmazonPay module instance * * @var AmazonPay */ public $module; /** * Sets `$module` member var with dependency injection. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param AmazonPay $module */ public function __construct(AmazonPay $module) { $this->module = $module; } /** * Register hook for adding sync option field to member page * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return void */ public function init() { add_filter('usces_filter_apply_addressform', [$this, 'allowLoginSetting'], 10, 3); } /** * Prepends Amazon allow login option to member information edit table * * @author Evan D Shaw <evandanielshaw@gmail.com> * @global \usc_e_shop $usces * @param string $formtag * @param string $type * @param string $data * @return string */ public function allowLoginSetting($formtag, $type, $data) { global $usces; $url = ''; if (isset($_SERVER['REQUEST_URI'])) { $url = esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])); } if (!$usces->is_member_page($url)) { return $formtag; } if (!$usces->is_member_logged_in()) { return $formtag; } $semantic = new Semantic(); $semantic->loadButtonCss(); $semantic->loadLoaderCss(); $semantic->loadIconCss(); $semantic->loadTransitionCss(); $semantic->loadPopupCss(); $semantic->loadSemanticJS(); wp_enqueue_script( self::COMP_JS_SLUG, WCEXAAP_PLUGIN_URL . '/dist/amazonSyncLogin.js', [Semantic::JS_SLUG], WCEXAAP_VERSION, true ); wp_set_script_translations(self::COMP_JS_SLUG, 'wcexaap', WCEXAAP_LANGDIR); wp_localize_script( self::COMP_JS_SLUG, AmazonPay::L10N, array_merge( $this->module->getScriptInjectionVariables(), [ 'synced' => (new MemberMeta((int)$_SESSION['usces_member']['ID']))->getAllowAmazonToWelcartLogin(), ] ) ); return '<div id="' . AmazonPay::VUE_APP_MOUNT_EL . '"></div>' . $formtag; } }
- __construct — Sets $module member var with dependency injection.
- allowLoginSetting — Prepends Amazon allow login option to member information edit table
- init — Register hook for adding sync option field to member page