Podcast no WordPress usando tipos de postagem personalizados

Este é um código aproximado para configurar um podcast do zero. Se alguém está procurando criar um plugin, este seria um bom ponto de partida.

Estou usando multisite, então movi a maioria dos caminhos de url para a seção de opções para poder configurá-los manualmente. A localização http do Podcast é uma correção de url multisite, pois ipad / iphones têm problemas para fazer streaming da pasta / files.

Cenário

theme-options.php

<?php

// Theme Options
// Chruch of the Word International
// http://www.churchoftheword.com

$themename
= "Options";
$shortname
= "cwi";
$version
= "1.0";

// Create theme options
global $options;
$options
= array (

array
( "name" => "General",
"type" => "section"),

array
( "type" => "open"),

array
( "name" => "iTunes Podcast",
"desc" => "",
"id" => $shortname."_podcast",
"type" => "text",
"std" => ""),

array
( "name" => "Short Description",
"desc" => "",
"id" => $shortname."_shortdesc",
"type" => "textarea",
"std" => ""),

array
( "name" => "Podcast local path",
"desc" => "",
"id" => $shortname."_podcastpath",
"type" => "textarea",
"std" => ""),

array
( "name" => "Podcast file location",
"desc" => "",
"id" => $shortname."_podcastfile",
"type" => "textarea",
"std" => ""),

array
( "name" => "Podcast http location",
"desc" => "",
"id" => $shortname."_podcasthttp",
"type" => "textarea",
"std" => ""),

array
( "name" => "Podcast Title in iTunes",
"desc" => "",
"id" => $shortname."_podcasttitle",
"type" => "text",
"std" => ""),

array
( "type" => "close"),

);

function p2h_add_admin() {

global $themename, $shortname, $options;

if ( isset ( $_GET['page'] ) && ( $_GET['page'] == basename(__FILE__) ) ) {

if ( isset ($_REQUEST['action']) && ( 'save' == $_REQUEST['action'] ) ){

foreach ( $options as $value ) {
if ( array_key_exists('id', $value) ) {
if ( isset( $_REQUEST[ $value['id'] ] ) ) {
update_option
( $value['id'], $_REQUEST[ $value['id'] ] );
}
else {
delete_option
( $value['id'] );
}
}
}
header
("Location: admin.php?page=".basename(__FILE__)."&saved=true");
}
else if ( isset ($_REQUEST['action']) && ( 'reset' == $_REQUEST['action'] ) ) {
foreach ($options as $value) {
if ( array_key_exists('id', $value) ) {
delete_option
( $value['id'] );
}
}
header
("Location: admin.php?page=".basename(__FILE__)."&reset=true");
}
}

add_menu_page
($themename, $themename, 'administrator', basename(__FILE__), 'p2h_admin');
add_submenu_page
(basename(__FILE__), $themename . ' Options', 'Theme Options', 'administrator', basename(__FILE__),'p2h_admin'); // Default
}

function p2h_add_init() {

$file_dir
=get_bloginfo('template_directory');
wp_enqueue_style
("p2hCss", $file_dir."/theme-options.css", false, "1.0", "all");

}

function p2h_admin() {

global $themename, $shortname, $version, $options;
$i
=0;

if ( isset ($_REQUEST['saved']) && ($_REQUEST['saved'] ) )echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
if ( isset ($_REQUEST['reset']) && ($_REQUEST['reset'] ) ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';

?>

<div class="wrap ">
<div class="options_wrap">
<h2 class="settings-title"><?php echo $themename; ?></h2>
<form method="post">

<?php foreach ($options as $value) {
switch ( $value['type'] ) {
case "section":
?>
<div class="section_wrap">
<h3 class="section_title"><?php echo $value['name']; ?></h3>
<div class="section_body">

<?php
break;
case 'text':
?>

<div class="options_input options_text">

<span class="labels"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></span>
<input name="
<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo stripslashes(get_option( $value['id']) ); } else { echo $value['std']; } ?>" />
<div class="options_desc"><?php echo $value['desc']; ?></div>
</div>

<?php
break;
case 'textarea':
?>
<div class="options_input options_textarea">
<span class="labels"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></span>
<textarea name="
<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_option( $value['id'] ) != "") { echo stripslashes(get_option( $value['id']) ); } else { echo $value['std']; } ?></textarea>
<div class="options_desc"><?php echo $value['desc']; ?></div>
</div>

<?php
break;
case 'select':
?>
<div class="options_input options_select">
<span class="labels"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></span>
<select name="
<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
<?php foreach ($value['options'] as $option) { ?>
<option
<?php if (get_option( $value['id'] ) == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?>
</select>
<div class="options_desc"><?php echo $value['desc']; ?></div>
</div>

<?php
break;
case "radio":
?>
<div class="options_input options_select">
<span class="labels"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></span>
<?php foreach ($value['options'] as $key=>$option) {
$radio_setting
= get_option($value['id']);
if($radio_setting != ''){
if ($key == get_option($value['id']) ) {
$checked
= "checked=\"checked\"""";
} else {
$checked
= """";
}
}else{
if($key == $value['std']){
$checked
= ""checked=\""checked\"""";
}else{
$checked
= """";
}
}?>
<input type=""radio"" name=""
<?php echo $value['id']; ?>"" value=""<?php echo $key; ?>"" <?php echo $checked; ?> /><?php echo $option; ?><br />
<?php } ?>
<div class=""options_desc""><?php echo $value['desc']; ?></div>
</div>

<?php
break;
case ""checkbox"":
?>
<div class=""options_input options_checkbox"">
<?php if(get_option($value['id'])){ $checked = ""checked=\""checked\""""; }else{ $checked = """";} ?>
<input type=""checkbox"" name=""
<?php echo $value['id']; ?>"" id=""<?php echo $value['id']; ?>"" value=""true"" <?php echo $checked; ?> />
<label for=""
<?php echo $value['id']; ?>""><?php echo $value['name']; ?></label>
<div class=""options_desc""><?php echo $value['desc']; ?></div>
</div>

<?php
break;
case ""close"":
$i
++;
?>
<span class=""submit""><input name=""save<?php echo $i; ?>"" type=""submit"" value=""Save Changes"" /></span>
</div><!--#section_body-->
</div><!--#section_wrap-->

<?php break;
}
}
?>

<input type=""hidden"" name=""action"" value=""save"" />
<span class=""submit"">
<input name=""save"" type=""submit"" value=""Save All Changes"" />
</span>
</form>

<form method=""post"">
<span class=""submit"">
<input name=""reset"" type=""submit"" value=""Reset All Options"" />
<input type=""hidden"" name=""action"" value=""reset"" />
</span>
</form>
<br/>
</div><!--#options-wrap-->

</div><!--#wrap-->
<?php
}
add_action
('admin_init'