Overview

Namespaces

  • None
  • VSP
    • Core
      • Abstracts
      • Interfaces
      • Traits
        • WC_Compatibility
    • Deprecation
    • Helper
    • Modules
      • Addons
      • Logger

Classes

  • VSP\Ajax
  • VSP\Ajaxer
  • VSP\Base
  • VSP\Cache
  • VSP\Core\Abstracts\Addon
  • VSP\Core\Abstracts\Log_Handler
  • VSP\Core\Abstracts\Plugin_Settings
  • VSP\Core\Instance_Handler
  • VSP\Deprecation\Actions
  • VSP\Deprecation\Filters
  • VSP\Error
  • VSP\Framework
  • VSP\Framework_Admin
  • VSP\Framework_Base
  • VSP\Framework_Modules
  • VSP\Helper
  • VSP\Helper\Price_Calculation
  • VSP\Modules\Addons
  • VSP\Modules\Addons\Admin
  • VSP\Modules\Addons\Core
  • VSP\Modules\Logger
  • VSP\Modules\Logger\File_Handler
  • VSP\Modules\Logger\Levels
  • VSP\Modules\Shortcode
  • VSP\Modules\System_Logs
  • VSP\Modules\System_Tools
  • VSP\Modules\WPOnion
  • VSP\Setup
  • VSP\WC_Compatibility
  • VSP_Framework_Loader

Interfaces

  • VSP\Core\Interfaces\Log_Handler
  • VSP\Core\Interfaces\Logger

Traits

  • VSP\Core\Traits\Array_Helper
  • VSP\Core\Traits\Framework
  • VSP\Core\Traits\String_Helper
  • VSP\Core\Traits\URL
  • VSP\Core\Traits\WC_Compatibility\Product
  • VSP\Core\Traits\WC_Compatibility\Version
  • VSP\Core\Traits\WC_Helper
  • VSP\Core\Traits\WP

Functions

  • vsp_add_wc_required_notice
  • vsp_ajax_action
  • vsp_current_screen
  • vsp_date_format
  • vsp_delete_cache
  • vsp_doing_it_wrong
  • vsp_force_load
  • vsp_force_load_vendors
  • vsp_get_cache
  • vsp_get_cache_defaults
  • vsp_get_file_paths
  • vsp_get_logger
  • vsp_get_time_in_seconds
  • vsp_is_admin
  • vsp_is_ajax
  • vsp_is_cron
  • vsp_is_error
  • vsp_is_frontend
  • vsp_is_heartbeat
  • vsp_is_json
  • vsp_is_request
  • vsp_is_screen
  • vsp_json_last_error
  • vsp_list_files
  • vsp_list_log_files
  • vsp_load_core_assets
  • vsp_load_file
  • vsp_log_msg
  • vsp_logger
  • vsp_make_log_list_tree
  • vsp_maybe_load
  • vsp_placeholder_img
  • vsp_print_log_files_ui
  • vsp_register_assets
  • vsp_register_plugin
  • vsp_send_callback_error
  • vsp_send_callback_success
  • vsp_send_json_callback
  • vsp_set_cache
  • vsp_set_time_limit
  • vsp_slashit
  • vsp_time_format
  • vsp_unslashit
  • vsp_url
  • vsp_validate_required_plugin
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 
<?php

defined( 'ABSPATH' ) || exit;

use VSP\Modules\Logger;
use VSP\Modules\Logger\File_Handler;

if ( ! function_exists( 'vsp_current_screen' ) ) {
    /**
     * Returns Either Full Screen Object or just the screen id.
     *
     * @param bool $only_id .
     *
     * @return bool|string|\WP_Screen
     */
    function vsp_current_screen( $only_id = true ) {
        $screen = get_current_screen();
        if ( false === $only_id ) {
            return $screen;
        }
        return isset( $screen->id ) ? $screen->id : false;
    }
}

if ( ! function_exists( 'vsp_is_screen' ) ) {
    /**
     * Checks provided Screen ID if its current screen.
     *
     * @param string $check_screen .
     * @param string $current_screen .
     *
     * @return bool
     */
    function vsp_is_screen( $check_screen = '', $current_screen = '' ) {
        if ( ! empty( $check_screen ) ) {
            $current_screen = ( empty( $current_screen ) ) ? vsp_current_screen( true ) : $current_screen;

            if ( is_array( $check_screen ) ) {
                return in_array( $current_screen, $check_screen, true );
            }
            return ( $check_screen === $current_screen );
        }
        return false;
    }
}

if ( ! function_exists( 'vsp_get_time_in_seconds' ) ) {
    /**
     * Returns Cache Time in numeric values
     *
     * @param string $time .
     *
     * @return float|int
     */
    function vsp_get_time_in_seconds( $time ) {
        $times = explode( '_', $time );
        if ( ! is_array( $times ) ) {
            return $time;
        }

        $time_limit = $times[0];
        $type       = $times[1];
        $time_limit = intval( $time_limit );

        switch ( $type ) {
            case 'seconds':
            case 'second':
            case 'sec':
                $time = $time_limit;
                break;

            case 'minute':
            case 'minutes':
            case 'min':
                $time = $time_limit * MINUTE_IN_SECONDS;
                break;

            case 'hour':
            case 'hours':
            case 'hrs':
                $time = $time_limit * HOUR_IN_SECONDS;
                break;

            case 'days':
            case 'day':
                $time = $time_limit * DAY_IN_SECONDS;
                break;

            case 'weeks':
            case 'week':
                $time = $time_limit * WEEK_IN_SECONDS;
                break;

            case 'month':
            case 'months':
                $time = $time_limit * MONTH_IN_SECONDS;
                break;

            case 'year':
            case 'years':
                $time = $time_limit * YEAR_IN_SECONDS;
                break;
        }

        return intval( $time );
    }
}

if ( ! function_exists( 'vsp_placeholder_img' ) ) {
    /**
     * Returns VSP Placeholder Image
     *
     * @return string
     */
    function vsp_placeholder_img() {
        return apply_filters( 'vsp/placeholder_img', vsp_url( 'assets/img/noimage.png' ) );
    }
}

if ( ! function_exists( 'vsp_set_time_limit' ) ) {
    /**
     * Wrapper for set_time_limit to see if it is enabled.
     *
     * @param int $limit Time limit.
     */
    function vsp_set_time_limit( $limit = 0 ) {
        // @codingStandardsIgnoreStart
        if ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
            @set_time_limit( $limit );
        }
        // @codingStandardsIgnoreEnd
    }
}

if ( ! function_exists( 'vsp_doing_it_wrong' ) ) {
    /**
     * Wrapper for vsp_doing_it_wrong.
     *
     * @param string $function Function used.
     * @param string $message Message to log.
     * @param string $version Version the message was added in.
     */
    function vsp_doing_it_wrong( $function, $message, $version ) {
        // @codingStandardsIgnoreStart
        $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
        if ( is_ajax() ) {
            do_action( 'doing_it_wrong_run', $function, $message, $version );
            vsp_log_msg( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
        } else {
            _doing_it_wrong( $function, $message, $version );
        }
        // @codingStandardsIgnoreEnd
    }
}

if ( ! function_exists( 'vsp_get_logger' ) ) {
    /**
     * Use the vsp_logging_class filter to change the logging class.
     * You may provide one of the following:
     *     - a class name which will be instantiated as `new $class` with no arguments
     *     - an instance which will be used directly as the logger
     * In either case, the class or instance *must* implement WC_Logger_Interface.
     *
     * @param bool $subpath
     * @param bool $file_name
     * @param bool $filesize
     *
     * @return \VSP\Modules\Logger
     *
     */
    function vsp_get_logger( $subpath = false, $file_name = null, $filesize = false ) {
        $class      = apply_filters( 'vsp/log/class', '\VSP\Modules\Logger' );
        $implements = class_implements( $class );
        if ( is_array( $implements ) && in_array( 'VSP\Core\Interfaces\Logger', $implements, true ) ) {
            $logger = ( is_object( $class ) ) ? $class : new $class( array( new File_Handler( $subpath, $file_name, $filesize ) ) );
        } else {
            /* translators: 1: class name 2: woocommerce_logging_class 3: WC_Logger_Interface */
            $smgs = sprintf( esc_html__( 'The class %1$s provided by %2$s filter must implement %3$s.', 'vsp-framework' ), '<code>' . esc_html( is_object( $class ) ? get_class( $class ) : $class ) . '</code>', '<code>vsp_logging_class</code>', '<code>\VSP\Core\Interfaces\Logger</code>' );
            vsp_doing_it_wrong( __FUNCTION__, $smgs, '3.0' );
            $logger = new Logger( array( new File_Handler( $subpath, $file_name, $filesize ) ) );
        }
        return $logger;
    }
}

if ( ! function_exists( 'vsp_logger' ) ) {
    /**
     * Returns An Valid Instance Of Logger To Handle Logs From VSP Framework.
     *
     * @return \VSP\Modules\Logger
     */
    function vsp_logger() {
        static $logger = null;
        if ( null === $logger ) {
            $logger = vsp_get_logger( false, null, false );
        }
        return $logger;
    }
}

if ( ! function_exists( 'vsp_log_msg' ) ) {
    /**
     * Logs Give message to a given handler
     *
     * @param string|array $messages
     * @param string       $type
     * @param bool         $handler
     * @param array        $context
     *
     * @return bool
     */
    function vsp_log_msg( $messages = '', $type = 'critical', $handler = false, $context = array() ) {
        $types = array( 'critical', 'emergency', 'alert', 'error', 'warning', 'notice', 'info', 'debug' );

        if ( ! in_array( $type, $types, true ) ) {
            return false;
        }

        if ( is_array( $messages ) ) {
            $messages = implode( PHP_EOL, $messages );
        }

        $messages .= PHP_EOL;

        if ( false === $handler ) {
            $handler = vsp_logger();
        }

        if ( $handler instanceof Logger && method_exists( $handler, $type ) ) {
            $handler->$type( $messages, $context );
            return true;
        } elseif ( vsp_logger() instanceof Logger && method_exists( vsp_logger(), $type ) ) {
            $msg     = array_merge( array( esc_html__( 'Tried To Log A Message But Failed Got unknown Handler', 'vsp-framework' ) ), wp_debug_backtrace_summary( null, 0, false ) );
            $content = <<<TEXT

//////////////////////// = VSP Critical = /////////////////////////////////
${msg}
${messages}
/////////////////////////////////////////////////////////////////

TEXT;

            vsp_log_msg( $content, 'notice', vsp_logger() );
        }
        return false;
    }
}

if ( ! function_exists( 'vsp_date_format' ) ) {
    /**
     * Returns Site's Date Format From Database
     *
     * @return mixed
     */
    function vsp_date_format() {
        return apply_filters( 'vsp/date/format', get_option( 'date_format' ) );
    }
}

if ( ! function_exists( 'vsp_time_format' ) ) {
    /**
     * Returns Site's Time Format From Database
     *
     * @return mixed
     */
    function vsp_time_format() {
        return apply_filters( 'vsp/time/format', get_option( 'time_format' ) );
    }
}

if ( ! function_exists( 'vsp_json_last_error' ) ) {
    /**
     * Checks if last json had any errors.
     *
     * @return string|null
     */
    function vsp_json_last_error() {
        switch ( function_exists( 'json_last_error' ) ? json_last_error() : -1 ) {
            case JSON_ERROR_NONE:
                return null;
                break;
            case JSON_ERROR_DEPTH:
                return esc_html__( 'Maximum stack depth exceeded', 'vsp-framework' );
                break;
            case JSON_ERROR_STATE_MISMATCH:
                return esc_html__( 'Underflow or the modes mismatch', 'vsp-framework' );
                break;
            case JSON_ERROR_CTRL_CHAR:
                return esc_html__( 'Unexpected control character found', 'vsp-framework' );
                break;
            case JSON_ERROR_SYNTAX:
                return esc_html__( 'Syntax error, malformed JSON', 'vsp-framework' );
                break;
            case JSON_ERROR_UTF8:
                return esc_html__( 'Malformed UTF-8 characters, possibly incorrectly encoded', 'vsp-framework' );
                break;
            default:
                return esc_html__( 'Unknown error', 'vsp-framework' );
                break;
        }
    }
}

if ( ! function_exists( 'vsp_is_json' ) ) {
    /**
     * Checks If Given String is JSON.
     *
     * @param string $string
     *
     * @return bool
     */
    function vsp_is_json( $string = '' ) {
        if ( is_string( $string ) ) {
            json_decode( $string );
            return ( json_last_error() === JSON_ERROR_NONE );
        }
        return false;
    }
}

if ( ! function_exists( 'vsp_is_error' ) ) {
    /**
     * Checks if given instance is a \VSP_Error Instance.
     *
     * @param $thing
     *
     * @return bool
     */
    function vsp_is_error( $thing ) {
        return ( $thing instanceof \VSP\Error );
    }
}
API documentation generated by ApiGen