]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/bookmark.php
WordPress 4.7
[autoinstalls/wordpress.git] / wp-includes / bookmark.php
index 1e178f436f58ca6a3a524065aad929bebbdd0bf3..718760be98cb3d695cc088543f110dc69565220f 100644 (file)
@@ -14,7 +14,8 @@
  * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param int|stdClass $bookmark
- * @param string $output Optional. Either OBJECT, ARRAY_N, or ARRAY_A constant
+ * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
+ *                       an stdClass object, an associative array, or a numeric array, respectively. Default OBJECT.
  * @param string $filter Optional, default is 'raw'.
  * @return array|object|null Type returned depends on $output value.
  */
@@ -128,11 +129,12 @@ function get_bookmarks( $args = '' ) {
        $r = wp_parse_args( $args, $defaults );
 
        $key = md5( serialize( $r ) );
-       if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
+       $cache = false;
+       if ( 'rand' !== $r['orderby'] && $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
                if ( is_array( $cache ) && isset( $cache[ $key ] ) ) {
                        $bookmarks = $cache[ $key ];
                        /**
-                        * Filter the returned list of bookmarks.
+                        * Filters the returned list of bookmarks.
                         *
                         * The first time the hook is evaluated in this file, it returns the cached
                         * bookmarks list. The second evaluation returns a cached bookmarks list if the
@@ -285,8 +287,10 @@ function get_bookmarks( $args = '' ) {
 
        $results = $wpdb->get_results( $query );
 
-       $cache[ $key ] = $results;
-       wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
+       if ( 'rand()' !== $orderby ) {
+               $cache[ $key ] = $results;
+               wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
+       }
 
        /** This filter is documented in wp-includes/bookmark.php */
        return apply_filters( 'get_bookmarks', $results, $r );
@@ -297,10 +301,10 @@ function get_bookmarks( $args = '' ) {
  *
  * @since 2.3.0
  *
- * @param object|array $bookmark Bookmark row
+ * @param stdClass|array $bookmark Bookmark row
  * @param string $context Optional, default is 'display'. How to filter the
  *             fields
- * @return object|array Same type as $bookmark but with fields sanitized.
+ * @return stdClass|array Same type as $bookmark but with fields sanitized.
  */
 function sanitize_bookmark($bookmark, $context = 'display') {
        $fields = array('link_id', 'link_url', 'link_name', 'link_image', 'link_target', 'link_category',
@@ -329,30 +333,30 @@ function sanitize_bookmark($bookmark, $context = 'display') {
 }
 
 /**
- * Sanitizes a bookmark field
+ * Sanitizes a bookmark field.
  *
  * Sanitizes the bookmark fields based on what the field name is. If the field
  * has a strict value set, then it will be tested for that, else a more generic
- * filtering is applied. After the more strict filter is applied, if the
- * $context is 'raw' then the value is immediately return.
+ * filtering is applied. After the more strict filter is applied, if the `$context`
+ * is 'raw' then the value is immediately return.
+ *
+ * Hooks exist for the more generic cases. With the 'edit' context, the {@see 'edit_$field'}
+ * filter will be called and passed the `$value` and `$bookmark_id` respectively.
  *
- * Hooks exist for the more generic cases. With the 'edit' context, the
- * 'edit_$field' filter will be called and passed the $value and $bookmark_id
- * respectively. With the 'db' context, the 'pre_$field' filter is called and
- * passed the value. The 'display' context is the final context and has the
- * $field has the filter name and is passed the $value, $bookmark_id, and
- * $context respectively.
+ * With the 'db' context, the {@see 'pre_$field'} filter is called and passed the value.
+ * The 'display' context is the final context and has the `$field` has the filter name
+ * and is passed the `$value`, `$bookmark_id`, and `$context`, respectively.
  *
  * @since 2.3.0
  *
- * @param string $field The bookmark field
- * @param mixed $value The bookmark field value
- * @param int $bookmark_id Bookmark ID
- * @param string $context How to filter the field value. Either 'raw', 'edit',
- *             'attribute', 'js', 'db', or 'display'
- * @return mixed The filtered value
+ * @param string $field       The bookmark field.
+ * @param mixed  $value       The bookmark field value.
+ * @param int    $bookmark_id Bookmark ID.
+ * @param string $context     How to filter the field value. Accepts 'raw', 'edit', 'attribute',
+ *                            'js', 'db', or 'display'
+ * @return mixed The filtered value.
  */
-function sanitize_bookmark_field($field, $value, $bookmark_id, $context) {
+function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) {
        switch ( $field ) {
        case 'link_id' : // ints
        case 'link_rating' :
@@ -404,9 +408,11 @@ function sanitize_bookmark_field($field, $value, $bookmark_id, $context) {
 }
 
 /**
- * Deletes bookmark cache
+ * Deletes the bookmark cache.
  *
  * @since 2.7.0
+ *
+ * @param int $bookmark_id Bookmark ID.
  */
 function clean_bookmark_cache( $bookmark_id ) {
        wp_cache_delete( $bookmark_id, 'bookmark' );