Exemplo n.º 1
0
 /**
  * Register the top-level 'Snippets' menu and associated 'Manage' subpage
  *
  * @uses add_menu_page() to register a top-level menu
  * @uses add_submenu_page() to register a sub-menu
  */
 function register()
 {
     /* Register the top-level menu */
     add_menu_page(__('Snippets', 'code-snippets'), __('Snippets', 'code-snippets'), get_snippets_cap(), code_snippets_get_menu_slug(), array($this, 'render'), 'div', is_network_admin() ? 21 : 67);
     /* Register the sub-menu */
     parent::register();
 }
Exemplo n.º 2
0
<?php

/**
 * HTML code for the Add New/Edit Snippet page
 *
 * @package Code_Snippets
 * @subpackage Views
 */
/* Bail if accessed directly */
if (!defined('ABSPATH')) {
    return;
}
global $pagenow;
$table = get_snippets_table_name();
$edit_id = code_snippets_get_menu_slug('edit') === $_REQUEST['page'] ? absint($_REQUEST['id']) : 0;
$snippet = get_snippet($edit_id);
?>
<div class="wrap">
	<h1><?php 
if ($edit_id) {
    esc_html_e('Edit Snippet', 'code-snippets');
    printf(' <a href="%1$s" class="page-title-action add-new-h2">%2$s</a>', code_snippets_get_menu_url('add'), esc_html_x('Add New', 'snippet', 'code-snippets'));
} else {
    esc_html_e('Add New Snippet', 'code-snippets');
}
?>
</h1>

	<form method="post" action="" style="margin-top: 10px;">
		<?php 
/* Output the hidden fields */
Exemplo n.º 3
0
/**
 * Add an Import Snippets page to the admin menu.
 *
 * @since 1.6
 * @uses add_submenu_page() To register the menu page
 */
function code_snippets_add_import_menu()
{
    $hook = add_submenu_page(code_snippets_get_menu_slug(), __('Import Snippets', 'code-snippets'), __('Import', 'code-snippets'), get_snippets_cap(), code_snippets_get_menu_slug('import'), 'code_snippets_render_import_menu');
    add_action('load-' . $hook, 'code_snippets_load_import_menu');
}
Exemplo n.º 4
0
 /**
  * Remove the old CodeMirror version used by the Debug Bar Console plugin
  * that is messing up the snippet editor
  */
 function remove_incompatible_codemirror()
 {
     global $pagenow;
     /* Try to discern if we are on the single snippet page as best as we can at this early time */
     is_admin() && 'admin.php' === $pagenow && isset($_GET['page']) && code_snippets_get_menu_slug('edit') === $_GET['page'] && remove_action('debug_bar_enqueue_scripts', 'debug_bar_console_scripts');
 }
Exemplo n.º 5
0
/**
 * Register the top-level 'Snippets' menu and associated 'Manage' subpage
 *
 * @since 1.0
 * @access private
 *
 * @uses add_menu_page() To register a top-level menu
 * @uses add_submenu_page() To register a sub-menu
 */
function code_snippets_add_manage_menu()
{
    $hook = add_menu_page(__('Snippets', 'code-snippets'), __('Snippets', 'code-snippets'), get_snippets_cap(), code_snippets_get_menu_slug(), 'code_snippets_render_manage_menu', 'div', is_network_admin() ? 21 : 67);
    add_submenu_page(code_snippets_get_menu_slug(), __('Snippets', 'code-snippets'), __('Manage', 'code-snippets'), get_snippets_cap(), code_snippets_get_menu_slug(), 'code_snippets_render_manage_menu');
    add_action('load-' . $hook, 'code_snippets_load_manage_menu');
}
Exemplo n.º 6
0
/**
 * Loads the help tabs for the Edit Snippets page
 *
 * @since 1.0
 * @access private
 * @uses wp_redirect To pass the results to the page
 */
function code_snippets_load_single_menu()
{
    /* Make sure the user has permission to be here */
    if (!current_user_can(get_snippets_cap())) {
        wp_die(__('You are not authorized to access this page.', 'code-snippets'));
    }
    /* Create the snippet tables if they don't exist */
    create_code_snippets_tables();
    /* Load the screen help tabs */
    require plugin_dir_path(__FILE__) . 'admin-help.php';
    /* Enqueue the code editor and other scripts and styles */
    add_action('admin_enqueue_scripts', 'code_snippets_enqueue_codemirror', 9);
    /* Don't allow visiting the edit snippet page without a valid ID */
    if (code_snippets_get_menu_slug('edit') === $_REQUEST['page']) {
        if (!isset($_REQUEST['id']) || 0 == $_REQUEST['id']) {
            wp_redirect(code_snippets_get_menu_url('add'));
            exit;
        }
    }
    /* Make sure the nonce validates before we do any snippet ops */
    if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'save_snippet')) {
        return;
    }
    /* Save the snippet if one has been submitted */
    if (isset($_POST['save_snippet']) || isset($_POST['save_snippet_activate']) || isset($_POST['save_snippet_deactivate'])) {
        /* Activate or deactivate the snippet before saving if we clicked the button */
        if (isset($_POST['save_snippet_activate'])) {
            $_POST['snippet_active'] = 1;
        } elseif (isset($_POST['save_snippet_deactivate'])) {
            $_POST['snippet_active'] = 0;
        }
        /* Save the snippet to the database */
        $result = save_snippet(stripslashes_deep($_POST));
        /* Build the status message and redirect */
        $query_args = array();
        if ($result && isset($_POST['save_snippet_activate'])) {
            /* Snippet was activated addition to saving*/
            $query_args['activated'] = true;
        } elseif ($result && isset($_POST['save_snippet_deactivate'])) {
            /* Snippet was deactivated addition to saving*/
            $query_args['deactivated'] = true;
        }
        if (!$result || $result < 1) {
            /* An error occurred */
            $query_args['invalid'] = true;
        } elseif (isset($_POST['snippet_id'])) {
            /* Existing snippet was updated */
            $query_args['id'] = $result;
            $query_args['updated'] = true;
        } else {
            /* New snippet was added */
            $query_args['id'] = $result;
            $query_args['added'] = true;
        }
        /* Redirect to edit snippet page */
        wp_redirect(add_query_arg($query_args, code_snippets_get_menu_url('edit')));
    } elseif (isset($_POST['snippet_id'], $_POST['delete_snippet'])) {
        delete_snippet($_POST['snippet_id']);
        wp_redirect(add_query_arg('delete', true, code_snippets_get_menu_url('manage')));
    } elseif (isset($_POST['snippet_id'], $_POST['export_snippet'])) {
        export_snippets($_POST['snippet_id']);
    }
}
Exemplo n.º 7
0
/**
 * Fetch the admin menu hook for a snippets menu
 * @param  string $menu The menu to retrieve the hook for
 * @return string       The menu's hook
 */
function code_snippets_get_menu_hook($menu = '')
{
    $slug = code_snippets_get_menu_slug($menu);
    return get_plugin_page_hookname($slug, 'snippets');
}
Exemplo n.º 8
0
 /**
  * Register the admin menu
  */
 public function register()
 {
     $this->add_menu(code_snippets_get_menu_slug($this->name), $this->label, $this->title);
 }
Exemplo n.º 9
0
/**
 * Register the setting sub-menu
 *
 * @since 2.0
 * @access private
 *
 * @uses add_submenu_page() To register a sub-menu
 */
function code_snippets_add_settings_menu()
{
    add_submenu_page(code_snippets_get_menu_slug(), __('Snippets Settings', 'code-snippets'), __('Settings', 'code-snippets'), get_snippets_cap(), code_snippets_get_menu_slug('settings'), 'code_snippets_render_settings_menu');
}