-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcuts-front-page-posts-page.php
101 lines (84 loc) · 2.78 KB
/
shortcuts-front-page-posts-page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Plugin Name: Shortcuts for Front Page and Posts Page
* Version: 1.0.1
* Plugin URI: https://romaindorr.fr
* Description: Very simple WordPress plugin to add in admin page screen 2 shortcuts for Front Page and Posts Page
* Author: Romain DORR
* Author URI: https://romaindorr.fr
* Domain Path: languages
* Text Domain: shortcuts-front-page-posts-page
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
defined( 'ABSPATH' ) or die( 'No direct load !' );
load_plugin_textdomain( 'shortcuts-front-page-posts-page', false, basename( dirname( __FILE__ ) ) . '/languages' );
// Constants
define( 'SHORTCUTS_FRONT_PAGE_POSTS_PAGE_DIR', plugin_dir_path( __FILE__ ) );
define( 'SHORTCUTS_FRONT_PAGE_POSTS_PAGE_URL', plugin_dir_url( __FILE__ ) );
define( 'SHORTCUTS_FRONT_PAGE_POSTS_PAGE_VERSION', '1.0.1' );
add_action( 'plugins_loaded', 'shortcuts_front_page_posts_page_init' );
function shortcuts_front_page_posts_page_init() {
// i18n
load_plugin_textdomain( 'shortcuts-front-page-posts-page', false, basename( SHORTCUTS_FRONT_PAGE_POSTS_PAGE_DIR ) . '/languages' );
$instance = Shortcuts_Front_Page_Posts_Page::getInstance();
$instance->hooks();
}
class Shortcuts_Front_Page_Posts_Page {
/**
* @var self
*/
protected static $instance;
protected function __construct() {
}
/**
* @return self
*/
final public static function getInstance() {
if ( is_null( self::$instance ) ) {
self::$instance = new static;
}
return self::$instance;
}
/**
* Hooks
*
* @return void
*/
public function hooks() {
add_filter( 'views_edit-page', array( __CLASS__, 'add_shortcuts' ) );
}
/**
* Display Shortcuts
*
* @return array
*/
public static function add_shortcuts( $views ) {
// Check if option exist
$show_on_front = get_option( 'show_on_front' );
if ( empty( $show_on_front ) || 'page' != $show_on_front ) {
return $views;
}
return array_merge( $views, self::get_edit_links() );
}
/**
* Get Edit Links for Front page and Posts Page
*
* @return array
*/
public static function get_edit_links() {
$edit_links = array();
$page_on_front = get_option( 'page_on_front' );
$page_for_posts = get_option( 'page_for_posts' );
if ( empty( $page_on_front ) && empty( $page_for_posts ) ) {
return $edit_links;
}
if ( ! empty( $page_on_front ) ) {
$edit_links['front-page'] = '<a href="' . get_edit_post_link( $page_on_front ) . '">' . esc_html__( 'Front Page', 'shortcuts-front-page-posts-page' ) . '</a>';
}
if ( ! empty( $page_for_posts ) ) {
$edit_links['posts-page'] = '<a href="' . get_edit_post_link( $page_for_posts ) . '">' . esc_html__( 'Posts Page', 'shortcuts-front-page-posts-page' ) . '</a>';
}
return apply_filters( 'shortcuts-front-page-posts-page-edit-links', $edit_links );
}
}