Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Create and load the 'wish-list.php' file, which is a collection of fu…

…nctions that I wish were added to WP core. This also introduces the hybrid_attachment_is_audio() and hybrid_attachment_is_video() functions.
  • Loading branch information...
commit 960d22b218cdad6f6a68143093ec9e2938f57d6f 1 parent 1becfb7
@justintadlock authored
View
14 functions/post-formats.php
@@ -134,20 +134,6 @@ function hybrid_clean_post_format_slug( $slug ) {
return str_replace( 'post-format-', '', $slug );
}
-/**
- * Checks if a post has any content. Useful if you need to check if the user has written any content
- * before performing any actions.
- *
- * @since 1.6.0
- * @access public
- * @param int $id The ID of the post.
- * @return bool
- */
-function hybrid_post_has_content( $id = 0 ) {
- $post = get_post( $id );
- return !empty( $post->post_content ) ? true : false;
-}
-
/* === Asides === */
/**
View
34 functions/utility.php
@@ -182,40 +182,6 @@ function hybrid_has_post_template( $template = '' ) {
}
/**
- * Retrieves the file with the highest priority that exists. The function searches both the stylesheet
- * and template directories. This function is similar to the locate_template() function in WordPress
- * but returns the file name with the URI path instead of the directory path.
- *
- * @since 1.5.0
- * @access public
- * @link http://core.trac.wordpress.org/ticket/18302
- * @param array $file_names The files to search for.
- * @return string
- */
-function hybrid_locate_theme_file( $file_names ) {
-
- $located = '';
-
- /* Loops through each of the given file names. */
- foreach ( (array) $file_names as $file ) {
-
- /* If the file exists in the stylesheet (child theme) directory. */
- if ( is_child_theme() && file_exists( trailingslashit( get_stylesheet_directory() ) . $file ) ) {
- $located = trailingslashit( get_stylesheet_directory_uri() ) . $file;
- break;
- }
-
- /* If the file exists in the template (parent theme) directory. */
- elseif ( file_exists( trailingslashit( get_template_directory() ) . $file ) ) {
- $located = trailingslashit( get_template_directory_uri() ) . $file;
- break;
- }
- }
-
- return $located;
-}
-
-/**
* The WordPress.org theme review requires that a link be provided to the single post page for untitled
* posts. This is a filter on 'the_title' so that an '(Untitled)' title appears in that scenario, allowing
* for the normal method to work.
View
98 functions/wish-list.php
@@ -0,0 +1,98 @@
+<?php
+/**
+ * Functions that I've found useful that I wish WordPress had equivalents too baked right into core. If
+ * there's a relevant Trac ticket, it'll be listed in with the function.
+ *
+ * @package HybridCore
+ * @subpackage Functions
+ * @author Justin Tadlock <justin@justintadlock.com>
+ * @copyright Copyright (c) 2008 - 2013, Justin Tadlock
+ * @link http://themehybrid.com/hybrid-core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ */
+
+/**
+ * Retrieves the file with the highest priority that exists. The function searches both the stylesheet
+ * and template directories. This function is similar to the locate_template() function in WordPress
+ * but returns the file name with the URI path instead of the directory path.
+ *
+ * @since 1.5.0
+ * @access public
+ * @link http://core.trac.wordpress.org/ticket/18302
+ * @param array $file_names The files to search for.
+ * @return string
+ */
+function hybrid_locate_theme_file( $file_names ) {
+
+ $located = '';
+
+ /* Loops through each of the given file names. */
+ foreach ( (array) $file_names as $file ) {
+
+ /* If the file exists in the stylesheet (child theme) directory. */
+ if ( is_child_theme() && file_exists( trailingslashit( get_stylesheet_directory() ) . $file ) ) {
+ $located = trailingslashit( get_stylesheet_directory_uri() ) . $file;
+ break;
+ }
+
+ /* If the file exists in the template (parent theme) directory. */
+ elseif ( file_exists( trailingslashit( get_template_directory() ) . $file ) ) {
+ $located = trailingslashit( get_template_directory_uri() ) . $file;
+ break;
+ }
+ }
+
+ return $located;
+}
+
+/**
+ * Checks if a post has any content. Useful if you need to check if the user has written any content
+ * before performing any actions.
+ *
+ * @since 1.6.0
+ * @access public
+ * @param int $id The ID of the post.
+ * @return bool
+ */
+function hybrid_post_has_content( $id = 0 ) {
+ $post = get_post( $id );
+ return !empty( $post->post_content ) ? true : false;
+}
+
+/**
+ * Checks if the current post has a mime type of 'audio'.
+ *
+ * @since 1.6.0
+ * @access public
+ * @param int $post_id
+ * @return bool
+ */
+function hybrid_attachment_is_audio( $post_id = 0 ) {
+
+ $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
+
+ $mime = get_post_mime_type( $post_id );
+ $mime_type = explode( '/', $mime );
+
+ return 'audio' == array_shift( $mime_type ) ? true : false;
+}
+
+/**
+ * Checks if the current post has a mime type of 'video'.
+ *
+ * @since 1.6.0
+ * @access public
+ * @param int $post_id
+ * @return bool
+ */
+function hybrid_attachment_is_video( $post_id = 0 ) {
+
+ $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
+
+ $mime = get_post_mime_type( $post_id );
+ $mime_type = explode( '/', $mime );
+
+ return 'video' == array_shift( $mime_type ) ? true : false;
+}
+
+?>
View
3  hybrid.php
@@ -248,6 +248,9 @@ function functions() {
/* Load the utility functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'utility.php' );
+ /* Load the wish-list functions. */
+ require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'wish-list.php' );
+
/* Load the theme settings functions if supported. */
require_if_theme_supports( 'hybrid-core-theme-settings', trailingslashit( HYBRID_FUNCTIONS ) . 'settings.php' );
Please sign in to comment.
Something went wrong with that request. Please try again.