is_on() ) { $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' ); $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_CSS . trim( $path, '/' ) ) ); $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ) ); } wp_enqueue_style( $handle, plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $media ); } function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) { global $fs_core_logger; if ( $fs_core_logger->is_on() ) { $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' ); $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_JS . trim( $path, '/' ) ) ); $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ) ); } wp_enqueue_script( $handle, plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $in_footer ); } function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) { return plugins_url( plugin_basename( $img_dir . '/' . trim( $path, '/' ) ) ); } /* Request handlers. --------------------------------------------------------------------------------------------*/ /** * @param string $key * @param mixed $def * * @return mixed */ function fs_request_get( $key, $def = false ) { return isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def; } function fs_request_has( $key ) { return isset( $_REQUEST[ $key ] ); } function fs_request_get_bool( $key, $def = false ) { if ( ! isset( $_REQUEST[ $key ] ) ) { return $def; } if ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) { return true; } if ( 0 == $_REQUEST[ $key ] || 'false' === strtolower( $_REQUEST[ $key ] ) ) { return false; } return $def; } function fs_request_is_post() { return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) ); } function fs_request_is_get() { return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) ); } function fs_get_action( $action_key = 'action' ) { if ( ! empty( $_REQUEST[ $action_key ] ) ) { return strtolower( $_REQUEST[ $action_key ] ); } if ( 'action' == $action_key ) { $action_key = 'fs_action'; if ( ! empty( $_REQUEST[ $action_key ] ) ) { return strtolower( $_REQUEST[ $action_key ] ); } } return false; } function fs_request_is_action( $action, $action_key = 'action' ) { return ( strtolower( $action ) === fs_get_action( $action_key ) ); } /** * @author Vova Feldman (@svovaf) * @since 1.0.0 * * @since 1.2.1.5 Allow nonce verification. * * @param string $action * @param string $action_key * @param string $nonce_key * * @return bool */ function fs_request_is_action_secure( $action, $action_key = 'action', $nonce_key = 'nonce' ) { if ( strtolower( $action ) !== fs_get_action( $action_key ) ) { return false; } $nonce = ! empty( $_REQUEST[ $nonce_key ] ) ? $_REQUEST[ $nonce_key ] : ''; if ( empty( $nonce ) || ( false === wp_verify_nonce( $nonce, $action ) ) ) { return false; } return true; } function fs_is_plugin_page( $menu_slug ) { return ( is_admin() && $_REQUEST['page'] === $menu_slug ); } /* Core UI. --------------------------------------------------------------------------------------------*/ /** * @param string $slug * @param string $page * @param string $action * @param string $title * @param array $params * @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( $slug, $page, $action, $title, $params = array(), $is_primary = true, $icon_class = false, $confirmation = false, $method = 'GET' ) { echo fs_ui_get_action_button( $slug, $page, $action, $title, $params, $is_primary, $icon_class, $confirmation, $method ); } /** * @author Vova Feldman (@svovaf) * @since 1.1.7 * * @param string $slug * @param string $page * @param string $action * @param string $title * @param array $params * @param bool $is_primary * @param string|bool $icon_class Optional class for an icon. * @param string|bool $confirmation Optional confirmation message before submit. * @param string $method * * @return string */ function fs_ui_get_action_button( $slug, $page, $action, $title, $params = array(), $is_primary = true, $icon_class = false, $confirmation = false, $method = 'GET' ) { // Prepend icon (if set). $title = ( is_string( $icon_class ) ? ' ' : '' ) . $title; if ( is_string( $confirmation ) ) { return sprintf( '
%s%s
', freemius( $slug )->_get_admin_page_url( $page, $params ), $method, $action, wp_nonce_field( $action, '_wpnonce', true, false ), 'button' . ( $is_primary ? ' button-primary' : '' ), $confirmation, $title ); } else if ( 'GET' !== strtoupper( $method ) ) { return sprintf( '
%s%s
', freemius( $slug )->_get_admin_page_url( $page, $params ), $method, $action, wp_nonce_field( $action, '_wpnonce', true, false ), 'button' . ( $is_primary ? ' button-primary' : '' ), $title ); } else { return sprintf( '%s', wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ), 'button' . ( $is_primary ? ' button-primary' : '' ), $title ); } } function fs_ui_action_link( $slug, $page, $action, $title, $params = array() ) { ?> $value ) { $lower_param = strtolower( $parameter ); // Skip ignore params. if ( in_array( $lower_param, $ignore_params ) || ( false !== $params_prefix && fs_starts_with( $lower_param, $params_prefix ) ) ) { continue; } if ( is_array( $value ) ) { // If two or more parameters share the same name, they are sorted by their value // Ref: Spec: 9.1.1 (1) natsort( $value ); foreach ( $value as $duplicate_value ) { $pairs[] = $lower_param . '=' . $duplicate_value; } } else { $pairs[] = $lower_param . '=' . $value; } } if ( 0 === count( $pairs ) ) { return ''; } return implode( "&", $pairs ); } } if ( ! function_exists( 'fs_urlencode_rfc3986' ) ) { /** * @author Vova Feldman (@svovaf) * @since 1.1.3 * * @param string|string[] $input * * @return array|mixed|string */ function fs_urlencode_rfc3986( $input ) { if ( is_array( $input ) ) { return array_map( 'fs_urlencode_rfc3986', $input ); } else if ( is_scalar( $input ) ) { return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $input ) ) ); } return ''; } } #endregion Url Canonization ------------------------------------------------------------------ function fs_download_image( $from, $to ) { $ch = curl_init( $from ); $fp = fopen( fs_normalize_path( $to ), 'wb' ); curl_setopt( $ch, CURLOPT_FILE, $fp ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_exec( $ch ); curl_close( $ch ); fclose( $fp ); } /* General Utilities --------------------------------------------------------------------------------------------*/ /** * Sorts an array by the value of the priority key. * * @author Daniel Iser (@danieliser) * @since 1.1.7 * * @param $a * @param $b * * @return int */ function fs_sort_by_priority( $a, $b ) { // If b has a priority and a does not, b wins. if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) { return 1; } // If b has a priority and a does not, b wins. elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) { return - 1; } // If neither has a priority or both priorities are equal its a tie. elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) { return 0; } // If both have priority return the winner. return ( $a['priority'] < $b['priority'] ) ? - 1 : 1; } #-------------------------------------------------------------------------------- #region Localization #-------------------------------------------------------------------------------- /** * @author Vova Feldman * @since 1.2.1.6 * * @param string $key * @param string $slug * * @return string */ function fs_esc_attr($key, $slug) { return esc_attr( __fs( $key, $slug ) ); } /** * @author Vova Feldman * @since 1.2.1.6 * * @param string $key * @param string $slug */ function fs_esc_attr_echo($key, $slug) { echo esc_attr( __fs( $key, $slug ) ); } /** * @author Vova Feldman * @since 1.2.1.6 * * @param string $key * @param string $slug * * @return string */ function fs_esc_js($key, $slug) { return esc_js( __fs( $key, $slug ) ); } /** * @author Vova Feldman * @since 1.2.1.6 * * @param string $key * @param string $slug */ function fs_esc_js_echo($key, $slug) { echo esc_js( __fs( $key, $slug ) ); } /** * @author Vova Feldman * @since 1.2.1.6 * * @param string $key * @param string $slug */ function fs_json_encode_echo($key, $slug) { echo json_encode( __fs( $key, $slug ) ); } /** * @author Vova Feldman * @since 1.2.1.6 * * @param string $key * @param string $slug * * @return string */ function fs_esc_html($key, $slug) { return esc_html( __fs( $key, $slug ) ); } /** * @author Vova Feldman * @since 1.2.1.6 * * @param string $key * @param string $slug */ function fs_esc_html_echo($key, $slug) { echo esc_html( __fs( $key, $slug ) ); } #endregion