Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Last active August 29, 2015 14:08
Show Gist options
  • Save ronalfy/8362047768b6877678c7 to your computer and use it in GitHub Desktop.
Save ronalfy/8362047768b6877678c7 to your computer and use it in GitHub Desktop.
WordPress Options Framework - Page Selector Option
<?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 );
}
@ronalfy
Copy link
Author

ronalfy commented Nov 1, 2014

Retrieving the page URL

<?php $page_url =  esc_url( get_permalink( of_get_option( 'header-bid-cta-page' ) ) ); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment