Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('admin_enqueue_scripts', 'reserver_admin_script');
- add_action('wp_enqueue_scripts', 'reserver_front_styles');
- /*
- * Function to initialize plugin hook.
- */
- function reserver_admin_script(){
- wp_enqueue_style('fa', plugins_url('reserver/src/fonts/fontawesome-pro-5.0.4/web-fonts-with-css/css/fontawesome-all.css'));
- wp_enqueue_style('bootstrapgrid', plugins_url('reserver/src/libs/bootstrap-grid.css'));
- wp_enqueue_style('semantic-button', plugins_url('reserver/src/libs/semantic-ui/components/button.min.css'));
- wp_enqueue_style('appcss', plugins_url('reserver/src/css/app.css'));
- wp_enqueue_script('cryptojs', plugins_url('reserver/src/libs/crypto-js.min.js'), array(), "", true);
- wp_enqueue_script('jq', plugins_url('reserver/src/libs/jquery.min.js'), array(), "", true);
- wp_enqueue_script('vuejs', plugins_url('reserver/src/libs/vue.min.js'), array(), "", true);
- wp_enqueue_script('appjs', plugins_url('reserver/src/js/rsvr.js'), array(), "", true);
- }
- /*
- * Initialize all styles to settings page of plugin.
- */
- function reserver_front_styles(){
- wp_enqueue_style('fa', plugins_url('reserver/src/fonts/fontawesome-pro-5.0.4/web-fonts-with-css/css/fontawesome-all.css'));
- wp_enqueue_style('bootstrapgrid', plugins_url('reserver/src/libs/bootstrap-grid.css'));
- wp_enqueue_style('semantic-button', plugins_url('reserver/src/libs/semantic-ui/components/button.min.css'));
- wp_enqueue_style('appcss', plugins_url('reserver/src/css/app.css'));
- wp_enqueue_script('cryptojs', plugins_url('reserver/src/libs/crypto-js.min.js'), array(), "", true);
- wp_enqueue_script('jq', plugins_url('reserver/src/libs/jquery.min.js'), array(), "", true);
- wp_enqueue_script('vuejs', plugins_url('reserver/src/libs/vue.min.js'), array(), "", true);
- wp_enqueue_script('appjs', plugins_url('reserver/src/js/rsvr.js'), array(), "", true);
- }
- /*
- * Add hook to register page of plugin.
- */
- add_action( 'admin_menu', 'reserver_register_main_page' );
- /*
- * Function to register page of plugin.
- */
- function reserver_register_main_page(){
- add_menu_page(
- 'Бронирование домов',
- 'Reserver',
- 'edit_others_posts',
- 'reserver_admin_page',
- 'reserver_get_admin_page',
- plugins_url( 'reserver/src/images/admin-menu-icon.png' ),
- null );
- }
- /*
- * Function responding to view admin page.
- */
- function reserver_get_admin_page(){
- require_once dirname( __FILE__ ) . '/includes/templates/template-admin-page.php';
- }
- /*
- * Getting all products to reserve application.
- */
- add_action('wp_ajax_nopriv_get_products', 'reserver_ajax_get_all_products');
- add_action('wp_ajax_get_products', 'reserver_ajax_get_all_products');
- function reserver_ajax_get_all_products(){
- // House lise for reserve
- $products = array();
- // Get all posts with post_type product
- $posts = get_posts( array(
- 'numberposts' => 3,
- 'category' => 0,
- 'orderby' => 'date',
- 'order' => 'DESC',
- 'include' => array(),
- 'exclude' => array(),
- 'meta_key' => '',
- 'meta_value' =>'',
- 'post_type' => 'product',
- 'suppress_filters' => true,
- ) );
- // In loop getting all data of post and fill result array
- foreach( $posts as $post ){
- setup_postdata($post);
- // product price
- $price = get_post_meta( $post->ID, "_price", true );
- // product thumb
- $imgID = get_post_meta( $post->ID, "_thumbnail_id", true );
- $thumb = wp_get_attachment_image_src( $imgID, 'full' );
- // product title
- $title = $post->post_title;
- // product description
- $desc = $post->post_content;
- $productData = array(
- 'name' => $title,
- 'thumbnail' => $thumb[0],
- 'properties' => array(
- 'name' => 'Описание',
- 'value' => $desc
- ),
- 'cost' => $price,
- 'selected' => false,
- );
- array_push($products, $productData);
- }
- // Reset global settings of var $post.
- wp_reset_postdata();
- // Return JSON string as a result.
- print(json_encode($products));
- die();
- }
- add_action('wp_ajax_nopriv_add_new_order', 'reserver_ajax_add_new_order');
- add_action('wp_ajax_add_new_order', 'reserver_ajax_add_new_order');
- /*
- * Function to create new order
- */
- function reserver_ajax_add_new_order(){
- global $wpdb;
- $table_name = $wpdb->prefix."reserver_order_items";
- $wpdb->insert($table_name, array('order_data' => $_POST['order'] ));
- die();
- }
- add_action('wp_ajax_nopriv_get_all_orders', 'reserver_ajax_get_all_orders');
- add_action('wp_ajax_get_all_orders', 'reserver_ajax_get_all_orders');
- /*
- * Function to get all orders.
- */
- function reserver_ajax_get_all_orders(){
- global $wpdb;
- $table_name = "reserver_order_items";
- $query_string = "SELECT `order_data` FROM $wpdb->prefix".$table_name." WHERE 1";
- echo json_encode($wpdb->get_results($query_string, OBJECT ));
- die();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement