1 ) ); } /** * Ensure a string is a valid email.. * * @since 1.7.0.9 * * @param mixed $i Number received. * @return int|false */ function charitable_validate_email( $i ) { return filter_var( $i, FILTER_VALIDATE_EMAIL ); } /** * Sanitize any checkbox value. * * @since 1.5.0 * * @param mixed $value Value set for checkbox, or false. * @return boolean */ function charitable_sanitize_checkbox( $value = false ) { return intval( true == $value || 'on' == $value ); } /** * Format an array of strings as a sentence part. * * If there is one item in the string, this will just return that item. * If there are two items, it will return a string like this: "x and y". * If there are three or more items, it will return a string like this: "x, y and z". * * @since 1.3.0 * * @param string[] $list The list. * @return string */ function charitable_list_to_sentence_part( $list ) { $list = array_values( $list ); if ( 1 == count( $list ) ) { return $list[0]; } if ( 2 == count( $list ) ) { return sprintf( /* translators: %1$s: first list item; %2$s: second list item. */ _x( '%1$s and %2$s', 'x and y', 'charitable' ), $list[0], $list[1] ); } $last = array_pop( $list ); return sprintf( /* translators: %1$s: all list items except last, comma-separated; %2$s: second list item. */ _x( '%1$s and %2$s', 'x and y', 'charitable' ), implode( ', ', $list ), $last ); } /** * Sanitizes a date passed in the format of January 29, 2009. * * We use WP_Locale to parse the month that the user has set. * * @global WP_Locale $wp_locale * * @since 1.4.10 * * @param string $date The date to be sanitized. * @param string $return_format The date format to return. Default is U (timestamp). * @return string|false */ function charitable_sanitize_date( $date, $return_format = 'U' ) { global $wp_locale; if ( empty( $date ) || ! $date ) { return false; } list( $month, $day, $year ) = explode( ' ', $date ); $day = trim( $day, ',' ); $month = 1 + array_search( $month, array_values( $wp_locale->month ), true ); $time = mktime( 0, 0, 0, $month, (int) $day, (int) $year ); if ( 'U' === $return_format ) { return $time; } return date( $return_format, $time ); } /** * Sanitizes a date passed in the format of yyyy/mm/dd. * * @since 1.7.0.8 * * @param string $date The date to be sanitized. * @param string $return_format The date format to return. Default is U (timestamp). * @return string|false */ function charitable_sanitize_date_alt_format( $date, $return_format = 'U' ) { global $wp_locale; if ( empty( $date ) || ! $date ) { return false; } $date_array = explode( '/', $date ); if ( count( $date_array ) !== 3 ) { return false; } $day = intval( $date_array[ 2 ] ); $month = intval( $date_array[ 1 ] ); $year = intval( $date_array[ 0 ] ); $day = trim( $day, ',' ); $month = trim( $month, ',' ); $time = mktime( 0, 0, 0, $month, (int) $day, (int) $year ); if ( 'U' === $return_format ) { return $time; } return date( $return_format, $time ); } /** * Sanitizes a date passed in the format of mm/dd/yyyy for form filters. * * @since 1.7.0.11 * * @param string $date The date to be sanitized. * @return string|false */ function charitable_sanitize_date_filter_format( $date = false ) { if ( empty( $date ) || ! $date ) { return false; } // Convert the date to a timestamp. $timestamp = strtotime( $date ); // If it's not empty and not equal to -1, then convert it to the mm/dd/yyyy format. $return_value = ( empty( $timestamp ) && -1 !== $timestamp ) ? '' : date( 'Y/m/d', $timestamp ); return $return_value; } /** * Sanitizes a date passed in the format of mm/dd/yyyy for form filters. * * @since 1.7.0.11 * * @param string $date The date to be sanitized. * @return string|false */ function charitable_sanitize_date_export_format( $date = false ) { if ( empty( $date ) || ! $date ) { return false; } // Convert the date to a timestamp. $timestamp = strtotime( $date ); // If it's not empty and not equal to -1, then convert it to the mm/dd/yyyy format. $return_value = ( empty( $timestamp ) && -1 !== $timestamp ) ? '' : date( 'Y/m/d', $timestamp ); return $return_value; } /** * Return a string containing the correct number & type of placeholders. * * @since 1.5.0 * * @param int $count The number of placeholders to add. * @param string $placeholder Type of placeholder to insert. * @return string */ function charitable_get_query_placeholders( $count = 1, $placeholder = '%s' ) { $placeholders = array_fill( 0, $count, $placeholder ); return implode( ', ', $placeholders ); } /** * Return a list of pages in id=>title format for use in a select dropdown. * * @see get_pages * * @since 1.6.0 * * @param array $args Optional arguments to be passed to get_pages. * @return array */ function charitable_get_pages_options( $args = array() ) { $pages = get_pages( $args ); if ( ! $pages ) { return array(); } return array_combine( wp_list_pluck( $pages, 'ID' ), wp_list_pluck( $pages, 'post_title' ) ); } /** * Checks whether this is localhost. * * This is not fullproof. It uses a safelist of IP addresses. * * @since 1.6.14 * * @return boolean */ function charitable_is_localhost() { if ( false !== ( defined( 'CHARITABLE_FORCE_NO_LOCALHOST_WITH_STRIPE_CONNECT' ) && CHARITABLE_FORCE_NO_LOCALHOST_WITH_STRIPE_CONNECT ) ) { return false; } /** * Filter list of localhost IP addresses. * * @since 1.6.14 * * @param array $ip_addresses The list of IP addresses. */ $safelist = apply_filters( 'charitable_localhost_ips', array( '127.0.0.1', '::1', ) ); return in_array( $_SERVER['REMOTE_ADDR'], $safelist ); } /** * Check whether we are currently using a block theme. * * @since Charitable version 1.6.55 * * @return boolean */ function charitable_is_block_theme() { return function_exists( 'wp_is_block_theme' ) && wp_is_block_theme(); }