= 0 ) ? '+' : '-', abs( $offset / 3600 ), abs( $offset % 3600 ) / 60 ); } } /** * Parse arguments with defaults recursively. * * @param array|object $args Arguments to parse. * @param array|object $defaults Default set. * * @return array|object Parsed arguments. * @see wp_parse_args() * */ function absp_parse_args_recursive( $args, $defaults = [] ) { if ( is_object( $args ) ) { $merged = get_object_vars( $args ); } elseif ( is_array( $args ) ) { $merged = $args; } else { wp_parse_str( $args, $merged ); } if ( is_object( $defaults ) ) { $defaults = get_object_vars( $defaults ); } if ( ! is_array( $defaults ) || empty( $defaults ) ) { return $merged; } if ( empty( $merged ) ) { return $defaults; } foreach ( $defaults as $key => &$value ) { if ( is_array( $value ) && isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ) { $merged[ $key ] = absp_parse_args_recursive( $merged[ $key ], $value ); } elseif ( is_numeric( $key ) ) { if ( ! in_array( $value, $merged ) ) { $merged[] = $value; } } else { $merged[ $key ] = $value; } } return $merged; } function absp_usort_position( $a, $b ) { return isset( $a['position'], $b['position'] ) ? $a['position'] > $b['position'] : 1; } /** * Retrieve or display nonce hidden field for forms. * Extend WordPress core wp_nonce_field for id conflict. * * @param int|string $action Optional. Action name. Default -1. * @param string $name Optional. Nonce name. Default '_wpnonce'. * @param bool $referer Optional. Whether to set the referer field for validation. Default true. * @param bool $echo Optional. Whether to display or return hidden form field. Default true. * * @return string Nonce field HTML markup. * @see wp_nonce_field() * */ function absp_nonce_field( $action = - 1, $name = '_wpnonce', $referer = true, $echo = true ) { $name = esc_attr( $name ); $id = wp_unique_id( $name ); $nonce_field = ''; if ( $referer ) { $nonce_field .= wp_referer_field( false ); } if ( $echo ) { echo $nonce_field; // phpcs:ignore } return $nonce_field; } /** * Common Kses for Widget Title. * * @param string $string string for stripping unwanted tag from. * * @return string|void */ function absp_widget_title_kses( $string, $echo = true ) { $allowed = [ 'span' => [ 'style' => [], 'class' => [], ], 'b' => [ 'style' => [], 'class' => [], ], 'strong' => [ 'style' => [], 'class' => [], ], 'u' => [ 'style' => [], 'class' => [], ], 'i' => [ 'style' => [], 'class' => [], ], 'br' => [ 'style' => [], 'class' => [], ], ]; $allowed = apply_filters( 'absp/widgets/the_title/allowed_html', $allowed ); if ( ! $echo ) { return wp_kses( $string, $allowed ); } echo wp_kses( $string, $allowed ); } if ( ! function_exists( 'wp_kses_post_e' ) ) { /** * Sanitizes content for allowed HTML tags for large (post) content. * * @param string $data Content to filter. * * @return void */ function wp_kses_post_e( $data ) { echo wp_kses_post( $data ); } } if ( ! function_exists( 'esc_tag' ) ) { function esc_tag( $tag ) { return Utils::validate_html_tag( $tag ); } } function absp_tag_name( $tag ) { echo Utils::validate_html_tag( $tag ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * @param string $tag * @param string $attribute_key * @param AbsoluteAddons\Absp_Widget $widget_instance */ function absp_tag_start( $tag, $attribute_key = '', $widget_instance = null ) { if ( $attribute_key && $widget_instance && method_exists( $widget_instance, 'print_attribute' ) ) { ?>< print_attribute( $attribute_key )?>><>>', ']]>', $text ); $text = wp_trim_words( $text, $length, $excerpt_more ); } return $text; } /** * Converts a string (e.g. 'yes' or 'no') to a bool. * * @param string|bool $string String to convert. If a bool is passed it will be returned as-is. * * @return bool */ function absp_string_to_bool( $string ) { return is_bool( $string ) ? $string : ( 'yes' === strtolower( $string ) || 1 === $string || 'true' === strtolower( $string ) || '1' === $string ); } /** * Remove trailing and leading slash from file name or path. * * @param string $path Name of the file or directory. * * @return string */ function absp_clean_file_path( $path ) { $path = ltrim( $path, '/\\' ); return untrailingslashit( $path ); } function absp_plugin_install_url( $slug ) { return admin_url( 'plugin-install.php?s=' . $slug . '&tab=search&type=term&absp_dependency=' . $slug ); } /** * Filter plugin-install-api results to help the user find correct plugin for widget dependency. * * @param object|WP_Error $result * @param string $action * @param object $args * * @return object|WP_Error * @noinspection PhpUnusedParameterInspection */ function absp_plugin_api_results_dependency_filter( $result, $action, $args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed $is_dep_check = isset( $_GET['absp_dependency'] ) && ! empty( $_GET['absp_dependency'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( $is_dep_check && ! is_wp_error( $result ) ) { $plugins = array_filter( $result->plugins, function ( $plugin ) use ( $args ) { return $args->search === $plugin['slug']; } ); if ( ! empty( $plugins ) ) { $result->plugins = $plugins; } $result->info = [ 'page' => 1, 'pages' => 1, 'results' => 1, ]; unset( $plugins ); } return $result; } /** * Check if a plugin is installed. * * @param string $basename Plugin dir/main-file path. * * @return bool */ function absp_is_plugin_installed( $basename ) { if ( ! function_exists( 'get_plugins' ) ) { include_once ABSPATH . '/wp-admin/includes/plugin.php'; } $plugins = get_plugins(); return isset( $plugins[ $basename ] ); } /** * Determines whether a plugin is active. * * @param string $plugin Path to the plugin file relative to the plugins directory. * * @return bool True, if in the active plugins list. False, not in the list. * @uses is_plugin_active() */ function absp_is_plugin_active( $plugin ) { if ( ! function_exists( 'is_plugin_active' ) ) { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } return is_plugin_active( $plugin ); } /** * Determines whether the plugin is inactive. * * Reverse of absp_is_plugin_active(). Used as a callback. * * @param string $plugin Path to the plugin file relative to the plugins directory. * * @return bool True if inactive. False if active. * @see absp_is_plugin_active() * */ function absp_is_plugin_inactive( $plugin ) { return ! absp_is_plugin_active( $plugin ); } /** * Get full path for file relative to plugin directory. * * @param string $path File or path to resolve. * * @return string */ function absp_plugin_path( $path ) { return ABSOLUTE_ADDONS_PATH . absp_clean_file_path( $path ); } /** * Get full url for file relative to this plugin directory. * * @param string $path Name of the file or directory to get the url for. * @param bool $echo echo or return default echo. * * @return string|void */ function absp_plugin_url( $path, $echo = true ) { $url = plugins_url( absp_clean_file_path( $path ), ABSOLUTE_ADDONS_FILE ); if ( ! $echo ) { return $url; } else { echo esc_url( $url ); } } /** * Get Default Placeholder url * * @param string $file_name Optional. File name * * @return string */ function absp_get_default_placeholder( $file_name = '' ) { if ( empty( $file_name ) ) { return Elementor\Utils::get_placeholder_image_src(); } $file_name = absp_clean_file_path( $file_name ); $file_name = 'assets/images/placeholder/' . $file_name; if ( ! file_exists( absp_plugin_path( $file_name ) ) ) { return ''; } return absp_plugin_url( $file_name, false ); } /** * @param string $file_name * @param bool $echo * * @return string|void */ function absp_default_placeholder_src( $file_name = '', $echo = true ) { if ( ! $echo ) { return absp_get_default_placeholder( $file_name ); } else { echo esc_url( absp_get_default_placeholder( $file_name ) ); } } /** * Get Default Placeholder Args for widget * * @return array */ function absp_get_placeholder() { return [ 'url' => Elementor\Utils::get_placeholder_image_src() ]; } /** * @param $regular_price * * @return array */ function absp_regular_pricing_price_format( $regular_price ) { $regular_price_float = number_format( $regular_price, 2, '.', '' ); $regular_price_parts = explode( '.', $regular_price_float ); return [ 'price_original_value' => $regular_price, 'price_float_value' => $regular_price_float, 'price_only_int' => $regular_price_parts[0], 'price_after_decimal_point' => $regular_price_parts[1], 'price_decimal_point' => _x( '.', 'Price Decimal Point', 'absolute-addons' ), ]; } /** * @param $price * * @return array */ function absp_pricing_price_format( $price ) { $price_float = number_format( $price, 2, '.', '' ); $price_parts = explode( '.', $price_float ); return [ 'original_value' => $price, 'float_value' => $price_float, 'only_int' => $price_parts[0], 'after_decimal_point' => $price_parts[1], 'decimal_point' => _x( '.', 'Price Table Decimal Point', 'absolute-addons' ), 'period_separator' => _x( '/', 'Pricing Table Period Separator', 'absolute-addons' ), ]; } function absp_remote_get( $url, $args = [] ) { if ( function_exists( 'vip_safe_wp_remote_get' ) ) { return vip_safe_wp_remote_get( $url, $args ); } else { return wp_remote_get( $url, $args ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get } } function absp_get_wp_time( $time = null ) { if ( null === $time ) { $time = time(); } elseif ( ! is_numeric( $time ) ) { $time = strtotime( $time ); } return false !== $time ? $time + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) : time(); } // End of file helper.php.