*/ public static function defaults() { $defaults = array( // Payment: bank transfer. 'bank_name' => '', 'bank_branch' => '', 'bank_branch_code' => '', 'bank_type' => 'ordinary', 'bank_number' => '', 'bank_holder' => '', 'pay_days' => 7, 'remind' => true, // Specified Commercial Transactions Act (tokushoho) page. 'law_seller' => '', 'law_manager' => '', 'law_address' => '', 'law_address_hide' => false, 'law_phone' => '', 'law_phone_hide' => false, 'law_email' => '', 'law_delivery' => __( 'You can download the product from My page right after we confirm your payment.', 'paygrab' ), 'law_cancel' => __( 'You can cancel your order before you pay. Because these are digital products, we cannot accept returns or cancellations after payment.', 'paygrab' ), 'law_environment' => '', // Pages. 'page_checkout' => 0, 'page_mypage' => 0, 'page_register' => 0, 'page_login' => 0, 'page_tokushoho' => 0, 'page_terms' => 0, // Members. 'register_role' => 'subscriber', 'email_verification' => true, 'terms_text' => '', 'terms_scroll' => false, // Look of the buyer's screens. 'design_style' => 'standard', 'key_color_mode' => 'theme', 'key_color' => '#0b6e6e', // Mail. 'mail_from_name' => '', 'mail_from' => '', 'mail_admin' => '', // When the plugin is deleted: keep everything (orders are accounting records) unless this is on. 'delete_data' => false, ); /** * Filters the default settings. Add-ons add their own keys here. * * @param array $defaults Defaults. */ return apply_filters( 'paygrab_default_settings', $defaults ); } /** * All settings merged with defaults. * * @return array */ public static function all() { if ( null === self::$cache ) { $saved = get_option( self::OPTION, array() ); self::$cache = array_merge( self::defaults(), is_array( $saved ) ? $saved : array() ); } return self::$cache; } /** * One setting. * * @param string $key Key. * @param mixed $fallback Value when the key is unknown. * @return mixed */ public static function get( $key, $fallback = null ) { $all = self::all(); return array_key_exists( $key, $all ) ? $all[ $key ] : $fallback; } /** * Save some settings (already sanitized). * * @param array $changes Key => value. * @return void */ public static function update( array $changes ) { $saved = get_option( self::OPTION, array() ); $saved = array_merge( is_array( $saved ) ? $saved : array(), $changes ); update_option( self::OPTION, $saved, true ); self::$cache = null; } /** * Forget the request cache (after another process saved). * * @return void */ public static function flush() { self::$cache = null; } /** * Whether the bank account needed for transfers is filled in. * * @return bool */ public static function bank_ready() { foreach ( array( 'bank_name', 'bank_branch', 'bank_number', 'bank_holder' ) as $key ) { if ( '' === trim( (string) self::get( $key ) ) ) { return false; } } return true; } /** * Tokushoho items that are still empty. * * @return string[] Setting keys. */ public static function missing_law_items() { $missing = array(); foreach ( array( 'law_seller', 'law_manager', 'law_address', 'law_phone', 'law_email' ) as $key ) { if ( in_array( $key, array( 'law_address', 'law_phone' ), true ) && self::get( $key . '_hide' ) ) { continue; } if ( '' === trim( (string) self::get( $key ) ) ) { $missing[] = $key; } } return $missing; } /** * Label of the bank account type. * * @return string */ public static function bank_type_label() { return 'checking' === self::get( 'bank_type' ) ? __( 'Checking', 'paygrab' ) : __( 'Ordinary', 'paygrab' ); } }