document.location.href="%s";', self::$_redirect ); // WPCS: xss ok. wp_die(); } /** * Attention * * @return string */ public static function _attention() { $msg = self::get_session_arr( '_attentions' ); self::set_session_arr( '_attentions' ); if ( 0 === count( $msg ) ) { return ''; } $msg = array_pop( $msg ); return self::_message( 'warning', $msg, __( 'Attention!', 'ti-woocommerce-wishlist' ) ); } /** * Error * * @return string */ public static function _error() { $msg = self::get_session_arr( '_errors' ); self::set_session_arr( '_errors' ); if ( 0 === count( $msg ) ) { return ''; } $msg = array_pop( $msg ); return self::_message( 'error', $msg[1], sprintf( __( 'Errors(%s)', 'ti-woocommerce-wishlist' ), $msg[0] ) ); } /** * Tip * * @return string */ public static function _tip() { $msg = self::get_session_arr( '_tips' ); self::set_session_arr( '_tips' ); if ( 0 === count( $msg ) ) { return ''; } $msg = array_pop( $msg ); return self::_message( 'info', $msg, __( 'Useful Tip', 'ti-woocommerce-wishlist' ) ); } /** * Message output * * @param string $_status Status for class. * @param string $_message Message text. * @param string $_header Header message. * * @return boolean */ private static function _message( $_status, $_message = '', $_header = '' ) { if ( empty( $_message ) ) { return false; } include self::file( 'message', '' ); return true; } /** * Include admin template * * @param string $name Name file. * @param string $type Folder section. * * @return boolean */ public static function file( $name, $type = 'admin' ) { if ( empty( $name ) ) { return self::file( 'null', '' ); } $path = array( 'views', $type, $name ); $path = implode( DIRECTORY_SEPARATOR, $path ); $path = sprintf( '%s%s.php', TINVWL_PATH, strtolower( $path ) ); if ( file_exists( $path ) ) { return $path; } return self::file( 'null', '' ); } /** * Ajax templates * * @param string $_template_name If empty returned JSON array. * @param array $_data Parameter for template. * @param string $_type Folder section. */ public static function ajax( $_template_name, $_data = array(), $_type = '' ) { if ( empty( $_template_name ) ) { if ( is_object( $_data ) || is_array( $_data ) ) { wp_send_json( $_data ); } $_data = (string) $_data; if ( empty( $_type ) ) { $_type = 'text/html'; } header( sprintf( 'Content-Type: %s', $_type ) ); echo $_data; // WPCS: xss ok. } else { if ( is_array( $_template_name ) ) { $_template_name = implode( '-', $_template_name ); } $_type = 'text/html'; header( sprintf( 'Content-Type: %s', $_type ) ); self::view( $_template_name, $_data ); } wp_die(); } /** * Create global template * * @param string $_template_name Name file. * @param array $_data Parameter for template. */ public static function render( $_template_name, $_data = array() ) { $_data = apply_filters( 'tinvwl_view_data_general', $_data ); self::init(); $_header = empty( $_data['_header'] ) ? '' : $_data['_header']; $_footer = empty( $_data['_footer'] ) ? '' : $_data['_footer']; include self::file( 'general', '' ); } /** * Create template * * @param string $_template_name Name file. * @param array $_data Parameter for template. * @param string $_type Folder section. */ public static function view( $_template_name, $_data = array(), $_type = 'admin' ) { if ( is_array( $_template_name ) ) { $_template_name = implode( '-', $_template_name ); } if ( is_string( $_template_name ) ) { $_data = apply_filters( 'tinvwl_view_data_' . $_template_name, $_data ); } if ( array_key_exists( 'options', $_data ) ) { TInvWL_Form::setoptions( $_data['options'] ); unset( $_data['options'] ); } if ( array_key_exists( 'value', $_data ) ) { TInvWL_Form::setvalue( $_data['value'] ); unset( $_data['value'] ); } extract( $_data ); // @codingStandardsIgnoreLine WordPress.VIP.RestrictedFunctions.extract if ( self::$debug && is_string( $_template_name ) ) { printf( "\r\n\r\n", esc_attr( @$_template_name ) ); // @codingStandardsIgnoreLine Generic.PHP.NoSilencedErrors.Discouraged } if ( is_object( $_template_name ) ) { $_template_name->Run(); } else { include self::file( $_template_name, $_type ); } if ( self::$debug && is_string( $_template_name ) ) { printf( "\r\n\r\n", esc_attr( @$_template_name ) ); // @codingStandardsIgnoreLine Generic.PHP.NoSilencedErrors.Discouraged } } /** * Generated header * * @param string $_name Title for page. */ public static function header( $_name = '' ) { $status_panel = self::status_panel(); $status_panel = apply_filters( 'tinvwl_view_panelstatus', $status_panel ); include self::file( 'header', '' ); } /** * Status icon * * @return array */ private static function status_panel() { return array( sprintf( '%s', 'https://templateinvaders.com/documentation/ti-woocommerce-wishlist-free/?utm_source=' . TINVWL_UTM_SOURCE . '&utm_campaign=' . TINVWL_UTM_CAMPAIGN . '&utm_medium=' . TINVWL_UTM_MEDIUM . '&utm_content=header_documentation&partner=' . TINVWL_UTM_SOURCE, __( 'read documentation', 'ti-woocommerce-wishlist' ) ), ); } /** * Formated admin url * * @param string $page Page title. * @param string $cat Category title. * @param array $arg Arguments array. * * @return string */ public static function admin_url( $page, $cat = '', $arg = array() ) { $protocol = is_ssl() ? 'https' : 'http'; $glue = '-'; $params = array( 'page' => implode( $glue, array_filter( array( self::$_name, $page ) ) ), 'cat' => $cat, ); if ( is_array( $arg ) ) { $params = array_merge( $params, $arg ); } $params = array_filter( $params ); $params = http_build_query( $params ); if ( is_string( $arg ) ) { $params = $params . '&' . $arg; } return admin_url( sprintf( 'admin.php?%s', $params ), $protocol ); } }