true, 'scroll_top_mobile_enable' => true, 'scroll_top_async_enable' => true, 'scroll_top_type' => 'icon', 'scroll_top_text' => esc_html__( 'Back to Top', 'scroll-top' ), 'scroll_top_position' => 'right', 'scroll_top_color' => '#ffffff', 'scroll_top_bg_color' => '#000000', 'scroll_top_radius' => 'rounded', 'scroll_top_animation' => 'fade', 'scroll_top_speed' => 300, 'scroll_top_distance' => 300, 'scroll_top_target' => '', 'scroll_top_css' => '', ); // Allow dev to filter the default settings. return apply_filters( 'scroll_top_default_settings', $default_settings ); } /** * Function for quickly grabbing settings for the plugin without having to call get_option() * every time we need a setting. * * @param string $option The option name. * @return string */ function scroll_top_get_plugin_settings( $option = '' ) { $settings = get_option( 'scroll_top_plugin_settings', scroll_top_get_default_settings() ); return isset( $settings[ $option ] ) ? $settings[ $option ] : false; } /** * Loads the scripts for the plugin. */ function scroll_top_load_scripts() { // Get the enable option. $enable = scroll_top_get_plugin_settings( 'scroll_top_enable' ); // Check if scroll top enable. if ( $enable ) { // Load the plugin front-end style. wp_enqueue_style( 'scroll-top-css', trailingslashit( ST_ASSETS ) . 'css/scroll-top.css', null, ST_VERSION ); // Load the jQuery plugin. wp_enqueue_script( 'scroll-top-js', trailingslashit( ST_ASSETS ) . 'js/jquery.scrollUp.min.js', array( 'jquery' ), ST_VERSION, true ); } } add_action( 'wp_enqueue_scripts', 'scroll_top_load_scripts' ); /** * Async javascript. * * @param string $tag The script tag. * @param string $handle The script handle. * @since 1.5 */ function scroll_top_async_scripts( $tag, $handle ) { // Get the async option value. $async = scroll_top_get_plugin_settings( 'scroll_top_async_enable' ); if ( ! $async || 'scroll-top-js' !== $handle ) { return $tag; } return str_replace( ' src', ' async defer src', $tag ); } add_filter( 'script_loader_tag', 'scroll_top_async_scripts', 10, 2 ); /** * Initialize the scrollup jquery plugin. */ function scroll_top_scrollup_init() { // Get the plugin settings value. $enable = scroll_top_get_plugin_settings( 'scroll_top_enable' ); $speed = scroll_top_get_plugin_settings( 'scroll_top_speed' ); $dist = scroll_top_get_plugin_settings( 'scroll_top_distance' ); $target = scroll_top_get_plugin_settings( 'scroll_top_target' ); $animate = scroll_top_get_plugin_settings( 'scroll_top_animation' ); $type = scroll_top_get_plugin_settings( 'scroll_top_type' ); $text = scroll_top_get_plugin_settings( 'scroll_top_text' ); // Scroll top type. $scroll_type = ''; if ( 'text' === $type ) { $scroll_type = esc_attr( $text ); } else { $scroll_type = ''; } // Scroll target. $scroll_target = ''; if ( ! empty( $target ) ) { $scroll_target = $target; } // Loads the scroll top. if ( $enable ) { echo ' ' . "\n"; } } add_action( 'wp_footer', 'scroll_top_scrollup_init', 99 ); /** * Custom inline css for plugin usage. */ function scroll_top_custom_css() { // Get the plugin settings value. $enable = scroll_top_get_plugin_settings( 'scroll_top_enable' ); $mobile = scroll_top_get_plugin_settings( 'scroll_top_mobile_enable' ); $color = scroll_top_get_plugin_settings( 'scroll_top_color' ); $bgcolor = scroll_top_get_plugin_settings( 'scroll_top_bg_color' ); $radius = scroll_top_get_plugin_settings( 'scroll_top_radius' ); $position = scroll_top_get_plugin_settings( 'scroll_top_position' ); $type = scroll_top_get_plugin_settings( 'scroll_top_type' ); $css = scroll_top_get_plugin_settings( 'scroll_top_css' ); // Border radius. $scroll_radius = '0'; if ( 'rounded' === $radius ) { $scroll_radius = '3px'; } elseif ( 'circle' === $radius ) { $scroll_radius = '50%'; } // Scroll top position. $scroll_position = ''; if ( 'right' === $position ) { $scroll_position = 'right:20px;'; } else { $scroll_position = 'left:20px;'; } // Scroll top font-size. $scroll_fontsize = ''; if ( 'text' === $type ) { $scroll_fontsize = 'font-size: 15px; width: auto !important; height: auto !important; padding: 5px 10px; text-decoration: none; color: ' . esc_attr( $color ) . ''; } // Enable on mobile. $scroll_mobile = ''; if ( false === $mobile ) { $scroll_mobile = '@media (max-width: 567px) { #scrollUp { display: none !important; } };'; } if ( $enable ) { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } } add_action( 'wp_head', 'scroll_top_custom_css' );