WordPressを読む 10-14 /blog/wp-includes/functions.php 14
2014/11/29
目次
/blog/wp-includes/functions.php 14
読込元 : /blog/wp-settings.php
読込元 : /blog/wp-load.php
関数
smilies_init()
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 | /** * Convert smiley code to the icon graphic file equivalent. * * You can turn off smilies, by going to the write setting screen and unchecking * the box, or by setting 'use_smilies' option to false or removing the option. * * Plugins may override the default smiley list by setting the $wpsmiliestrans * to an array, with the key the code the blogger types in and the value the * image file. * * The $wp_smiliessearch global is for the regular expression and is set each * time the function is called. * * The full list of smilies can be found in the function and won't be listed in * the description. Probably should create a Codex page for it, so that it is * available. * * @global array $wpsmiliestrans * @global array $wp_smiliessearch * * @since 2.2.0 */ function smilies_init() { global $wpsmiliestrans, $wp_smiliessearch; // don't bother setting up smilies if they are disabled if ( !get_option( 'use_smilies' ) ) return; if ( !isset( $wpsmiliestrans ) ) { $wpsmiliestrans = array( ':mrgreen:' => 'icon_mrgreen.gif', ':neutral:' => 'icon_neutral.gif', ':twisted:' => 'icon_twisted.gif', ':arrow:' => 'icon_arrow.gif', ':shock:' => 'icon_eek.gif', ':smile:' => 'icon_smile.gif', ':???:' => 'icon_confused.gif', ':cool:' => 'icon_cool.gif', ':evil:' => 'icon_evil.gif', ':grin:' => 'icon_biggrin.gif', ':idea:' => 'icon_idea.gif', ':oops:' => 'icon_redface.gif', ':razz:' => 'icon_razz.gif', ':roll:' => 'icon_rolleyes.gif', ':wink:' => 'icon_wink.gif', ':cry:' => 'icon_cry.gif', ':eek:' => 'icon_surprised.gif', ':lol:' => 'icon_lol.gif', ':mad:' => 'icon_mad.gif', ':sad:' => 'icon_sad.gif', '8-)' => 'icon_cool.gif', '8-O' => 'icon_eek.gif', ':-(' => 'icon_sad.gif', ':-)' => 'icon_smile.gif', ':-?' => 'icon_confused.gif', ':-D' => 'icon_biggrin.gif', ':-P' => 'icon_razz.gif', ':-o' => 'icon_surprised.gif', ':-x' => 'icon_mad.gif', ':-|' => 'icon_neutral.gif', ';-)' => 'icon_wink.gif', // This one transformation breaks regular text with frequency. // '8)' => 'icon_cool.gif', '8O' => 'icon_eek.gif', ':(' => 'icon_sad.gif', ':)' => 'icon_smile.gif', ':?' => 'icon_confused.gif', ':D' => 'icon_biggrin.gif', ':P' => 'icon_razz.gif', ':o' => 'icon_surprised.gif', ':x' => 'icon_mad.gif', ':|' => 'icon_neutral.gif', ';)' => 'icon_wink.gif', ':!:' => 'icon_exclaim.gif', ':?:' => 'icon_question.gif', ); } if (count($wpsmiliestrans) == 0) { return; } /* * NOTE: we sort the smilies in reverse key order. This is to make sure * we match the longest possible smilie (:???: vs :?) as the regular * expression used below is first-match */ krsort($wpsmiliestrans); $spaces = wp_spaces_regexp(); // Begin first "subpattern" $wp_smiliessearch = '/(?<=' . $spaces . '|^)'; $subchar = ''; foreach ( (array) $wpsmiliestrans as $smiley => $img ) { $firstchar = substr($smiley, 0, 1); $rest = substr($smiley, 1); // new subpattern? if ($firstchar != $subchar) { if ($subchar != '') { $wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern" $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern" } $subchar = $firstchar; $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:'; } else { $wp_smiliessearch .= '|'; } $wp_smiliessearch .= preg_quote($rest, '/'); } $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m'; } |
関数
wp_parse_args()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /** * Merge user defined arguments into defaults array. * * This function is used throughout WordPress to allow for both string or array * to be merged into another array. * * @since 2.2.0 * * @param string|array $args Value to merge with $defaults * @param array $defaults Optional. Array that serves as the defaults. Default empty. * @return array Merged user defined values with defaults. */ function wp_parse_args( $args, $defaults = '' ) { if ( is_object( $args ) ) $r = get_object_vars( $args ); elseif ( is_array( $args ) ) $r =& $args; else wp_parse_str( $args, $r ); if ( is_array( $defaults ) ) return array_merge( $defaults, $r ); return $r; } |
関数
wp_parse_id_list()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Clean up an array, comma- or space-separated list of IDs. * * @since 3.0.0 * * @param array|string $list List of ids. * @return array Sanitized array of IDs. */ function wp_parse_id_list( $list ) { if ( !is_array($list) ) $list = preg_split('/[\s,]+/', $list); return array_unique(array_map('absint', $list)); } |
関数
wp_array_slice_assoc()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /** * Extract a slice of an array, given a list of keys. * * @since 3.1.0 * * @param array $array The original array. * @param array $keys The list of keys. * @return array The array slice. */ function wp_array_slice_assoc( $array, $keys ) { $slice = array(); foreach ( $keys as $key ) if ( isset( $array[ $key ] ) ) $slice[ $key ] = $array[ $key ]; return $slice; } |
関数
wp_filter_object_list()
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 | /** * Filters a list of objects, based on a set of key => value arguments. * * @since 3.0.0 * * @param array $list An array of objects to filter * @param array $args Optional. An array of key => value arguments to match * against each object. Default empty array. * @param string $operator Optional. The logical operation to perform. 'or' means * only one element from the array needs to match; 'and' * means all elements must match. Default 'and'. * @param bool|string $field A field from the object to place instead of the entire object. * Default false. * @return array A list of objects or object fields. */ function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) { if ( ! is_array( $list ) ) return array(); $list = wp_list_filter( $list, $args, $operator ); if ( $field ) $list = wp_list_pluck( $list, $field ); return $list; } |
関数
wp_list_filter()
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 | /** * Filters a list of objects, based on a set of key => value arguments. * * @since 3.1.0 * * @param array $list An array of objects to filter. * @param array $args Optional. An array of key => value arguments to match * against each object. Default empty array. * @param string $operator Optional. The logical operation to perform. 'AND' means * all elements from the array must match. 'OR' means only * one element needs to match. 'NOT' means no elements may * match. Default 'AND'. * @return array Array of found values. */ function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { if ( ! is_array( $list ) ) return array(); if ( empty( $args ) ) return $list; $operator = strtoupper( $operator ); $count = count( $args ); $filtered = array(); foreach ( $list as $key => $obj ) { $to_match = (array) $obj; $matched = 0; foreach ( $args as $m_key => $m_value ) { if ( array_key_exists( $m_key, $to_match ) && $m_value == $to_match[ $m_key ] ) $matched++; } if ( ( 'AND' == $operator && $matched == $count ) || ( 'OR' == $operator && $matched > 0 ) || ( 'NOT' == $operator && 0 == $matched ) ) { $filtered[$key] = $obj; } } return $filtered; } |