Example #1
0
 /**
  * Count and cache the number of characters in a post's content. Or
  * retrieve the count if it has already been cached.
  *
  * @since 1.0.
  *
  * @param  int $post_id The post's id
  * @return int          The character count of the post
  */
 function oxford_get_post_char_count($post_id = 0)
 {
     if (0 === absint($post_id)) {
         $post_id = get_the_ID();
     }
     // Use cached value if available
     $char_count = oxford_get_post_meta('cache', $post_id, 'char-count');
     if (false !== $char_count) {
         return absint($char_count);
     } else {
         $content = wp_strip_all_tags(strip_shortcodes(get_post($post_id)->post_content), true);
         $char_count = strlen($content);
         // Cache the value
         oxford_update_post_meta('cache', $post_id, 'char-count', $char_count);
         return $char_count;
     }
 }
Example #2
0
 /**
  * Flush the cached comment object from post meta.
  *
  * @since 1.0.
  *
  * @param int $post_id The id of the post.
  */
 function oxford_flush_recent_comment($post_id)
 {
     oxford_update_post_meta('cache', $post_id, 'recent-comment', null);
 }
Example #3
0
 /**
  * Flush the cached featured image ids if a featured image is updated or removed.
  *
  * @since 1.0.
  *
  * @param int    $meta_id   Unused.
  * @param int    $object_id The id of the post being updated.
  * @param string $meta_key  The meta key being updated.
  */
 function oxford_flush_featured_images_changethumb($meta_id, $object_id, $meta_key)
 {
     if ('_thumbnail_id' === $meta_key || '_oxford-secondary-image-id' === $meta_key) {
         oxford_update_post_meta('cache', $object_id, 'featured-images', null);
     }
 }
Example #4
0
 /**
  * Sanitize, validate, and save the meta for post background.
  *
  * @since 1.0.
  *
  * @param int $post_id The id of the post currently being edited.
  */
 function oxford_post_meta_save($post_id)
 {
     // Checks save status
     $is_autosave = wp_is_post_autosave($post_id);
     $is_revision = wp_is_post_revision($post_id);
     $is_valid_nonce = isset($_POST['oxford_nonce']) && wp_verify_nonce($_POST['oxford_nonce'], basename(__FILE__)) ? 'true' : 'false';
     // Exits script depending on save status
     if ($is_autosave || $is_revision || !$is_valid_nonce) {
         return;
     }
     // Sanitize/save Background Color if necessary
     if (isset($_POST['post-background-color']) && ($sanitized_hex = oxford_maybe_hash_hex_color($_POST['post-background-color']))) {
         if ('#ffffff' === $sanitized_hex) {
             oxford_update_post_meta('settings', $post_id, 'post-background-color', null);
         } else {
             if ($sanitized_hex !== oxford_get_post_meta('settings', $post_id, 'post-background-color')) {
                 oxford_update_post_meta('settings', $post_id, 'post-background-color', $sanitized_hex);
             }
         }
     }
     // Sanitize/save Single Column if necessary
     $single_column = oxford_get_post_meta('settings', $post_id, 'post-single-column');
     if (isset($_POST['post-single-column']) && !$single_column) {
         oxford_update_post_meta('settings', $post_id, 'post-single-column', true);
     } else {
         if (!isset($_POST['post-single-column']) && $single_column) {
             oxford_update_post_meta('settings', $post_id, 'post-single-column', null);
         }
     }
     // If there are no settings, remove the meta entry
     $post_meta_settings = get_post_meta($post_id, '_oxford-post-settings', true);
     if (empty($post_meta_settings)) {
         delete_post_meta($post_id, '_oxford-post-settings');
     }
 }