global $wpdb; $options = array(); $res = $wpdb->get_col( "SELECT SQL_NO_CACHE option_name FROM $wpdb->options WHERE option_name LIKE 'dgwt_wcas_%'" ); if ( ! empty( $res ) && is_array( $res ) ) { $options = $res; } return $options; } /** * Load necessary user files to handle current_user_can() in SHORTINIT mode * * @return void */ public static function loadUserFiles__premium_only() { require_once ABSPATH . WPINC . '/default-constants.php'; wp_plugin_directory_constants(); wp_cookie_constants(); require_once ABSPATH . WPINC . '/rest-api.php'; require_once ABSPATH . WPINC . '/kses.php'; require_once ABSPATH . WPINC . '/class-wp-user.php'; require_once ABSPATH . WPINC . '/class-wp-roles.php'; require_once ABSPATH . WPINC . '/class-wp-role.php'; require_once ABSPATH . WPINC . '/class-wp-session-tokens.php'; require_once ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php'; require_once ABSPATH . WPINC . '/user.php'; require_once ABSPATH . WPINC . '/pluggable.php'; require_once ABSPATH . WPINC . '/capabilities.php'; } /** * Does the "Shop manager" role have access to the plugin settings? * * @return bool */ public static function shopManagerHasAccess() { return defined( 'DGWT_WCAS_ALLOW_SHOP_MANAGER_ACCESS' ) && DGWT_WCAS_ALLOW_SHOP_MANAGER_ACCESS; } /** * Clear phrase before processing regex expression. * Some user inputs might contain special characters which should be escaped. * * @return string */ public static function escPhraseForRegex( $phrase ) { $phrase = preg_replace_callback( "/([!@#$&()\-\[\]{}\\`.+,\/\"\\'])/", function ( $matches ) { return '\\' . $matches[0]; }, $phrase ); return $phrase; } /** * Esc not allowed HTML tags for No Results text * * @return string */ public static function ksesNoResults( $content ) { $content = wp_kses( $content, array( 'div' => array( 'class' => array(), ), 'span' => array( 'class' => array(), ), 'a' => array( 'href' => array(), ), 'br' => array(), 'p' => array(), 'em' => array(), 'b' => array(), 'ol' => array(), 'ul' => array(), 'li' => array(), 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array() ) ); return $content; } /** * Convert text to Greeklish * * @param string $text * * @return string */ public static function convertToGreeklish__premium_only( $text ) { $greekLatinMap = array( 'ευα' => 'eva', 'ευη' => 'evi', 'ευε' => 'eve', 'ευκ' => 'efk', 'ευμ' => 'evm', 'χτ' => 'kt', 'ντ' => 'nt', 'ευ' => 'ef', 'ά' => 'a', 'ώ' => 'o', 'έ' => 'e', 'ό' => 'o', 'ί' => 'i', 'ή' => 'i', 'ϊ' => 'i', 'ϋ' => 'i', 'ύ' => 'i', 'λλ' => 'l', 'σσ' => 's', 'τζ' => 'g', 'γγ' => 'g', 'γκ' => 'g', 'κκ' => 'k', 'μμ' => 'm', 'νν' => 'n', 'φφ' => 'f', 'ρρ' => 'r', 'ττ' => 't', 'αι' => 'e', 'οι' => 'i', 'ει' => 'i', 'υι' => 'i', 'ου' => 'ou', 'σ' => 's', 'τ' => 't', 'υ' => 'i', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'o', 'α' => 'a', 'β' => 'v', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'i', 'θ' => '', 'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => 'ks', 'ο' => 'o', 'ρ' => 'r', 'π' => 'p', 'oi' => 'i', 'mb' => 'mp', 'ei' => 'i', 'll' => 'l', 'gk' => 'g', 'kk' => 'k', 'ff' => 'f', 'mm' => 'm', 'nn' => 'n', 'rr' => 'r', 'tt' => 't', 'ph' => 'f', 'oy' => 'ou', 'ai' => 'e', 'ss' => 's', 'th' => '', 'w' => 'o', 'h' => 'i', 'd' => 'nt', 'b' => 'mp', 'c' => 'k', 'y' => 'i', ); return strtr( mb_strtolower( $text ), $greekLatinMap ); } /** * Check if the text contains Greek characters * * @param string $text * * @return bool */ public static function isGreekText__premium_only( $text ) { preg_match_all( '/[\p{Greek}]+/u', $text, $matches, PREG_SET_ORDER, 0 ); return ! empty( $matches ); } /** * Remove Greek accents * * @param string $text The text to process. * * @return string */ public static function removeGreekAccents( $text ) { $chars = array( 'Ά' => 'Α', 'ά' => 'α', 'Έ' => 'Ε', 'έ' => 'α', 'Ί' => 'Ι', 'ί' => 'ι', 'ΐ' => 'ϊ', 'Ύ' => 'Υ', 'ύ' => 'υ', 'ΰ' => 'ϋ', 'Ή' => 'Η', 'ή' => 'η', 'Ό' => 'Ο', 'ό' => 'ο', 'Ώ' => 'Ω', 'ώ' => 'ω', ); return strtr( $text, $chars ); } /** * Test if phrase contains blacklisted term * * @param string $phrase Search phrase. * * @return bool */ public static function phraseContainsBlacklistedTerm( $phrase ) { $blacklistedTerms = apply_filters( 'dgwt/wcas/blacklisted_terms', array() ); if ( is_array( $blacklistedTerms ) ) { foreach ( $blacklistedTerms as $term ) { if ( mb_stripos( $phrase, $term ) !== false ) { return true; } } } if ( apply_filters( 'dgwt/wcas/blacklisted_terms/check_js', true ) && self::containsJsScript( $phrase ) ) { return true; } return false; } /** * Get specific label of the post type * * @param string|\WP_Post_Type $postType * @param string $label * * @return string */ public static function getPostTypeLabel( $postType, $label ) { $text = ''; $obj = null; $label = sanitize_key( $label ); if ( is_string( $postType ) ) { $obj = get_post_type_object( $postType ); } if ( is_object( $postType ) && is_a( $postType, 'WP_Post_Type' ) ) { $obj = $postType; } if ( ! empty( $obj->labels ) && ! empty( $obj->labels->$label ) ) { $text = $obj->labels->$label; } return $text; } /** * Check if the string contains JS script * * @param string $text * * @return bool */ public static function containsJsScript( $text ) { return ! empty( $text ) && preg_match( '/]*?>/', $text ); } /** * Remove content of