Created
August 26, 2018 12:45
-
-
Save eto4detak/3c558426e9048e2de8c5e04b329bb81c to your computer and use it in GitHub Desktop.
wp php admin add page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//****************admin********************* | |
//страница настроек | |
add_action('admin_menu', 'compare_cars_wc_submenu_page_url', 999); | |
function compare_cars_wc_submenu_page_url() { | |
add_submenu_page( 'edit.php?post_type=pixad-autos', __('Compare page', 'compare_cars'), _x('Compare page', 'menu', 'compare_cars'), 'manage_options', 'compare-cars', 'compare_cars_submenu_page' ); | |
} | |
function compare_cars_submenu_page(){ | |
?> | |
<div class="wrap"> | |
<h3><?php echo get_admin_page_title() ?></h3> | |
<form action="options.php" method="POST"> | |
<?php | |
settings_fields( 'compare_opt_gr' ); | |
do_settings_sections( 'compare_page1' ); | |
submit_button(); | |
?> | |
</form> | |
</div> | |
<?php | |
} | |
add_action('admin_init', 'compare_cars_settings_page'); | |
function compare_cars_settings_page(){ | |
register_setting( 'compare_opt_gr', 'compare_cars_templ', 'compare_sanitize_clb' ); | |
add_settings_section( 'section_id', __('Compare settings', 'compare_cars'), '', 'compare_page1' ); | |
add_settings_field('primer_field1', __('Select compare page', 'compare_cars'), 'compare_fields_display', 'compare_page1', 'section_id' ); | |
add_settings_field('compare_field_favorite', __('Not use favorite', 'compare_cars'), 'compare_fields_favorite', 'compare_page1', 'section_id' ); | |
add_settings_field('compare_field_resize', __('Resize', 'compare_cars'), 'compare_fields_resize', 'compare_page1', 'section_id' ); | |
} | |
function compare_fields_display(){ | |
$val = get_option('compare_cars_templ'); | |
$template = !empty($val['template']) ? $val['template'] : -1; | |
?> | |
<select name="compare_cars_templ[template]"> | |
<option value="-1"> | |
<?php echo esc_attr( __( 'Select page', 'compare_cars' ) ); ?></option> | |
<?php | |
$pages = get_pages(); | |
foreach ( $pages as $page ) { | |
$option = '<option value="' . $page->ID . '" ' . selected( $template, $page->ID ) . '>'; | |
$option .= $page->post_title; | |
$option .= '</option>'; | |
echo $option; | |
} | |
?> | |
</select> | |
<?php | |
} | |
function compare_fields_favorite(){ | |
$val = get_option('compare_cars_templ'); | |
$no_favorite = !empty($val['no_favorite']) ? $val['no_favorite'] : false; | |
?> | |
<label><input type="checkbox" name="compare_cars_templ[no_favorite]" value="1" <?php checked( 1, $no_favorite ) ?> /></label> | |
<?php | |
} | |
function compare_fields_resize(){ | |
$val = get_option('compare_cars_templ'); | |
$resize = !empty($val['resize']) ? $val['resize'] : false; | |
?> | |
<label><input type="checkbox" name="compare_cars_templ[resize]" value="1" <?php checked( 1, $resize ) ?> /></label> | |
<?php | |
} | |
function compare_sanitize_clb( $options ){ | |
return $options; | |
} | |
//****************end admin********************* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment