Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Diese URLs aus der Metabox müssen noch abgespeichert werden
- add_action( 'save_post', 'us_save_post' );
- function us_save_post( $post_id ){
- //Wir prüfen zunächst, ob wir unsere URL
- //abspeichern wollen und können
- if(
- ! isset( $_POST['us_nonce'] ) ||
- ! wp_verify_nonce( $_POST['us_nonce'], 'save-url' ) ||
- ! current_user_can( 'edit_post', $post_id ) ||
- ! isset( $_POST['url'] ) ||
- wp_is_post_revision( $post_id )
- )
- return;
- //Wir reorganisieren unsere URL, um sie URL-konform zu machen.
- //So werden wir beispielsweise Anführungszeichen in %22 umwandeln.
- $url = parse_url( urldecode( stripslashes( $_POST['url'] ) ) );
- if( ! isset( $url['scheme'] ) || ! isset( $url['host'] ) )
- return;
- $url_string = $url['scheme'] . '://';
- if( isset( $url['user'] ) && isset( $url['password'] ) )
- $url_string .= $url['user'] . ':' . $url['password'] . '.';
- $url_string .= $url['host'];
- if( isset( $url['port'] ) )
- $url_string .= ':' . $url['port'];
- if( isset( $url['path'] ) )
- $url_string .= $url['path'];
- if( isset( $url['query'] ) ){
- $queries = explode( '&', $url['query'] );
- foreach( $queries as $key => $val ){
- $query = explode( '=', $val );
- $query_key = $query[0];
- unset( $query[0] );
- $query_value = urlencode( implode( '=', $query ) );
- $queries[ $key ] = $query_key . '=' . $query_value;
- }
- $url_string .= '?' . implode( '&', $queries );
- }
- if( isset( $url['fragment'] ) )
- $url_string .= '#' . urlencode( $url['fragment'] ) ;
- //Wir speichern unsere URL
- update_post_meta( $post_id, 'url', $url_string );
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement