Guest User

Untitled

a guest
Jan 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. <?php
  2. /**
  3. * Adds and controls pointers for contextual help/tutorials
  4. *
  5. * @author WooThemes
  6. * @category Admin
  7. * @package WooCommerce/Admin
  8. * @version 2.4.0
  9. */
  10.  
  11. if ( ! defined( 'ABSPATH' ) ) {
  12. exit;
  13. }
  14.  
  15. /**
  16. * SD_Admin_Pointers Class.
  17. */
  18. class SD_Admin_Pointers {
  19.  
  20. /**
  21. * Constructor.
  22. */
  23. public function __construct() {
  24. add_action( 'admin_enqueue_scripts', array( $this, 'create_product_tutorial' ), 1000 );
  25. }
  26.  
  27. /**
  28. * Pointers for creating a product.
  29. */
  30. public function create_product_tutorial() {
  31. $user_id = get_current_user_id();
  32. $show_tutorial = get_user_meta( $user_id, 'not_show_tutorial' );
  33. if ( ! isset( $_GET['tutorial'] ) || !current_user_can('smart_dealer') || $show_tutorial ) {
  34. return;
  35. }
  36. // If tutorial var is exist in $_GET.
  37. if ( 'show' == $_GET['tutorial'] ) {
  38. update_user_meta( $user_id, 'not_show_tutorial', true );
  39. }
  40.  
  41. // These pointers will chain - they will not be shown at once.
  42. // Don't run on WP < 3.3
  43. if ( get_bloginfo( 'version' ) < '3.3' )
  44. return;
  45. $screen = get_current_screen();
  46. $screen_id = $screen->id;
  47.  
  48. // Get pointers for this screen
  49. $pointers = array();
  50. if( 'smart_deal' == $screen_id && current_user_can('smart_dealer')){
  51. $pointers['title'] = array(
  52. 'target' => "#title",
  53. 'next' => 'content',
  54. 'next_trigger' => array(
  55. 'target' => '#title',
  56. 'event' => 'input',
  57. ),
  58. 'options' => array(
  59. 'content' => '<h3>' . esc_html__( 'Deal Title', 'dx-smart-deal' ) . '</h3>' .
  60. '<p>' . esc_html__( 'Give your new Deal a title here. This is a required field and will be what your customers will see on Smart deal page.', 'dx-smart-deal' ) . '</p>',
  61. 'position' => array(
  62. 'edge' => 'top',
  63. 'align' => 'left',
  64. ),
  65. ),
  66. );
  67. $pointers['content'] = array(
  68. 'target' => "#wp-content-editor-container",
  69. 'next' => 'clickthrough-url',
  70. 'next_trigger' => array(),
  71. 'options' => array(
  72. 'content' => '<h3>' . esc_html__( 'Deal description', 'dx-smart-deal' ) . '</h3>' .
  73. '<p>' . esc_html__( 'This is your Deal main content. Here you should describe your Deal in detail.', 'dx-smart-deal' ) . '</p>',
  74. 'position' => array(
  75. 'edge' => 'bottom',
  76. 'align' => 'middle',
  77. ),
  78. ),
  79. );
  80.  
  81. $pointers['clickthrough-url'] = array(
  82. 'target' => "#acf-field_59f34fe7c7012",
  83. 'next' => 'company-name',
  84. 'next_trigger' => array(),
  85. 'options' => array(
  86. 'content' => '<h3>' . esc_html__( 'Click Through URL', 'dx-smart-deal' ) . '</h3>' .
  87. '<p>' . esc_html__( 'Click Through URL is the External URL of your deal', 'dx-smart-deal' ) . '</p>',
  88. 'position' => array(
  89. 'edge' => 'bottom',
  90. 'align' => 'middle',
  91. ),
  92. ),
  93. );
  94. $pointers['company-name'] = array(
  95. 'target' => "#acf-field_5a2fe11317dbe",
  96. 'next' => 'deal-duration',
  97. 'next_trigger' => array(),
  98. 'options' => array(
  99. 'content' => '<h3>' . esc_html__( 'Company Name', 'dx-smart-deal' ) . '</h3>' .
  100. '<p>' . esc_html__( 'Here you should give your company name deal. It visible on deal page.', 'dx-smart-deal' ) . '</p>',
  101. 'position' => array(
  102. 'edge' => 'bottom',
  103. 'align' => 'middle',
  104. ),
  105. ),
  106. );
  107. $pointers['deal-duration'] = array(
  108. 'target' => "#acf-group_5509e5d9b31f3",
  109. 'next' => 'smart_deal_categorydiv',
  110. 'next_trigger' => array(),
  111. 'options' => array(
  112. 'content' => '<h3>' . esc_html__( 'DealDeal Duration', 'dx-smart-deal' ) . '</h3>' .
  113. '<p>' . esc_html__( 'This is your Deal Duration. Here you should give the date from when this deal will be active.', 'dx-smart-deal' ) . '</p>',
  114. 'position' => array(
  115. 'edge' => 'bottom',
  116. 'align' => 'middle',
  117. ),
  118. ),
  119. );
  120. $pointers['smart_deal_categorydiv'] = array(
  121. 'target' => "#smart_deal_categorydiv",
  122. 'next' => 'smart_deal_location',
  123. 'next_trigger' => array(),
  124. 'options' => array(
  125. 'content' => '<h3>' . esc_html__( 'Deal category', 'dx-smart-deal' ) . '</h3>' .
  126. '<p>' . esc_html__( 'This is your Deal category. Here you should select the category of your deal.', 'dx-smart-deal' ) . '</p>',
  127. 'position' => array(
  128. 'edge' => 'bottom',
  129. 'align' => 'middle',
  130. ),
  131. ),
  132. );
  133. $pointers['smart_deal_location'] = array(
  134. 'target' => "#acf-group_59f33e62777f4",
  135. 'next' => 'smart_deal_coupon_code',
  136. 'next_trigger' => array(),
  137. 'options' => array(
  138. 'content' => '<h3>' . esc_html__( 'Deal Location', 'dx-smart-deal' ) . '</h3>' .
  139. '<p>' . esc_html__( 'This is your Deal Location. Here you should select the location of your deal.', 'dx-smart-deal' ) . '</p>',
  140. 'position' => array(
  141. 'edge' => 'bottom',
  142. 'align' => 'middle',
  143. ),
  144. ),
  145. );
  146. $pointers['smart_deal_coupon_code'] = array(
  147. 'target' => "#acf-field_5a28f4ebc2e2d",
  148. 'next' => 'smart_deal_details',
  149. 'next_trigger' => array(),
  150. 'options' => array(
  151. 'content' => '<h3>' . esc_html__( 'Coupon Code', 'dx-smart-deal' ) . '</h3>' .
  152. '<p>' . esc_html__( 'This is available Coupon code for Deal. Here you should provide End Users available Coupon code for Your Deal.', 'dx-smart-deal' ) . '</p>',
  153. 'position' => array(
  154. 'edge' => 'top',
  155. 'align' => 'middle',
  156. ),
  157. ),
  158. );
  159. $pointers['smart_deal_details'] = array(
  160. 'target' => "#acf-field_5a28f9396900c",
  161. 'next' => 'smart_deal_restriction',
  162. 'next_trigger' => array(),
  163. 'options' => array(
  164. 'content' => '<h3>' . esc_html__( 'Deal Details', 'dx-smart-deal' ) . '</h3>' .
  165. '<p>' . esc_html__( 'This is about Deal Details. Here you should give some more details for Your Deal.', 'dx-smart-deal' ) . '</p>',
  166. 'position' => array(
  167. 'edge' => 'top',
  168. 'align' => 'middle',
  169. ),
  170. ),
  171. );
  172. $pointers['smart_deal_restriction'] = array(
  173. 'target' => "#acf-field_5a29021a888ea",
  174. 'next' => 'smart_deal_featured',
  175. 'next_trigger' => array(),
  176. 'options' => array(
  177. 'content' => '<h3>' . esc_html__( 'Restrictions and Fine Print', 'dx-smart-deal' ) . '</h3>' .
  178. '<p>' . esc_html__( 'This is about Deal Restrictions and Fine Print. Here you should give attractive offers or fine print for Your Deal.', 'dx-smart-deal' ) . '</p>',
  179. 'position' => array(
  180. 'edge' => 'top',
  181. 'align' => 'middle',
  182. ),
  183. ),
  184. );
  185.  
  186. $pointers['smart_deal_featured'] = array(
  187. 'target' => "#acf-group_5a52518f2b842",
  188. 'next' => 'apply-coupon-for-payment',
  189. 'next_trigger' => array(),
  190. 'options' => array(
  191. 'content' => '<h3>' . esc_html__( 'Deal Featured Image', 'dx-smart-deal' ) . '</h3>' .
  192. '<p>' . esc_html__( 'Select a Image for your deal that will be displayed on your deal page', 'dx-smart-deal' ) . '</p>',
  193. 'position' => array(
  194. 'edge' => 'bottom',
  195. 'align' => 'middle',
  196. ),
  197. ),
  198. );
  199. $pointers['apply-coupon-for-payment'] = array(
  200. 'target' => "#major-publishing-actions",
  201. 'next' => 'checkout-by-paypal',
  202. 'next_trigger' => array(),
  203. 'options' => array(
  204. 'content' => '<h3>' . esc_html__( 'Apply Coupon Code', 'dx-smart-deal' ) . '</h3>' .
  205. '<p>' . esc_html__( 'Apply Coupon code to get discount for deal publish on Smart Deal section.', 'dx-smart-deal' ) . '</p>',
  206. 'position' => array(
  207. 'edge' => 'bottom',
  208. 'align' => 'middle',
  209. ),
  210. ),
  211. );
  212.  
  213. $pointers['checkout-by-paypal'] = array(
  214. 'target' => "#publish",
  215. 'next' => 'publish-deal',
  216. 'next_trigger' => array(),
  217. 'options' => array(
  218. 'content' => '<h3>' . esc_html__( 'Publish Deal', 'dx-smart-deal' ) . '</h3>' .
  219. '<p>' . esc_html__( 'Publish your deal and make it visible on Smart Deal section.', 'dx-smart-deal' ) . '</p>',
  220. 'position' => array(
  221. 'edge' => 'bottom',
  222. 'align' => 'middle',
  223. ),
  224. ),
  225. );
  226. }
  227.  
  228. if ( ! $pointers || ! is_array( $pointers ) )
  229. return;
  230. // Get dismissed pointers
  231. $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
  232. $valid_pointers =array();
  233.  
  234. // Check pointers and remove dismissed ones.
  235. foreach ( $pointers as $pointer_id => $pointer ) {
  236.  
  237. // Sanity check
  238. if ( in_array( $pointer_id, $dismissed ) || empty( $pointer ) || empty( $pointer_id ) || empty( $pointer['target'] ) || empty( $pointer['options'] ) )
  239. continue;
  240.  
  241. $pointer['pointer_id'] = $pointer_id;
  242.  
  243. // Add the pointer to $valid_pointers array
  244. $valid_pointers['pointers'][] = $pointer;
  245. }
  246.  
  247. // No valid pointers? Stop here.
  248. if ( empty( $valid_pointers ) )
  249. return;
  250.  
  251. // Add pointers style to queue.
  252. wp_enqueue_style( 'wp-pointer' );
  253.  
  254. // Add pointers script to queue. Add custom script.
  255. wp_enqueue_script( 'wptuts-pointer', plugins_url( '_inc/smart-dealer-tutorial.js', dirname(__FILE__) ), array( 'wp-pointer' ) );
  256.  
  257. // Add pointer options to script.
  258. wp_localize_script( 'wptuts-pointer', 'wptutsPointer', $valid_pointers );
  259.  
  260. }
  261.  
  262. }
  263.  
  264. new SD_Admin_Pointers();
Add Comment
Please, Sign In to add comment