コード例 #1
0
    function page_actions()
    {
        _msan_update_notices_cache();
        wp_localize_script('msan-notice-manager', 'msan', array('notices' => array_values(msan_get_notices()), 'url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('msan-manage-notices')));
        wp_enqueue_script('msan-notice-manager');
        wp_enqueue_style('msan-notice-manager');
        ?>
		<script type="text/template" id="tmpl-msan-notice">
			<div class="msan-notice-message"> <%- message %></div>
			<div class="msan-notice-toolbar">
				<span class="msan-notice-updated"> <%- last_update %> </span>
				<% if( typeof id != 'undefined' ){ %><span class="msan-notice-id"> #<%- id %> </span><% } %>
				<a href="#" class="msan-delete-notice"><?php 
        esc_html_e('Delete', 'multisite-admin-notices');
        ?>
</a>
				<a href="#" class="msan-edit-notice"><?php 
        esc_html_e('Edit', 'multisite-admin-notices');
        ?>
</a>
			</div>
		</script>
		
		<script type="text/template" id="tmpl-msan-notice-edit">
			<div class="msan-notice-message">
				<textarea><%- message %></textarea>
			</div>
			<div class="msan-notice-toolbar">
				<span class="msan-notice-updated"> <%- last_update %> </span>
				<% if( typeof id != 'undefined' ){ %><span class="msan-notice-id"> #<%- id %> </span><% } %>
				<a href="#" class="msan-cancel-update"><?php 
        esc_html_e('Cancel', 'multisite-admin-notices');
        ?>
</a>
				<a href="#" class="msan-update-notice"><?php 
        esc_html_e('Update', 'multisite-admin-notices');
        ?>
</a>
			</div>
		</script><?php 
    }
コード例 #2
0
/**
 * Create a notice, currently the only support attribute in $args is 'message'    
 */
function msan_delete_notice($notice_id)
{
    $original_blog_id = get_current_blog_id();
    $main_blog_id = BLOG_ID_CURRENT_SITE;
    if (get_post_type($notice_id) != MSAN_NOTICE_CPT) {
        return false;
    }
    //Maybe switch to blog
    if ($original_blog_id != $main_blog_id) {
        switch_to_blog($main_blog_id);
    }
    wp_delete_post($notice_id, true);
    // Force delete
    _msan_update_notices_cache();
    //Make sure original blog is restored
    if ($original_blog_id != $main_blog_id) {
        restore_current_blog();
    }
    return true;
}