Edit File by line
/home/barbar84/www/wp-inclu...
File: post.php
[2500] Fix | Delete
if ( $prefixed ) {
[2501] Fix | Delete
[2502] Fix | Delete
/**
[2503] Fix | Delete
* Filters the value of a specific post field to edit.
[2504] Fix | Delete
*
[2505] Fix | Delete
* The dynamic portion of the hook name, `$field`, refers to the post
[2506] Fix | Delete
* field name.
[2507] Fix | Delete
*
[2508] Fix | Delete
* @since 2.3.0
[2509] Fix | Delete
*
[2510] Fix | Delete
* @param mixed $value Value of the post field.
[2511] Fix | Delete
* @param int $post_id Post ID.
[2512] Fix | Delete
*/
[2513] Fix | Delete
$value = apply_filters( "edit_{$field}", $value, $post_id );
[2514] Fix | Delete
[2515] Fix | Delete
/**
[2516] Fix | Delete
* Filters the value of a specific post field to edit.
[2517] Fix | Delete
*
[2518] Fix | Delete
* The dynamic portion of the hook name, `$field_no_prefix`, refers to
[2519] Fix | Delete
* the post field name.
[2520] Fix | Delete
*
[2521] Fix | Delete
* @since 2.3.0
[2522] Fix | Delete
*
[2523] Fix | Delete
* @param mixed $value Value of the post field.
[2524] Fix | Delete
* @param int $post_id Post ID.
[2525] Fix | Delete
*/
[2526] Fix | Delete
$value = apply_filters( "{$field_no_prefix}_edit_pre", $value, $post_id );
[2527] Fix | Delete
} else {
[2528] Fix | Delete
$value = apply_filters( "edit_post_{$field}", $value, $post_id );
[2529] Fix | Delete
}
[2530] Fix | Delete
[2531] Fix | Delete
if ( in_array( $field, $format_to_edit, true ) ) {
[2532] Fix | Delete
if ( 'post_content' === $field ) {
[2533] Fix | Delete
$value = format_to_edit( $value, user_can_richedit() );
[2534] Fix | Delete
} else {
[2535] Fix | Delete
$value = format_to_edit( $value );
[2536] Fix | Delete
}
[2537] Fix | Delete
} else {
[2538] Fix | Delete
$value = esc_attr( $value );
[2539] Fix | Delete
}
[2540] Fix | Delete
} elseif ( 'db' === $context ) {
[2541] Fix | Delete
if ( $prefixed ) {
[2542] Fix | Delete
[2543] Fix | Delete
/**
[2544] Fix | Delete
* Filters the value of a specific post field before saving.
[2545] Fix | Delete
*
[2546] Fix | Delete
* The dynamic portion of the hook name, `$field`, refers to the post
[2547] Fix | Delete
* field name.
[2548] Fix | Delete
*
[2549] Fix | Delete
* @since 2.3.0
[2550] Fix | Delete
*
[2551] Fix | Delete
* @param mixed $value Value of the post field.
[2552] Fix | Delete
*/
[2553] Fix | Delete
$value = apply_filters( "pre_{$field}", $value );
[2554] Fix | Delete
[2555] Fix | Delete
/**
[2556] Fix | Delete
* Filters the value of a specific field before saving.
[2557] Fix | Delete
*
[2558] Fix | Delete
* The dynamic portion of the hook name, `$field_no_prefix`, refers
[2559] Fix | Delete
* to the post field name.
[2560] Fix | Delete
*
[2561] Fix | Delete
* @since 2.3.0
[2562] Fix | Delete
*
[2563] Fix | Delete
* @param mixed $value Value of the post field.
[2564] Fix | Delete
*/
[2565] Fix | Delete
$value = apply_filters( "{$field_no_prefix}_save_pre", $value );
[2566] Fix | Delete
} else {
[2567] Fix | Delete
$value = apply_filters( "pre_post_{$field}", $value );
[2568] Fix | Delete
[2569] Fix | Delete
/**
[2570] Fix | Delete
* Filters the value of a specific post field before saving.
[2571] Fix | Delete
*
[2572] Fix | Delete
* The dynamic portion of the hook name, `$field`, refers to the post
[2573] Fix | Delete
* field name.
[2574] Fix | Delete
*
[2575] Fix | Delete
* @since 2.3.0
[2576] Fix | Delete
*
[2577] Fix | Delete
* @param mixed $value Value of the post field.
[2578] Fix | Delete
*/
[2579] Fix | Delete
$value = apply_filters( "{$field}_pre", $value );
[2580] Fix | Delete
}
[2581] Fix | Delete
} else {
[2582] Fix | Delete
[2583] Fix | Delete
// Use display filters by default.
[2584] Fix | Delete
if ( $prefixed ) {
[2585] Fix | Delete
[2586] Fix | Delete
/**
[2587] Fix | Delete
* Filters the value of a specific post field for display.
[2588] Fix | Delete
*
[2589] Fix | Delete
* The dynamic portion of the hook name, `$field`, refers to the post
[2590] Fix | Delete
* field name.
[2591] Fix | Delete
*
[2592] Fix | Delete
* @since 2.3.0
[2593] Fix | Delete
*
[2594] Fix | Delete
* @param mixed $value Value of the prefixed post field.
[2595] Fix | Delete
* @param int $post_id Post ID.
[2596] Fix | Delete
* @param string $context Context for how to sanitize the field.
[2597] Fix | Delete
* Accepts 'raw', 'edit', 'db', 'display',
[2598] Fix | Delete
* 'attribute', or 'js'. Default 'display'.
[2599] Fix | Delete
*/
[2600] Fix | Delete
$value = apply_filters( "{$field}", $value, $post_id, $context );
[2601] Fix | Delete
} else {
[2602] Fix | Delete
$value = apply_filters( "post_{$field}", $value, $post_id, $context );
[2603] Fix | Delete
}
[2604] Fix | Delete
[2605] Fix | Delete
if ( 'attribute' === $context ) {
[2606] Fix | Delete
$value = esc_attr( $value );
[2607] Fix | Delete
} elseif ( 'js' === $context ) {
[2608] Fix | Delete
$value = esc_js( $value );
[2609] Fix | Delete
}
[2610] Fix | Delete
}
[2611] Fix | Delete
[2612] Fix | Delete
return $value;
[2613] Fix | Delete
}
[2614] Fix | Delete
[2615] Fix | Delete
/**
[2616] Fix | Delete
* Make a post sticky.
[2617] Fix | Delete
*
[2618] Fix | Delete
* Sticky posts should be displayed at the top of the front page.
[2619] Fix | Delete
*
[2620] Fix | Delete
* @since 2.7.0
[2621] Fix | Delete
*
[2622] Fix | Delete
* @param int $post_id Post ID.
[2623] Fix | Delete
*/
[2624] Fix | Delete
function stick_post( $post_id ) {
[2625] Fix | Delete
$post_id = (int) $post_id;
[2626] Fix | Delete
$stickies = get_option( 'sticky_posts' );
[2627] Fix | Delete
$updated = false;
[2628] Fix | Delete
[2629] Fix | Delete
if ( ! is_array( $stickies ) ) {
[2630] Fix | Delete
$stickies = array( $post_id );
[2631] Fix | Delete
} else {
[2632] Fix | Delete
$stickies = array_unique( array_map( 'intval', $stickies ) );
[2633] Fix | Delete
}
[2634] Fix | Delete
[2635] Fix | Delete
if ( ! in_array( $post_id, $stickies, true ) ) {
[2636] Fix | Delete
$stickies[] = $post_id;
[2637] Fix | Delete
$updated = update_option( 'sticky_posts', array_values( $stickies ) );
[2638] Fix | Delete
}
[2639] Fix | Delete
[2640] Fix | Delete
if ( $updated ) {
[2641] Fix | Delete
/**
[2642] Fix | Delete
* Fires once a post has been added to the sticky list.
[2643] Fix | Delete
*
[2644] Fix | Delete
* @since 4.6.0
[2645] Fix | Delete
*
[2646] Fix | Delete
* @param int $post_id ID of the post that was stuck.
[2647] Fix | Delete
*/
[2648] Fix | Delete
do_action( 'post_stuck', $post_id );
[2649] Fix | Delete
}
[2650] Fix | Delete
}
[2651] Fix | Delete
[2652] Fix | Delete
/**
[2653] Fix | Delete
* Un-stick a post.
[2654] Fix | Delete
*
[2655] Fix | Delete
* Sticky posts should be displayed at the top of the front page.
[2656] Fix | Delete
*
[2657] Fix | Delete
* @since 2.7.0
[2658] Fix | Delete
*
[2659] Fix | Delete
* @param int $post_id Post ID.
[2660] Fix | Delete
*/
[2661] Fix | Delete
function unstick_post( $post_id ) {
[2662] Fix | Delete
$post_id = (int) $post_id;
[2663] Fix | Delete
$stickies = get_option( 'sticky_posts' );
[2664] Fix | Delete
[2665] Fix | Delete
if ( ! is_array( $stickies ) ) {
[2666] Fix | Delete
return;
[2667] Fix | Delete
}
[2668] Fix | Delete
[2669] Fix | Delete
$stickies = array_values( array_unique( array_map( 'intval', $stickies ) ) );
[2670] Fix | Delete
[2671] Fix | Delete
if ( ! in_array( $post_id, $stickies, true ) ) {
[2672] Fix | Delete
return;
[2673] Fix | Delete
}
[2674] Fix | Delete
[2675] Fix | Delete
$offset = array_search( $post_id, $stickies, true );
[2676] Fix | Delete
if ( false === $offset ) {
[2677] Fix | Delete
return;
[2678] Fix | Delete
}
[2679] Fix | Delete
[2680] Fix | Delete
array_splice( $stickies, $offset, 1 );
[2681] Fix | Delete
[2682] Fix | Delete
$updated = update_option( 'sticky_posts', $stickies );
[2683] Fix | Delete
[2684] Fix | Delete
if ( $updated ) {
[2685] Fix | Delete
/**
[2686] Fix | Delete
* Fires once a post has been removed from the sticky list.
[2687] Fix | Delete
*
[2688] Fix | Delete
* @since 4.6.0
[2689] Fix | Delete
*
[2690] Fix | Delete
* @param int $post_id ID of the post that was unstuck.
[2691] Fix | Delete
*/
[2692] Fix | Delete
do_action( 'post_unstuck', $post_id );
[2693] Fix | Delete
}
[2694] Fix | Delete
}
[2695] Fix | Delete
[2696] Fix | Delete
/**
[2697] Fix | Delete
* Return the cache key for wp_count_posts() based on the passed arguments.
[2698] Fix | Delete
*
[2699] Fix | Delete
* @since 3.9.0
[2700] Fix | Delete
* @access private
[2701] Fix | Delete
*
[2702] Fix | Delete
* @param string $type Optional. Post type to retrieve count Default 'post'.
[2703] Fix | Delete
* @param string $perm Optional. 'readable' or empty. Default empty.
[2704] Fix | Delete
* @return string The cache key.
[2705] Fix | Delete
*/
[2706] Fix | Delete
function _count_posts_cache_key( $type = 'post', $perm = '' ) {
[2707] Fix | Delete
$cache_key = 'posts-' . $type;
[2708] Fix | Delete
[2709] Fix | Delete
if ( 'readable' === $perm && is_user_logged_in() ) {
[2710] Fix | Delete
$post_type_object = get_post_type_object( $type );
[2711] Fix | Delete
[2712] Fix | Delete
if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
[2713] Fix | Delete
$cache_key .= '_' . $perm . '_' . get_current_user_id();
[2714] Fix | Delete
}
[2715] Fix | Delete
}
[2716] Fix | Delete
[2717] Fix | Delete
return $cache_key;
[2718] Fix | Delete
}
[2719] Fix | Delete
[2720] Fix | Delete
/**
[2721] Fix | Delete
* Count number of posts of a post type and if user has permissions to view.
[2722] Fix | Delete
*
[2723] Fix | Delete
* This function provides an efficient method of finding the amount of post's
[2724] Fix | Delete
* type a blog has. Another method is to count the amount of items in
[2725] Fix | Delete
* get_posts(), but that method has a lot of overhead with doing so. Therefore,
[2726] Fix | Delete
* when developing for 2.5+, use this function instead.
[2727] Fix | Delete
*
[2728] Fix | Delete
* The $perm parameter checks for 'readable' value and if the user can read
[2729] Fix | Delete
* private posts, it will display that for the user that is signed in.
[2730] Fix | Delete
*
[2731] Fix | Delete
* @since 2.5.0
[2732] Fix | Delete
*
[2733] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[2734] Fix | Delete
*
[2735] Fix | Delete
* @param string $type Optional. Post type to retrieve count. Default 'post'.
[2736] Fix | Delete
* @param string $perm Optional. 'readable' or empty. Default empty.
[2737] Fix | Delete
* @return object Number of posts for each status.
[2738] Fix | Delete
*/
[2739] Fix | Delete
function wp_count_posts( $type = 'post', $perm = '' ) {
[2740] Fix | Delete
global $wpdb;
[2741] Fix | Delete
[2742] Fix | Delete
if ( ! post_type_exists( $type ) ) {
[2743] Fix | Delete
return new stdClass;
[2744] Fix | Delete
}
[2745] Fix | Delete
[2746] Fix | Delete
$cache_key = _count_posts_cache_key( $type, $perm );
[2747] Fix | Delete
[2748] Fix | Delete
$counts = wp_cache_get( $cache_key, 'counts' );
[2749] Fix | Delete
if ( false !== $counts ) {
[2750] Fix | Delete
// We may have cached this before every status was registered.
[2751] Fix | Delete
foreach ( get_post_stati() as $status ) {
[2752] Fix | Delete
if ( ! isset( $counts->{$status} ) ) {
[2753] Fix | Delete
$counts->{$status} = 0;
[2754] Fix | Delete
}
[2755] Fix | Delete
}
[2756] Fix | Delete
[2757] Fix | Delete
/** This filter is documented in wp-includes/post.php */
[2758] Fix | Delete
return apply_filters( 'wp_count_posts', $counts, $type, $perm );
[2759] Fix | Delete
}
[2760] Fix | Delete
[2761] Fix | Delete
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
[2762] Fix | Delete
[2763] Fix | Delete
if ( 'readable' === $perm && is_user_logged_in() ) {
[2764] Fix | Delete
$post_type_object = get_post_type_object( $type );
[2765] Fix | Delete
if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
[2766] Fix | Delete
$query .= $wpdb->prepare(
[2767] Fix | Delete
" AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
[2768] Fix | Delete
get_current_user_id()
[2769] Fix | Delete
);
[2770] Fix | Delete
}
[2771] Fix | Delete
}
[2772] Fix | Delete
[2773] Fix | Delete
$query .= ' GROUP BY post_status';
[2774] Fix | Delete
[2775] Fix | Delete
$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
[2776] Fix | Delete
$counts = array_fill_keys( get_post_stati(), 0 );
[2777] Fix | Delete
[2778] Fix | Delete
foreach ( $results as $row ) {
[2779] Fix | Delete
$counts[ $row['post_status'] ] = $row['num_posts'];
[2780] Fix | Delete
}
[2781] Fix | Delete
[2782] Fix | Delete
$counts = (object) $counts;
[2783] Fix | Delete
wp_cache_set( $cache_key, $counts, 'counts' );
[2784] Fix | Delete
[2785] Fix | Delete
/**
[2786] Fix | Delete
* Modify returned post counts by status for the current post type.
[2787] Fix | Delete
*
[2788] Fix | Delete
* @since 3.7.0
[2789] Fix | Delete
*
[2790] Fix | Delete
* @param object $counts An object containing the current post_type's post
[2791] Fix | Delete
* counts by status.
[2792] Fix | Delete
* @param string $type Post type.
[2793] Fix | Delete
* @param string $perm The permission to determine if the posts are 'readable'
[2794] Fix | Delete
* by the current user.
[2795] Fix | Delete
*/
[2796] Fix | Delete
return apply_filters( 'wp_count_posts', $counts, $type, $perm );
[2797] Fix | Delete
}
[2798] Fix | Delete
[2799] Fix | Delete
/**
[2800] Fix | Delete
* Count number of attachments for the mime type(s).
[2801] Fix | Delete
*
[2802] Fix | Delete
* If you set the optional mime_type parameter, then an array will still be
[2803] Fix | Delete
* returned, but will only have the item you are looking for. It does not give
[2804] Fix | Delete
* you the number of attachments that are children of a post. You can get that
[2805] Fix | Delete
* by counting the number of children that post has.
[2806] Fix | Delete
*
[2807] Fix | Delete
* @since 2.5.0
[2808] Fix | Delete
*
[2809] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[2810] Fix | Delete
*
[2811] Fix | Delete
* @param string|string[] $mime_type Optional. Array or comma-separated list of
[2812] Fix | Delete
* MIME patterns. Default empty.
[2813] Fix | Delete
* @return object An object containing the attachment counts by mime type.
[2814] Fix | Delete
*/
[2815] Fix | Delete
function wp_count_attachments( $mime_type = '' ) {
[2816] Fix | Delete
global $wpdb;
[2817] Fix | Delete
[2818] Fix | Delete
$and = wp_post_mime_type_where( $mime_type );
[2819] Fix | Delete
$count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A );
[2820] Fix | Delete
[2821] Fix | Delete
$counts = array();
[2822] Fix | Delete
foreach ( (array) $count as $row ) {
[2823] Fix | Delete
$counts[ $row['post_mime_type'] ] = $row['num_posts'];
[2824] Fix | Delete
}
[2825] Fix | Delete
$counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and" );
[2826] Fix | Delete
[2827] Fix | Delete
/**
[2828] Fix | Delete
* Modify returned attachment counts by mime type.
[2829] Fix | Delete
*
[2830] Fix | Delete
* @since 3.7.0
[2831] Fix | Delete
*
[2832] Fix | Delete
* @param object $counts An object containing the attachment counts by
[2833] Fix | Delete
* mime type.
[2834] Fix | Delete
* @param string|string[] $mime_type Array or comma-separated list of MIME patterns.
[2835] Fix | Delete
*/
[2836] Fix | Delete
return apply_filters( 'wp_count_attachments', (object) $counts, $mime_type );
[2837] Fix | Delete
}
[2838] Fix | Delete
[2839] Fix | Delete
/**
[2840] Fix | Delete
* Get default post mime types.
[2841] Fix | Delete
*
[2842] Fix | Delete
* @since 2.9.0
[2843] Fix | Delete
* @since 5.3.0 Added the 'Documents', 'Spreadsheets', and 'Archives' mime type groups.
[2844] Fix | Delete
*
[2845] Fix | Delete
* @return array List of post mime types.
[2846] Fix | Delete
*/
[2847] Fix | Delete
function get_post_mime_types() {
[2848] Fix | Delete
$post_mime_types = array( // array( adj, noun )
[2849] Fix | Delete
'image' => array(
[2850] Fix | Delete
__( 'Images' ),
[2851] Fix | Delete
__( 'Manage Images' ),
[2852] Fix | Delete
/* translators: %s: Number of images. */
[2853] Fix | Delete
_n_noop(
[2854] Fix | Delete
'Image <span class="count">(%s)</span>',
[2855] Fix | Delete
'Images <span class="count">(%s)</span>'
[2856] Fix | Delete
),
[2857] Fix | Delete
),
[2858] Fix | Delete
'audio' => array(
[2859] Fix | Delete
__( 'Audio' ),
[2860] Fix | Delete
__( 'Manage Audio' ),
[2861] Fix | Delete
/* translators: %s: Number of audio files. */
[2862] Fix | Delete
_n_noop(
[2863] Fix | Delete
'Audio <span class="count">(%s)</span>',
[2864] Fix | Delete
'Audio <span class="count">(%s)</span>'
[2865] Fix | Delete
),
[2866] Fix | Delete
),
[2867] Fix | Delete
'video' => array(
[2868] Fix | Delete
__( 'Video' ),
[2869] Fix | Delete
__( 'Manage Video' ),
[2870] Fix | Delete
/* translators: %s: Number of video files. */
[2871] Fix | Delete
_n_noop(
[2872] Fix | Delete
'Video <span class="count">(%s)</span>',
[2873] Fix | Delete
'Video <span class="count">(%s)</span>'
[2874] Fix | Delete
),
[2875] Fix | Delete
),
[2876] Fix | Delete
'document' => array(
[2877] Fix | Delete
__( 'Documents' ),
[2878] Fix | Delete
__( 'Manage Documents' ),
[2879] Fix | Delete
/* translators: %s: Number of documents. */
[2880] Fix | Delete
_n_noop(
[2881] Fix | Delete
'Document <span class="count">(%s)</span>',
[2882] Fix | Delete
'Documents <span class="count">(%s)</span>'
[2883] Fix | Delete
),
[2884] Fix | Delete
),
[2885] Fix | Delete
'spreadsheet' => array(
[2886] Fix | Delete
__( 'Spreadsheets' ),
[2887] Fix | Delete
__( 'Manage Spreadsheets' ),
[2888] Fix | Delete
/* translators: %s: Number of spreadsheets. */
[2889] Fix | Delete
_n_noop(
[2890] Fix | Delete
'Spreadsheet <span class="count">(%s)</span>',
[2891] Fix | Delete
'Spreadsheets <span class="count">(%s)</span>'
[2892] Fix | Delete
),
[2893] Fix | Delete
),
[2894] Fix | Delete
'archive' => array(
[2895] Fix | Delete
_x( 'Archives', 'file type group' ),
[2896] Fix | Delete
__( 'Manage Archives' ),
[2897] Fix | Delete
/* translators: %s: Number of archives. */
[2898] Fix | Delete
_n_noop(
[2899] Fix | Delete
'Archive <span class="count">(%s)</span>',
[2900] Fix | Delete
'Archives <span class="count">(%s)</span>'
[2901] Fix | Delete
),
[2902] Fix | Delete
),
[2903] Fix | Delete
);
[2904] Fix | Delete
[2905] Fix | Delete
$ext_types = wp_get_ext_types();
[2906] Fix | Delete
$mime_types = wp_get_mime_types();
[2907] Fix | Delete
[2908] Fix | Delete
foreach ( $post_mime_types as $group => $labels ) {
[2909] Fix | Delete
if ( in_array( $group, array( 'image', 'audio', 'video' ), true ) ) {
[2910] Fix | Delete
continue;
[2911] Fix | Delete
}
[2912] Fix | Delete
[2913] Fix | Delete
if ( ! isset( $ext_types[ $group ] ) ) {
[2914] Fix | Delete
unset( $post_mime_types[ $group ] );
[2915] Fix | Delete
continue;
[2916] Fix | Delete
}
[2917] Fix | Delete
[2918] Fix | Delete
$group_mime_types = array();
[2919] Fix | Delete
foreach ( $ext_types[ $group ] as $extension ) {
[2920] Fix | Delete
foreach ( $mime_types as $exts => $mime ) {
[2921] Fix | Delete
if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
[2922] Fix | Delete
$group_mime_types[] = $mime;
[2923] Fix | Delete
break;
[2924] Fix | Delete
}
[2925] Fix | Delete
}
[2926] Fix | Delete
}
[2927] Fix | Delete
$group_mime_types = implode( ',', array_unique( $group_mime_types ) );
[2928] Fix | Delete
[2929] Fix | Delete
$post_mime_types[ $group_mime_types ] = $labels;
[2930] Fix | Delete
unset( $post_mime_types[ $group ] );
[2931] Fix | Delete
}
[2932] Fix | Delete
[2933] Fix | Delete
/**
[2934] Fix | Delete
* Filters the default list of post mime types.
[2935] Fix | Delete
*
[2936] Fix | Delete
* @since 2.5.0
[2937] Fix | Delete
*
[2938] Fix | Delete
* @param array $post_mime_types Default list of post mime types.
[2939] Fix | Delete
*/
[2940] Fix | Delete
return apply_filters( 'post_mime_types', $post_mime_types );
[2941] Fix | Delete
}
[2942] Fix | Delete
[2943] Fix | Delete
/**
[2944] Fix | Delete
* Check a MIME-Type against a list.
[2945] Fix | Delete
*
[2946] Fix | Delete
* If the wildcard_mime_types parameter is a string, it must be comma separated
[2947] Fix | Delete
* list. If the real_mime_types is a string, it is also comma separated to
[2948] Fix | Delete
* create the list.
[2949] Fix | Delete
*
[2950] Fix | Delete
* @since 2.5.0
[2951] Fix | Delete
*
[2952] Fix | Delete
* @param string|string[] $wildcard_mime_types Mime types, e.g. audio/mpeg or image (same as image/*)
[2953] Fix | Delete
* or flash (same as *flash*).
[2954] Fix | Delete
* @param string|string[] $real_mime_types Real post mime type values.
[2955] Fix | Delete
* @return array array(wildcard=>array(real types)).
[2956] Fix | Delete
*/
[2957] Fix | Delete
function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) {
[2958] Fix | Delete
$matches = array();
[2959] Fix | Delete
if ( is_string( $wildcard_mime_types ) ) {
[2960] Fix | Delete
$wildcard_mime_types = array_map( 'trim', explode( ',', $wildcard_mime_types ) );
[2961] Fix | Delete
}
[2962] Fix | Delete
if ( is_string( $real_mime_types ) ) {
[2963] Fix | Delete
$real_mime_types = array_map( 'trim', explode( ',', $real_mime_types ) );
[2964] Fix | Delete
}
[2965] Fix | Delete
[2966] Fix | Delete
$patternses = array();
[2967] Fix | Delete
$wild = '[-._a-z0-9]*';
[2968] Fix | Delete
[2969] Fix | Delete
foreach ( (array) $wildcard_mime_types as $type ) {
[2970] Fix | Delete
$mimes = array_map( 'trim', explode( ',', $type ) );
[2971] Fix | Delete
foreach ( $mimes as $mime ) {
[2972] Fix | Delete
$regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );
[2973] Fix | Delete
[2974] Fix | Delete
$patternses[][ $type ] = "^$regex$";
[2975] Fix | Delete
[2976] Fix | Delete
if ( false === strpos( $mime, '/' ) ) {
[2977] Fix | Delete
$patternses[][ $type ] = "^$regex/";
[2978] Fix | Delete
$patternses[][ $type ] = $regex;
[2979] Fix | Delete
}
[2980] Fix | Delete
}
[2981] Fix | Delete
}
[2982] Fix | Delete
asort( $patternses );
[2983] Fix | Delete
[2984] Fix | Delete
foreach ( $patternses as $patterns ) {
[2985] Fix | Delete
foreach ( $patterns as $type => $pattern ) {
[2986] Fix | Delete
foreach ( (array) $real_mime_types as $real ) {
[2987] Fix | Delete
if ( preg_match( "#$pattern#", $real )
[2988] Fix | Delete
&& ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ], true ) )
[2989] Fix | Delete
) {
[2990] Fix | Delete
$matches[ $type ][] = $real;
[2991] Fix | Delete
}
[2992] Fix | Delete
}
[2993] Fix | Delete
}
[2994] Fix | Delete
}
[2995] Fix | Delete
[2996] Fix | Delete
return $matches;
[2997] Fix | Delete
}
[2998] Fix | Delete
[2999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function