: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
if ( ! defined( 'ABSPATH' ) ) {
if ( ! function_exists( 'fs_dummy' ) ) {
--------------------------------------------------------------------------------------------*/
if ( ! function_exists( 'fs_get_url_daily_cache_killer' ) ) {
function fs_get_url_daily_cache_killer() {
return date( '\YY\Mm\Dd' );
--------------------------------------------------------------------------------------------*/
if ( ! function_exists( 'fs_get_template_path' ) ) {
function fs_get_template_path( $path ) {
return WP_FS__DIR_TEMPLATES . '/' . trim( $path, '/' );
function fs_include_template( $path, &$params = null ) {
include fs_get_template_path( $path );
function fs_include_once_template( $path, &$params = null ) {
include_once fs_get_template_path( $path );
function fs_require_template( $path, &$params = null ) {
require fs_get_template_path( $path );
function fs_require_once_template( $path, &$params = null ) {
require_once fs_get_template_path( $path );
function fs_get_template( $path, &$params = null ) {
require fs_get_template_path( $path );
/* Scripts and styles including.
--------------------------------------------------------------------------------------------*/
if ( ! function_exists( 'fs_asset_url' ) ) {
* Generates an absolute URL to the given path. This function ensures that the URL will be correct whether the asset
* is inside a plugin's folder or a theme's folder.
* Path: C:/xampp/htdocs/fswp/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css
* URL: http://fswp:8080/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css
* Path: C:/xampp/htdocs/fswp/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css
* URL: http://fswp:8080/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css
* @author Leo Fajardo (@leorw)
* @param string $asset_abs_path Asset's absolute path.
* @return string Asset's URL.
function fs_asset_url( $asset_abs_path ) {
$wp_content_dir = fs_normalize_path( WP_CONTENT_DIR );
$asset_abs_path = fs_normalize_path( $asset_abs_path );
if ( 0 === strpos( $asset_abs_path, $wp_content_dir ) ) {
// Handle both theme and plugin assets located in the standard directories.
$asset_rel_path = str_replace( $wp_content_dir, '', $asset_abs_path );
$asset_url = content_url( fs_normalize_path( $asset_rel_path ) );
$wp_plugins_dir = fs_normalize_path( WP_PLUGIN_DIR );
if ( 0 === strpos( $asset_abs_path, $wp_plugins_dir ) ) {
// Try to handle plugin assets that may be located in a non-standard plugins directory.
$asset_rel_path = str_replace( $wp_plugins_dir, '', $asset_abs_path );
$asset_url = plugins_url( fs_normalize_path( $asset_rel_path ) );
// Try to handle theme assets that may be located in a non-standard themes directory.
$active_theme_stylesheet = get_stylesheet();
$wp_themes_dir = fs_normalize_path( trailingslashit( get_theme_root( $active_theme_stylesheet ) ) );
$asset_rel_path = str_replace( $wp_themes_dir, '', fs_normalize_path( $asset_abs_path ) );
$asset_url = trailingslashit( get_theme_root_uri( $active_theme_stylesheet ) ) . fs_normalize_path( $asset_rel_path );
if ( ! function_exists( 'fs_enqueue_local_style' ) ) {
function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) {
wp_enqueue_style( $handle, fs_asset_url( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ), $deps, $ver, $media );
if ( ! function_exists( 'fs_enqueue_local_script' ) ) {
function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) {
wp_enqueue_script( $handle, fs_asset_url( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ), $deps, $ver, $in_footer );
if ( ! function_exists( 'fs_img_url' ) ) {
function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) {
return ( fs_asset_url( $img_dir . '/' . trim( $path, '/' ) ) );
#--------------------------------------------------------------------------------
#region Request handlers.
#--------------------------------------------------------------------------------
if ( ! function_exists( 'fs_request_get_raw' ) ) {
* A helper function to fetch GET/POST user input with an optional default value when the input is not set.
* This function does not do sanitization. It is up to the caller to properly sanitize and validate the input.
* The return of this function is always unslashed.
* @param string|bool $type When set to 'get', it will look for the value passed via query string. When
* set to 'post', it will look for the value passed via the POST request's body. Otherwise,
* it will check if the parameter was passed using any of the mentioned two methods.
function fs_request_get_raw( $key, $def = false, $type = false ) {
if ( is_string( $type ) ) {
$type = strtolower( $type );
* Note to WordPress.org reviewers:
* This is a helper function to fetch GET/POST user input with an optional default value when the input is not set. The actual sanitization is done in the scope of the function's usage.
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$value = isset( $_POST[ $key ] ) ? $_POST[ $key ] : $def;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$value = isset( $_GET[ $key ] ) ? $_GET[ $key ] : $def;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$value = isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def;
// Don't unslash if the value itself is empty (empty string, null, empty array etc).
return empty( $value ) ? $value : wp_unslash( $value );
if ( ! function_exists( 'fs_sanitize_input' ) ) {
* Sanitizes input recursively (if an array).
* @uses sanitize_text_field()
function fs_sanitize_input( $input ) {
if ( is_array( $input ) ) {
foreach ( $input as $key => $value ) {
$input[ $key ] = fs_sanitize_input( $value );
// Allow empty values to pass through as-is, like `null`, `''`, `0`, `'0'` etc.
$input = empty( $input ) ? $input : sanitize_text_field( $input );
if ( ! function_exists( 'fs_request_get' ) ) {
* A helper method to fetch GET/POST user input with an optional default value when the input is not set.
* @author Vova Feldman (@svovaf)
* @note The return value is always sanitized with sanitize_text_field().
* @param string|bool $type Since 1.2.1.7 - when set to 'get' will look for the value passed via querystring, when
* set to 'post' will look for the value passed via the POST request's body, otherwise,
* will check if the parameter was passed in any of the two.
function fs_request_get( $key, $def = false, $type = false ) {
return fs_sanitize_input( fs_request_get_raw( $key, $def, $type ) );
if ( ! function_exists( 'fs_request_has' ) ) {
function fs_request_has( $key ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
return isset( $_REQUEST[ $key ] );
if ( ! function_exists( 'fs_request_get_bool' ) ) {
* A helper method to fetch GET/POST user boolean input with an optional default value when the input is not set.
* @author Vova Feldman (@svovaf)
function fs_request_get_bool( $key, $def = false ) {
$val = fs_request_get( $key, null );
} else if ( is_numeric( $val ) ) {
} else if ( 0 == $val ) {
} else if ( is_string( $val ) ) {
$val = strtolower( $val );
} else if ( 'false' === $val ) {
if ( ! function_exists( 'fs_request_is_post' ) ) {
function fs_request_is_post() {
return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
if ( ! function_exists( 'fs_request_is_get' ) ) {
function fs_request_is_get() {
return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
if ( ! function_exists( 'fs_get_action' ) ) {
function fs_get_action( $action_key = 'action' ) {
// phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( ! empty( $_REQUEST[ $action_key ] ) && is_string( $_REQUEST[ $action_key ] ) ) {
return strtolower( $_REQUEST[ $action_key ] );
if ( 'action' == $action_key ) {
$action_key = 'fs_action';
if ( ! empty( $_REQUEST[ $action_key ] ) && is_string( $_REQUEST[ $action_key ] ) ) {
return strtolower( $_REQUEST[ $action_key ] );
// phpcs:enable WordPress.Security.NonceVerification.Recommended
if ( ! function_exists( 'fs_request_is_action' ) ) {
function fs_request_is_action( $action, $action_key = 'action' ) {
return ( strtolower( $action ) === fs_get_action( $action_key ) );
if ( ! function_exists( 'fs_request_is_action_secure' ) ) {
* @author Vova Feldman (@svovaf)
* @since 1.2.1.5 Allow nonce verification.
* @param string $action_key
* @param string $nonce_key
function fs_request_is_action_secure(
if ( strtolower( $action ) !== fs_get_action( $action_key ) ) {
$nonce = ! empty( $_REQUEST[ $nonce_key ] ) ?
$_REQUEST[ $nonce_key ] :
( false === wp_verify_nonce( $nonce, $action ) )
if ( ! function_exists( 'fs_is_plugin_page' ) ) {
function fs_is_plugin_page( $page_slug ) {
return ( is_admin() && $page_slug === fs_request_get( 'page' ) );
if ( ! function_exists( 'fs_get_raw_referer' ) ) {
* Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
* Do not use for redirects, use {@see wp_get_referer()} instead.
* @return string|false Referer URL on success, false on failure.
function fs_get_raw_referer() {
if ( function_exists( 'wp_get_raw_referer' ) ) {
return wp_get_raw_referer();
if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
return wp_unslash( $_REQUEST['_wp_http_referer'] );
} else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
return wp_unslash( $_SERVER['HTTP_REFERER'] );
--------------------------------------------------------------------------------------------*/
if ( ! function_exists( 'fs_ui_action_button' ) ) {
* @param number $module_id
* @param string $button_class
* @param bool $is_primary
* @param string|bool $icon_class Optional class for an icon (since 1.1.7).
* @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7).
* @param string $method Since 1.1.7
* @uses fs_ui_get_action_button()
function fs_ui_action_button(
echo fs_ui_get_action_button(
if ( ! function_exists( 'fs_ui_get_action_button' ) ) {
* @author Vova Feldman (@svovaf)
* @param number $module_id
* @param string $button_class
* @param bool $is_primary
* @param string|bool $icon_class Optional class for an icon.
* @param string|bool $confirmation Optional confirmation message before submit.
function fs_ui_get_action_button(
// Prepend icon (if set).
$title = ( is_string( $icon_class ) ? '<i class="' . $icon_class . '"></i> ' : '' ) . $title;
if ( is_string( $confirmation ) ) {
return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="if (confirm(\'%s\')) this.parentNode.submit(); return false;">%s</a></form>',
freemius( $module_id )->_get_admin_page_url( $page, $params ),
wp_nonce_field( $action, '_wpnonce', true, false ),
'button' . ( ! empty( $button_class ) ? ' ' . $button_class : '' ) . ( $is_primary ? ' button-primary' : '' ) . ( $is_small ? ' button-small' : '' ),
} else if ( 'GET' !== strtoupper( $method ) ) {
return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="this.parentNode.submit(); return false;">%s</a></form>',
freemius( $module_id )->_get_admin_page_url( $page, $params ),
wp_nonce_field( $action, '_wpnonce', true, false ),
'button' . ( ! empty( $button_class ) ? ' ' . $button_class : '' ) . ( $is_primary ? ' button-primary' : '' ) . ( $is_small ? ' button-small' : '' ),
return sprintf( '<a href="%s" class="%s">%s</a></form>',
wp_nonce_url( freemius( $module_id )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ),
'button' . ( ! empty( $button_class ) ? ' ' . $button_class : '' ) . ( $is_primary ? ' button-primary' : '' ) . ( $is_small ? ' button-small' : '' ),
function fs_ui_action_link( $module_id, $page, $action, $title, $params = array() ) {
href="<?php echo wp_nonce_url( freemius( $module_id )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php
if ( ! function_exists( 'fs_get_entity' ) ) {
* @author Leo Fajardo (@leorw)