コード例 #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'), code_snippets()->get_cap(), code_snippets()->get_menu_slug(), array($this, 'render'), 'div', is_network_admin() ? 21 : 67);
     /* Register the sub-menu */
     parent::register();
 }
コード例 #2
0
 /**
  * Register and handle the help tabs for the import snippets admin page
  */
 private function load_import_help()
 {
     $manage_url = code_snippets()->get_menu_url('manage');
     $this->screen->add_help_tab(array('id' => 'overview', 'title' => __('Overview', 'code-snippets'), 'content' => '<p>' . __('Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can load snippets from a Code Snippets (.xml) import file into the database with your existing snippets.', 'code-snippets') . '</p>'));
     $this->screen->add_help_tab(array('id' => 'import', 'title' => __('Importing', 'code-snippets'), 'content' => '<p>' . __('You can load your snippets from a code snippets (.xml) export file using this page.', 'code-snippets') . sprintf(__('Snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href="%s">Manage Snippets</a> page.</p>', 'code-snippets'), $manage_url) . '</p>'));
     $this->screen->add_help_tab(array('id' => 'export', 'title' => __('Exporting', 'code-snippets'), 'content' => '<p>' . sprintf(__('You can save your snippets to a Code Snippets (.xml) export file using the <a href="%s">Manage Snippets</a> page.', 'code-snippets'), $manage_url) . '</p>'));
 }
コード例 #3
0
 /**
  * Executed when the admin page is loaded
  */
 public function load()
 {
     /* Make sure the user has permission to be here */
     if (!current_user_can(code_snippets()->get_cap())) {
         wp_die(__('You are not authorized to access this page.', 'code-snippets'));
     }
     /* Create the snippet tables if they don't exist */
     code_snippets()->db->create_tables();
 }
コード例 #4
0
ファイル: editor-preview.php プロジェクト: shwetadubey/upfit
/**
 * Load the CSS and JavaScript for the editor preview field
 *
 * @param string $hook The current page hook
 */
function code_snippets_editor_settings_preview_assets($hook)
{
    /* Only load on the settings page */
    if (code_snippets()->get_menu_hook('settings') !== $hook) {
        return;
    }
    /* Enqueue scripts for the editor preview */
    code_snippets_enqueue_codemirror();
    /* Enqueue ALL themes */
    $themes_dir = plugin_dir_path(CODE_SNIPPETS_FILE) . 'css/min/cmthemes/';
    $themes = glob($themes_dir . '*.css');
    foreach ($themes as $theme) {
        $theme = str_replace($themes_dir, '', $theme);
        $theme = str_replace('.css', '', $theme);
        wp_enqueue_style('code-snippets-codemirror-theme-' . $theme, plugins_url("css/min/cmthemes/{$theme}.css", CODE_SNIPPETS_FILE), array('code-snippets-codemirror'));
    }
    wp_enqueue_script('jquery');
}
コード例 #5
0
ファイル: class-shortcode.php プロジェクト: shwetadubey/upfit
 function enqueue_prism($posts)
 {
     if (empty($posts) || code_snippets_get_setting('general', 'disable_prism')) {
         return $posts;
     }
     $found = false;
     foreach ($posts as $post) {
         if (false !== stripos($post->post_content, '[code_snippet')) {
             $found = true;
             break;
         }
     }
     if (!$found) {
         return $posts;
     }
     $plugin = code_snippets();
     wp_enqueue_style('code-snippets-prism', plugins_url('js/vendor/prism.css', $plugin->file), array(), $plugin->version);
     wp_enqueue_script('code-snippets-prism', plugins_url('js/vendor/prism.js', $plugin->file), array(), $plugin->version, true);
     return $posts;
 }
コード例 #6
0
ファイル: upgrade.php プロジェクト: shwetadubey/upfit
/**
 * Preform upgrade tasks such as deleting and updating options
 * @since 2.0
 */
function code_snippets_upgrader()
{
    /* Get the current plugin version from the database */
    $prev_version = get_option('code_snippets_version');
    /* Check if this is the first plugin run */
    if (!$prev_version) {
        /* Register capabilities */
        $role = get_role(apply_filters('code_snippets_role', 'administrator'));
        $role->add_cap(apply_filters('code_snippets_cap', 'manage_snippets'));
    }
    /* Check if we have upgraded from an older version */
    if (version_compare($prev_version, CODE_SNIPPETS_VERSION, '<')) {
        /* Upgrade the database tables */
        code_snippets()->db->create_tables(true);
        /* Update the plugin version stored in the database */
        update_option('code_snippets_version', CODE_SNIPPETS_VERSION);
    }
    /* Run multisite-only upgrades */
    if (is_multisite() && is_main_site()) {
        /* Get the current plugin version from the database */
        $prev_ms_version = get_site_option('code_snippets_version');
        /* Check if this is the first plugin run */
        if (!$prev_ms_version) {
            /* Register multisite capabilities */
            $network_cap = apply_filters('code_snippets_network_cap', 'manage_network_snippets');
            $supers = get_super_admins();
            foreach ($supers as $admin) {
                $user = new WP_User(0, $admin);
                $user->add_cap($network_cap);
            }
        }
        /* Check if we have upgraded from an older version */
        if (version_compare($prev_ms_version, CODE_SNIPPETS_VERSION, '<')) {
            /* Update the plugin version stored in the database */
            update_site_option('code_snippets_version', CODE_SNIPPETS_VERSION);
        }
    }
}
コード例 #7
0
ファイル: functions.php プロジェクト: shwetadubey/upfit
/**
 * Return the appropriate snippet table name
 *
 * @deprecated Use code_snippets()->db->get_table_name() instead
 * @since 2.0
 * @param string|bool|null $multisite Retrieve the multisite table name or the site table name?
 * @return string The snippet table name
 */
function get_snippets_table_name($multisite = null)
{
    return code_snippets()->db->get_table_name($multisite);
}
コード例 #8
0
ファイル: code-snippets.php プロジェクト: shwetadubey/upfit
    }
    /* Remove namespace from class name */
    $class_file = str_replace('Code_Snippets_', '', $class_name);
    /* Convert class name format to file name format */
    $class_file = strtolower($class_file);
    $class_file = str_replace('_', '-', $class_file);
    $class_path = dirname(__FILE__) . '/php/';
    if ('Menu' === substr($class_name, -4, 4)) {
        $class_path .= 'admin-menus/';
    }
    /* Load the class */
    require_once $class_path . "class-{$class_file}.php";
}
spl_autoload_register('code_snippets_autoload');
/**
 * Retrieve the instance of the main plugin class
 *
 * @since [NEXT_VERSION]
 * @return Code_Snippets
 */
function code_snippets()
{
    static $plugin;
    if (is_null($plugin)) {
        $plugin = new Code_Snippets(CODE_SNIPPETS_VERSION, __FILE__);
    }
    return $plugin;
}
code_snippets()->load_plugin();
/* Execute the snippets once the plugins are loaded */
add_action('plugins_loaded', 'execute_active_snippets', 1);
コード例 #9
0
ファイル: class-edit-menu.php プロジェクト: shwetadubey/upfit
 /**
  * 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');
 }
コード例 #10
0
ファイル: edit.php プロジェクト: shwetadubey/upfit
<?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 = code_snippets()->db->get_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 */
コード例 #11
0
ファイル: class-admin.php プロジェクト: shwetadubey/upfit
 /**
  * Adds a link pointing to the Manage Snippets page
  *
  * @since 2.0
  *
  * @param  array $links The existing plugin action links
  *
  * @return array        The modified plugin action links
  */
 function plugin_settings_link($links)
 {
     array_unshift($links, sprintf('<a href="%1$s" title="%2$s">%3$s</a>', code_snippets()->get_menu_url(), __('Manage your existing snippets', 'code-snippets'), __('Manage', 'code-snippets')));
     return $links;
 }