示例#1
0
/**
 * Get the attributes for the code editor
 *
 * @param  array        $override_atts Pass an array of attributes to override the saved ones
 * @param  bool         $json_encode   Encode the data as JSON
 * @return array|string                Array if $json_encode is false, JSON string if it is true
 */
function code_snippets_get_editor_atts($override_atts, $json_encode)
{
    $settings = code_snippets_get_settings();
    $settings = $settings['editor'];
    $fields = code_snippets_get_settings_fields();
    $fields = $fields['editor'];
    $saved_atts = array('matchBrackets' => true);
    foreach ($fields as $field_id => $field) {
        $saved_atts[$field['codemirror']] = $settings[$field_id];
    }
    $atts = wp_parse_args($override_atts, $saved_atts);
    $atts = apply_filters('code_snippets_codemirror_atts', $atts);
    if ($json_encode) {
        /* JSON_UNESCAPED_SLASHES was added in PHP 5.4 */
        if (version_compare(phpversion(), '5.4.0', '>=')) {
            $atts = json_encode($atts, JSON_UNESCAPED_SLASHES);
        } else {
            /* Use a fallback for < 5.4 */
            $atts = str_replace('\\/', '/', json_encode($atts));
        }
    }
    return $atts;
}
示例#2
0
/**
 * Add a description editor to the single snippet page
 *
 * @since 1.7
 * @access private
 * @param object $snippet The snippet being used for this page
 */
function code_snippets_description_editor_box($snippet)
{
    $settings = code_snippets_get_settings();
    $settings = $settings['description_editor'];
    $media_buttons = $settings['media_buttons'];
    echo '<label for="snippet_description"><h3>';
    $heading = __('Description', 'code-snippets');
    echo $media_buttons ? $heading : "<div>{$heading}</div>";
    echo '</h3></label>';
    remove_editor_styles();
    // stop custom theme styling interfering with the editor
    wp_editor($snippet->description, 'description', apply_filters('code_snippets/admin/description_editor_settings', array('textarea_name' => 'snippet_description', 'textarea_rows' => $settings['rows'], 'teeny' => !$settings['use_full_mce'], 'media_buttons' => $media_buttons)));
}
示例#3
0
 /**
  * Add a description editor to the single snippet page
  * @param Snippet $snippet The snippet being used for this page
  */
 function render_description_editor(Snippet $snippet)
 {
     $settings = code_snippets_get_settings();
     $settings = $settings['description_editor'];
     $heading = __('Description', 'code-snippets');
     /* Hack to remove space between heading and editor tabs */
     if (!$settings['media_buttons'] && 'false' !== get_user_option('rich_editing')) {
         $heading = "<div>{$heading}</div>";
     }
     echo '<label for="snippet_description"><h3>', $heading, '</h3></label>';
     remove_editor_styles();
     // stop custom theme styling interfering with the editor
     wp_editor($snippet->desc, 'description', apply_filters('code_snippets/admin/description_editor_settings', array('textarea_name' => 'snippet_description', 'textarea_rows' => $settings['rows'], 'teeny' => !$settings['use_full_mce'], 'media_buttons' => $settings['media_buttons'])));
 }
示例#4
0
/**
 * Validate the settings
 * @param array $input
 * @return array
 */
function code_snippets_settings_validate(array $input)
{
    $settings = code_snippets_get_settings();
    $settings_fields = code_snippets_get_settings_fields();
    // Don't directly loop through $input as it does not include as deselected checkboxes
    foreach ($settings_fields as $section_id => $fields) {
        // Loop through fields
        foreach ($fields as $field) {
            $field_id = $field['id'];
            switch ($field['type']) {
                case 'checkbox':
                    $settings[$section_id][$field_id] = isset($input[$section_id][$field_id]) && 'on' === $input[$section_id][$field_id];
                    break;
                case 'number':
                    $settings[$section_id][$field_id] = absint($input[$section_id][$field_id]);
                    break;
                default:
                    $settings[$section_id][$field_id] = $input[$section_id][$field_id];
            }
        }
    }
    /* Add an updated message */
    add_settings_error('code-snippets-settings-notices', 'settings-saved', __('Settings saved.', 'code-snippets'), 'updated');
    return $settings;
}