Populate meta box with current selections
This commit is contained in:
parent
90de7cb6f6
commit
798ac5f30e
2 changed files with 34 additions and 5 deletions
|
@ -40,7 +40,7 @@ class LBRY_Network
|
|||
add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
|
||||
|
||||
// Save the post meta on 'save_post' hook
|
||||
add_action('save_post', array($this, 'save_post_meta'));
|
||||
add_action('save_post', array($this, 'save_post_meta'), 10, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,11 +61,34 @@ class LBRY_Network
|
|||
/**
|
||||
* Handles saving the post meta that is relative to publishing to the LBRY Network
|
||||
*/
|
||||
public function save_post_meta()
|
||||
public function save_post_meta($post_id, $post)
|
||||
{
|
||||
// Verify the nonce before proceeding.
|
||||
if (!isset($_POST['_lbrynonce']) || !wp_verify_nonce($_POST['_lbrynonce'], 'lbry_publish_channels')) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
public function meta_box_html()
|
||||
// Check if the current user has permission to edit the post.
|
||||
$post_type = get_post_type_object($post->post_type);
|
||||
if (!current_user_can($post_type->cap->edit_post, $post_id)) {
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
$meta_key = 'lbry_channels';
|
||||
$new_channels = (isset($_POST[$meta_key]) ? $_POST[$meta_key] : null);
|
||||
$cur_channels = get_post_meta($post_id, $meta_key);
|
||||
|
||||
// COMBAK: Make this a bit more efficent if they have lots of channels
|
||||
// Start with clean meta, then add new channels if there are any
|
||||
delete_post_meta($post_id, $meta_key);
|
||||
if ($new_channels) {
|
||||
foreach ($new_channels as $channel) {
|
||||
add_post_meta($post_id, $meta_key, $channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function meta_box_html($post)
|
||||
{
|
||||
require_once(LBRY_ABSPATH . 'templates/meta_box.php');
|
||||
}
|
||||
|
|
|
@ -6,14 +6,20 @@ $unnatributed = (object) array(
|
|||
);
|
||||
$channels = LBRY()->daemon->channel_list();
|
||||
array_unshift($channels, $unnatributed);
|
||||
$cur_channels = get_post_meta($post->ID, 'lbry_channels');
|
||||
?>
|
||||
<?php wp_nonce_field('lbry_publish_channels', '_lbrynonce'); ?>
|
||||
<h4>Choose which channels you would like to publish this post to:</h4>
|
||||
<ul class="categorychecklist">
|
||||
<?php if ($channels): ?>
|
||||
<?php foreach ($channels as $channel): ?>
|
||||
<li>
|
||||
<label class="selectit">
|
||||
<input type="checkbox" name="channels[]" value="<?= $channel->permanent_url ?>">
|
||||
<input type="checkbox" name="lbry_channels[]" value="<?= $channel->permanent_url ?>"
|
||||
<?php if (in_array($channel->permanent_url, $cur_channels)): ?>
|
||||
checked="true"
|
||||
<?php endif; ?>
|
||||
>
|
||||
<?= $channel->name ?>
|
||||
</label>
|
||||
<br />
|
||||
|
|
Loading…
Reference in a new issue