Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. add_action('admin_enqueue_scripts', 'reserver_admin_script');
  2. add_action('wp_enqueue_scripts', 'reserver_front_styles');
  3. /*
  4. * Function to initialize plugin hook.
  5. */
  6. function reserver_admin_script(){
  7. wp_enqueue_style('fa', plugins_url('reserver/src/fonts/fontawesome-pro-5.0.4/web-fonts-with-css/css/fontawesome-all.css'));
  8. wp_enqueue_style('bootstrapgrid', plugins_url('reserver/src/libs/bootstrap-grid.css'));
  9.  
  10. wp_enqueue_style('semantic-button', plugins_url('reserver/src/libs/semantic-ui/components/button.min.css'));
  11.  
  12. wp_enqueue_style('appcss', plugins_url('reserver/src/css/app.css'));
  13.  
  14. wp_enqueue_script('cryptojs', plugins_url('reserver/src/libs/crypto-js.min.js'), array(), "", true);
  15. wp_enqueue_script('jq', plugins_url('reserver/src/libs/jquery.min.js'), array(), "", true);
  16. wp_enqueue_script('vuejs', plugins_url('reserver/src/libs/vue.min.js'), array(), "", true);
  17. wp_enqueue_script('appjs', plugins_url('reserver/src/js/rsvr.js'), array(), "", true);
  18. }
  19. /*
  20. * Initialize all styles to settings page of plugin.
  21. */
  22. function reserver_front_styles(){
  23. wp_enqueue_style('fa', plugins_url('reserver/src/fonts/fontawesome-pro-5.0.4/web-fonts-with-css/css/fontawesome-all.css'));
  24. wp_enqueue_style('bootstrapgrid', plugins_url('reserver/src/libs/bootstrap-grid.css'));
  25.  
  26. wp_enqueue_style('semantic-button', plugins_url('reserver/src/libs/semantic-ui/components/button.min.css'));
  27.  
  28. wp_enqueue_style('appcss', plugins_url('reserver/src/css/app.css'));
  29.  
  30. wp_enqueue_script('cryptojs', plugins_url('reserver/src/libs/crypto-js.min.js'), array(), "", true);
  31. wp_enqueue_script('jq', plugins_url('reserver/src/libs/jquery.min.js'), array(), "", true);
  32. wp_enqueue_script('vuejs', plugins_url('reserver/src/libs/vue.min.js'), array(), "", true);
  33. wp_enqueue_script('appjs', plugins_url('reserver/src/js/rsvr.js'), array(), "", true);
  34. }
  35. /*
  36. * Add hook to register page of plugin.
  37. */
  38. add_action( 'admin_menu', 'reserver_register_main_page' );
  39. /*
  40. * Function to register page of plugin.
  41. */
  42. function reserver_register_main_page(){
  43. add_menu_page(
  44. 'Бронирование домов',
  45. 'Reserver',
  46. 'edit_others_posts',
  47. 'reserver_admin_page',
  48. 'reserver_get_admin_page',
  49. plugins_url( 'reserver/src/images/admin-menu-icon.png' ),
  50. null );
  51. }
  52.  
  53. /*
  54. * Function responding to view admin page.
  55. */
  56. function reserver_get_admin_page(){
  57. require_once dirname( __FILE__ ) . '/includes/templates/template-admin-page.php';
  58. }
  59.  
  60. /*
  61. * Getting all products to reserve application.
  62. */
  63. add_action('wp_ajax_nopriv_get_products', 'reserver_ajax_get_all_products');
  64. add_action('wp_ajax_get_products', 'reserver_ajax_get_all_products');
  65.  
  66. function reserver_ajax_get_all_products(){
  67.  
  68. // House lise for reserve
  69. $products = array();
  70.  
  71. // Get all posts with post_type product
  72. $posts = get_posts( array(
  73. 'numberposts' => 3,
  74. 'category' => 0,
  75. 'orderby' => 'date',
  76. 'order' => 'DESC',
  77. 'include' => array(),
  78. 'exclude' => array(),
  79. 'meta_key' => '',
  80. 'meta_value' =>'',
  81. 'post_type' => 'product',
  82. 'suppress_filters' => true,
  83. ) );
  84.  
  85. // In loop getting all data of post and fill result array
  86. foreach( $posts as $post ){
  87. setup_postdata($post);
  88.  
  89. // product price
  90. $price = get_post_meta( $post->ID, "_price", true );
  91. // product thumb
  92. $imgID = get_post_meta( $post->ID, "_thumbnail_id", true );
  93. $thumb = wp_get_attachment_image_src( $imgID, 'full' );
  94. // product title
  95. $title = $post->post_title;
  96. // product description
  97. $desc = $post->post_content;
  98.  
  99. $productData = array(
  100. 'name' => $title,
  101. 'thumbnail' => $thumb[0],
  102. 'properties' => array(
  103. 'name' => 'Описание',
  104. 'value' => $desc
  105. ),
  106. 'cost' => $price,
  107. 'selected' => false,
  108. );
  109.  
  110. array_push($products, $productData);
  111. }
  112.  
  113. // Reset global settings of var $post.
  114. wp_reset_postdata();
  115.  
  116. // Return JSON string as a result.
  117. print(json_encode($products));
  118. die();
  119. }
  120.  
  121. add_action('wp_ajax_nopriv_add_new_order', 'reserver_ajax_add_new_order');
  122. add_action('wp_ajax_add_new_order', 'reserver_ajax_add_new_order');
  123. /*
  124. * Function to create new order
  125. */
  126. function reserver_ajax_add_new_order(){
  127. global $wpdb;
  128. $table_name = $wpdb->prefix."reserver_order_items";
  129.  
  130. $wpdb->insert($table_name, array('order_data' => $_POST['order'] ));
  131.  
  132. die();
  133. }
  134.  
  135. add_action('wp_ajax_nopriv_get_all_orders', 'reserver_ajax_get_all_orders');
  136. add_action('wp_ajax_get_all_orders', 'reserver_ajax_get_all_orders');
  137. /*
  138. * Function to get all orders.
  139. */
  140. function reserver_ajax_get_all_orders(){
  141. global $wpdb;
  142.  
  143. $table_name = "reserver_order_items";
  144. $query_string = "SELECT `order_data` FROM $wpdb->prefix".$table_name." WHERE 1";
  145.  
  146. echo json_encode($wpdb->get_results($query_string, OBJECT ));
  147.  
  148. die();
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement