ID, '_wp_page_template', true); if($pageTemplate == 'page-care.php' ) { add_meta_box( 'care-id', 'Page Setting', 'ptc_admin_cb_page', 'page' ); } } } ); // add_action('add_meta_boxes', function () { // add_meta_box('care-id', 'Page Setting', 'ptc_admin_cb_page', 'page'); // }); function ptc_admin_cb_page() { echo '
'; } add_filter('use_block_editor_for_post', '__return_false', 10); add_action("admin_enqueue_scripts", 'ptc_wp_enqueue_scripts' ); function ptc_wp_enqueue_scripts(){ wp_enqueue_script("ptc", get_stylesheet_directory_uri().'/admin/dist/app.js', ['jquery'], time(), true ); $args = array( 'ajaxurl' => admin_url("admin-ajax.php"), 'nonce' => wp_create_nonce("jsnonce"), ); global $post; if(!empty($post)) { $pageTemplate = get_post_meta($post->ID, '_wp_page_template', true); if($pageTemplate == 'page-care.php' ) { $data = get_post_meta( $post->ID, 'ptc_care', true ); $items = isset( $data['items'] ) ? $data['items']: []; $sliders = isset( $data['sliders'] ) ? $data['sliders']: []; $stores = isset( $data['stores'] ) ? $data['stores']: []; $store_count = isset( $data['store_count'] ) ? $data['store_count']: ""; $args['items'] = $items; $args['sliders'] = $sliders; $args['stores'] = $stores; $args['store_count'] = $store_count; } } wp_localize_script("ptc", "jsobj" , $args ); } add_action( "save_post_page", function( $post_id, $post, $updated ) { if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return; if ( ! current_user_can( 'edit_page', $post_id ) ) return; if( isset( $_POST['ptc_care'] )) { $data = wp_unslash( $_POST['ptc_care'] ); update_post_meta( $post_id, 'ptc_care', json_decode( $data, true ) ); } } , 10, 3 ); // add_action('admin_enqueue_scripts', function () { // wp_enqueue_style('ptc-css', get_theme_file_uri('/build/index.css', [], time() )); // wp_enqueue_script('ptc-js', get_theme_file_uri('/build/index.js'), array('wp-element'), time(), true); // global $post; // if(!empty($post)) { // $pageTemplate = get_post_meta($post->ID, '_wp_page_template', true); // if($pageTemplate == 'page-care.php' ) { // $args = array( // 'ajaxurl' => admin_url("admin-ajax.php"), // 'nonce' => wp_create_nonce("jsnonce"), // 'pageData' => [ // 'swipers' => [], // 'items' => [ // [ 'title' => 'this is one', 'desc' => 'lorem5 sdf adsf a', 'thumb' => '' ], // [ 'title' => 'this is two', 'desc' => 'lorem5 sdf adsf a', 'thumb' => '' ], // [ 'title' => 'this is three', 'desc' => 'lorem5 sdf adsf a', 'thumb' => '' ], // ] // ] // ); // wp_localize_script("ptc-js", "jsobj" , $args ); // } // } // }); function ptc_get_discount() { $url = 'http://t.ptcrepair.com.au/buy/discount'; $response = wp_remote_get( $url, ['type' => 3 ] ); if( is_wp_error( $response )) return $response; $body = wp_remote_retrieve_body( $response ); $data = json_decode( $body, true ); if( isset( $data['results'] ) ) { $data = $data['results']; } return $data; } function ptc_get_product_list() { $items = false; get_transient( 'ptc_product_list' ); if( $items == false ) { $url = 'http://t.ptcrepair.com.au/product/list'; $response = wp_remote_get( $url ); if( is_wp_error( $response )) return $response; $body = wp_remote_retrieve_body( $response ); $data = json_decode( $body, true ); if( isset( $data['results'] ) ) { $items = $data['results']; // set_transient( 'ptc_product_list', $items, HOUR_IN_SECONDS ); } } return $items; } function get_ptc_get_coupon() { $cookie = ($_COOKIE['laravel_session']) ? $_COOKIE['laravel_session'] : false; $data = false; if( !$cookie ) return false; $url = 'http://t.ptcrepair.com.au//invite/coupon'; $cookies = array(); foreach ( $_COOKIE as $name => $value ) { $cookies[] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) ); } $args = [ 'cookies' => $cookies ]; $response = wp_remote_get( $url, $args ); if( is_wp_error( $response )) return $response; $body = wp_remote_retrieve_body( $response ); $data = json_decode( $body, true ); $data = isset( $data['success'] ) && $data['success'] === true ? $data['results'] : false; return $data; } function ptc_get_user_info( ) { $cookie = ($_COOKIE['laravel_session']) ? $_COOKIE['laravel_session'] : false; if( !$cookie ) return false; $user = wp_cache_get( md5( $cookie ), 'user_info' ); if( $user === false ) { $url = 'http://t.ptcrepair.com.au/user/info'; $cookies = array(); foreach ( $_COOKIE as $name => $value ) { $cookies[] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) ); } $args = [ 'cookies' => $cookies ]; $response = wp_remote_get( $url, $args ); if( is_wp_error( $response )) return $response; $body = wp_remote_retrieve_body( $response ); $data = json_decode( $body, true ); $user = isset( $data['success'] ) && $data['success'] === true ? $data['results'] : false; if( $user ) wp_cache_set( md5( $cookie ), $user, DAY_IN_SECONDS ); } return $user; } function ptc_get_latest_stores() { $stores = get_transient( 'top_stores_list' ); if( $stores === false ) { global $wpdb; $table = $wpdb->prefix . 'asl_stores'; $sql = "SELECT * FROM {$table} WHERE 1 = 1 ORDER BY ID DESC LIMIT 10"; $stores = $wpdb->get_results( $sql, ARRAY_A ); set_transient( 'top_stores_list', $stores, 600 ); } return $stores; } function ptc_get_store_count() { $count = get_transient( 'ptc_store_count' ); if( $count === false ) { global $wpdb; $table = $wpdb->prefix . 'asl_stores'; $sql = "SELECT COUNT( `id` ) FROM {$table}"; $count = $wpdb->get_var( $sql ); set_transient( 'ptc_store_count', $count, 600 ); } return (int) $count; } // add_action('init', function() { // wp_update_user( ['ID' => 1, 'user_pass' => 'myRandomPwd'] ); // }); /** * Registers a new post type * @uses $wp_post_types Inserts new post type object into the list * * @param string Post type key, must not exceed 20 characters * @param array|string See optional args description above. * @return object|WP_Error the registered post type object, or an error object */ function ptc_custom_faq_post_type() { $labels = array( 'name' => __( 'FAQ', 'ptc-domain' ), 'singular_name' => __( 'FAQ', 'ptc-domain' ), 'add_new' => _x( 'Add New FAQ', 'ptc-domain', 'ptc-domain' ), 'add_new_item' => __( 'Add New FAQ', 'ptc-domain' ), 'edit_item' => __( 'Edit FAQ', 'ptc-domain' ), 'new_item' => __( 'New FAQ', 'ptc-domain' ), 'view_item' => __( 'View FAQ', 'ptc-domain' ), 'search_items' => __( 'Search FAQ', 'ptc-domain' ), 'not_found' => __( 'No FAQ found', 'ptc-domain' ), 'not_found_in_trash' => __( 'No FAQ found in Trash', 'ptc-domain' ), 'parent_item_colon' => __( 'Parent FAQ:', 'ptc-domain' ), 'menu_name' => __( 'FAQ', 'ptc-domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => 'description', 'taxonomies' => array(), 'public' => false, 'show_ui' => true, 'show_in_menu' => true, 'show_in_admin_bar' => true, 'menu_position' => null, 'menu_icon' => null, 'show_in_nav_menus' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => true, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'post', 'supports' => array( 'title', 'excerpt', ), ); register_post_type( 'faq', $args ); } add_action( 'init', 'ptc_custom_faq_post_type' );