| Server IP : 213.186.33.4 / Your IP : 216.73.216.222 Web Server : Apache System : Linux webm005.cluster103.gra.hosting.ovh.net 6.18.39-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Tue Jul 21 12:03:15 CEST 2026 x86_64 User : karinebmkh ( 644538) PHP Version : 8.4.22 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/karinebmkh/www2/wp-content/themes/novablog/includes/ |
Upload File : |
<?php
add_action('admin_menu', 'novablog_add_box_page');
function novablog_add_box_page() {
global $novablog_meta_box_page;
$novablog_meta_box_page = array(
'id' => 'my-meta-box-page',
'title' => esc_html__('Page Options', 'novablog'),
'page' => 'page',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => esc_html__('Title', 'novablog'),
'desc' => esc_html__('Input title for the page.', 'novablog'),
'id' => 'novablog_page_tit',
'type' => 'text',
'std' => ''
),
array(
'name' => esc_html__('Subtitle', 'novablog'),
'desc' => esc_html__('Input subtitle for the page.', 'novablog'),
'id' => 'novablog_page_sub',
'type' => 'textarea',
'std' => ''
),
array( "name" => esc_html__('Enable / disable title','novablog'),
"desc" => esc_html__('Enable or disable title and subtitle.','novablog'),
"id" => "novablog_page_title_enable",
"type" => "select",
"std" => esc_html__('enable','novablog'),
"options" => array(esc_html__('enable','novablog'), esc_html__('disable','novablog'))
)
)
);
add_meta_box($novablog_meta_box_page['id'], $novablog_meta_box_page['title'], 'novablog_show_box_page', $novablog_meta_box_page['page'], $novablog_meta_box_page['context'], $novablog_meta_box_page['priority']);
}
/*-----------------------------------------------------------------------------------*/
/* Callback function to show fields in meta box
/*-----------------------------------------------------------------------------------*/
function novablog_show_box_page() {
global $novablog_meta_box_page, $post;
echo '<p>'.esc_html__('Please fill additional fields for page. ', 'novablog').'</p>';
// Use nonce for verification
echo '<input type="hidden" name="my_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
echo '<table class="form-table">';
foreach ($novablog_meta_box_page['fields'] as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field['id'], true);
switch ($field['type']) {
//If Text
case 'text':
echo '<tr>',
'<th><label for="', $field['id'], '"><span class="novablog-table-name">', $field['name'], '</span><span class="novablog-table-desc">'. $field['desc'].'</span></label></th>',
'<td>';
echo '<input class="novablog-input" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : stripslashes(htmlspecialchars(( $field['std']), ENT_QUOTES)), '" size="30" />';
break;
//If textarea
case 'textarea':
echo '<tr>',
'<th><label for="', $field['id'], '"><span class="novablog-table-name">', $field['name'], '</span><span class="novablog-table-desc">'. $field['desc'].'</span></label></th>',
'<td>';
echo '<textarea class="novablog-textarea" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : stripslashes(htmlspecialchars(( $field['std']), ENT_QUOTES)), '" rows="8" cols="5">', $meta ? $meta : stripslashes(htmlspecialchars(( $field['std']), ENT_QUOTES)), '</textarea>';
break;
//If Select
case 'select':
echo '<tr>',
'<th><label for="', $field['id'], '"><span class="novablog-table-name">', $field['name'], '</span><span class="novablog-table-desc">'. $field['desc'].'</span></label></th>',
'<td>';
echo'<select id="' . $field['id'] . '" name="'.$field['id'].'">';
foreach ($field['options'] as $option) {
echo'<option';
if ($meta == $option ) {
echo ' selected="selected"';
}
echo'>'. $option .'</option>';
}
echo'</select>';
break;
}
}
echo '</table>';
}
add_action('save_post', 'novablog_save_data_page');
/*-----------------------------------------------------------------------------------*/
/* Save data when post is edited
/*-----------------------------------------------------------------------------------*/
function novablog_save_data_page($post_id) {
global $novablog_meta_box_page;
// verify nonce
if (!isset($_POST['my_meta_box_nonce']) || !wp_verify_nonce($_POST['my_meta_box_nonce'], basename(__FILE__))) {
return $post_id;
}
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
// check permissions
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
foreach ($novablog_meta_box_page['fields'] as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = sanitize_text_field($_POST[$field['id']]);
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
}