add notice
Этот коммит содержится в:
родитель
f84205e5ce
Коммит
aa5677fcf6
@ -16,7 +16,8 @@ module.exports = function(grunt) {
|
|||||||
compile: {
|
compile: {
|
||||||
|
|
||||||
files: {
|
files: {
|
||||||
'css/batch.css':'css/batch.styl'
|
'css/batch.css':'css/batch.styl',
|
||||||
|
'css/notice.css':'css/notice.styl'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -24,7 +25,8 @@ module.exports = function(grunt) {
|
|||||||
csso: {
|
csso: {
|
||||||
dist: {
|
dist: {
|
||||||
files: {
|
files: {
|
||||||
'css/batch.css':'css/batch.css'
|
'css/batch.css':'css/batch.css',
|
||||||
|
'css/notice.css':'css/notice.css'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
71
batch.php
71
batch.php
@ -16,9 +16,15 @@ add_action( 'wp_ajax_batch_operations', 'batch_operations_process' );
|
|||||||
// Add translations
|
// Add translations
|
||||||
add_action( 'init', 'batch_operations_load_translation_file' );
|
add_action( 'init', 'batch_operations_load_translation_file' );
|
||||||
|
|
||||||
|
// Add huck for view messages
|
||||||
|
add_action( 'admin_notices', 'batch_operations_notice_view' );
|
||||||
|
|
||||||
global $batch_operations_version;
|
global $batch_operations_version;
|
||||||
$batch_operations_version = '0.1.0';
|
$batch_operations_version = '0.1.0';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load translation file
|
||||||
|
*/
|
||||||
function batch_operations_load_translation_file() {
|
function batch_operations_load_translation_file() {
|
||||||
load_plugin_textdomain( 'batch-operations', false, '/batch_operations/languages' );
|
load_plugin_textdomain( 'batch-operations', false, '/batch_operations/languages' );
|
||||||
}
|
}
|
||||||
@ -155,12 +161,14 @@ function batch_operations_process () {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li> operations: (required) Array of operations to be performed, where each item is an array consisting of the name of an implementation of callback_batch_operation() and an array of parameter. Example:
|
* <li> operations: (required) Array of operations to be performed, where each item is an array consisting of the name
|
||||||
|
* of an implementation of callback_batch_operation() and an array of parameter. Example:
|
||||||
* <li> title: A safe, translated string to use as the title for the progress page. Defaults to __('Processing').
|
* <li> title: A safe, translated string to use as the title for the progress page. Defaults to __('Processing').
|
||||||
* <li> init_message: Message displayed while the processing is initialized. Defaults to __('Initializing.').
|
* <li> init_message: Message displayed while the processing is initialized. Defaults to __('Initializing.').
|
||||||
* <li> progress_message: Message displayed while processing the batch. Available placeholders are %current% and %total%.
|
* <li> progress_message: Message displayed while processing the batch. Available placeholders are %current% and %total%.
|
||||||
* <li> error_message: Message displayed if an error occurred while processing the batch. Defaults to __('An error has occurred.').
|
* <li> error_message: Message displayed if an error occurred while processing the batch. Defaults to __('An error has occurred.').
|
||||||
* <li> finished: Name of an implementation of callback_batch_finished(). This is executed after the batch has completed. This should be used to perform any result massaging that may be needed, and possibly save data in $_SESSION for display after final page redirection.
|
* <li> finished: Name of an implementation of callback_batch_finished(). This is executed after the batch has completed. This should be used to perform any result massaging that may be needed, and possibly save data in $_SESSION for display after final page redirection.
|
||||||
|
* </ul>
|
||||||
*
|
*
|
||||||
* Sample callback_batch_operation():
|
* Sample callback_batch_operation():
|
||||||
*
|
*
|
||||||
@ -169,23 +177,27 @@ function batch_operations_process () {
|
|||||||
* $context['results'][] = $text . $id;
|
* $context['results'][] = $text . $id;
|
||||||
* $context['message'] = 'Text + id ='.$text . $id;
|
* $context['message'] = 'Text + id ='.$text . $id;
|
||||||
* }
|
* }
|
||||||
|
* </pre>
|
||||||
*
|
*
|
||||||
* The $context array gathers batch context information about the execution (read),
|
* The $context array gathers batch context information about the execution (read),
|
||||||
* as well as 'return values' for the current operation (write)
|
* as well as 'return values' for the current operation (write)
|
||||||
* The following keys are provided :
|
* The following keys are provided :
|
||||||
|
*
|
||||||
* 'results' (read / write): The array of results gathered so far by
|
* 'results' (read / write): The array of results gathered so far by
|
||||||
* the batch processing, for the current operation to append its own.
|
* the batch processing, for the current operation to append its own.
|
||||||
|
*
|
||||||
* 'message' (write): A text message displayed in the progress page.
|
* 'message' (write): A text message displayed in the progress page.
|
||||||
* The following keys allow for multi-step operations :
|
* The following keys allow for multi-step operations :
|
||||||
|
*
|
||||||
* 'sandbox' (read / write): An array that can be freely used to
|
* 'sandbox' (read / write): An array that can be freely used to
|
||||||
* store persistent data between iterations. It is recommended to
|
* store persistent data between iterations. It is recommended to
|
||||||
* use this instead of $_SESSION, which is unsafe if the user
|
* use this instead of $_SESSION, which is unsafe if the user
|
||||||
* continues browsing in a separate window while the batch is processing.
|
* continues browsing in a separate window while the batch is processing.
|
||||||
|
*
|
||||||
* 'finished' (write): A float number between 0 and 1 informing
|
* 'finished' (write): A float number between 0 and 1 informing
|
||||||
* the processing engine of the completion level for the operation.
|
* the processing engine of the completion level for the operation.
|
||||||
* 1 (or no value explicitly set) means the operation is finished
|
* 1 (or no value explicitly set) means the operation is finished
|
||||||
* and the batch processing can continue to the next operation.
|
* and the batch processing can continue to the next operation.
|
||||||
* </pre>
|
|
||||||
*
|
*
|
||||||
* @param array $batch_arr array operations and more
|
* @param array $batch_arr array operations and more
|
||||||
* @param string $redirect Url to redirect to when the batch has finished processing
|
* @param string $redirect Url to redirect to when the batch has finished processing
|
||||||
@ -229,3 +241,58 @@ function batch_operations_start( $batch_arr, $redirect = NULL )
|
|||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set message for next view for current user
|
||||||
|
*
|
||||||
|
* @param string $message message text
|
||||||
|
* @param string $type type of message: info, success, warning, error. default - info
|
||||||
|
*/
|
||||||
|
function batch_operations_notice( $message, $type = 'info' ) {
|
||||||
|
|
||||||
|
if ( false === ( $messages = get_transient( 'batch_operations_notice' ) ) ) {
|
||||||
|
$messages = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$messages[ get_current_user_id() ][] = array(
|
||||||
|
'message' => $message,
|
||||||
|
'type' => $type
|
||||||
|
);
|
||||||
|
|
||||||
|
set_transient( 'batch_operations_notice', $messages );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* View message
|
||||||
|
*/
|
||||||
|
function batch_operations_notice_view() {
|
||||||
|
if ( $messages = get_transient( 'batch_operations_notice' ) ) {
|
||||||
|
$current_uid = get_current_user_id();
|
||||||
|
if ( ! empty( $messages[ $current_uid ] ) ) {
|
||||||
|
// if version < 4.1.1 then add css
|
||||||
|
global $wp_version;
|
||||||
|
|
||||||
|
$version = explode( '.', $wp_version );
|
||||||
|
|
||||||
|
if ( 4 > $version[0] || ( ( 4 == $version[0] && 1 >= $version[1] ) && 2 == count( $version ) ) ) {
|
||||||
|
global $batch_operations_version;
|
||||||
|
wp_enqueue_style( 'batch_operations_script', plugin_dir_url('') . 'batch_operations/css/notice.css', array(), $batch_operations_version );
|
||||||
|
}
|
||||||
|
|
||||||
|
// print message
|
||||||
|
foreach ( $messages[ $current_uid ] as $key => $value ) {
|
||||||
|
echo '<div class="notice notice-' . $value['type'] . '"><p>' . $value['message'] . '</p></div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
//delete messages
|
||||||
|
unset( $messages[ $current_uid ] );
|
||||||
|
|
||||||
|
if ( empty( $messages ) ) {
|
||||||
|
delete_transient( 'batch_operations_notice' );
|
||||||
|
} else {
|
||||||
|
set_transient( 'batch_operations_notice', $messages );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -74,6 +74,11 @@ function batch_operations_test_page_view() {
|
|||||||
batch_operations_start($batch,get_admin_url( null, 'tools.php' ) . "?page=batch-operations-test");
|
batch_operations_start($batch,get_admin_url( null, 'tools.php' ) . "?page=batch-operations-test");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 10:
|
||||||
|
$batch['operations'][]=array('test_batch_operation_messages',array());
|
||||||
|
batch_operations_start($batch,get_admin_url( null, 'tools.php' ) . "?page=batch-operations-test");
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -91,11 +96,22 @@ function batch_operations_test_page_view() {
|
|||||||
<li><a href="tools.php?page=batch-operations-test&test=7">Test params</a>
|
<li><a href="tools.php?page=batch-operations-test&test=7">Test params</a>
|
||||||
<li><a href="tools.php?page=batch-operations-test&test=8">Test operations in class</a>
|
<li><a href="tools.php?page=batch-operations-test&test=8">Test operations in class</a>
|
||||||
<li><a href="tools.php?page=batch-operations-test&test=9">Test redirect</a>
|
<li><a href="tools.php?page=batch-operations-test&test=9">Test redirect</a>
|
||||||
|
<li><a href="tools.php?page=batch-operations-test&test=10">Test messages</a>
|
||||||
|
<li><a href="tools.php?page=batch-operations-test&test=11">Test finished_callback</a>
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_batch_operation_messages( &$context ) {
|
||||||
|
batch_operations_notice('default');
|
||||||
|
batch_operations_notice('info','info');
|
||||||
|
batch_operations_notice('success','success');
|
||||||
|
batch_operations_notice('warning','warning');
|
||||||
|
batch_operations_notice('error','error');
|
||||||
|
$context['message'] = "Messages test";
|
||||||
|
}
|
||||||
|
|
||||||
function test_batch_operation( &$context ) {
|
function test_batch_operation( &$context ) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
$context['message'] = 'Yeap! Work!';
|
$context['message'] = 'Yeap! Work!';
|
||||||
|
1
css/notice.css
Обычный файл
1
css/notice.css
Обычный файл
@ -0,0 +1 @@
|
|||||||
|
.notice{background:#fff;border-left:4px solid #fff;-moz-box-shadow:2px 2px 5px #888;-webkit-box-shadow:2px 2px 5px #888;box-shadow:2px 2px 5px #888;margin:15px;padding:1px 12px}.notice p{margin:.5em 0;padding:2px}.notice-info{border-color:#2ea2cc}.notice-success{border-color:#7ad03a}.notice-warning{border-color:#ffba00}.notice-error{border-color:#dd3d36}
|
31
css/notice.styl
Обычный файл
31
css/notice.styl
Обычный файл
@ -0,0 +1,31 @@
|
|||||||
|
@import "ShortCSS/ShortCSS"
|
||||||
|
|
||||||
|
.notice
|
||||||
|
-bg white
|
||||||
|
-brl 4px solid #fff
|
||||||
|
bx-shadow 2px 2px 5px #888
|
||||||
|
-m 15px
|
||||||
|
-p 1px 12px
|
||||||
|
|
||||||
|
p
|
||||||
|
-m .5em 0
|
||||||
|
-p 2px
|
||||||
|
|
||||||
|
|
||||||
|
.notice-info
|
||||||
|
-brc #2ea2cc
|
||||||
|
|
||||||
|
|
||||||
|
.notice-success
|
||||||
|
-brc #7ad03a
|
||||||
|
|
||||||
|
|
||||||
|
.notice-warning
|
||||||
|
-brc #ffba00
|
||||||
|
|
||||||
|
|
||||||
|
.notice-error
|
||||||
|
-brc #dd3d36
|
||||||
|
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче
Block a user