add test module, translation & function for change title and init message
Этот коммит содержится в:
родитель
8335bf1ac8
Коммит
0153b3b1d0
46
batch.php
46
batch.php
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
// Create table on activate
|
// Create table on activate
|
||||||
register_activation_hook( ABSPATH . PLUGINDIR . '/batch_operations/batch.php', 'batch_operations_install');
|
register_activation_hook( ABSPATH . PLUGINDIR . '/batch_operations/batch.php', 'batch_operations_install');
|
||||||
|
// Delete table if deactivate
|
||||||
|
register_deactivation_hook( ABSPATH . PLUGINDIR . '/batch_operations/batch.php', 'batch_operations_deactivate' );
|
||||||
|
|
||||||
// Add backend page without menu item
|
// Add backend page without menu item
|
||||||
add_action( 'admin_menu', 'batch_operations_add_page' );
|
add_action( 'admin_menu', 'batch_operations_add_page' );
|
||||||
@ -16,14 +18,20 @@ add_action( 'admin_menu', 'batch_operations_add_page' );
|
|||||||
// Add JSON query for run operation
|
// Add JSON query for run operation
|
||||||
add_action( 'wp_ajax_batch_operations', 'batch_operations_process' );
|
add_action( 'wp_ajax_batch_operations', 'batch_operations_process' );
|
||||||
|
|
||||||
|
// Add translations
|
||||||
|
add_action( 'init', 'batch_operations_load_translation_file');
|
||||||
|
|
||||||
global $batch_operations_version;
|
global $batch_operations_version;
|
||||||
$batch_operations_version = '0.1.0a';
|
$batch_operations_version = '0.1.0';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create table on activate
|
* Create table on activate
|
||||||
*/
|
*/
|
||||||
function batch_operations_install () {
|
function batch_operations_install () {
|
||||||
|
if ( ! current_user_can( 'activate_plugins' ) )
|
||||||
|
return;
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$table_name = $wpdb->prefix . 'batch_operations';
|
$table_name = $wpdb->prefix . 'batch_operations';
|
||||||
@ -41,33 +49,63 @@ function batch_operations_install () {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete table if deactivate
|
||||||
|
*/
|
||||||
|
function batch_operations_deactivate(){
|
||||||
|
if ( ! current_user_can( 'activate_plugins' ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$query = 'DROP TABLE `' . $wpdb->prefix . 'batch_operations' . '`';
|
||||||
|
$wpdb->query( $query );
|
||||||
|
}
|
||||||
|
|
||||||
|
function batch_operations_load_translation_file() {
|
||||||
|
load_plugin_textdomain( 'batch-operations', false, '/batch_operations/languages' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add backend page without menu item
|
* Add backend page without menu item
|
||||||
*/
|
*/
|
||||||
function batch_operations_add_page() {
|
function batch_operations_add_page() {
|
||||||
add_management_page( 'Batch operations', '', 'edit_posts', 'batch-operations', 'batch_operations_page_view' );
|
add_submenu_page(null,'Batch operations','Batch operations','edit_posts','batch-operations','batch_operations_page_view');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View batch operations page
|
* View batch operations page
|
||||||
*/
|
*/
|
||||||
function batch_operations_page_view() {
|
function batch_operations_page_view() {
|
||||||
|
global $wpdb;
|
||||||
//WP>=3.3
|
//WP>=3.3
|
||||||
wp_enqueue_script( 'jquery' );
|
wp_enqueue_script( 'jquery' );
|
||||||
wp_enqueue_script( 'batch_operations_script', plugin_dir_url('') . 'batch_operations/js/batch.min.js' );
|
wp_enqueue_script( 'batch_operations_script', plugin_dir_url('') . 'batch_operations/js/batch.min.js' );
|
||||||
wp_enqueue_style( 'batch_operations_script', plugin_dir_url('') . 'batch_operations/css/batch.css' );
|
wp_enqueue_style( 'batch_operations_script', plugin_dir_url('') . 'batch_operations/css/batch.css' );
|
||||||
|
|
||||||
$id = ( intval( $_REQUEST["id"] ) < 0 )? 0 : intval( $_REQUEST["id"] );
|
$id = ( intval( $_REQUEST["id"] ) < 0 )? 0 : intval( $_REQUEST["id"] );
|
||||||
|
|
||||||
|
$current_array = $wpdb->get_var( 'SELECT `operations` FROM `' . $wpdb->prefix . "batch_operations` WHERE `id` = $id;" );
|
||||||
|
|
||||||
|
$title = __( 'Processing', 'batch-operations' );
|
||||||
|
$init_message = '';
|
||||||
|
if ( ! empty( $current_array ) ) {
|
||||||
|
$current_array = unserialize( $current_array );
|
||||||
|
$title = ( empty ( $current_array['title'] ) ) ? $title : $current_array['title'] ;
|
||||||
|
$init_message = ( empty ( $current_array['init_message'] ) ) ? __( 'Initializing.', 'batch-operations' ) : $current_array['init_message'] ;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var batch_id=<?php print $id; ?>,successful_page='<?php print get_admin_url(); ?>';
|
var batch_id=<?php print $id; ?>,successful_page='<?php print get_admin_url(); ?>';
|
||||||
</script>
|
</script>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<?php screen_icon(); ?>
|
<?php screen_icon(); ?>
|
||||||
<h2><?php echo get_admin_page_title() ?></h2>
|
<h2><?php echo $title ?></h2>
|
||||||
<div class="batch-progress">
|
<div class="batch-progress">
|
||||||
<span style="width:0%;"></span>
|
<span style="width:0%;"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="batch-message"></div>
|
<div class="batch-message"><?php echo $init_message; ?></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
53
batch_test.php
Обычный файл
53
batch_test.php
Обычный файл
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Plugin Name: Batch operations TEST
|
||||||
|
* Description: DEV TEST
|
||||||
|
* Version: 0.1.0
|
||||||
|
* Author: Igor V Belousov
|
||||||
|
* Author URI: http://belousovv.ru/
|
||||||
|
*/
|
||||||
|
|
||||||
|
add_action( 'admin_menu', 'batch_operations_test_add_page' );
|
||||||
|
|
||||||
|
function batch_operations_test_add_page() {
|
||||||
|
add_management_page( 'Batch operations TEST', 'Batch TEST', 'edit_posts', 'batch-operations-test', 'batch_operations_test_page_view' );
|
||||||
|
}
|
||||||
|
|
||||||
|
function batch_operations_test_page_view() {
|
||||||
|
|
||||||
|
$test = ( empty ($_REQUEST["test"] ) )? 0 : $_REQUEST["test"];
|
||||||
|
|
||||||
|
switch ($test) {
|
||||||
|
case 2:
|
||||||
|
$batch['operations'][]=array('test_batch_operation',array());
|
||||||
|
batch_operations_start($batch);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
$batch['title']="Custom Title";
|
||||||
|
$batch['init_message']="Custom Init Message";
|
||||||
|
$batch['operations'][]=array('test_batch_operation',array());
|
||||||
|
batch_operations_start($batch);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<?php screen_icon(); ?>
|
||||||
|
<h2><?php echo get_admin_page_title() ?></h2>
|
||||||
|
<ol>
|
||||||
|
<li><a href="tools.php?page=batch-operations&id=0">$current_array is empty</a>
|
||||||
|
<li><a href="tools.php?page=batch-operations-test&test=2">Default <strong>title</strong> & <strong>init_message</strong></a>
|
||||||
|
<li><a href="tools.php?page=batch-operations-test&test=3">Set <strong>custom title</strong> & <strong>custom init_message</strong></a>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_batch_operation(&$context) {
|
||||||
|
sleep(1);
|
||||||
|
$context['message'] = 'Yeap! Work!';
|
||||||
|
}
|
Двоичные данные
languages/batch-operations-ru_RU.mo
Обычный файл
Двоичные данные
languages/batch-operations-ru_RU.mo
Обычный файл
Двоичный файл не отображается.
22
languages/batch-operations-ru_RU.po
Обычный файл
22
languages/batch-operations-ru_RU.po
Обычный файл
@ -0,0 +1,22 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Batch operations\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2015-06-09 15:05+0300\n"
|
||||||
|
"PO-Revision-Date: 2015-06-09 15:07+0300\n"
|
||||||
|
"Last-Translator: Igor V Belousov <igor@belousovv.ru>\n"
|
||||||
|
"Language-Team: <igor@belousovv.ru>\n"
|
||||||
|
"Language: ru_RU\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.5.5\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
|
||||||
|
#: batch.php:90
|
||||||
|
msgid "Processing"
|
||||||
|
msgstr "Обработка"
|
||||||
|
|
||||||
|
#: batch.php:95
|
||||||
|
msgid "Initializing."
|
||||||
|
msgstr "Инициализация."
|
20
languages/batch-operations.pot
Обычный файл
20
languages/batch-operations.pot
Обычный файл
@ -0,0 +1,20 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Batch operations 0.1.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: igor@belousovv.ru\n"
|
||||||
|
"POT-Creation-Date: 2015-06-09 15:05+0300\n"
|
||||||
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
"Language: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=CHARSET\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
|
#: batch.php:90
|
||||||
|
msgid "Processing"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: batch.php:95
|
||||||
|
msgid "Initializing."
|
||||||
|
msgstr ""
|
Загрузка…
Ссылка в новой задаче
Block a user