Last active
August 29, 2015 14:08
-
-
Save ronalfy/8362047768b6877678c7 to your computer and use it in GitHub Desktop.
WordPress Options Framework - Page Selector Option
This file contains 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 | |
/* | |
Place in functions.php or custom plugin | |
example usage | |
$options[] = array( | |
'name' => __('Bid Text Page', 'options_framework_theme'), | |
'desc' => __('The bid page', 'options_framework_theme'), | |
'id' => 'header-bid-cta-page', | |
'type' => 'page_select'); | |
?> | |
/*------------------------------------*\ | |
Options Framework - Add Page Selector | |
\*------------------------------------*/ | |
add_filter( 'optionsframework_page_select', 'opubco_page_select', 15, 3 ); | |
function opubco_page_select( $option_name, $value, $val ) { | |
$val = !empty( $val ) ? absint( $val ): 0; | |
$id = !isset( $value[ 'id' ] ) ? 'home_page_select' : $value[ 'id' ]; | |
$pages = wp_dropdown_pages( array( 'depth' => -1, 'selected' => $val, 'echo' => false, 'name' => sprintf( '%s[%s]', $option_name, $id ), 'id' => $id ) ); | |
return $pages; | |
} | |
add_filter( 'of_sanitize_page_select', 'opubco_page_select_sanitization', 10, 2); | |
function opubco_page_select_sanitization( $input, $option ) { | |
return absint( $input ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Retrieving the page URL