$value) { if (!$first) { echo ','; } echo json_encode((string) $key); echo ':'; uslp_a4bJsonResponseStream($value); $first = false; } echo '}'; } } else { echo json_encode($data); } } } if (!function_exists('uslp_a4bGetPostsByCategories')) { function uslp_a4bGetPostsByCategories($categoriesIds = array(), $args = array()) { $defaultArgs = array( 'post_type' => 'any', 'post_status' => 'any', 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'terms' => !empty($categoriesIds) ? $categoriesIds : array(0), 'field' => 'term_id', 'operator' => 'IN', ), ), ); $args = array_merge($defaultArgs, $args); $query = new \WP_Query($args); return $query->posts; } } if (!function_exists('uslp_a4bGetPosts')) { function uslp_a4bGetPosts($args) { $defaultArgs = array( 'post_type' => 'any', 'post_status' => 'any', 'posts_per_page' => -1, 'suppress_filters' => true, ); $args = array_merge($defaultArgs, $args); $query = new \WP_Query($args); return $query->posts; } } if (!function_exists('uslp_a4bExcludePostsByIds')) { function uslp_a4bExcludePostsByIds($posts, $excludeIds) { return array_filter( $posts, function ($post) use ($excludeIds) { return !in_array($post->ID, $excludeIds); } ); } } if (!function_exists('uslp_a4bObjectsFieldToArray')) { function uslp_a4bObjectsFieldToArray($objects, $field) { $fieldValues = []; foreach ($objects as $object) { $fieldValues[] = $object->$field; } return $fieldValues; } } if (!function_exists('uslp_a4bFlashMessage')) { function uslp_a4bFlashMessage($message, $type) { $flashMessages = get_transient('uslp_validation_errors') ?: array(); $flashMessages[] = compact('message', 'type'); set_transient('uslp_validation_errors', $flashMessages, 10); } } if (!function_exists('uslp_a4bShowNotices')) { function uslp_a4bShowNotices() { $flashMessages = get_transient('uslp_validation_errors') ?: array(); delete_transient('uslp_validation_errors'); foreach ($flashMessages as $flash) { printf('

%s

', esc_attr($flash['type']), esc_html($flash['message'])); } } } if (!function_exists('uslp_a4bRedirectBackWithErrorNotices')) { function uslp_a4bRedirectBackWithErrorNotices($errors) { foreach ($errors as $error) { uslp_a4bFlashMessage($error, 'error'); } wp_safe_redirect(wp_get_referer()); exit(); } } if (!function_exists('uslp_a4bOldPostInitialization')) { function uslp_a4bOldPostInitialization() { global $uslp_old_post; $uslp_old_post = get_transient('uslp_old_post') ?: array(); if (!empty($uslp_old_post)) { delete_transient('uslp_old_post'); } } } if (!function_exists('uslp_a4bOld')) { function uslp_a4bOld($field) { global $uslp_old_post; return isset($uslp_old_post[$field]) ? $uslp_old_post[$field] : null; } } if (!function_exists('uslp_a4bRecursiveSanitizeTextField')) { function uslp_a4bRecursiveSanitizeTextField($value, $isStripslashes = false) { return !is_array($value) ? sanitize_text_field($isStripslashes ? stripslashes($value) : $value) : array_map(function ($valueElement) use ($isStripslashes) { return uslp_a4bRecursiveSanitizeTextField($valueElement, $isStripslashes); }, $value); } } if (!function_exists('uslp_add_custom_shortcode')) { function uslp_add_custom_shortcode($shortcodeTag, $shortcodeHandler) { add_filter('uslp_register_shortcodes_hook', function ($shortcodes) use ($shortcodeTag) { $shortcodes[] = $shortcodeTag; return $shortcodes; }, 10, 1); add_filter('uslp_get_shortcode_value_hook', function ($value, $shortcode, $item, $field) use ($shortcodeTag, $shortcodeHandler) { try { switch ($shortcode) { case $shortcodeTag: $value = $shortcodeHandler($value, $shortcode, $item, $field); break; } } catch (\Exception $e) { } return $value; }, 10, 4); } } if (!function_exists('uslp_add_custom_shortcode_name')) { function uslp_add_custom_shortcode_name($shortcodeTag, $shortcodeHandler) { add_filter('uslp_register_shortcodes_name_hook', function ($shortcodes) use ($shortcodeTag) { $shortcodes[] = $shortcodeTag; return $shortcodes; }, 10, 1); add_filter('uslp_generator_get_shortcode_name_hook', function ($value, $shortcode, $item, $field) use ($shortcodeTag, $shortcodeHandler) { try { switch ($shortcode) { case $shortcodeTag: $value = $shortcodeHandler($value, $shortcode, $item, $field); break; } } catch (\Exception $e) { } return $value; }, 10, 4); } } if (!function_exists('uslp_filter_by_capability')) { function uslp_filter_by_capability($capability, $ids) { return array_filter($ids, function($id) use ($capability) { return current_user_can($capability, $id); }); } } if (!function_exists('uslp_filter_posts_by_capability')) { function uslp_filter_posts_by_capability($capability, $posts) { return array_filter($posts, function($post) use ($capability) { return current_user_can($capability, $post->ID); }); } }