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.
1 2 3 4 5 6 7 8 9 |
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.
1 2 3 4 5 6 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
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.
1 2 3 |
<? 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.