Datei drafts-for-friends.php
:
<?php
/*
Plugin Name: Drafts for Friends
Plugin URI: https://wp-plugin-erstellen.de
Version: 0.1.0
Author: Florian Simeth
Author URI: https://florian-simeth.de
Description: Allows to create links to draft posts.
Text Domain: drafts-for-friends
Domain Path: /languages
License: GPL
*/
add_action( 'admin_menu', 'dff_menus' );
function dff_menus() {
add_submenu_page(
'edit.php', # Eltern-Menü
__( 'Drafts for Friends', 'drafts-for-friends' ), # Seitentitel
__( 'Drafts for Friends', 'drafts-for-friends' ), # Menütitel
'manage_options', # Benutzerrecht
'drafts-for-friends', # Menü-Slug
'dff_settings_page_render' # Funktionsname
);
}
function dff_settings_page_render() {
?>
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<?php
include( plugin_dir_path( __FILE__ ) . '/templates/released-posts.php' );
include( plugin_dir_path( __FILE__ ) . '/templates/new-draft-form.php' );
?>
</div>
<?php
}
function dff_draft_select_options() {
$query = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'draft',
'meta_query' => array(
array(
'key' => 'dff_key',
'compare' => 'NOT EXISTS',
),
),
) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
printf(
'<option value="%d">%s</option>',
get_the_ID(),
esc_attr( get_the_title() )
);
}
} else {
printf(
'<option value="0">%s</option>',
esc_attr__( 'No drafts found.', 'drafts-for-friends' )
);
}
}
Datei templates/new-draft-form.php
: