iBegins
 

Code thêm nút đóng mã nguồn php – WordPress

Bước 1 :

Cài plugin : TinyMCE Advanced

Tạo folder trong đường dẫn vào plugin : /ibegins.net/public_html/wp-content/plugins

Đặt tên cho folder đó ví dụ : button-php

Bước 2 :

Tạo tiếp một file trong folder trên sẽ thành : /ibegins.net/public_html/wp-content/plugins/button-php/

Đặt tên dưới dạng file : button-php.php : /ibegins.net/public_html/wp-content/plugins/button-php/button-php.php

Gắn code sau vào file button-php.php :

/*
Plugin Name: Visual Editor Buttons PHP
Plugin URI: http://ibegins.net/
Description: Adds a button to visual editor[php_][/_php].
Author: Văn Tưởng
 */
// init process for registering our button
add_action('init', 'ibegins_shortcode_button_init');
function ibegins_shortcode_button_init() {

//Abort early if the user will never see TinyMCE
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') && get_user_option('rich_editing') == 'true')
return;

//Add a callback to regiser our tinymce plugin
add_filter("mce_external_plugins", "ibegins_register_tinymce_plugin");

// Add a callback to add our button to the TinyMCE toolbar
add_filter('mce_buttons', 'ibegins_add_tinymce_button');
}

//This callback registers our plug-in
function ibegins_register_tinymce_plugin($plugin_array) {
$plugin_array['ibegins_button'] = plugin_dir_url( __FILE__ ) . 'button-js.js';
return $plugin_array;
}

//This callback adds our button to the toolbar
function ibegins_add_tinymce_button($buttons) {
//Add the button ID to the $button array
$buttons[] = "ibegins_button";
return $buttons;
}

Bước 3 :

Tạo tiếp một file JS trong folder button-php :  /ibegins.net/public_html/wp-content/plugins/button-php/

Đặt tên file JS đó button-js.js : /ibegins.net/public_html/wp-content/plugins/button-php/button-js.js

Gắn code sau vào file button-js.js :

jQuery(document).ready(function($) {

tinymce.create('tinymce.plugins.ibegins_plugin', {
init : function(ed, url) {
// Register command for when button is clicked
ed.addCommand('ibegins_insert_shortcode', function() {
selected = tinyMCE.activeEditor.selection.getContent();

if( selected ){
//If text is selected when button is clicked
//Wrap shortcode around it.
content = '
[php_]'+selected+'[/_php]
';
}else{
content = '
[php_]';
                    }

                    tinymce.execCommand('mceInsertContent', false, content);
                });

            // Register buttons - trigger above command when clicked
            ed.addButton('ibegins_button', {title : 'Insert [php]

‘, cmd : ‘ibegins_insert_shortcode’, image: url + ‘/HTML5.png’ });
},
});

// Register our TinyMCE plugin
// first parameter is the button ID1
// second parameter must match the first parameter of the tinymce.create() function above
tinymce.PluginManager.add(‘ibegins_button’, tinymce.plugins.ibegins_plugin);
});

[/php]

Bước 4 :

Tải file ảnh và thay đường link ảnh trong button-js.js trong folder button-php

Bước 5 :

Vào quản lý admin website và kích hoạt plugin đó lên.

 

Chú ý : bỏ dấu gạch _ ở chữ php.

Chúc bạn thành công.

 

 

Ngày 1 Tháng Ba, 2018 ( 489 )

Tagged with: , ,

Bình luận bài viết

Đăng nhập để bình luận và xem các bình luận khác.