From 0153b3b1d009c8678114a56cbee6faece3a04cca Mon Sep 17 00:00:00 2001 From: Igor V Belousov Date: Tue, 9 Jun 2015 15:18:27 +0300 Subject: [PATCH] add test module, translation & function for change title and init message --- batch.php | 48 ++++++++++++++++++++++--- batch_test.php | 53 ++++++++++++++++++++++++++++ languages/batch-operations-ru_RU.mo | Bin 0 -> 562 bytes languages/batch-operations-ru_RU.po | 22 ++++++++++++ languages/batch-operations.pot | 20 +++++++++++ 5 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 batch_test.php create mode 100644 languages/batch-operations-ru_RU.mo create mode 100644 languages/batch-operations-ru_RU.po create mode 100644 languages/batch-operations.pot diff --git a/batch.php b/batch.php index 1bbd7c7..9318fdd 100644 --- a/batch.php +++ b/batch.php @@ -8,7 +8,9 @@ */ // 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_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_action( 'wp_ajax_batch_operations', 'batch_operations_process' ); +// Add translations +add_action( 'init', 'batch_operations_load_translation_file'); + global $batch_operations_version; -$batch_operations_version = '0.1.0a'; +$batch_operations_version = '0.1.0'; /** * Create table on activate */ function batch_operations_install () { + if ( ! current_user_can( 'activate_plugins' ) ) + return; + global $wpdb; $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 */ 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 */ function batch_operations_page_view() { + global $wpdb; //WP>=3.3 wp_enqueue_script( 'jquery' ); 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' ); + $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'] ; + } + ?>
-

+

-
+
+
+ +

+
    +
  1. $current_array is empty +
  2. Default title & init_message +
  3. Set custom title & custom init_message +
+
+ 1+0dec8 z5+|M^oEjCuGdM56voOmdaY2mq^L+TP@r*!C0vkr&Zz7 zQ>y!5gu{Xj+R)d=v8K&rmsRu3vP5$lwDuELGw>o}+rj~-pQB35qE!~H(@M;vcrjXz zA{4SV3}n&$echK**AUjR#0X`3!fC^4J=2CB(kk?HZuNj}NGxofyrzTD>#ZU-WSe2j_07-xE@OrRk|K7Tjhh*=1{Q zx?;*7VAzgIbr*k<)3p=nf+MyEs`$8K{Fa8UbhHx2VT?Cr$_{jHQmB<}IW7AVf8!tg jXnf^Ie(3M<{O5;7HvSV5f9vnYzp#GiAIHD_e?KJ8nr5zd literal 0 HcmV?d00001 diff --git a/languages/batch-operations-ru_RU.po b/languages/batch-operations-ru_RU.po new file mode 100644 index 0000000..4e80dac --- /dev/null +++ b/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 \n" +"Language-Team: \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 "Инициализация." diff --git a/languages/batch-operations.pot b/languages/batch-operations.pot new file mode 100644 index 0000000..68febfb --- /dev/null +++ b/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 \n" +"Language-Team: LANGUAGE \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 ""