woocommerce/includes/admin/class-wc-admin-pointers.php

287 lines
9.2 KiB
PHP
Raw Normal View History

2015-04-30 12:30:03 +00:00
<?php
/**
2015-11-03 13:53:50 +00:00
* Adds and controls pointers for contextual help/tutorials
2015-04-30 12:30:03 +00:00
*
2015-08-07 13:37:45 +00:00
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin
* @version 2.4.0
2015-04-30 12:30:03 +00:00
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WC_Admin_Pointers Class.
2015-04-30 12:30:03 +00:00
*/
class WC_Admin_Pointers {
/**
* Constructor.
2015-04-30 12:30:03 +00:00
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'setup_pointers_for_screen' ) );
}
/**
* Setup pointers for screen.
2015-04-30 12:30:03 +00:00
*/
public function setup_pointers_for_screen() {
if ( ! $screen = get_current_screen() ) {
return;
}
2015-04-30 12:30:03 +00:00
switch ( $screen->id ) {
case 'product':
2015-04-30 12:30:03 +00:00
$this->create_product_tutorial();
break;
2015-04-30 12:30:03 +00:00
}
}
/**
* Pointers for creating a product.
2015-04-30 12:30:03 +00:00
*/
public function create_product_tutorial() {
if ( ! isset( $_GET['tutorial'] ) || ! current_user_can( 'manage_options' ) ) {
return;
}
// These pointers will chain - they will not be shown at once.
$pointers = array(
'pointers' => array(
'title' => array(
'target' => '#title',
2015-04-30 12:30:03 +00:00
'next' => 'content',
'next_trigger' => array(
'target' => '#title',
'event' => 'input',
2015-04-30 12:30:03 +00:00
),
'options' => array(
'content' => '<h3>' . esc_html__( 'Product name', 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__( 'Give your new product a name here. This is a required field and will be what your customers will see in your store.', 'woocommerce' ) . '</p>',
'position' => array(
'edge' => 'top',
'align' => 'left',
),
),
2015-04-30 12:30:03 +00:00
),
'content' => array(
'target' => '#wp-content-editor-container',
2015-04-30 12:34:51 +00:00
'next' => 'product-type',
'next_trigger' => array(),
2015-04-30 12:30:03 +00:00
'options' => array(
'content' => '<h3>' . esc_html__( 'Product description', 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__( 'This is your products main body of content. Here you should describe your product in detail.', 'woocommerce' ) . '</p>',
'position' => array(
'edge' => 'bottom',
'align' => 'middle',
),
),
2015-04-30 12:30:03 +00:00
),
'product-type' => array(
'target' => '#product-type',
2015-04-30 12:30:03 +00:00
'next' => 'virtual',
'next_trigger' => array(
'target' => '#product-type',
'event' => 'change blur click',
2015-04-30 12:30:03 +00:00
),
'options' => array(
'content' => '<h3>' . esc_html__( 'Choose product type', 'woocommerce' ) . '</h3>' .
2015-04-30 12:34:51 +00:00
'<p>' . esc_html__( 'Choose a type for this product. Simple is suitable for most physical goods and services (we recommend setting up a simple product for now).', 'woocommerce' ) . '</p>' .
2015-08-07 13:37:45 +00:00
'<p>' . esc_html__( 'Variable is for more complex products such as t-shirts with multiple sizes.', 'woocommerce' ) . '</p>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__( 'Grouped products are for grouping several simple products into one.', 'woocommerce' ) . '</p>' .
'<p>' . esc_html__( 'Finally, external products are for linking off-site.', 'woocommerce' ) . '</p>',
'position' => array(
'edge' => 'bottom',
'align' => 'middle',
),
),
2015-04-30 12:30:03 +00:00
),
'virtual' => array(
'target' => '#_virtual',
2015-04-30 12:30:03 +00:00
'next' => 'downloadable',
'next_trigger' => array(
'target' => '#_virtual',
'event' => 'change',
2015-04-30 12:30:03 +00:00
),
'options' => array(
'content' => '<h3>' . esc_html__( 'Virtual products', 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__( 'Check the "Virtual" box if this is a non-physical item, for example a service, which does not need shipping.', 'woocommerce' ) . '</p>',
'position' => array(
'edge' => 'bottom',
'align' => 'middle',
),
),
2015-04-30 12:30:03 +00:00
),
'downloadable' => array(
'target' => '#_downloadable',
2015-04-30 12:30:03 +00:00
'next' => 'regular_price',
'next_trigger' => array(
'target' => '#_downloadable',
'event' => 'change',
2015-04-30 12:30:03 +00:00
),
'options' => array(
'content' => '<h3>' . esc_html__( 'Downloadable products', 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__( 'If purchasing this product gives a customer access to a downloadable file, e.g. software, check this box.', 'woocommerce' ) . '</p>',
'position' => array(
'edge' => 'bottom',
'align' => 'middle',
),
),
2015-04-30 12:30:03 +00:00
),
'regular_price' => array(
'target' => '#_regular_price',
2015-04-30 12:30:03 +00:00
'next' => 'postexcerpt',
'next_trigger' => array(
'target' => '#_regular_price',
'event' => 'input',
2015-04-30 12:30:03 +00:00
),
'options' => array(
'content' => '<h3>' . esc_html__( 'Prices', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( 'Next you need to give your product a price.', 'woocommerce' ) . '</p>',
2015-04-30 12:30:03 +00:00
'position' => array(
'edge' => 'bottom',
'align' => 'middle',
),
),
2015-04-30 12:30:03 +00:00
),
'postexcerpt' => array(
'target' => '#postexcerpt',
2015-04-30 12:30:03 +00:00
'next' => 'postimagediv',
'next_trigger' => array(
'target' => '#postexcerpt',
'event' => 'input',
2015-04-30 12:30:03 +00:00
),
'options' => array(
'content' => '<h3>' . esc_html__( 'Product short description', 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__( 'Add a quick summary for your product here. This will appear on the product page under the product name.', 'woocommerce' ) . '</p>',
'position' => array(
'edge' => 'bottom',
'align' => 'middle',
),
),
2015-04-30 12:30:03 +00:00
),
'postimagediv' => array(
'target' => '#postimagediv',
'next' => 'product_tag',
2015-04-30 12:30:03 +00:00
'options' => array(
'content' => '<h3>' . esc_html__( 'Product images', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( "Upload or assign an image to your product here. This image will be shown in your store's catalog.", 'woocommerce' ) . '</p>',
2015-04-30 12:30:03 +00:00
'position' => array(
2015-04-30 12:34:51 +00:00
'edge' => 'right',
'align' => 'middle',
),
),
2015-04-30 12:30:03 +00:00
),
'product_tag' => array(
'target' => '#tagsdiv-product_tag',
'next' => 'product_catdiv',
2015-04-30 12:30:03 +00:00
'options' => array(
'content' => '<h3>' . esc_html__( 'Product tags', 'woocommerce' ) . '</h3>' .
2017-08-03 06:19:57 +00:00
'<p>' . esc_html__( 'You can optionally "tag" your products here. Tags are a method of labeling your products to make them easier for customers to find.', 'woocommerce' ) . '</p>',
2015-04-30 12:30:03 +00:00
'position' => array(
2015-04-30 12:34:51 +00:00
'edge' => 'right',
'align' => 'middle',
),
),
2015-04-30 12:30:03 +00:00
),
'product_catdiv' => array(
'target' => '#product_catdiv',
'next' => 'submitdiv',
2015-04-30 12:30:03 +00:00
'options' => array(
'content' => '<h3>' . esc_html__( 'Product categories', 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__( 'Optionally assign categories to your products to make them easier to browse through and find in your store.', 'woocommerce' ) . '</p>',
'position' => array(
2015-04-30 12:34:51 +00:00
'edge' => 'right',
'align' => 'middle',
),
),
2015-04-30 12:30:03 +00:00
),
'submitdiv' => array(
'target' => '#submitdiv',
'next' => '',
2015-04-30 12:30:03 +00:00
'options' => array(
'content' => '<h3>' . esc_html__( 'Publish your product!', 'woocommerce' ) . '</h3>' .
2015-04-30 12:30:03 +00:00
'<p>' . esc_html__( 'When you are finished editing your product, hit the "Publish" button to publish your product to your store.', 'woocommerce' ) . '</p>',
'position' => array(
2015-04-30 12:34:51 +00:00
'edge' => 'right',
'align' => 'middle',
),
),
),
),
2015-04-30 12:30:03 +00:00
);
$this->enqueue_pointers( $pointers );
}
/**
* Enqueue pointers and add script to page.
*
* @param array $pointers
2015-04-30 12:30:03 +00:00
*/
public function enqueue_pointers( $pointers ) {
$pointers = wp_json_encode( $pointers );
2015-04-30 12:30:03 +00:00
wp_enqueue_style( 'wp-pointer' );
wp_enqueue_script( 'wp-pointer' );
wc_enqueue_js(
"jQuery( function( $ ) {
2015-04-30 12:30:03 +00:00
var wc_pointers = {$pointers};
setTimeout( init_wc_pointers, 800 );
function init_wc_pointers() {
$.each( wc_pointers.pointers, function( i ) {
show_wc_pointer( i );
return false;
});
2015-04-30 12:30:03 +00:00
}
function show_wc_pointer( id ) {
var pointer = wc_pointers.pointers[ id ];
var options = $.extend( pointer.options, {
pointerClass: 'wp-pointer wc-pointer',
close: function() {
if ( pointer.next ) {
show_wc_pointer( pointer.next );
}
},
buttons: function( event, t ) {
var close = '" . esc_js( __( 'Dismiss', 'woocommerce' ) ) . "',
next = '" . esc_js( __( 'Next', 'woocommerce' ) ) . "',
button = $( '<a class=\"close\" href=\"#\">' + close + '</a>' ),
button2 = $( '<a class=\"button button-primary\" href=\"#\">' + next + '</a>' ),
wrapper = $( '<div class=\"wc-pointer-buttons\" />' );
button.bind( 'click.pointer', function(e) {
e.preventDefault();
t.element.pointer('destroy');
});
button2.bind( 'click.pointer', function(e) {
e.preventDefault();
t.element.pointer('close');
});
wrapper.append( button );
wrapper.append( button2 );
return wrapper;
},
} );
var this_pointer = $( pointer.target ).pointer( options );
this_pointer.pointer( 'open' );
2015-04-30 12:30:03 +00:00
if ( pointer.next_trigger ) {
$( pointer.next_trigger.target ).on( pointer.next_trigger.event, function() {
setTimeout( function() { this_pointer.pointer( 'close' ); }, 400 );
});
}
2015-04-30 12:30:03 +00:00
}
});"
);
2015-04-30 12:30:03 +00:00
}
}
new WC_Admin_Pointers();