function_exists( 'get_woocommerce_currency' ) ? get_woocommerce_currency() : 'USD', 'post_types' => array( 'post' ), 'paid_status' => 'publish', 'gateways' => array( 'stripe', 'paypal', 'woocommerce' ), 'stripe_secret_key' => '', 'stripe_webhook_secret' => '', 'paypal_mode' => 'sandbox', 'paypal_client_id' => '', 'paypal_secret' => '', 'paypal_webhook_id' => '', 'submit_page' => 0, 'dashboard_page' => 0, 'delete_data' => 0, ); } function postfee_get_settings() { return wp_parse_args( (array) get_option( 'postfee_settings', array() ), postfee_default_settings() ); } function postfee_setting( $key, $default = '' ) { $settings = postfee_get_settings(); return isset( $settings[ $key ] ) ? $settings[ $key ] : $default; } function postfee_currency() { return strtoupper( postfee_setting( 'currency', 'USD' ) ); } /** * Currencies offered in the settings, as code => name. */ function postfee_currencies() { $currencies = array( 'AED' => __( 'United Arab Emirates dirham', 'postfee' ), 'AUD' => __( 'Australian dollar', 'postfee' ), 'BRL' => __( 'Brazilian real', 'postfee' ), 'CAD' => __( 'Canadian dollar', 'postfee' ), 'CHF' => __( 'Swiss franc', 'postfee' ), 'CLP' => __( 'Chilean peso', 'postfee' ), 'CNY' => __( 'Chinese yuan', 'postfee' ), 'COP' => __( 'Colombian peso', 'postfee' ), 'CZK' => __( 'Czech koruna', 'postfee' ), 'DKK' => __( 'Danish krone', 'postfee' ), 'EGP' => __( 'Egyptian pound', 'postfee' ), 'EUR' => __( 'Euro', 'postfee' ), 'GBP' => __( 'Pound sterling', 'postfee' ), 'HKD' => __( 'Hong Kong dollar', 'postfee' ), 'HUF' => __( 'Hungarian forint', 'postfee' ), 'IDR' => __( 'Indonesian rupiah', 'postfee' ), 'ILS' => __( 'Israeli new shekel', 'postfee' ), 'INR' => __( 'Indian rupee', 'postfee' ), 'JPY' => __( 'Japanese yen', 'postfee' ), 'KRW' => __( 'South Korean won', 'postfee' ), 'MXN' => __( 'Mexican peso', 'postfee' ), 'MYR' => __( 'Malaysian ringgit', 'postfee' ), 'NGN' => __( 'Nigerian naira', 'postfee' ), 'NOK' => __( 'Norwegian krone', 'postfee' ), 'NZD' => __( 'New Zealand dollar', 'postfee' ), 'PEN' => __( 'Peruvian sol', 'postfee' ), 'PHP' => __( 'Philippine peso', 'postfee' ), 'PKR' => __( 'Pakistani rupee', 'postfee' ), 'PLN' => __( 'Polish złoty', 'postfee' ), 'RON' => __( 'Romanian leu', 'postfee' ), 'SAR' => __( 'Saudi riyal', 'postfee' ), 'SEK' => __( 'Swedish krona', 'postfee' ), 'SGD' => __( 'Singapore dollar', 'postfee' ), 'THB' => __( 'Thai baht', 'postfee' ), 'TRY' => __( 'Turkish lira', 'postfee' ), 'TWD' => __( 'New Taiwan dollar', 'postfee' ), 'UAH' => __( 'Ukrainian hryvnia', 'postfee' ), 'USD' => __( 'United States dollar', 'postfee' ), 'VND' => __( 'Vietnamese đồng', 'postfee' ), 'ZAR' => __( 'South African rand', 'postfee' ), ); $currencies = (array) apply_filters( 'postfee_currencies', $currencies ); // Keep the saved currency selectable even when it is not in the list. $current = postfee_currency(); if ( ! isset( $currencies[ $current ] ) ) { $currencies[ $current ] = $current; } asort( $currencies ); return $currencies; } /** * Post types users are allowed to submit and pay for. */ function postfee_post_types() { $types = array_filter( (array) postfee_setting( 'post_types', array( 'post' ) ), 'post_type_exists' ); return apply_filters( 'postfee_post_types', array_values( $types ) ); } function postfee_is_zero_decimal( $currency ) { return in_array( strtoupper( $currency ), array( 'BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF' ), true ); } /** * Amounts are stored and sent to gateways in the currency's smallest unit. */ function postfee_to_minor( $amount, $currency = '' ) { $currency = $currency ? $currency : postfee_currency(); return (int) round( (float) $amount * ( postfee_is_zero_decimal( $currency ) ? 1 : 100 ) ); } function postfee_format_price( $minor, $currency = '' ) { $currency = strtoupper( $currency ? $currency : postfee_currency() ); $zero = postfee_is_zero_decimal( $currency ); $number = number_format_i18n( $minor / ( $zero ? 1 : 100 ), $zero ? 0 : 2 ); $symbols = array( 'USD' => '$', 'EUR' => '€', 'GBP' => '£', 'ILS' => '₪', 'JPY' => '¥', 'CAD' => 'CA$', 'AUD' => 'A$', 'INR' => '₹', ); $symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : $currency . ' '; return apply_filters( 'postfee_format_price', $symbol . $number, $minor, $currency ); } /** * Current UTC time in MySQL format. All table datetimes are stored in UTC. */ function postfee_now( $offset = 0 ) { return gmdate( 'Y-m-d H:i:s', time() + $offset ); } function postfee_format_date( $mysql_utc ) { return $mysql_utc ? wp_date( get_option( 'date_format' ), strtotime( $mysql_utc . ' UTC' ) ) : ''; } /** * URL of the submit or dashboard page, falling back to the page being viewed. */ function postfee_page_url( $which, $args = array() ) { $page_id = absint( postfee_setting( $which . '_page' ) ); $url = $page_id ? get_permalink( $page_id ) : ''; if ( ! $url ) { $url = get_queried_object_id() ? get_permalink( get_queried_object_id() ) : home_url( '/' ); } return $args ? add_query_arg( $args, $url ) : $url; }