WordPress – nowy przycisk w edytorze

  wordpress

Całość ładnie opisana tutaj http://vaughnroyko.com/add-custom-class-file-link-in-wordpress/

// Add PDF button next to Add Media
function add_pdf_button() {
    echo '<a href="#" id="add-pdf" class="button" title="Add PDF"><span class="dashicons-before dashicons-format-aside wp-media-buttons-icon"></span> Add PDF</a>';
}

add_action('media_buttons', 'add_pdf_button', 15);


// Include JavaScript for button functionality
function include_add_pdf_js_file() {
    wp_enqueue_script('media_button', get_template_directory_uri() . '/js/add-pdf.js', array('jquery'), '1.0', true);
}

add_action('wp_enqueue_media', 'include_add_pdf_js_file');

//Add CSS for editor styling to show PDF icon
function pdf_add_editor_style() {
	add_editor_style(get_template_directory_uri() . '/css/add-pdf.css');
}

add_action( 'admin_init', 'pdf_add_editor_style' );
 

a w pliku.js

var file_frame;

jQuery('#add-pdf').live('click', function( event ){

    event.preventDefault();

    // If the media frame already exists, reopen it.
    if ( file_frame ) {
        file_frame.open();
        return;
    }

    // Construct our media frame with only pdfs shown
    file_frame = wp.media.frames.file_frame = wp.media({
        title: 'Add PDF',
        multiple: false,
        library: {
            type: 'application/pdf',
        },
    });

    // When something is selected, insert our new link with a custom class into the editor
    file_frame.on( 'select', function() {
        attachment = file_frame.state().get('selection').first().toJSON();
        wp.media.editor.insert('<a class="pdf" href="' + attachment.url + '">' + attachment.title + '</a>');
    });

    file_frame.open();

});

No i css

a.pdf::before {
    content: "\f123";
    color: #888;
    font-size: 20px;
    line-height: 1;
    font-family: dashicons;
    text-decoration: inherit;
    vertical-align: top;
    padding-right: 5px;
}