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 +
+
+ \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 ""