Removing the Themes submenu. Displaying errors on the theme page. Metabox for audio files.
Adding code to a file functions.php your topic, will remove the item for all users Themes, except for the user specified in the code id. You can only allow yourself to change themes.
add_action( 'admin_init', 'slt_lock_theme' );
function slt_lock_theme() {
global $submenu, $userdata;
get_currentuserinfo();
if ( $userdata->ID != 1 ) {
unset( $submenu['themes.php'][5] );
unset( $submenu['themes.php'][15] );
}
}
Displaying error messages
Add error text and display it on the theme selection page. Just add the code to the file functions.php.
add_action( 'admin_notices', 'custom_error_notice' );
function custom_error_notice(){
global $current_screen;
if ( $current_screen->parent_base == 'themes' )
echo '<div class="error"><p>Warning - If you modify template files this could cause problems with your website.</p></div>';
}Code checked, everything is working.
Metabox for adding audio recordings
Think, it will be interesting to work with the code for displaying an audio file on a page using a metabox. In the metabox, you can easily select the desired audio file from the media library.
In total we will have two codes. The first code is inserted into the functions.php file.
add_action("admin_init", "audio_init");
add_action('save_post', 'save_audio_link');
function audio_init(){
add_meta_box("mp3-audio", "MP3 AUDIO", "audio_link", "post", "normal", "low");
}
function audio_link(){
global $post;
$custom = get_post_custom($post->ID);
$link = $custom["link"][0];
$count = 0;
echo '<div class="link_header">';
$query_audio_args = array(
'post_type' => 'attachment',
'post_mime_type' =>'audio',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query_audio = new WP_Query( $query_audio_args );
$audio = array();
echo '<select name="link">';
echo '<option class="audio_select">SELECT AUDIO FILE</option>';
foreach ( $query_audio->posts as $file) {
if($link == $audio[]= $file->guid){
echo '<option value="'.$audio[]= $file->guid.'" selected="true">'.$audio[]= $file->guid.'</option>';
}else{
echo '<option value="'.$audio[]= $file->guid.'">'.$audio[]= $file->guid.'</option>';
}
$count++;
}
echo '</select><br /></div>';
echo '<p>Selecting an audio file from the above list to attach to this post.</p>';
echo '<div class="audio_count"><span>Files:</span> <b>'.$count.'</b></div>';
}
function save_audio_link(){
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ return $post->ID; }
update_post_meta($post->ID, "link", $_POST["link"]);
}
add_action( 'admin_head', 'audio_css' );
function audio_css() {
echo '<style type="text/css">
.audio_select{
font-weight:bold;
background:#e5e5e5;
}
.audio_count{
font-size:9px;
color:#0066ff;
text-transform:uppercase;
background:#f3f3f3;
border-top:solid 1px #e5e5e5;
padding:6px 6px 6px 12px;
margin:0px -6px -8px -6px;
-moz-border-radius:0px 0px 6px 6px;
-webkit-border-radius:0px 0px 6px 6px;
border-radius:0px 0px 6px 6px;
}
.audio_count span{color:#666;}
</style>';
}
function audio_file_url(){
global $wp_query;
$custom = get_post_custom($wp_query->post->ID);
echo $custom['link'][0];
}Second code paste in the right place of your topic, where you want to display the address of the attached file.
<?
audio_file_url()
?>Next, upload a new file and select it in the created metabox, after which it will be displayed on the page in the right place. Good luck with development.
/*

- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.







