我为Wordpress创建了一个自定义主题,并自定义了后端,使其具有白色标签的外观和感觉。我可以从管理员菜单加载选项页面并保存设置(推送到CSS文件)。
当我尝试从编辑器级别访问此文件时,它会尝试加载:http://MYURL.COM/wp-admin/functions.php
而不是http://MYURL.COM/wp-admin/admin.php?page=functions.php
我最初能够使用编辑器帐户调出选项菜单。当我试图保存它时,我会收到无法保存的错误。在改变访问级别的同时,问题似乎变得更加严重。
我浏览了3-4页的搜索,但找不到与我的问题相关的内容,抱歉!
下面是我的函数代码。php:
<?php
$themename = "Sleek v0.1";
$shortname = "sleek";
$options = array (
/*Declare the variables needed*/
array( "name" => "General Settings",
"type" => "title"),
array( "type" => "open"),
array( "name" => "Call Analytics Number",
"desc" => "This is the call tracking number for the marketing campaign.",
"id" => $shortname."_phone_number",
"type" => "text",
"std" => "(888) 555-5555"),
array( "name" => "MerchEngines Customer ID",
"desc" => "This is the Customer ID in the MerchEngines dashboard",
"id" => $shortname."_cust_id",
"type" => "text",
"std" => "0000"),
array( "name" => "Navigation",
"type" => "title"),
array( "type" => "open"),
array( "name" => "Navigation Bar Background Color",
"desc" => "This is the background color for the top navigation bar and footer. (Default: #000000)",
"id" => $shortname."_navBarColor",
"type" => "text",
"std" => "#000000"),
array( "name" => "Navigation Bar Text Color",
"desc" => "This is the text for the top navigation bar and footer. (Default: #ffffff)",
"id" => $shortname."_navTextColor",
"type" => "text",
"std" => "#ffffff"),
array( "name" => "Current Tab Color",
"desc" => "This is the tab color for the current page (Default: #920000)",
"id" => $shortname."_currentTabColor",
"type" => "text",
"std" => "#920000"),
array( "name" => "Hover Tab Color",
"desc" => "This is the tab color for the current page. (Default: #920000)",
"id" => $shortname."_hoverTabColor",
"type" => "text",
"std" => "#c00000"),
array( "name" => "Call to Action",
"type" => "title"),
array( "type" => "open"),
array( "name" => "Stand Out Font Color",
"desc" => "This is the contrast color used by the CTA phone numbers and the stand out wording within the inForm. (Default: #c00000)",
"id" => $shortname."_CTAstandOutColor",
"type" => "text",
"std" => "#c00000"),
array( "name" => "Base Color",
"desc" => "This is the base color used by the CTA text and the base wording within the inForm. (Default: #000000)",
"id" => $shortname."_CTAbaseColor",
"type" => "text",
"std" => "#000000"),
array( "name" => "Checkmark Color",
"desc" => "This is the color of the \'Feature\' checkmarks. Color options are: red, darkred, blue, darkblue, green, darkgreen, purple, and orange (Default: red)",
"id" => $shortname."_checkMarkColor",
"type" => "text",
"std" => "red"),
array( "name" => "Bottom Call to Action Text",
"desc" => "This is the bottom call to action text following the phone number. (Default: for more information!)",
"id" => $shortname."_bottomCTAText",
"type" => "text",
"std" => "for more information!"),
array( "name" => "Test Drop Down",
"desc" => "Test for a drop down box.",
"id" => $shortname."_test_dropdown",
"type" => "select",
"std" => "red",
"options" => "red, green, blue"),
array( "type" => "close")
);
function mytheme_add_admin() {
global $themename, $shortname, $options;
if ( $_GET[\'page\'] == basename(__FILE__) ) {
if ( \'save\' == $_REQUEST[\'action\'] ) {
foreach ($options as $value) {
update_option( $value[\'id\'], $_REQUEST[ $value[\'id\'] ] ); }
foreach ($options as $value) {
if( isset( $_REQUEST[ $value[\'id\'] ] ) ) { update_option( $value[\'id\'], $_REQUEST[ $value[\'id\'] ] ); } else { delete_option( $value[\'id\'] ); } }
header("Location: themes.php?page=functions.php&saved=true");
die;
} else if( \'reset\' == $_REQUEST[\'action\'] ) {
foreach ($options as $value) {
delete_option( $value[\'id\'] ); }
header("Location: themes.php?page=functions.php&reset=true");
die;
}
}
add_menu_page($themename." Options", "".$themename." Options", \'edit_themes\', basename(__FILE__), \'mytheme_admin\');
}
function mytheme_add_init() {
$file_dir=get_bloginfo(\'template_directory\');
wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all");
}
function mytheme_admin() {
global $themename, $shortname, $options;
if ( $_REQUEST[\'saved\'] ) echo \'<div id="message" class="updated fade"><p><strong>\'.$themename.\' settings saved.</strong></p></div>\';
if ( $_REQUEST[\'reset\'] ) echo \'<div id="message" class="updated fade"><p><strong>\'.$themename.\' settings reset.</strong></p></div>\';
?>
<div class="wrap">
<h2><?php echo $themename; ?> Settings</h2>
<form method="post">
<?php foreach ($options as $value) {
switch ( $value[\'type\'] ) {
case "open":
?>
<table width="100%" border="0" style="background-color:#cdcdcd; padding:10px;">
<?php break;
case "close":
?>
</table><br />
<?php break;
case "title":
?>
<table width="100%" border="0" style="background-color:#868686; padding:5px 10px;"><tr>
<td colspan="2"><h3 style="font-family:Georgia,\'Times New Roman\',Times,serif;"><?php echo $value[\'name\']; ?></h3></td>
</tr>
<?php break;
case \'text\':
?>
<tr>
<td width="20%" rowspan="2" valign="middle"><strong><?php echo $value[\'name\']; ?></strong></td>
<td width="80%"><input style="width:400px;" name="<?php echo $value[\'id\']; ?>" id="<?php echo $value[\'id\']; ?>" type="<?php echo $value[\'type\']; ?>" value="<?php if ( get_settings( $value[\'id\'] ) != "") { echo get_settings( $value[\'id\'] ); } else { echo $value[\'std\']; } ?>" /></td>
</tr>
<tr>
<td><small><?php echo $value[\'desc\']; ?></small></td>
</tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
<?php
break;
case \'textarea\':
?>
<tr>
<td width="20%" rowspan="2" valign="middle"><strong><?php echo $value[\'name\']; ?></strong></td>
<td width="80%"><textarea name="<?php echo $value[\'id\']; ?>" style="width:400px; height:200px;" type="<?php echo $value[\'type\']; ?>" cols="" rows=""><?php if ( get_settings( $value[\'id\'] ) != "") { echo get_settings( $value[\'id\'] ); } else { echo $value[\'std\']; } ?></textarea></td>
</tr>
<tr>
<td><small><?php echo $value[\'desc\']; ?></small></td>
</tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
<?php
break;
case \'select\':
?>
<tr>
<td width="20%" rowspan="2" valign="middle"><strong><?php echo $value[\'name\']; ?></strong></td>
<td width="80%"><select style="width:240px;" name="<?php echo $value[\'id\']; ?>" id="<?php echo $value[\'id\']; ?>"><?php foreach ($value[\'options\'] as $option) { ?><option<?php if ( get_settings( $value[\'id\'] ) == $option) { echo \' selected="selected"\'; } elseif ($option == $value[\'std\']) { echo \' selected="selected"\'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
</tr>
<tr>
<td><small><?php echo $value[\'desc\']; ?></small></td>
</tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
<?php
break;
case "checkbox":
?>
<tr>
<td width="20%" rowspan="2" valign="middle"><strong><?php echo $value[\'name\']; ?></strong></td>
<td width="80%"><?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; ?> />
</td>
</tr>
<tr>
<td><small><?php echo $value[\'desc\']; ?></small></td>
</tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
<?php break;
}
}
?>
<p class="submit">
<input name="save" type="submit" value="Save changes" />
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
</div>
<?php
}add_action(\'admin_menu\', \'mytheme_add_admin\');
add_action(\'admin_init\', \'mytheme_add_init\');
?>