| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
Plugin Name: oik fields |
| 5 |
Plugin URI: http://www.oik-plugins.com/oik |
| 6 |
Description: [bw_field] [bw_fields] shortcodes to display Custom Fields (post metadata) |
| 7 |
Version: 1.7 |
| 8 |
Author: bobbingwide |
| 9 |
Author URI: http://www.bobbingwide.com |
| 10 |
License: GPL2 |
| 11 |
|
| 12 |
Copyright 2011 Bobbing Wide (email : herb@bobbingwide.com ) |
| 13 |
|
| 14 |
This program is free software; you can redistribute it and/or modify |
| 15 |
it under the terms of the GNU General Public License version 2, |
| 16 |
as published by the Free Software Foundation. |
| 17 |
|
| 18 |
You may NOT assume that you can use any other version of the GPL. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
The license for this software can likely be found here: |
| 26 |
http://www.gnu.org/licenses/gpl-2.0.html |
| 27 |
|
| 28 |
*/ |
| 29 |
|
| 30 |
require_once( 'bobbfunc.inc' ); |
| 31 |
require_once( 'bobbingwide.inc' ); |
| 32 |
/* This include will enable oik shortcodes even if the oik base is not enabled. Is this is good idea? */ |
| 33 |
require_once( 'oik-add-shortcodes.php' ); |
| 34 |
/* Include functions to determine level of Artisteer theme whilst Artisteer doesn't provide it */ |
| 35 |
//require_once( 'oik-artisteer.php' ); |
| 36 |
|
| 37 |
|
| 38 |
bw_add_shortcode( 'bw_field', 'bw_metadata' ); |
| 39 |
bw_add_shortcode( 'bw_fields', 'bw_metadata' ); |
| 40 |
// bw_add_shortcode( 'bw_metadata', 'bw_metadata' ); |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* Format a field - by what method? |
| 45 |
* |
| 46 |
*/ |
| 47 |
function bw_format_field( $customfield ) { |
| 48 |
bw_trace2(); |
| 49 |
foreach ( $customfield as $key => $value ) { |
| 50 |
bw_theme_field( $key, $value ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* format the meta data for the 'post' |
| 56 |
*/ |
| 57 |
function bw_format_meta( $customfields ) { |
| 58 |
|
| 59 |
bw_trace2(); |
| 60 |
foreach ( $customfields as $key => $customfield ) { |
| 61 |
$cf = array( $key => $customfield[0] ); |
| 62 |
bw_format_field( $cf ); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Wrapper to get_post_meta |
| 68 |
*/ |
| 69 |
function bw_metadata( $atts = NULL ) { |
| 70 |
$post_id = bw_array_get( $atts, "id", get_the_id()); |
| 71 |
|
| 72 |
$name = bw_array_get( $atts, "name", NULL ); |
| 73 |
if ( NULL == $name ) { |
| 74 |
// the_meta(); |
| 75 |
$customfields = get_post_custom( $post_id ); |
| 76 |
bw_format_meta( $customfields ); |
| 77 |
} |
| 78 |
else { |
| 79 |
$name = wp_strip_all_tags( $name, TRUE ); |
| 80 |
$names = explode( ",", $name ); |
| 81 |
|
| 82 |
foreach ( $names as $name ) { |
| 83 |
$post_meta = get_post_meta( $post_id, $name, FALSE ); |
| 84 |
bw_trace2( $post_meta ); |
| 85 |
$customfields = array( $name => $post_meta ); |
| 86 |
bw_format_meta( $customfields ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
return( bw_ret() ); |
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Theme a custom field |
| 96 |
*/ |
| 97 |
|
| 98 |
function bw_theme_field( $key, $value ) { |
| 99 |
bw_trace2(); |
| 100 |
$funcname = "bw_theme_field_" . $key; |
| 101 |
|
| 102 |
if ( function_exists( $funcname ) ) { |
| 103 |
$funcname( $key, $value ); |
| 104 |
} else { |
| 105 |
_bw_theme_field_default( $key, $value ); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Default theming of metadata based on field name ( $key ) |
| 111 |
* or content? ( $value ) |
| 112 |
*/ |
| 113 |
|
| 114 |
function _bw_theme_field_default( $key, $value ) { |
| 115 |
|
| 116 |
$funcname = "_bw_theme_field_default_" . $key; |
| 117 |
if ( function_exists( $funcname ) ) { |
| 118 |
$funcname( $key, $value ); |
| 119 |
} else { |
| 120 |
// this could be a function called _bw_theme_field_default__unknown_key |
| 121 |
span( "metadata $key" ); |
| 122 |
span( $key ); |
| 123 |
e( $key ); |
| 124 |
epan( $key ); |
| 125 |
span( "value" ); |
| 126 |
e( $value ); |
| 127 |
epan( "value" ); |
| 128 |
epan( "metadata $key" ); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Default function to display a field of name "bw_header_image" |
| 134 |
* |
| 135 |
* A 'bw_header image' field contains the full file name of the image to be used as the header image |
| 136 |
* It's not exactly related to "custom header image" but could be. |
| 137 |
*/ |
| 138 |
function _bw_theme_field_default_bw_header_image( $key, $value ) { |
| 139 |
image( $key, $value ); |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
/** |
| 144 |
* Template tag to return the header image for a specific page |
| 145 |
* |
| 146 |
* |
| 147 |
* If none is specified then it doesn't return anything |
| 148 |
* so should we then call custom_header logic? |
| 149 |
*/ |
| 150 |
if ( !(function_exists( "bw_header_image" ))) { |
| 151 |
|
| 152 |
function bw_header_image() { |
| 153 |
return( bw_metadata( array( "name" => "bw_header_image" ))); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|