Created
November 4, 2014 01:48
-
-
Save ronalfy/313144f3e99245bd8df6 to your computer and use it in GitHub Desktop.
WordPress - Add Edit Link to Options-Reading Pages
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 | |
//Tested by adding to functions.php - Should work in a custom plugin though | |
class opubco_reader_edit { | |
public function __construct() { | |
add_action( 'admin_head-options-reading.php', array( $this, 'init' ) ); | |
} | |
public function init() { | |
add_filter( 'wp_dropdown_pages', array( 'opubco_reader_edit', 'add_edit_links' ) ); | |
} | |
public static function add_edit_links( $output ) { | |
if ( 'page' != get_option( 'show_on_front' ) ) return $output; | |
if ( strstr( $output, 'page_on_front' ) ) { | |
$page_id = absint( get_option( 'page_on_front' ) ); | |
if ( $page_id > 0 ) { | |
$output = $output . sprintf( ' <a href="%s">Edit</a>', esc_url( add_query_arg( array( 'post' => $page_id, 'action' => 'edit' ), admin_url( 'post.php' ) ) ) ); | |
} | |
} elseif ( strstr( $output, 'page_for_posts' ) ) { | |
$page_id = absint( get_option( 'page_for_posts' ) ); | |
if ( $page_id > 0 ) { | |
$output = $output . sprintf( ' <a href="%s">Edit</a>', esc_url( add_query_arg( array( 'post' => $page_id, 'action' => 'edit' ), admin_url( 'post.php' ) ) ) ); | |
} | |
} | |
return $output; | |
} | |
} | |
new opubco_reader_edit; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Eh, I could've used one if conditional. Re-factor if you want :D