@@ -481,7 +481,7 @@ |
||
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** SIGN UP - Display the commercial & newsletter form |
| 484 | - * @return void |
|
| 484 | + * @return string |
|
| 485 | 485 | */ |
| 486 | 486 | function display_commercial_newsletter_form() { |
| 487 | 487 | $output = ''; |
@@ -1,8 +1,8 @@ |
||
| 1 | 1 | <?php if ( !defined( 'ABSPATH' ) ) exit; |
| 2 | 2 | class wps_account_ctr { |
| 3 | 3 | /** Define the main directory containing the template for the current plugin |
| 4 | - * @var string |
|
| 5 | - */ |
|
| 4 | + * @var string |
|
| 5 | + */ |
|
| 6 | 6 | private $template_dir; |
| 7 | 7 | /** |
| 8 | 8 | * Define the directory name for the module in order to check into frontend |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_account_ctr { |
| 3 | 3 | /** Define the main directory containing the template for the current plugin |
| 4 | 4 | * @var string |
@@ -19,50 +19,50 @@ discard block |
||
| 19 | 19 | $this->template_dir = WPS_ACCOUNT_PATH . WPS_ACCOUNT_DIR . "/templates/"; |
| 20 | 20 | /** Shortcodes **/ |
| 21 | 21 | // Sign up Display Shortcode |
| 22 | - add_shortcode( 'wps_signup', array( &$this, 'display_signup' ) ); |
|
| 22 | + add_shortcode('wps_signup', array(&$this, 'display_signup')); |
|
| 23 | 23 | // Log in Form Display Shortcode |
| 24 | - add_shortcode( 'wpshop_login', array( &$this, 'get_login_form')); |
|
| 24 | + add_shortcode('wpshop_login', array(&$this, 'get_login_form')); |
|
| 25 | 25 | //Log in first step |
| 26 | - add_shortcode( 'wps_first_login', array( &$this, 'get_login_first_step')); |
|
| 26 | + add_shortcode('wps_first_login', array(&$this, 'get_login_first_step')); |
|
| 27 | 27 | // Forgot password Form |
| 28 | - add_shortcode( 'wps_forgot_password', array( &$this, 'get_forgot_password_form')); |
|
| 28 | + add_shortcode('wps_forgot_password', array(&$this, 'get_forgot_password_form')); |
|
| 29 | 29 | // Renew password form |
| 30 | - add_shortcode( 'wps_renew_password', array( &$this, 'get_renew_password_form')); |
|
| 30 | + add_shortcode('wps_renew_password', array(&$this, 'get_renew_password_form')); |
|
| 31 | 31 | //Account informations |
| 32 | - add_shortcode( 'wps_account_informations', array($this, 'display_account_informations') ); |
|
| 32 | + add_shortcode('wps_account_informations', array($this, 'display_account_informations')); |
|
| 33 | 33 | //Account form |
| 34 | - add_shortcode( 'wps_account_informations_form', array($this, 'account_informations_form') ); |
|
| 34 | + add_shortcode('wps_account_informations_form', array($this, 'account_informations_form')); |
|
| 35 | 35 | |
| 36 | 36 | /** Ajax Actions **/ |
| 37 | 37 | // add_action('wap_ajax_wps_display_connexion_form', array(&$this, 'wps_ajax_get_login_form_interface') ); |
| 38 | 38 | // add_action('wap_ajax_nopriv_wps_display_connexion_form', array(&$this, 'wps_ajax_get_login_form_interface') ); |
| 39 | 39 | |
| 40 | - add_action('wp_ajax_wps_login_request', array(&$this, 'control_login_form_request') ); |
|
| 41 | - add_action('wp_ajax_nopriv_wps_login_request', array(&$this, 'control_login_form_request') ); |
|
| 40 | + add_action('wp_ajax_wps_login_request', array(&$this, 'control_login_form_request')); |
|
| 41 | + add_action('wp_ajax_nopriv_wps_login_request', array(&$this, 'control_login_form_request')); |
|
| 42 | 42 | |
| 43 | - add_action('wp_ajax_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request') ); |
|
| 44 | - add_action('wp_ajax_nopriv_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request') ); |
|
| 43 | + add_action('wp_ajax_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request')); |
|
| 44 | + add_action('wp_ajax_nopriv_wps_forgot_password_request', array(&$this, 'wps_forgot_password_request')); |
|
| 45 | 45 | |
| 46 | - add_action('wp_ajax_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew') ); |
|
| 47 | - add_action('wp_ajax_nopriv_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew') ); |
|
| 46 | + add_action('wp_ajax_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew')); |
|
| 47 | + add_action('wp_ajax_nopriv_wps_forgot_password_renew', array(&$this, 'wps_forgot_password_renew')); |
|
| 48 | 48 | |
| 49 | - add_action('wp_ajax_wps_signup_request', array(&$this, 'wps_save_signup_form') ); |
|
| 50 | - add_action('wp_ajax_nopriv_wps_signup_request', array(&$this, 'wps_save_signup_form_nopriv') ); |
|
| 49 | + add_action('wp_ajax_wps_signup_request', array(&$this, 'wps_save_signup_form')); |
|
| 50 | + add_action('wp_ajax_nopriv_wps_signup_request', array(&$this, 'wps_save_signup_form_nopriv')); |
|
| 51 | 51 | |
| 52 | - add_action('wp_ajax_wps_login_first_request', array(&$this, 'wps_login_first_request') ); |
|
| 53 | - add_action('wp_ajax_nopriv_wps_login_first_request', array(&$this, 'wps_login_first_request') ); |
|
| 52 | + add_action('wp_ajax_wps_login_first_request', array(&$this, 'wps_login_first_request')); |
|
| 53 | + add_action('wp_ajax_nopriv_wps_login_first_request', array(&$this, 'wps_login_first_request')); |
|
| 54 | 54 | |
| 55 | - add_action( 'wp_ajax_wps_save_account_informations', array($this, 'wps_save_account_informations') ); |
|
| 55 | + add_action('wp_ajax_wps_save_account_informations', array($this, 'wps_save_account_informations')); |
|
| 56 | 56 | |
| 57 | - add_action( 'wp_ajax_wps_account_reload_informations', array($this, 'wps_account_reload_informations') ); |
|
| 57 | + add_action('wp_ajax_wps_account_reload_informations', array($this, 'wps_account_reload_informations')); |
|
| 58 | 58 | |
| 59 | - add_action( 'wp_ajax_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal') ); |
|
| 60 | - add_action( 'wp_ajax_nopriv_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal') ); |
|
| 59 | + add_action('wp_ajax_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal')); |
|
| 60 | + add_action('wp_ajax_nopriv_wps_fill_forgot_password_modal', array($this, 'wps_fill_forgot_password_modal')); |
|
| 61 | 61 | |
| 62 | - add_action( 'wp_ajax_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal') ); |
|
| 63 | - add_action( 'wp_ajax_nopriv_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal') ); |
|
| 62 | + add_action('wp_ajax_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal')); |
|
| 63 | + add_action('wp_ajax_nopriv_wps_fill_account_informations_modal', array($this, 'wps_fill_account_informations_modal')); |
|
| 64 | 64 | |
| 65 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') ); |
|
| 65 | + add_action('wp_enqueue_scripts', array($this, 'add_scripts')); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -70,32 +70,32 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | function add_scripts() { |
| 72 | 72 | wp_enqueue_script('jquery'); |
| 73 | - wp_enqueue_script( 'wps_forgot_password_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_forgot_password.js' ); |
|
| 74 | - wp_enqueue_script( 'wps_login_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_login.js' ); |
|
| 75 | - wp_enqueue_script( 'wps_signup_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_signup.js' ); |
|
| 76 | - wp_enqueue_script( 'wps_account_js', WPS_ACCOUNT_URL.'wps_customer/assets/frontend/js/wps_account.js' ); |
|
| 73 | + wp_enqueue_script('wps_forgot_password_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_forgot_password.js'); |
|
| 74 | + wp_enqueue_script('wps_login_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_login.js'); |
|
| 75 | + wp_enqueue_script('wps_signup_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_signup.js'); |
|
| 76 | + wp_enqueue_script('wps_account_js', WPS_ACCOUNT_URL . 'wps_customer/assets/frontend/js/wps_account.js'); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** LOG IN - Display log in Form **/ |
| 80 | - function get_login_form( $force_login = false ) { |
|
| 80 | + function get_login_form($force_login = false) { |
|
| 81 | 81 | $args = array(); |
| 82 | - if ( get_current_user_id() != 0 ) { |
|
| 83 | - return __( 'You are already logged', 'wpshop'); |
|
| 82 | + if (get_current_user_id() != 0) { |
|
| 83 | + return __('You are already logged', 'wpshop'); |
|
| 84 | 84 | } |
| 85 | 85 | else { |
| 86 | - $action = !empty( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 87 | - $key = !empty( $_GET['key'] ) ? sanitize_text_field( $_GET['key'] ) : ''; |
|
| 88 | - $login = !empty( $_GET['login'] ) ? sanitize_text_field( $_GET['login'] ) : 0; |
|
| 89 | - if ( !empty($action) && $action == 'retrieve_password' && !empty($key) && !empty($login) && !$force_login ) { |
|
| 86 | + $action = !empty($_GET['action']) ? sanitize_text_field($_GET['action']) : ''; |
|
| 87 | + $key = !empty($_GET['key']) ? sanitize_text_field($_GET['key']) : ''; |
|
| 88 | + $login = !empty($_GET['login']) ? sanitize_text_field($_GET['login']) : 0; |
|
| 89 | + if (!empty($action) && $action == 'retrieve_password' && !empty($key) && !empty($login) && !$force_login) { |
|
| 90 | 90 | $output = self::get_renew_password_form(); |
| 91 | 91 | } |
| 92 | 92 | else { |
| 93 | 93 | ob_start(); |
| 94 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form") ); |
|
| 94 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form")); |
|
| 95 | 95 | $output = ob_get_contents(); |
| 96 | 96 | ob_end_clean(); |
| 97 | - if ( !$force_login ) { |
|
| 98 | - $output .= do_shortcode( '[wps_signup]' ); |
|
| 97 | + if (!$force_login) { |
|
| 98 | + $output .= do_shortcode('[wps_signup]'); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | return $output; |
@@ -105,53 +105,53 @@ discard block |
||
| 105 | 105 | /** LOG IN - AJAX - Action to connect **/ |
| 106 | 106 | function control_login_form_request() { |
| 107 | 107 | |
| 108 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 108 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 109 | 109 | |
| 110 | - if ( !wp_verify_nonce( $_wpnonce, 'control_login_form_request' ) ) |
|
| 110 | + if (!wp_verify_nonce($_wpnonce, 'control_login_form_request')) |
|
| 111 | 111 | wp_die(); |
| 112 | 112 | |
| 113 | 113 | $result = ''; |
| 114 | 114 | $status = false; |
| 115 | - $origin = sanitize_text_field( $_POST['wps-checking-origin'] ); |
|
| 116 | - $wps_login_user_login = !empty( $_POST['wps_login_user_login'] ) ? sanitize_text_field( $_POST['wps_login_user_login' ] ) : ''; |
|
| 117 | - $wps_login_password = !empty( $_POST['wps_login_password'] ) ? sanitize_text_field( $_POST['wps_login_password' ] ) : ''; |
|
| 118 | - $page_account_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id') ); |
|
| 119 | - if ( !empty($wps_login_user_login) && !empty($wps_login_password) ) { |
|
| 115 | + $origin = sanitize_text_field($_POST['wps-checking-origin']); |
|
| 116 | + $wps_login_user_login = !empty($_POST['wps_login_user_login']) ? sanitize_text_field($_POST['wps_login_user_login']) : ''; |
|
| 117 | + $wps_login_password = !empty($_POST['wps_login_password']) ? sanitize_text_field($_POST['wps_login_password']) : ''; |
|
| 118 | + $page_account_id = wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')); |
|
| 119 | + if (!empty($wps_login_user_login) && !empty($wps_login_password)) { |
|
| 120 | 120 | $creds = array(); |
| 121 | 121 | // Test if an user exist with this login |
| 122 | - $user_checking = get_user_by( 'login', $wps_login_user_login ); |
|
| 123 | - if( !empty($user_checking) ) { |
|
| 122 | + $user_checking = get_user_by('login', $wps_login_user_login); |
|
| 123 | + if (!empty($user_checking)) { |
|
| 124 | 124 | $creds['user_login'] = $wps_login_user_login; |
| 125 | 125 | } |
| 126 | 126 | else { |
| 127 | - if ( is_email($wps_login_user_login) ) { |
|
| 128 | - $user_checking = get_user_by( 'email', $wps_login_user_login ); |
|
| 127 | + if (is_email($wps_login_user_login)) { |
|
| 128 | + $user_checking = get_user_by('email', $wps_login_user_login); |
|
| 129 | 129 | $creds['user_login'] = $user_checking->user_login; |
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | - $creds['user_password'] = wpshop_tools::varSanitizer( $_POST['wps_login_password'] ); |
|
| 133 | - $creds['remember'] = !empty( $_POST['wps_login_remember_me'] ) ? (int) $_POST['wps_login_remember_me'] : false; |
|
| 134 | - $user = wp_signon( $creds, false ); |
|
| 135 | - if ( is_wp_error($user) ) { |
|
| 136 | - $result = '<div class="wps-alert-error">' .__('Connexion error', 'wpshop'). '</div>'; |
|
| 132 | + $creds['user_password'] = wpshop_tools::varSanitizer($_POST['wps_login_password']); |
|
| 133 | + $creds['remember'] = !empty($_POST['wps_login_remember_me']) ? (int)$_POST['wps_login_remember_me'] : false; |
|
| 134 | + $user = wp_signon($creds, false); |
|
| 135 | + if (is_wp_error($user)) { |
|
| 136 | + $result = '<div class="wps-alert-error">' . __('Connexion error', 'wpshop') . '</div>'; |
|
| 137 | 137 | } |
| 138 | 138 | else { |
| 139 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 140 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
|
| 141 | - if( $origin == $page_account_id ) { |
|
| 142 | - $result = get_permalink( $page_account_id ); |
|
| 139 | + $permalink_option = get_option('permalink_structure'); |
|
| 140 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 141 | + if ($origin == $page_account_id) { |
|
| 142 | + $result = get_permalink($page_account_id); |
|
| 143 | 143 | } |
| 144 | 144 | else { |
| 145 | - $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
|
| 145 | + $result = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=3'; |
|
| 146 | 146 | } |
| 147 | 147 | $status = true; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | else { |
| 151 | - $result = '<div class="wps-alert-error">' .__('E-Mail and Password are required', 'wpshop'). '</div>'; |
|
| 151 | + $result = '<div class="wps-alert-error">' . __('E-Mail and Password are required', 'wpshop') . '</div>'; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - echo json_encode( array( $status, $result) ); |
|
| 154 | + echo json_encode(array($status, $result)); |
|
| 155 | 155 | die(); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | * LOG IN - AJAX - Display log in Form in Ajax |
| 160 | 160 | */ |
| 161 | 161 | function wps_ajax_get_login_form_interface() { |
| 162 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 162 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 163 | 163 | |
| 164 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_ajax_get_login_form_interface' ) ) |
|
| 164 | + if (!wp_verify_nonce($_wpnonce, 'wps_ajax_get_login_form_interface')) |
|
| 165 | 165 | wp_die(); |
| 166 | 166 | |
| 167 | - $response = array( 'status' => true, 'response' => self::get_login_form() ); |
|
| 168 | - echo json_encode( $response ); |
|
| 167 | + $response = array('status' => true, 'response' => self::get_login_form()); |
|
| 168 | + echo json_encode($response); |
|
| 169 | 169 | die(); |
| 170 | 170 | } |
| 171 | 171 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | function get_login_first_step() { |
| 174 | 174 | $output = ''; |
| 175 | 175 | ob_start(); |
| 176 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "login/login-form", "first") ); |
|
| 176 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form", "first")); |
|
| 177 | 177 | $output .= ob_get_contents(); |
| 178 | 178 | ob_end_clean(); |
| 179 | 179 | return $output; |
@@ -183,39 +183,39 @@ discard block |
||
| 183 | 183 | * LOG IN - First Step log in request |
| 184 | 184 | */ |
| 185 | 185 | function wps_login_first_request() { |
| 186 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 186 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 187 | 187 | |
| 188 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_login_first_request' ) ) |
|
| 188 | + if (!wp_verify_nonce($_wpnonce, 'wps_login_first_request')) |
|
| 189 | 189 | wp_die(); |
| 190 | 190 | |
| 191 | 191 | $status = false; $login_action = false; $response = ''; |
| 192 | - $user_email = ( !empty($_POST['email_address']) ) ? wpshop_tools::varSanitizer( $_POST['email_address'] ) : null; |
|
| 193 | - if ( !empty($user_email) ) { |
|
| 192 | + $user_email = (!empty($_POST['email_address'])) ? wpshop_tools::varSanitizer($_POST['email_address']) : null; |
|
| 193 | + if (!empty($user_email)) { |
|
| 194 | 194 | $status = true; |
| 195 | 195 | /** Check if a user exist with it's email **/ |
| 196 | - $checking_user = get_user_by( 'login', $user_email); |
|
| 197 | - if ( !empty($checking_user) ) { |
|
| 196 | + $checking_user = get_user_by('login', $user_email); |
|
| 197 | + if (!empty($checking_user)) { |
|
| 198 | 198 | $login_action = true; |
| 199 | - $user_firstname = get_user_meta( $checking_user->ID, 'first_name', true ); |
|
| 199 | + $user_firstname = get_user_meta($checking_user->ID, 'first_name', true); |
|
| 200 | 200 | $response = $user_firstname; |
| 201 | 201 | } |
| 202 | 202 | else { |
| 203 | - $checking_user = get_user_by( 'email', $user_email); |
|
| 204 | - if ( !empty( $checking_user ) ) { |
|
| 203 | + $checking_user = get_user_by('email', $user_email); |
|
| 204 | + if (!empty($checking_user)) { |
|
| 205 | 205 | $login_action = true; |
| 206 | - $user_firstname = get_user_meta( $checking_user->ID, 'first_name', true ); |
|
| 206 | + $user_firstname = get_user_meta($checking_user->ID, 'first_name', true); |
|
| 207 | 207 | $response = $user_firstname; |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if( !$login_action && is_email($user_email) ) { |
|
| 211 | + if (!$login_action && is_email($user_email)) { |
|
| 212 | 212 | $response = $user_email; |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | else { |
| 216 | - $response = '<div class="wps-alert-error">' .__( 'An e-mail address is required', 'wpshop' ). '</div>'; |
|
| 216 | + $response = '<div class="wps-alert-error">' . __('An e-mail address is required', 'wpshop') . '</div>'; |
|
| 217 | 217 | } |
| 218 | - echo json_encode( array( 'status'=> $status, 'response' => $response, 'login_action' => $login_action) ); |
|
| 218 | + echo json_encode(array('status'=> $status, 'response' => $response, 'login_action' => $login_action)); |
|
| 219 | 219 | die(); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -224,9 +224,9 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | function get_forgot_password_form() { |
| 226 | 226 | $output = ''; |
| 227 | - if ( get_current_user_id() == 0 ) { |
|
| 227 | + if (get_current_user_id() == 0) { |
|
| 228 | 228 | ob_start(); |
| 229 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "forgot-password/forgot-password") ); |
|
| 229 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "forgot-password/forgot-password")); |
|
| 230 | 230 | $output = ob_get_contents(); |
| 231 | 231 | ob_end_clean(); |
| 232 | 232 | } |
@@ -237,16 +237,16 @@ discard block |
||
| 237 | 237 | * FORGOT PASSWORD - AJAX - Fill the forgot password modal |
| 238 | 238 | */ |
| 239 | 239 | function wps_fill_forgot_password_modal() { |
| 240 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 240 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 241 | 241 | |
| 242 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_forgot_password_modal' ) ) |
|
| 242 | + if (!wp_verify_nonce($_wpnonce, 'wps_fill_forgot_password_modal')) |
|
| 243 | 243 | wp_die(); |
| 244 | 244 | |
| 245 | 245 | $status = false; $title = $content = ''; |
| 246 | - $title = __( 'Forgot password', 'wpshop' ); |
|
| 246 | + $title = __('Forgot password', 'wpshop'); |
|
| 247 | 247 | $content = do_shortcode('[wps_forgot_password]'); |
| 248 | 248 | $status = true; |
| 249 | - echo json_encode( array('status' => $status, 'title' => $title, 'content' => $content) ); |
|
| 249 | + echo json_encode(array('status' => $status, 'title' => $title, 'content' => $content)); |
|
| 250 | 250 | wp_die(); |
| 251 | 251 | } |
| 252 | 252 | |
@@ -254,48 +254,48 @@ discard block |
||
| 254 | 254 | * FORGOT PASSWORD- AJAX - Forgot Password Request |
| 255 | 255 | */ |
| 256 | 256 | function wps_forgot_password_request() { |
| 257 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 257 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 258 | 258 | |
| 259 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_request' ) ) |
|
| 259 | + if (!wp_verify_nonce($_wpnonce, 'wps_forgot_password_request')) |
|
| 260 | 260 | wp_die(); |
| 261 | 261 | |
| 262 | 262 | global $wpdb; |
| 263 | 263 | $status = false; $result = ''; |
| 264 | - $user_login = ( !empty( $_POST['wps_user_login']) ) ? wpshop_tools::varSanitizer($_POST['wps_user_login']) : null; |
|
| 265 | - if ( !empty($user_login) ) { |
|
| 264 | + $user_login = (!empty($_POST['wps_user_login'])) ? wpshop_tools::varSanitizer($_POST['wps_user_login']) : null; |
|
| 265 | + if (!empty($user_login)) { |
|
| 266 | 266 | $existing_user = false; |
| 267 | 267 | $key_for_update = 'user_login'; |
| 268 | 268 | $exist_user = get_user_by('login', $user_login); |
| 269 | - if( !empty($exist_user) ) { |
|
| 269 | + if (!empty($exist_user)) { |
|
| 270 | 270 | $existing_user = true; |
| 271 | 271 | } |
| 272 | 272 | else { |
| 273 | 273 | $exist_user = get_user_by('email', $user_login); |
| 274 | 274 | $key_for_update = 'user_email'; |
| 275 | - if ( !empty($exist_user) ) { |
|
| 275 | + if (!empty($exist_user)) { |
|
| 276 | 276 | $existing_user = true; |
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( $existing_user ) { |
|
| 280 | + if ($existing_user) { |
|
| 281 | 281 | $key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE $key_for_update = %s", $user_login)); |
| 282 | - if ( empty($key) ) { |
|
| 282 | + if (empty($key)) { |
|
| 283 | 283 | $key = wp_generate_password(20, false); |
| 284 | 284 | $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login)); |
| 285 | 285 | } |
| 286 | 286 | $this->send_forgot_password_email($key, $user_login, $exist_user); |
| 287 | - $result = '<div class="wps-alert-info">' .__('An e-mail with an password renew link has been sent to you', 'wpshop'). '</div>'; |
|
| 287 | + $result = '<div class="wps-alert-info">' . __('An e-mail with an password renew link has been sent to you', 'wpshop') . '</div>'; |
|
| 288 | 288 | $status = true; |
| 289 | 289 | } |
| 290 | 290 | else { |
| 291 | - $result = '<div class="wps-alert-error">' .__('No customer account corresponds to this email', 'wpshop'). '</div>'; |
|
| 291 | + $result = '<div class="wps-alert-error">' . __('No customer account corresponds to this email', 'wpshop') . '</div>'; |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | else { |
| 295 | - $result = '<div class="wps-alert-error">' .__('Please fill the required field', 'wpshop'). '</div>'; |
|
| 295 | + $result = '<div class="wps-alert-error">' . __('Please fill the required field', 'wpshop') . '</div>'; |
|
| 296 | 296 | } |
| 297 | - $response = array( $status, $result ); |
|
| 298 | - echo json_encode( $response ); |
|
| 297 | + $response = array($status, $result); |
|
| 298 | + echo json_encode($response); |
|
| 299 | 299 | die(); |
| 300 | 300 | } |
| 301 | 301 | |
@@ -304,67 +304,67 @@ discard block |
||
| 304 | 304 | * @param string $key |
| 305 | 305 | * @param string $user_login |
| 306 | 306 | */ |
| 307 | - function send_forgot_password_email($key, $user_login, $exist_user){ |
|
| 307 | + function send_forgot_password_email($key, $user_login, $exist_user) { |
|
| 308 | 308 | $user_data = $exist_user->data; |
| 309 | 309 | $email = $user_data->user_email; |
| 310 | 310 | $wps_message = new wps_message_ctr(); |
| 311 | - $first_name = get_user_meta( $user_data->ID, 'first_name', true ); |
|
| 312 | - $last_name = get_user_meta( $user_data->ID, 'last_name', true ); |
|
| 313 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 314 | - $link = '<a href="' .get_permalink( wpshop_tools::get_page_id( get_option('wpshop_checkout_page_id') ) ).( (!empty($permalink_option)) ? '?' : '&').'order_step=2&action=retrieve_password&key=' .$key. '&login=' .rawurlencode($user_login). '">' .get_permalink( wpshop_tools::get_page_id( get_option('wpshop_checkout_page_id') ) ). '&action=retrieve_password&key=' .$key. '&login=' .rawurlencode($user_login). '</a>'; |
|
| 315 | - if( !empty($key) && !empty( $user_login ) ) { |
|
| 311 | + $first_name = get_user_meta($user_data->ID, 'first_name', true); |
|
| 312 | + $last_name = get_user_meta($user_data->ID, 'last_name', true); |
|
| 313 | + $permalink_option = get_option('permalink_structure'); |
|
| 314 | + $link = '<a href="' . get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=2&action=retrieve_password&key=' . $key . '&login=' . rawurlencode($user_login) . '">' . get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id'))) . '&action=retrieve_password&key=' . $key . '&login=' . rawurlencode($user_login) . '</a>'; |
|
| 315 | + if (!empty($key) && !empty($user_login)) { |
|
| 316 | 316 | $wps_message->wpshop_prepared_email($email, |
| 317 | 317 | 'WPSHOP_FORGOT_PASSWORD_MESSAGE', |
| 318 | - array( 'customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'forgot_password_link' => $link) |
|
| 318 | + array('customer_first_name' => $first_name, 'customer_last_name' => $last_name, 'forgot_password_link' => $link) |
|
| 319 | 319 | ); |
| 320 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** FORGOT PASSWORD - AJAX - Make renew password action **/ |
| 324 | 324 | function wps_forgot_password_renew() { |
| 325 | - check_ajax_referer( 'wps_forgot_password_renew' ); |
|
| 325 | + check_ajax_referer('wps_forgot_password_renew'); |
|
| 326 | 326 | |
| 327 | 327 | global $wpdb; |
| 328 | 328 | $status = false; $result = $form = ''; |
| 329 | - $password = ( !empty( $_POST['pass1']) ) ? wpshop_tools::varSanitizer( $_POST['pass1'] ) : null; |
|
| 330 | - $confirm_password = ( !empty( $_POST['pass2']) ) ? wpshop_tools::varSanitizer( $_POST['pass2'] ) : null; |
|
| 331 | - $activation_key = ( !empty( $_POST['activation_key']) ) ? wpshop_tools::varSanitizer( $_POST['activation_key'] ) : null; |
|
| 332 | - $login = ( !empty( $_POST['user_login']) ) ? wpshop_tools::varSanitizer( $_POST['user_login'] ) : null; |
|
| 333 | - if ( !empty($password) && !empty($confirm_password) && $confirm_password == $password ) { |
|
| 334 | - if ( !empty($activation_key) && !empty($login) ) { |
|
| 329 | + $password = (!empty($_POST['pass1'])) ? wpshop_tools::varSanitizer($_POST['pass1']) : null; |
|
| 330 | + $confirm_password = (!empty($_POST['pass2'])) ? wpshop_tools::varSanitizer($_POST['pass2']) : null; |
|
| 331 | + $activation_key = (!empty($_POST['activation_key'])) ? wpshop_tools::varSanitizer($_POST['activation_key']) : null; |
|
| 332 | + $login = (!empty($_POST['user_login'])) ? wpshop_tools::varSanitizer($_POST['user_login']) : null; |
|
| 333 | + if (!empty($password) && !empty($confirm_password) && $confirm_password == $password) { |
|
| 334 | + if (!empty($activation_key) && !empty($login)) { |
|
| 335 | 335 | $existing_user = false; |
| 336 | - $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $activation_key, $login ) ); |
|
| 337 | - if( !empty($user) ) { |
|
| 336 | + $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $activation_key, $login)); |
|
| 337 | + if (!empty($user)) { |
|
| 338 | 338 | $existing_user = true; |
| 339 | 339 | } |
| 340 | 340 | else { |
| 341 | - $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_email = %s", $activation_key, $login ) ); |
|
| 342 | - if( !empty($user) ) { |
|
| 341 | + $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_email = %s", $activation_key, $login)); |
|
| 342 | + if (!empty($user)) { |
|
| 343 | 343 | $existing_user = true; |
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - if ( $existing_user ){ |
|
| 347 | + if ($existing_user) { |
|
| 348 | 348 | wp_set_password($password, $user->ID); |
| 349 | 349 | wp_password_change_notification($user); |
| 350 | 350 | $status = true; |
| 351 | - $result = '<div class="wps-alert-success">' .__('Your password has been updated', 'wpshop'). '. <a href="#" id="display_connexion_form"> ' .__('Connect you', 'wpshop').' !</a></div>'; |
|
| 352 | - $form = self::get_login_form( true ); |
|
| 351 | + $result = '<div class="wps-alert-success">' . __('Your password has been updated', 'wpshop') . '. <a href="#" id="display_connexion_form"> ' . __('Connect you', 'wpshop') . ' !</a></div>'; |
|
| 352 | + $form = self::get_login_form(true); |
|
| 353 | 353 | } |
| 354 | 354 | else { |
| 355 | - $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
|
| 355 | + $result = '<div class=" wps-alert-error">' . __('Invalid activation key', 'wpshop') . '</div>'; |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | else { |
| 359 | - $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
|
| 359 | + $result = '<div class=" wps-alert-error">' . __('Invalid activation key', 'wpshop') . '</div>'; |
|
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | 362 | else { |
| 363 | - $result = '<div class="wps-alert-error">' .__('Password and confirmation password are differents', 'wpshop'). '</div>'; |
|
| 363 | + $result = '<div class="wps-alert-error">' . __('Password and confirmation password are differents', 'wpshop') . '</div>'; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - $response = array( $status, $result, $form ); |
|
| 367 | - echo json_encode( $response); |
|
| 366 | + $response = array($status, $result, $form); |
|
| 367 | + echo json_encode($response); |
|
| 368 | 368 | die(); |
| 369 | 369 | } |
| 370 | 370 | |
@@ -373,9 +373,9 @@ discard block |
||
| 373 | 373 | * @return string |
| 374 | 374 | */ |
| 375 | 375 | function get_renew_password_form() { |
| 376 | - if ( get_current_user_id() == 0 ) { |
|
| 376 | + if (get_current_user_id() == 0) { |
|
| 377 | 377 | ob_start(); |
| 378 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "forgot-password/password-renew") ); |
|
| 378 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "forgot-password/password-renew")); |
|
| 379 | 379 | $output = ob_get_contents(); |
| 380 | 380 | ob_end_clean(); |
| 381 | 381 | } |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | |
| 385 | 385 | /** FORGOT PASSWORD - AJAX - Get Forgot Password form **/ |
| 386 | 386 | function wps_ajax_get_forgot_password_form() { |
| 387 | - echo json_encode( array(self::get_forgot_password_form() ) ); |
|
| 387 | + echo json_encode(array(self::get_forgot_password_form())); |
|
| 388 | 388 | die(); |
| 389 | 389 | } |
| 390 | 390 | |
@@ -392,29 +392,29 @@ discard block |
||
| 392 | 392 | * SIGN UP - Display Sign up form |
| 393 | 393 | * @return string |
| 394 | 394 | */ |
| 395 | - function display_signup( $args = array() ) { |
|
| 395 | + function display_signup($args = array()) { |
|
| 396 | 396 | global $wpdb; |
| 397 | 397 | $output = ''; |
| 398 | - if ( get_current_user_id() == 0 || !empty($args) ) { |
|
| 398 | + if (get_current_user_id() == 0 || !empty($args)) { |
|
| 399 | 399 | $fields_to_output = $signup_fields = array(); |
| 400 | 400 | |
| 401 | - $password_attribute = $signup_form_attributes = array(); |
|
| 401 | + $password_attribute = $signup_form_attributes = array(); |
|
| 402 | 402 | |
| 403 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 403 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 404 | 404 | |
| 405 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $entity_id); |
|
| 406 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
| 405 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 406 | + $customer_entity_id = $wpdb->get_var($query); |
|
| 407 | 407 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
| 408 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
| 409 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_GROUP.' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid' ); |
|
| 410 | - $customer_attributes_sections = $wpdb->get_results( $query ); |
|
| 411 | - foreach( $customer_attributes_sections as $k => $customer_attributes_section ) { |
|
| 412 | - foreach( $account_attributes[$customer_attributes_section->id]['attribut'] as $attribute ) { |
|
| 408 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 409 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid'); |
|
| 410 | + $customer_attributes_sections = $wpdb->get_results($query); |
|
| 411 | + foreach ($customer_attributes_sections as $k => $customer_attributes_section) { |
|
| 412 | + foreach ($account_attributes[$customer_attributes_section->id]['attribut'] as $attribute) { |
|
| 413 | 413 | $signup_fields[] = $attribute; |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | ob_start(); |
| 417 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "signup/signup") ); |
|
| 417 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "signup/signup")); |
|
| 418 | 418 | $output = ob_get_contents(); |
| 419 | 419 | ob_end_clean(); |
| 420 | 420 | } |
@@ -422,119 +422,119 @@ discard block |
||
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | function wps_save_signup_form_nopriv() { |
| 425 | - $this->wps_save_signup_form( true ); |
|
| 425 | + $this->wps_save_signup_form(true); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
| 429 | 429 | * SIGN UP - Save sign up form |
| 430 | 430 | */ |
| 431 | - function wps_save_signup_form( $connect = false ) { |
|
| 432 | - $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
|
| 431 | + function wps_save_signup_form($connect = false) { |
|
| 432 | + $_wpnonce = !empty($_POST['_wpnonce']) ? sanitize_text_field($_POST['_wpnonce']) : ''; |
|
| 433 | 433 | |
| 434 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_signup_form' ) ) |
|
| 434 | + if (!wp_verify_nonce($_wpnonce, 'wps_save_signup_form')) |
|
| 435 | 435 | wp_die(); |
| 436 | 436 | |
| 437 | 437 | global $wpdb, $wpshop; |
| 438 | - $user_id = ( !empty( $_POST['wps_sign_up_request_from_admin'] ) ) ? (int) $_POST['wps_sign_up_request_from_admin'] : get_current_user_id(); |
|
| 438 | + $user_id = (!empty($_POST['wps_sign_up_request_from_admin'])) ? (int)$_POST['wps_sign_up_request_from_admin'] : get_current_user_id(); |
|
| 439 | 439 | $wps_message = new wps_message_ctr(); |
| 440 | 440 | $status = $account_creation = false; $result = ''; |
| 441 | - $exclude_user_meta = array( 'user_email', 'user_pass' ); |
|
| 442 | - $attribute = !empty( $_POST['attribute'] ) ? (array) $_POST['attribute'] : array(); |
|
| 443 | - $element_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 444 | - if ( !empty( $element_id) ){ |
|
| 445 | - $query = $wpdb->prepare('SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d', $element_id ); |
|
| 446 | - $attribute_set_id = $wpdb->get_var( $query ); |
|
| 447 | - if ( !empty($attribute_set_id) ){ |
|
| 448 | - $group = wps_address::get_addresss_form_fields_by_type( $attribute_set_id ); |
|
| 449 | - foreach ( $group as $attribute_sets ) { |
|
| 450 | - foreach ( $attribute_sets as $attribute_set_field ) { |
|
| 451 | - if( !empty($user_id) ) { |
|
| 452 | - foreach( $attribute_set_field['content'] as $attribute_code => $att_def ) { |
|
| 453 | - if( $attribute_code != 'account_user_email' ) { |
|
| 441 | + $exclude_user_meta = array('user_email', 'user_pass'); |
|
| 442 | + $attribute = !empty($_POST['attribute']) ? (array)$_POST['attribute'] : array(); |
|
| 443 | + $element_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 444 | + if (!empty($element_id)) { |
|
| 445 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id); |
|
| 446 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 447 | + if (!empty($attribute_set_id)) { |
|
| 448 | + $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); |
|
| 449 | + foreach ($group as $attribute_sets) { |
|
| 450 | + foreach ($attribute_sets as $attribute_set_field) { |
|
| 451 | + if (!empty($user_id)) { |
|
| 452 | + foreach ($attribute_set_field['content'] as $attribute_code => $att_def) { |
|
| 453 | + if ($attribute_code != 'account_user_email') { |
|
| 454 | 454 | $attribute_set_field['content'][$attribute_code]['required'] = 'no'; |
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | - $validate = $wpshop->validateForm($attribute_set_field['content'], $attribute ); |
|
| 458 | + $validate = $wpshop->validateForm($attribute_set_field['content'], $attribute); |
|
| 459 | 459 | } |
| 460 | - if ( empty($wpshop->errors) ) { |
|
| 461 | - $user_name = !empty($attribute['varchar']['user_login']) ? sanitize_text_field( $attribute['varchar']['user_login'] ) : sanitize_email( $attribute['varchar']['user_email'] ); |
|
| 462 | - $user_pass = ( !empty($attribute['varchar']['user_pass']) && !empty($_POST['wps_signup_account_creation']) ) ? sanitize_text_field( $attribute['varchar']['user_pass'] ) : wp_generate_password( 12, false ); |
|
| 460 | + if (empty($wpshop->errors)) { |
|
| 461 | + $user_name = !empty($attribute['varchar']['user_login']) ? sanitize_text_field($attribute['varchar']['user_login']) : sanitize_email($attribute['varchar']['user_email']); |
|
| 462 | + $user_pass = (!empty($attribute['varchar']['user_pass']) && !empty($_POST['wps_signup_account_creation'])) ? sanitize_text_field($attribute['varchar']['user_pass']) : wp_generate_password(12, false); |
|
| 463 | 463 | |
| 464 | - if ( $user_id == 0 ) { |
|
| 465 | - $user_id = wp_create_user($user_name, $user_pass, sanitize_email( $attribute['varchar']['user_email'] ) ); |
|
| 466 | - if ( !is_object( $user_id) ) { |
|
| 464 | + if ($user_id == 0) { |
|
| 465 | + $user_id = wp_create_user($user_name, $user_pass, sanitize_email($attribute['varchar']['user_email'])); |
|
| 466 | + if (!is_object($user_id)) { |
|
| 467 | 467 | $account_creation = true; |
| 468 | 468 | /** Update newsletter user preferences **/ |
| 469 | 469 | $newsletter_preferences = array(); |
| 470 | - $newsletters_site = !empty( $_POST['newsletters_site'] ) ? (bool) $_POST['newsletters_site'] : false; |
|
| 471 | - if( $newsletters_site ) { |
|
| 470 | + $newsletters_site = !empty($_POST['newsletters_site']) ? (bool)$_POST['newsletters_site'] : false; |
|
| 471 | + if ($newsletters_site) { |
|
| 472 | 472 | $newsletter_preferences['newsletters_site'] = 1; |
| 473 | 473 | } |
| 474 | - $newsletters_site_partners = !empty( $_POST['newsletters_site_partners'] ) ? (bool) $_POST['newsletters_site_partners'] : false; |
|
| 475 | - if( $newsletters_site_partners ) { |
|
| 474 | + $newsletters_site_partners = !empty($_POST['newsletters_site_partners']) ? (bool)$_POST['newsletters_site_partners'] : false; |
|
| 475 | + if ($newsletters_site_partners) { |
|
| 476 | 476 | $newsletter_preferences['newsletters_site_partners'] = 1; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - update_user_meta( $user_id, 'user_preferences', $newsletter_preferences); |
|
| 479 | + update_user_meta($user_id, 'user_preferences', $newsletter_preferences); |
|
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - $customer_entity_request = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
| 484 | - $customer_post_ID = $wpdb->get_var( $customer_entity_request ); |
|
| 483 | + $customer_entity_request = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
| 484 | + $customer_post_ID = $wpdb->get_var($customer_entity_request); |
|
| 485 | 485 | |
| 486 | - if( !empty( $attribute ) ) { |
|
| 486 | + if (!empty($attribute)) { |
|
| 487 | 487 | $user_info = $address_forms = $all_addresses_form = array(); |
| 488 | - $billing_option = get_option( 'wpshop_billing_address' ); |
|
| 489 | - foreach( $attribute as $type => $attributes ) { |
|
| 490 | - if( !empty( $billing_option['integrate_into_register_form'] ) && $billing_option['integrate_into_register_form'] == 'yes' && ctype_digit( (string) $type ) ) { |
|
| 488 | + $billing_option = get_option('wpshop_billing_address'); |
|
| 489 | + foreach ($attribute as $type => $attributes) { |
|
| 490 | + if (!empty($billing_option['integrate_into_register_form']) && $billing_option['integrate_into_register_form'] == 'yes' && ctype_digit((string)$type)) { |
|
| 491 | 491 | //wps_address::save_address_infos( (int) $type ); |
| 492 | - foreach( $attributes as $sub_type => $sub_attributes ) { |
|
| 493 | - if( !is_array( $sub_attributes ) ) { |
|
| 494 | - $address_forms[$type][$sub_type] = sanitize_text_field( $sub_attributes ); |
|
| 492 | + foreach ($attributes as $sub_type => $sub_attributes) { |
|
| 493 | + if (!is_array($sub_attributes)) { |
|
| 494 | + $address_forms[$type][$sub_type] = sanitize_text_field($sub_attributes); |
|
| 495 | 495 | continue; |
| 496 | 496 | } |
| 497 | - foreach( $sub_attributes as $sub_meta => $sub_attribute_value ) { |
|
| 498 | - $address_forms[$type][$sub_type][$sub_meta] = sanitize_text_field( $sub_attribute_value ); |
|
| 497 | + foreach ($sub_attributes as $sub_meta => $sub_attribute_value) { |
|
| 498 | + $address_forms[$type][$sub_type][$sub_meta] = sanitize_text_field($sub_attribute_value); |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | } else { |
| 502 | - foreach( $attributes as $meta => $attribute_value ) { |
|
| 503 | - $user_info[$meta] = sanitize_text_field( $attribute_value ); |
|
| 504 | - if( !empty( $billing_option['integrate_into_register_form'] ) && $billing_option['integrate_into_register_form'] == 'yes' && isset( $billing_option['integrate_into_register_form_matching_field'], $billing_option['integrate_into_register_form_matching_field'][$meta] ) ) { |
|
| 502 | + foreach ($attributes as $meta => $attribute_value) { |
|
| 503 | + $user_info[$meta] = sanitize_text_field($attribute_value); |
|
| 504 | + if (!empty($billing_option['integrate_into_register_form']) && $billing_option['integrate_into_register_form'] == 'yes' && isset($billing_option['integrate_into_register_form_matching_field'], $billing_option['integrate_into_register_form_matching_field'][$meta])) { |
|
| 505 | 505 | $all_addresses_form[$type][$meta] = $user_info[$meta]; |
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | } |
| 509 | 509 | } |
| 510 | - wps_customer_ctr::save_customer_synchronize( $customer_post_ID, $user_id, $user_info ); |
|
| 511 | - foreach( $address_forms as $type_of_form => $address_form ) { |
|
| 512 | - $address_form = array_merge_recursive( $all_addresses_form, $address_form ); |
|
| 513 | - wps_address::save_address_infos( (int) $type_of_form, 0, array( 'type_of_form' => (int) $type_of_form, 'attribute' => array( $type_of_form => $address_form ) ), $customer_post_ID ); |
|
| 510 | + wps_customer_ctr::save_customer_synchronize($customer_post_ID, $user_id, $user_info); |
|
| 511 | + foreach ($address_forms as $type_of_form => $address_form) { |
|
| 512 | + $address_form = array_merge_recursive($all_addresses_form, $address_form); |
|
| 513 | + wps_address::save_address_infos((int)$type_of_form, 0, array('type_of_form' => (int)$type_of_form, 'attribute' => array($type_of_form => $address_form)), $customer_post_ID); |
|
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - if ( !empty( $_SESSION ) && !empty( $_SESSION[ 'cart' ] ) ) { |
|
| 518 | - $permalink_option = get_option( 'permalink_structure' ); |
|
| 519 | - $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' )); |
|
| 520 | - $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
|
| 517 | + if (!empty($_SESSION) && !empty($_SESSION['cart'])) { |
|
| 518 | + $permalink_option = get_option('permalink_structure'); |
|
| 519 | + $checkout_page_id = wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')); |
|
| 520 | + $result = get_permalink($checkout_page_id) . ((!empty($permalink_option)) ? '?' : '&') . 'order_step=3'; |
|
| 521 | 521 | } |
| 522 | 522 | else { |
| 523 | - $account_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id' )); |
|
| 524 | - $result = get_permalink( $account_page_id ); |
|
| 523 | + $account_page_id = wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id')); |
|
| 524 | + $result = get_permalink($account_page_id); |
|
| 525 | 525 | } |
| 526 | 526 | $status = true; |
| 527 | 527 | |
| 528 | - if ( $account_creation && !empty( $user_id ) && $connect ) { |
|
| 528 | + if ($account_creation && !empty($user_id) && $connect) { |
|
| 529 | 529 | $secure_cookie = is_ssl() ? true : false; |
| 530 | - wp_set_auth_cookie( $user_id, true, $secure_cookie ); |
|
| 530 | + wp_set_auth_cookie($user_id, true, $secure_cookie); |
|
| 531 | 531 | } |
| 532 | - $wps_message->wpshop_prepared_email( sanitize_email($attribute['varchar']['user_email']), 'WPSHOP_SIGNUP_MESSAGE', array('customer_first_name' => ( !empty($attribute['varchar']['first_name']) ) ? sanitize_text_field( $attribute['varchar']['first_name'] ) : '', 'customer_last_name' => ( !empty($attribute['varchar']['last_name']) ) ? sanitize_text_field( $attribute['varchar']['last_name'] ) : '', 'customer_user_email' => ( !empty($attribute['varchar']['user_email']) ) ? sanitize_email( $attribute['varchar']['user_email'] ) : '') ); |
|
| 532 | + $wps_message->wpshop_prepared_email(sanitize_email($attribute['varchar']['user_email']), 'WPSHOP_SIGNUP_MESSAGE', array('customer_first_name' => (!empty($attribute['varchar']['first_name'])) ? sanitize_text_field($attribute['varchar']['first_name']) : '', 'customer_last_name' => (!empty($attribute['varchar']['last_name'])) ? sanitize_text_field($attribute['varchar']['last_name']) : '', 'customer_user_email' => (!empty($attribute['varchar']['user_email'])) ? sanitize_email($attribute['varchar']['user_email']) : '')); |
|
| 533 | 533 | |
| 534 | 534 | } else { |
| 535 | - $result = '<div class="wps-alert-error">' .__('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 536 | - foreach( $wpshop->errors as $error ){ |
|
| 537 | - $result .= '<li>' .$error. '</li>'; |
|
| 535 | + $result = '<div class="wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 536 | + foreach ($wpshop->errors as $error) { |
|
| 537 | + $result .= '<li>' . $error . '</li>'; |
|
| 538 | 538 | } |
| 539 | 539 | $result .= '</div>'; |
| 540 | 540 | } |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - wp_die( json_encode( array( $status, $result, $user_id ) ) ); |
|
| 546 | + wp_die(json_encode(array($status, $result, $user_id))); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** SIGN UP - Display the commercial & newsletter form |
@@ -551,10 +551,10 @@ discard block |
||
| 551 | 551 | */ |
| 552 | 552 | function display_commercial_newsletter_form() { |
| 553 | 553 | $output = ''; |
| 554 | - $user_preferences = get_user_meta( get_current_user_id(), 'user_preferences', true ); |
|
| 555 | - $wpshop_cart_option = get_option( 'wpshop_cart_option' ); |
|
| 554 | + $user_preferences = get_user_meta(get_current_user_id(), 'user_preferences', true); |
|
| 555 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 556 | 556 | ob_start(); |
| 557 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "signup/signup", "newsletter") ); |
|
| 557 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "signup/signup", "newsletter")); |
|
| 558 | 558 | $output = ob_get_contents(); |
| 559 | 559 | ob_end_clean(); |
| 560 | 560 | |
@@ -565,88 +565,88 @@ discard block |
||
| 565 | 565 | * ACCOUNT - Display Account informations |
| 566 | 566 | * @return string |
| 567 | 567 | */ |
| 568 | - function display_account_informations( $customer_id = '', $force_edition_form = false, $customer_link = false ) { |
|
| 568 | + function display_account_informations($customer_id = '', $force_edition_form = false, $customer_link = false) { |
|
| 569 | 569 | global $wpdb; |
| 570 | 570 | $output = $attributes_sections_tpl = $attribute_details = ''; |
| 571 | - $is_from_admin = ( !empty($customer_id) ) ? true : false; |
|
| 572 | - $customer_id = ( !empty($customer_id) ) ? $customer_id : get_current_user_id(); |
|
| 573 | - if( $customer_id != 0 ) { |
|
| 571 | + $is_from_admin = (!empty($customer_id)) ? true : false; |
|
| 572 | + $customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id(); |
|
| 573 | + if ($customer_id != 0) { |
|
| 574 | 574 | $screen = get_current_screen(); |
| 575 | - if( ( is_admin() && isset( $screen ) && is_object( $screen ) && $screen->post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) || $force_edition_form ) { |
|
| 576 | - $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 577 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id ); |
|
| 578 | - $cid = $wpdb->get_var( $query ); |
|
| 575 | + if ((is_admin() && isset($screen) && is_object($screen) && $screen->post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) || $force_edition_form) { |
|
| 576 | + $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 577 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id); |
|
| 578 | + $cid = $wpdb->get_var($query); |
|
| 579 | 579 | |
| 580 | 580 | $fields_to_output = $signup_fields = array(); |
| 581 | 581 | |
| 582 | - $password_attribute = $signup_form_attributes = array(); |
|
| 582 | + $password_attribute = $signup_form_attributes = array(); |
|
| 583 | 583 | |
| 584 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 584 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 585 | 585 | |
| 586 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $entity_id); |
|
| 587 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
| 586 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 587 | + $customer_entity_id = $wpdb->get_var($query); |
|
| 588 | 588 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
| 589 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
| 590 | - $query = $wpdb->prepare('SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_GROUP.' WHERE attribute_set_id = %d', $attributes_set->id ); |
|
| 591 | - $customer_attributes_sections = $wpdb->get_results( $query ); |
|
| 592 | - foreach( $customer_attributes_sections as $k => $attributes_section ) { |
|
| 589 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 590 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d', $attributes_set->id); |
|
| 591 | + $customer_attributes_sections = $wpdb->get_results($query); |
|
| 592 | + foreach ($customer_attributes_sections as $k => $attributes_section) { |
|
| 593 | 593 | $signup_fields[$attributes_section->name] = array(); |
| 594 | - if ( !empty( $account_attributes[$attributes_section->id] ) ) { |
|
| 595 | - foreach( $account_attributes[$attributes_section->id]['attribut'] as $attribute ) { |
|
| 594 | + if (!empty($account_attributes[$attributes_section->id])) { |
|
| 595 | + foreach ($account_attributes[$attributes_section->id]['attribut'] as $attribute) { |
|
| 596 | 596 | $signup_fields[$attributes_section->name][] = $attribute; |
| 597 | 597 | } |
| 598 | 598 | } |
| 599 | 599 | } |
| 600 | 600 | ob_start(); |
| 601 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"backend", "customer-informations/customer_informations_form") ); |
|
| 601 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "backend", "customer-informations/customer_informations_form")); |
|
| 602 | 602 | $output = ob_get_contents(); |
| 603 | 603 | ob_end_clean(); |
| 604 | 604 | } else { |
| 605 | - $customer_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 606 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id ); |
|
| 607 | - $cid = $wpdb->get_var( $query ); |
|
| 608 | - |
|
| 609 | - if( !empty($customer_entity_id) ) { |
|
| 610 | - $query = $wpdb->prepare( 'SELECT * FROM '.WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d AND status = %s AND default_set = %s', $customer_entity_id, 'valid', 'yes' ); |
|
| 611 | - $attributes_sets = $wpdb->get_results( $query ); |
|
| 612 | - foreach( $attributes_sets as $attributes_set ) { |
|
| 613 | - if( !empty($attributes_set->id) ) { |
|
| 614 | - $query = $wpdb->prepare( 'SELECT * FROM '. WPSHOP_DBT_ATTRIBUTE_GROUP. ' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid'); |
|
| 615 | - $attributes_sections = $wpdb->get_results( $query ); |
|
| 616 | - |
|
| 617 | - if( !empty($attributes_sections) ) { |
|
| 618 | - foreach( $attributes_sections as $attributes_section ) { |
|
| 619 | - $query = $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_DETAILS. ' WHERE status = %s AND entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', 'valid', $customer_entity_id, $attributes_set->id, $attributes_section->id); |
|
| 620 | - $attributes_details = $wpdb->get_results( $query ); |
|
| 621 | - |
|
| 622 | - foreach( $attributes_details as $attributes_detail ) { |
|
| 623 | - $query = $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE. ' WHERE id = %d AND status = %s', $attributes_detail->attribute_id, 'valid' ); |
|
| 624 | - $attribute_def = $wpdb->get_row( $query ); |
|
| 625 | - |
|
| 626 | - $query = $wpdb->prepare( 'SELECT value FROM '.WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX.strtolower($attribute_def->data_type). ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $attribute_def->id, $cid ); |
|
| 627 | - $attribute_value = $wpdb->get_var( $query ); |
|
| 605 | + $customer_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 606 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $customer_id); |
|
| 607 | + $cid = $wpdb->get_var($query); |
|
| 608 | + |
|
| 609 | + if (!empty($customer_entity_id)) { |
|
| 610 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND status = %s AND default_set = %s', $customer_entity_id, 'valid', 'yes'); |
|
| 611 | + $attributes_sets = $wpdb->get_results($query); |
|
| 612 | + foreach ($attributes_sets as $attributes_set) { |
|
| 613 | + if (!empty($attributes_set->id)) { |
|
| 614 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND status = %s', $attributes_set->id, 'valid'); |
|
| 615 | + $attributes_sections = $wpdb->get_results($query); |
|
| 616 | + |
|
| 617 | + if (!empty($attributes_sections)) { |
|
| 618 | + foreach ($attributes_sections as $attributes_section) { |
|
| 619 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE status = %s AND entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', 'valid', $customer_entity_id, $attributes_set->id, $attributes_section->id); |
|
| 620 | + $attributes_details = $wpdb->get_results($query); |
|
| 621 | + |
|
| 622 | + foreach ($attributes_details as $attributes_detail) { |
|
| 623 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d AND status = %s', $attributes_detail->attribute_id, 'valid'); |
|
| 624 | + $attribute_def = $wpdb->get_row($query); |
|
| 625 | + |
|
| 626 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_PREFIX . strtolower($attribute_def->data_type) . ' WHERE entity_type_id = %d AND attribute_id = %d AND entity_id = %d ', $customer_entity_id, $attribute_def->id, $cid); |
|
| 627 | + $attribute_value = $wpdb->get_var($query); |
|
| 628 | 628 | |
| 629 | 629 | /** Check attribute type for specific type display */ |
| 630 | - if ( "datetime" == $attribute_def->data_type ) { |
|
| 631 | - $attribute_value = mysql2date( get_option( 'date_format' ) . ( ( substr( $attribute_value, -9 ) != ' 00:00:00' ) ? ' ' . get_option( 'time_format' ) : '' ), $attribute_value, true); |
|
| 630 | + if ("datetime" == $attribute_def->data_type) { |
|
| 631 | + $attribute_value = mysql2date(get_option('date_format') . ((substr($attribute_value, -9) != ' 00:00:00') ? ' ' . get_option('time_format') : ''), $attribute_value, true); |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | /** Check attribute input type in order to get specific value */ |
| 635 | - if ( in_array( $attribute_def->backend_input, array( 'multiple-select', 'select', 'radio', 'checkbox' ) ) ) { |
|
| 636 | - if ( $attribute_def->data_type_to_use == 'custom' ) { |
|
| 637 | - $query = $wpdb->prepare("SELECT label FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d AND status = 'valid' AND id = %d", $attribute_def->id, $attribute_value ); |
|
| 638 | - $attribute_value = $wpdb->get_var( $query ); |
|
| 635 | + if (in_array($attribute_def->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'))) { |
|
| 636 | + if ($attribute_def->data_type_to_use == 'custom') { |
|
| 637 | + $query = $wpdb->prepare("SELECT label FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d AND status = 'valid' AND id = %d", $attribute_def->id, $attribute_value); |
|
| 638 | + $attribute_value = $wpdb->get_var($query); |
|
| 639 | 639 | } |
| 640 | - else if ( $attribute_def->data_type_to_use == 'internal') { |
|
| 641 | - $associated_post = get_post( $atribute_value ); |
|
| 640 | + else if ($attribute_def->data_type_to_use == 'internal') { |
|
| 641 | + $associated_post = get_post($atribute_value); |
|
| 642 | 642 | $attribute_value = $associated_post->post_title; |
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - if( !empty( $attribute_def ) ) { |
|
| 647 | - if( $attribute_def->frontend_input != 'password' ) { |
|
| 646 | + if (!empty($attribute_def)) { |
|
| 647 | + if ($attribute_def->frontend_input != 'password') { |
|
| 648 | 648 | ob_start(); |
| 649 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "account/account_informations_element") ); |
|
| 649 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations_element")); |
|
| 650 | 650 | $attribute_details .= ob_get_contents(); |
| 651 | 651 | ob_end_clean(); |
| 652 | 652 | } |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | ob_start(); |
| 657 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "account/account_informations_group_element") ); |
|
| 657 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations_group_element")); |
|
| 658 | 658 | $attributes_sections_tpl .= ob_get_contents(); |
| 659 | 659 | ob_end_clean(); |
| 660 | 660 | |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | ob_start(); |
| 668 | - require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations") ); |
|
| 668 | + require_once(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_informations")); |
|
| 669 | 669 | $output = ob_get_contents(); |
| 670 | 670 | ob_end_clean(); |
| 671 | 671 | } |
@@ -679,85 +679,85 @@ discard block |
||
| 679 | 679 | function account_informations_form() { |
| 680 | 680 | global $wpdb; |
| 681 | 681 | $output = ''; |
| 682 | - if ( get_current_user_id() != 0 ) { |
|
| 682 | + if (get_current_user_id() != 0) { |
|
| 683 | 683 | // Customer ID data |
| 684 | - $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 685 | - $query = $wpdb->prepare( 'SELECT ID FROM ' .$wpdb->posts. ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, get_current_user_id() ); |
|
| 686 | - $cid = $wpdb->get_var( $query ); |
|
| 684 | + $customer_entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 685 | + $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_author = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, get_current_user_id()); |
|
| 686 | + $cid = $wpdb->get_var($query); |
|
| 687 | 687 | |
| 688 | 688 | $fields_to_output = $signup_fields = array(); |
| 689 | 689 | |
| 690 | - $password_attribute = $signup_form_attributes = array(); |
|
| 690 | + $password_attribute = $signup_form_attributes = array(); |
|
| 691 | 691 | |
| 692 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 692 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 693 | 693 | |
| 694 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_SET.' WHERE entity_id = %d', $entity_id); |
|
| 695 | - $customer_entity_id = $wpdb->get_var( $query ); |
|
| 694 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 695 | + $customer_entity_id = $wpdb->get_var($query); |
|
| 696 | 696 | $attributes_set = wpshop_attributes_set::getElement($customer_entity_id); |
| 697 | - $account_attributes = wpshop_attributes_set::getAttributeSetDetails( ( !empty($attributes_set->id) ) ? $attributes_set->id : '', "'valid'"); |
|
| 698 | - $query = $wpdb->prepare('SELECT id FROM '.WPSHOP_DBT_ATTRIBUTE_GROUP.' WHERE attribute_set_id = %d', $attributes_set->id ); |
|
| 699 | - $customer_attributes_sections = $wpdb->get_results( $query ); |
|
| 700 | - foreach( $customer_attributes_sections as $k => $customer_attributes_section ) { |
|
| 701 | - if ( !empty( $account_attributes[$customer_attributes_section->id] ) ) { |
|
| 702 | - foreach( $account_attributes[$customer_attributes_section->id]['attribut'] as $attribute ) { |
|
| 697 | + $account_attributes = wpshop_attributes_set::getAttributeSetDetails((!empty($attributes_set->id)) ? $attributes_set->id : '', "'valid'"); |
|
| 698 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d', $attributes_set->id); |
|
| 699 | + $customer_attributes_sections = $wpdb->get_results($query); |
|
| 700 | + foreach ($customer_attributes_sections as $k => $customer_attributes_section) { |
|
| 701 | + if (!empty($account_attributes[$customer_attributes_section->id])) { |
|
| 702 | + foreach ($account_attributes[$customer_attributes_section->id]['attribut'] as $attribute) { |
|
| 703 | 703 | $signup_fields[] = $attribute; |
| 704 | 704 | } |
| 705 | 705 | } |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | ob_start(); |
| 709 | - require( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir,"frontend", "account/account_form") ); |
|
| 709 | + require(wpshop_tools::get_template_part(WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "account/account_form")); |
|
| 710 | 710 | $output = ob_get_contents(); |
| 711 | 711 | ob_end_clean(); |
| 712 | 712 | } |
| 713 | 713 | return $output; |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - function save_account_informations( $cid, $args, $admin = true ) { |
|
| 716 | + function save_account_informations($cid, $args, $admin = true) { |
|
| 717 | 717 | global $wpdb, $wpshop; |
| 718 | 718 | |
| 719 | - $exclude_user_meta = array( 'user_email', 'user_pass' ); |
|
| 719 | + $exclude_user_meta = array('user_email', 'user_pass'); |
|
| 720 | 720 | $wps_entities = new wpshop_entities(); |
| 721 | - $element_id = $wps_entities->get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ); |
|
| 721 | + $element_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 722 | 722 | |
| 723 | - $query = $wpdb->prepare( 'SELECT post_author FROM ' .$wpdb->posts. ' WHERE post_type = %s AND ID = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $cid ); |
|
| 724 | - $user_id = $wpdb->get_var( $query ); |
|
| 723 | + $query = $wpdb->prepare('SELECT post_author FROM ' . $wpdb->posts . ' WHERE post_type = %s AND ID = %d', WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $cid); |
|
| 724 | + $user_id = $wpdb->get_var($query); |
|
| 725 | 725 | |
| 726 | 726 | $user_name = !empty($args['attribute']['varchar']['user_login']) ? $args['attribute']['varchar']['user_login'] : $args['attribute']['varchar']['user_email']; |
| 727 | 727 | $user_pass = !empty($args['attribute']['varchar']['user_pass']) ? $args['attribute']['varchar']['user_pass'] : ''; |
| 728 | 728 | |
| 729 | - $query = $wpdb->prepare('SELECT id FROM ' .WPSHOP_DBT_ATTRIBUTE_SET. ' WHERE entity_id = %d', $element_id ); |
|
| 730 | - $attribute_set_id = $wpdb->get_var( $query ); |
|
| 731 | - if ( !empty($attribute_set_id) ) { |
|
| 732 | - $group = wps_address::get_addresss_form_fields_by_type( $attribute_set_id ); |
|
| 729 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $element_id); |
|
| 730 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 731 | + if (!empty($attribute_set_id)) { |
|
| 732 | + $group = wps_address::get_addresss_form_fields_by_type($attribute_set_id); |
|
| 733 | 733 | //Save data in attribute tables, ckeck first if exist to know if Insert or Update |
| 734 | - wpshop_attributes::saveAttributeForEntity( $args['attribute'], $element_id, $cid ); |
|
| 735 | - foreach ( $group as $attribute_sets ) { |
|
| 736 | - foreach ( $attribute_sets as $attribute_set_field ) { |
|
| 737 | - if( $admin ) { |
|
| 738 | - $validate = $wpshop->validateForm($attribute_set_field['content'], $args['attribute'] ); |
|
| 734 | + wpshop_attributes::saveAttributeForEntity($args['attribute'], $element_id, $cid); |
|
| 735 | + foreach ($group as $attribute_sets) { |
|
| 736 | + foreach ($attribute_sets as $attribute_set_field) { |
|
| 737 | + if ($admin) { |
|
| 738 | + $validate = $wpshop->validateForm($attribute_set_field['content'], $args['attribute']); |
|
| 739 | 739 | } |
| 740 | - if ( empty($wpshop->errors) || !$admin ) { |
|
| 740 | + if (empty($wpshop->errors) || !$admin) { |
|
| 741 | 741 | $wpshop_attributes = new wpshop_attributes(); |
| 742 | - foreach( $attribute_set_field['content'] as $attribute ) { |
|
| 743 | - $attribute_def = wpshop_attributes::getElement( $attribute['name'], "'valid'", 'code'); |
|
| 744 | - if ( !in_array( $attribute['name'], $exclude_user_meta ) ) { |
|
| 745 | - update_user_meta( $user_id, $attribute['name'], wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ); |
|
| 742 | + foreach ($attribute_set_field['content'] as $attribute) { |
|
| 743 | + $attribute_def = wpshop_attributes::getElement($attribute['name'], "'valid'", 'code'); |
|
| 744 | + if (!in_array($attribute['name'], $exclude_user_meta)) { |
|
| 745 | + update_user_meta($user_id, $attribute['name'], wpshop_tools::varSanitizer($args['attribute'][$attribute['data_type']][$attribute['name']])); |
|
| 746 | 746 | } |
| 747 | 747 | else { |
| 748 | - wp_update_user( array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ) ); |
|
| 748 | + wp_update_user(array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer($args['attribute'][$attribute['data_type']][$attribute['name']]))); |
|
| 749 | 749 | } |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | /** Update newsletter user preferences **/ |
| 753 | 753 | $newsletter_preferences = array(); |
| 754 | - if( !empty($args['newsletters_site']) ) { |
|
| 754 | + if (!empty($args['newsletters_site'])) { |
|
| 755 | 755 | $newsletter_preferences['newsletters_site'] = 1; |
| 756 | 756 | } |
| 757 | - if( !empty($args['newsletters_site_partners']) ) { |
|
| 757 | + if (!empty($args['newsletters_site_partners'])) { |
|
| 758 | 758 | $newsletter_preferences['newsletters_site_partners'] = 1; |
| 759 | 759 | } |
| 760 | - update_user_meta( $user_id, 'user_preferences', $newsletter_preferences); |
|
| 760 | + update_user_meta($user_id, 'user_preferences', $newsletter_preferences); |
|
| 761 | 761 | } else { |
| 762 | 762 | return $wpshop->errors; |
| 763 | 763 | } |
@@ -769,22 +769,22 @@ discard block |
||
| 769 | 769 | /** |
| 770 | 770 | * ACCOUNT - Save account informations |
| 771 | 771 | */ |
| 772 | - function wps_save_account_informations () { |
|
| 773 | - check_ajax_referer( 'wps_save_account_informations' ); |
|
| 772 | + function wps_save_account_informations() { |
|
| 773 | + check_ajax_referer('wps_save_account_informations'); |
|
| 774 | 774 | |
| 775 | 775 | global $wpdb; |
| 776 | 776 | $status = false; $response = ''; |
| 777 | 777 | |
| 778 | 778 | $user_id = get_current_user_id(); |
| 779 | - if ( !empty($user_id) ) { |
|
| 780 | - $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_author = %d", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id ); |
|
| 781 | - $cid = $wpdb->get_var( $query ); |
|
| 779 | + if (!empty($user_id)) { |
|
| 780 | + $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_author = %d", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, $user_id); |
|
| 781 | + $cid = $wpdb->get_var($query); |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | - $errors = $this->save_account_informations( $cid, $_POST ); |
|
| 785 | - if( !empty( $errors ) ) { |
|
| 786 | - $response = '<div class="wps-alert-error">' .__('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 787 | - foreach( $errors as $error ){ |
|
| 784 | + $errors = $this->save_account_informations($cid, $_POST); |
|
| 785 | + if (!empty($errors)) { |
|
| 786 | + $response = '<div class="wps-alert-error">' . __('Some errors have been detected', 'wpshop') . ' : <ul>'; |
|
| 787 | + foreach ($errors as $error) { |
|
| 788 | 788 | $response .= '<li>' . $error . '</li>'; |
| 789 | 789 | } |
| 790 | 790 | $response .= '</div>'; |
@@ -793,7 +793,7 @@ discard block |
||
| 793 | 793 | $status = true; |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | - wp_die( json_encode( array( 'status' => $status, 'response' => $response) ) ); |
|
| 796 | + wp_die(json_encode(array('status' => $status, 'response' => $response))); |
|
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | /** |
@@ -804,23 +804,23 @@ discard block |
||
| 804 | 804 | |
| 805 | 805 | $status = false; |
| 806 | 806 | $response = do_shortcode('[wps_account_informations]'); |
| 807 | - if( !empty($response) ) { |
|
| 807 | + if (!empty($response)) { |
|
| 808 | 808 | $status = true; |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | - wp_die( json_encode( array( 'status' => $status, 'response' => $response ) ) ); |
|
| 811 | + wp_die(json_encode(array('status' => $status, 'response' => $response))); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
| 815 | 815 | * ACCOUNT - AJAX - Fill account informations modal |
| 816 | 816 | */ |
| 817 | 817 | function wps_fill_account_informations_modal() { |
| 818 | - check_ajax_referer( 'wps_fill_account_informations_modal' ); |
|
| 818 | + check_ajax_referer('wps_fill_account_informations_modal'); |
|
| 819 | 819 | |
| 820 | 820 | $title = $content = ''; |
| 821 | 821 | $title = __('Edit your account informations', 'wpshop'); |
| 822 | - $content = do_shortcode( '[wps_account_informations_form]' ); |
|
| 823 | - echo json_encode( array( 'status' => true, 'title' => $title, 'content' => $content) ); |
|
| 822 | + $content = do_shortcode('[wps_account_informations_form]'); |
|
| 823 | + echo json_encode(array('status' => true, 'title' => $title, 'content' => $content)); |
|
| 824 | 824 | wp_die(); |
| 825 | 825 | } |
| 826 | 826 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_account_ctr { |
| 3 | 5 | /** Define the main directory containing the template for the current plugin |
| 4 | 6 | * @var string |
@@ -81,15 +83,13 @@ discard block |
||
| 81 | 83 | $args = array(); |
| 82 | 84 | if ( get_current_user_id() != 0 ) { |
| 83 | 85 | return __( 'You are already logged', 'wpshop'); |
| 84 | - } |
|
| 85 | - else { |
|
| 86 | + } else { |
|
| 86 | 87 | $action = !empty( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
| 87 | 88 | $key = !empty( $_GET['key'] ) ? sanitize_text_field( $_GET['key'] ) : ''; |
| 88 | 89 | $login = !empty( $_GET['login'] ) ? sanitize_text_field( $_GET['login'] ) : 0; |
| 89 | 90 | if ( !empty($action) && $action == 'retrieve_password' && !empty($key) && !empty($login) && !$force_login ) { |
| 90 | 91 | $output = self::get_renew_password_form(); |
| 91 | - } |
|
| 92 | - else { |
|
| 92 | + } else { |
|
| 93 | 93 | ob_start(); |
| 94 | 94 | require_once( wpshop_tools::get_template_part( WPS_ACCOUNT_DIR, $this->template_dir, "frontend", "login/login-form") ); |
| 95 | 95 | $output = ob_get_contents(); |
@@ -107,8 +107,9 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 109 | 109 | |
| 110 | - if ( !wp_verify_nonce( $_wpnonce, 'control_login_form_request' ) ) |
|
| 111 | - wp_die(); |
|
| 110 | + if ( !wp_verify_nonce( $_wpnonce, 'control_login_form_request' ) ) { |
|
| 111 | + wp_die(); |
|
| 112 | + } |
|
| 112 | 113 | |
| 113 | 114 | $result = ''; |
| 114 | 115 | $status = false; |
@@ -122,8 +123,7 @@ discard block |
||
| 122 | 123 | $user_checking = get_user_by( 'login', $wps_login_user_login ); |
| 123 | 124 | if( !empty($user_checking) ) { |
| 124 | 125 | $creds['user_login'] = $wps_login_user_login; |
| 125 | - } |
|
| 126 | - else { |
|
| 126 | + } else { |
|
| 127 | 127 | if ( is_email($wps_login_user_login) ) { |
| 128 | 128 | $user_checking = get_user_by( 'email', $wps_login_user_login ); |
| 129 | 129 | $creds['user_login'] = $user_checking->user_login; |
@@ -134,20 +134,17 @@ discard block |
||
| 134 | 134 | $user = wp_signon( $creds, false ); |
| 135 | 135 | if ( is_wp_error($user) ) { |
| 136 | 136 | $result = '<div class="wps-alert-error">' .__('Connexion error', 'wpshop'). '</div>'; |
| 137 | - } |
|
| 138 | - else { |
|
| 137 | + } else { |
|
| 139 | 138 | $permalink_option = get_option( 'permalink_structure' ); |
| 140 | 139 | $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ); |
| 141 | 140 | if( $origin == $page_account_id ) { |
| 142 | 141 | $result = get_permalink( $page_account_id ); |
| 143 | - } |
|
| 144 | - else { |
|
| 142 | + } else { |
|
| 145 | 143 | $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
| 146 | 144 | } |
| 147 | 145 | $status = true; |
| 148 | 146 | } |
| 149 | - } |
|
| 150 | - else { |
|
| 147 | + } else { |
|
| 151 | 148 | $result = '<div class="wps-alert-error">' .__('E-Mail and Password are required', 'wpshop'). '</div>'; |
| 152 | 149 | } |
| 153 | 150 | |
@@ -161,8 +158,9 @@ discard block |
||
| 161 | 158 | function wps_ajax_get_login_form_interface() { |
| 162 | 159 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 163 | 160 | |
| 164 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_ajax_get_login_form_interface' ) ) |
|
| 165 | - wp_die(); |
|
| 161 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_ajax_get_login_form_interface' ) ) { |
|
| 162 | + wp_die(); |
|
| 163 | + } |
|
| 166 | 164 | |
| 167 | 165 | $response = array( 'status' => true, 'response' => self::get_login_form() ); |
| 168 | 166 | echo json_encode( $response ); |
@@ -185,8 +183,9 @@ discard block |
||
| 185 | 183 | function wps_login_first_request() { |
| 186 | 184 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 187 | 185 | |
| 188 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_login_first_request' ) ) |
|
| 189 | - wp_die(); |
|
| 186 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_login_first_request' ) ) { |
|
| 187 | + wp_die(); |
|
| 188 | + } |
|
| 190 | 189 | |
| 191 | 190 | $status = false; $login_action = false; $response = ''; |
| 192 | 191 | $user_email = ( !empty($_POST['email_address']) ) ? wpshop_tools::varSanitizer( $_POST['email_address'] ) : null; |
@@ -198,8 +197,7 @@ discard block |
||
| 198 | 197 | $login_action = true; |
| 199 | 198 | $user_firstname = get_user_meta( $checking_user->ID, 'first_name', true ); |
| 200 | 199 | $response = $user_firstname; |
| 201 | - } |
|
| 202 | - else { |
|
| 200 | + } else { |
|
| 203 | 201 | $checking_user = get_user_by( 'email', $user_email); |
| 204 | 202 | if ( !empty( $checking_user ) ) { |
| 205 | 203 | $login_action = true; |
@@ -211,8 +209,7 @@ discard block |
||
| 211 | 209 | if( !$login_action && is_email($user_email) ) { |
| 212 | 210 | $response = $user_email; |
| 213 | 211 | } |
| 214 | - } |
|
| 215 | - else { |
|
| 212 | + } else { |
|
| 216 | 213 | $response = '<div class="wps-alert-error">' .__( 'An e-mail address is required', 'wpshop' ). '</div>'; |
| 217 | 214 | } |
| 218 | 215 | echo json_encode( array( 'status'=> $status, 'response' => $response, 'login_action' => $login_action) ); |
@@ -239,8 +236,9 @@ discard block |
||
| 239 | 236 | function wps_fill_forgot_password_modal() { |
| 240 | 237 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 241 | 238 | |
| 242 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_forgot_password_modal' ) ) |
|
| 243 | - wp_die(); |
|
| 239 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_fill_forgot_password_modal' ) ) { |
|
| 240 | + wp_die(); |
|
| 241 | + } |
|
| 244 | 242 | |
| 245 | 243 | $status = false; $title = $content = ''; |
| 246 | 244 | $title = __( 'Forgot password', 'wpshop' ); |
@@ -256,8 +254,9 @@ discard block |
||
| 256 | 254 | function wps_forgot_password_request() { |
| 257 | 255 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 258 | 256 | |
| 259 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_request' ) ) |
|
| 260 | - wp_die(); |
|
| 257 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_forgot_password_request' ) ) { |
|
| 258 | + wp_die(); |
|
| 259 | + } |
|
| 261 | 260 | |
| 262 | 261 | global $wpdb; |
| 263 | 262 | $status = false; $result = ''; |
@@ -268,8 +267,7 @@ discard block |
||
| 268 | 267 | $exist_user = get_user_by('login', $user_login); |
| 269 | 268 | if( !empty($exist_user) ) { |
| 270 | 269 | $existing_user = true; |
| 271 | - } |
|
| 272 | - else { |
|
| 270 | + } else { |
|
| 273 | 271 | $exist_user = get_user_by('email', $user_login); |
| 274 | 272 | $key_for_update = 'user_email'; |
| 275 | 273 | if ( !empty($exist_user) ) { |
@@ -286,12 +284,10 @@ discard block |
||
| 286 | 284 | $this->send_forgot_password_email($key, $user_login, $exist_user); |
| 287 | 285 | $result = '<div class="wps-alert-info">' .__('An e-mail with an password renew link has been sent to you', 'wpshop'). '</div>'; |
| 288 | 286 | $status = true; |
| 289 | - } |
|
| 290 | - else { |
|
| 287 | + } else { |
|
| 291 | 288 | $result = '<div class="wps-alert-error">' .__('No customer account corresponds to this email', 'wpshop'). '</div>'; |
| 292 | 289 | } |
| 293 | - } |
|
| 294 | - else { |
|
| 290 | + } else { |
|
| 295 | 291 | $result = '<div class="wps-alert-error">' .__('Please fill the required field', 'wpshop'). '</div>'; |
| 296 | 292 | } |
| 297 | 293 | $response = array( $status, $result ); |
@@ -336,8 +332,7 @@ discard block |
||
| 336 | 332 | $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $activation_key, $login ) ); |
| 337 | 333 | if( !empty($user) ) { |
| 338 | 334 | $existing_user = true; |
| 339 | - } |
|
| 340 | - else { |
|
| 335 | + } else { |
|
| 341 | 336 | $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_email = %s", $activation_key, $login ) ); |
| 342 | 337 | if( !empty($user) ) { |
| 343 | 338 | $existing_user = true; |
@@ -350,16 +345,13 @@ discard block |
||
| 350 | 345 | $status = true; |
| 351 | 346 | $result = '<div class="wps-alert-success">' .__('Your password has been updated', 'wpshop'). '. <a href="#" id="display_connexion_form"> ' .__('Connect you', 'wpshop').' !</a></div>'; |
| 352 | 347 | $form = self::get_login_form( true ); |
| 353 | - } |
|
| 354 | - else { |
|
| 348 | + } else { |
|
| 355 | 349 | $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
| 356 | 350 | } |
| 357 | - } |
|
| 358 | - else { |
|
| 351 | + } else { |
|
| 359 | 352 | $result = '<div class=" wps-alert-error">' .__('Invalid activation key', 'wpshop'). '</div>'; |
| 360 | 353 | } |
| 361 | - } |
|
| 362 | - else { |
|
| 354 | + } else { |
|
| 363 | 355 | $result = '<div class="wps-alert-error">' .__('Password and confirmation password are differents', 'wpshop'). '</div>'; |
| 364 | 356 | } |
| 365 | 357 | |
@@ -431,8 +423,9 @@ discard block |
||
| 431 | 423 | function wps_save_signup_form( $connect = false ) { |
| 432 | 424 | $_wpnonce = !empty( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : ''; |
| 433 | 425 | |
| 434 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_signup_form' ) ) |
|
| 435 | - wp_die(); |
|
| 426 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_save_signup_form' ) ) { |
|
| 427 | + wp_die(); |
|
| 428 | + } |
|
| 436 | 429 | |
| 437 | 430 | global $wpdb, $wpshop; |
| 438 | 431 | $user_id = ( !empty( $_POST['wps_sign_up_request_from_admin'] ) ) ? (int) $_POST['wps_sign_up_request_from_admin'] : get_current_user_id(); |
@@ -518,8 +511,7 @@ discard block |
||
| 518 | 511 | $permalink_option = get_option( 'permalink_structure' ); |
| 519 | 512 | $checkout_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' )); |
| 520 | 513 | $result = get_permalink( $checkout_page_id ).( ( !empty($permalink_option) ) ? '?' : '&').'order_step=3'; |
| 521 | - } |
|
| 522 | - else { |
|
| 514 | + } else { |
|
| 523 | 515 | $account_page_id = wpshop_tools::get_page_id( get_option( 'wpshop_myaccount_page_id' )); |
| 524 | 516 | $result = get_permalink( $account_page_id ); |
| 525 | 517 | } |
@@ -636,8 +628,7 @@ discard block |
||
| 636 | 628 | if ( $attribute_def->data_type_to_use == 'custom' ) { |
| 637 | 629 | $query = $wpdb->prepare("SELECT label FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE attribute_id = %d AND status = 'valid' AND id = %d", $attribute_def->id, $attribute_value ); |
| 638 | 630 | $attribute_value = $wpdb->get_var( $query ); |
| 639 | - } |
|
| 640 | - else if ( $attribute_def->data_type_to_use == 'internal') { |
|
| 631 | + } else if ( $attribute_def->data_type_to_use == 'internal') { |
|
| 641 | 632 | $associated_post = get_post( $atribute_value ); |
| 642 | 633 | $attribute_value = $associated_post->post_title; |
| 643 | 634 | } |
@@ -743,8 +734,7 @@ discard block |
||
| 743 | 734 | $attribute_def = wpshop_attributes::getElement( $attribute['name'], "'valid'", 'code'); |
| 744 | 735 | if ( !in_array( $attribute['name'], $exclude_user_meta ) ) { |
| 745 | 736 | update_user_meta( $user_id, $attribute['name'], wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ); |
| 746 | - } |
|
| 747 | - else { |
|
| 737 | + } else { |
|
| 748 | 738 | wp_update_user( array('ID' => $user_id, $attribute['name'] => wpshop_tools::varSanitizer( $args['attribute'][$attribute['data_type']][$attribute['name']]) ) ); |
| 749 | 739 | } |
| 750 | 740 | } |
@@ -788,8 +778,7 @@ discard block |
||
| 788 | 778 | $response .= '<li>' . $error . '</li>'; |
| 789 | 779 | } |
| 790 | 780 | $response .= '</div>'; |
| 791 | - } |
|
| 792 | - else { |
|
| 781 | + } else { |
|
| 793 | 782 | $status = true; |
| 794 | 783 | } |
| 795 | 784 | |
@@ -77,6 +77,12 @@ |
||
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | + /** |
|
| 81 | + * @param string $page_title |
|
| 82 | + * @param string $menu_title |
|
| 83 | + * @param string $menu_slug |
|
| 84 | + * @param string[] $callback |
|
| 85 | + */ |
|
| 80 | 86 | public function set_submenu_page_help( $page_title, $menu_title, $menu_slug, $callback ) { |
| 81 | 87 | $this->sub_menus[$menu_slug] = array( |
| 82 | 88 | 'page_title' => $page_title |
@@ -20,8 +20,8 @@ |
||
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Appelle le template dans wps_installer backend about / Call the template in wps_installer backend about |
|
| 24 | - */ |
|
| 23 | + * Appelle le template dans wps_installer backend about / Call the template in wps_installer backend about |
|
| 24 | + */ |
|
| 25 | 25 | public function render_menu() { |
| 26 | 26 | require_once( wpshop_tools::get_template_part( WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "about" ) ); |
| 27 | 27 | } |
@@ -1,20 +1,20 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_help_menus_ctr { |
| 3 | 3 | public $sub_menus; |
| 4 | 4 | |
| 5 | 5 | public function __construct() { |
| 6 | - $this->set_submenu_page_help( __( 'Shortcodes', 'wpshop' ), __( 'Shortcodes', 'wpshop' ), WPSHOP_URL_SLUG_SHORTCODES, array( 'wpshop_display', 'display_page' ) ); |
|
| 6 | + $this->set_submenu_page_help(__('Shortcodes', 'wpshop'), __('Shortcodes', 'wpshop'), WPSHOP_URL_SLUG_SHORTCODES, array('wpshop_display', 'display_page')); |
|
| 7 | 7 | |
| 8 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
| 9 | - add_action( 'menu_order', array( $this, 'admin_menu_order' ), 12 ); |
|
| 10 | - add_action( 'custom_menu_order', array( $this, 'admin_custom_menu_order' ) ); |
|
| 8 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
| 9 | + add_action('menu_order', array($this, 'admin_menu_order'), 12); |
|
| 10 | + add_action('custom_menu_order', array($this, 'admin_custom_menu_order')); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Ajout du menu pour le logiciel de caisse dans le backend / Create a new administration menu into backend |
| 15 | 15 | */ |
| 16 | 16 | public function admin_menu() { |
| 17 | - add_menu_page( __( 'Help', 'wpshop' ), __( 'Help', 'wpshop' ), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_ABOUT, array($this, 'render_menu'), 'dashicons-editor-help' ); |
|
| 17 | + add_menu_page(__('Help', 'wpshop'), __('Help', 'wpshop'), 'wpshop_view_dashboard', WPSHOP_URL_SLUG_ABOUT, array($this, 'render_menu'), 'dashicons-editor-help'); |
|
| 18 | 18 | |
| 19 | 19 | $this->create_submenu_page_help(); |
| 20 | 20 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * Appelle le template dans wps_installer backend about / Call the template in wps_installer backend about |
| 24 | 24 | */ |
| 25 | 25 | public function render_menu() { |
| 26 | - require_once( wpshop_tools::get_template_part( WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "about" ) ); |
|
| 26 | + require_once(wpshop_tools::get_template_part(WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "about")); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -33,19 +33,19 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return array The new admin menu order with the POS addon placed |
| 35 | 35 | */ |
| 36 | - public function admin_menu_order( $current_menu_order ) { |
|
| 36 | + public function admin_menu_order($current_menu_order) { |
|
| 37 | 37 | /** Create a new menu order */ |
| 38 | 38 | $wps_pos_menu_ordered = array(); |
| 39 | 39 | |
| 40 | 40 | /** Read the current existing menu order for rearrange it */ |
| 41 | - foreach ( $current_menu_order as $menu_item ) { |
|
| 42 | - if ( 'edit.php?post_type=wps_highlighting' == $menu_item ) { |
|
| 41 | + foreach ($current_menu_order as $menu_item) { |
|
| 42 | + if ('edit.php?post_type=wps_highlighting' == $menu_item) { |
|
| 43 | 43 | $wps_pos_menu_ordered[] = 'edit.php?post_type=wps_highlighting'; |
| 44 | 44 | $wps_pos_menu_ordered[] = WPSHOP_URL_SLUG_ABOUT; |
| 45 | 45 | |
| 46 | - unset( $current_menu_order[ array_search( WPSHOP_URL_SLUG_ABOUT, $current_menu_order ) ] ); |
|
| 46 | + unset($current_menu_order[array_search(WPSHOP_URL_SLUG_ABOUT, $current_menu_order)]); |
|
| 47 | 47 | } |
| 48 | - else if ( WPSHOP_URL_SLUG_ABOUT != $menu_item ) { |
|
| 48 | + else if (WPSHOP_URL_SLUG_ABOUT != $menu_item) { |
|
| 49 | 49 | $wps_pos_menu_ordered[] = $menu_item; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | * @return boolean A boolean var defining if we apply admin menu reorder for current user |
| 60 | 60 | */ |
| 61 | 61 | public function admin_custom_menu_order() { |
| 62 | - return current_user_can( 'manage_options' ); |
|
| 62 | + return current_user_can('manage_options'); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public function create_submenu_page_help() { |
| 66 | - if( is_array( $this->sub_menus ) ) { |
|
| 67 | - foreach ( $this->sub_menus as $slug => $data ) |
|
| 66 | + if (is_array($this->sub_menus)) { |
|
| 67 | + foreach ($this->sub_menus as $slug => $data) |
|
| 68 | 68 | { |
| 69 | 69 | add_submenu_page( |
| 70 | 70 | WPSHOP_URL_SLUG_ABOUT |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function set_submenu_page_help( $page_title, $menu_title, $menu_slug, $callback ) { |
|
| 80 | + public function set_submenu_page_help($page_title, $menu_title, $menu_slug, $callback) { |
|
| 81 | 81 | $this->sub_menus[$menu_slug] = array( |
| 82 | 82 | 'page_title' => $page_title |
| 83 | 83 | ,'menu_title' => $menu_title |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_help_menus_ctr { |
| 3 | 5 | public $sub_menus; |
| 4 | 6 | |
@@ -44,8 +46,7 @@ discard block |
||
| 44 | 46 | $wps_pos_menu_ordered[] = WPSHOP_URL_SLUG_ABOUT; |
| 45 | 47 | |
| 46 | 48 | unset( $current_menu_order[ array_search( WPSHOP_URL_SLUG_ABOUT, $current_menu_order ) ] ); |
| 47 | - } |
|
| 48 | - else if ( WPSHOP_URL_SLUG_ABOUT != $menu_item ) { |
|
| 49 | + } else if ( WPSHOP_URL_SLUG_ABOUT != $menu_item ) { |
|
| 49 | 50 | $wps_pos_menu_ordered[] = $menu_item; |
| 50 | 51 | } |
| 51 | 52 | } |
@@ -81,7 +81,7 @@ |
||
| 81 | 81 | * Save the current state of installation process |
| 82 | 82 | * |
| 83 | 83 | * @param string $setted_state A parameter setted for saving the state of installation ( in progress, completed, ignored ) |
| 84 | - * @param array $current_db_version The current value for database version option |
|
| 84 | + * @param string $current_db_version The current value for database version option |
|
| 85 | 85 | */ |
| 86 | 86 | function installer_state_saver( $setted_state, $current_db_version ) { |
| 87 | 87 | $current_db_version['installation_state'] = $setted_state; |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Module controller class definition file |
| 4 | 6 | * |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * Module controller class definition file |
| 4 | 4 | * |
@@ -28,34 +28,34 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @param integer $the_step_to_save The current step to save |
| 30 | 30 | */ |
| 31 | - function save_step( $the_step_to_save ) { |
|
| 31 | + function save_step($the_step_to_save) { |
|
| 32 | 32 | |
| 33 | - switch ( $the_step_to_save ) { |
|
| 33 | + switch ($the_step_to_save) { |
|
| 34 | 34 | case 1: |
| 35 | 35 | /** Save company informations */ |
| 36 | - $wpshop_company_info = !empty( $_POST['wpshop_company_info'] ) ? sanitize_text_field( $_POST['wpshop_company_info'] ) : ''; |
|
| 37 | - if ( !empty( $wpshop_company_info ) ) { |
|
| 38 | - update_option( 'wpshop_company_info', $wpshop_company_info ); |
|
| 36 | + $wpshop_company_info = !empty($_POST['wpshop_company_info']) ? sanitize_text_field($_POST['wpshop_company_info']) : ''; |
|
| 37 | + if (!empty($wpshop_company_info)) { |
|
| 38 | + update_option('wpshop_company_info', $wpshop_company_info); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** Save the company logo in case a file is sended */ |
| 42 | - $shop_logo = !empty( $_POST['wpshop_logo'] ) ? sanitize_text_field( $_POST['wpshop_logo'] ) : ''; |
|
| 43 | - if ( !empty( $shop_logo ) ) { |
|
| 44 | - update_option( 'wpshop_logo', $shop_logo ); |
|
| 42 | + $shop_logo = !empty($_POST['wpshop_logo']) ? sanitize_text_field($_POST['wpshop_logo']) : ''; |
|
| 43 | + if (!empty($shop_logo)) { |
|
| 44 | + update_option('wpshop_logo', $shop_logo); |
|
| 45 | 45 | } |
| 46 | 46 | break; |
| 47 | 47 | |
| 48 | 48 | case 2: |
| 49 | 49 | /** Save shop type */ |
| 50 | - $wpshop_shop_type = !empty( $_POST['wpshop_shop_type'] ) ? sanitize_text_field( $_POST[ 'wpshop_shop_type' ] ) : ''; |
|
| 51 | - if ( !empty( $wpshop_shop_type ) ) { |
|
| 52 | - update_option( 'wpshop_shop_type', $wpshop_shop_type ); |
|
| 50 | + $wpshop_shop_type = !empty($_POST['wpshop_shop_type']) ? sanitize_text_field($_POST['wpshop_shop_type']) : ''; |
|
| 51 | + if (!empty($wpshop_shop_type)) { |
|
| 52 | + update_option('wpshop_shop_type', $wpshop_shop_type); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** Save shop price piloting */ |
| 56 | - $wpshop_shop_price_piloting = !empty( $_POST[ 'wpshop_shop_price_piloting' ] ) ? sanitize_text_field( $_POST[ 'wpshop_shop_price_piloting' ] ) : ''; |
|
| 57 | - if ( !empty( $wpshop_shop_price_piloting ) ) { |
|
| 58 | - update_option( 'wpshop_shop_price_piloting', $wpshop_shop_price_piloting ); |
|
| 56 | + $wpshop_shop_price_piloting = !empty($_POST['wpshop_shop_price_piloting']) ? sanitize_text_field($_POST['wpshop_shop_price_piloting']) : ''; |
|
| 57 | + if (!empty($wpshop_shop_price_piloting)) { |
|
| 58 | + update_option('wpshop_shop_price_piloting', $wpshop_shop_price_piloting); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** Insert default pages */ |
@@ -63,21 +63,21 @@ discard block |
||
| 63 | 63 | //add_action( 'init', array( 'wps_message_ctr', 'create_default_message' ) ); |
| 64 | 64 | |
| 65 | 65 | /** In case the user want to insert default datas */ |
| 66 | - $wps_installer_data_insertion = !empty( $_POST[ 'wps-installer-data-insertion' ] ) ? sanitize_text_field( $_POST[ 'wps-installer-data-insertion' ] ) : ''; |
|
| 67 | - if ( !empty( $wps_installer_data_insertion ) && ( 'yes' == $wps_installer_data_insertion ) ) { |
|
| 66 | + $wps_installer_data_insertion = !empty($_POST['wps-installer-data-insertion']) ? sanitize_text_field($_POST['wps-installer-data-insertion']) : ''; |
|
| 67 | + if (!empty($wps_installer_data_insertion) && ('yes' == $wps_installer_data_insertion)) { |
|
| 68 | 68 | /** Insert sample datas */ |
| 69 | - add_action( 'init', array( 'wpshop_install', 'import_sample_datas' ) ); |
|
| 69 | + add_action('init', array('wpshop_install', 'import_sample_datas')); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $wps_current_db_version = get_option( 'wpshop_db_options', 0 ); |
|
| 73 | - $wps_current_db_version[ 'installation_state' ] = 'completed'; |
|
| 74 | - $wps_current_db_version[ 'installation_date' ] = current_time( 'mysql', 0 ); |
|
| 75 | - update_option( 'wpshop_db_options', $wps_current_db_version ); |
|
| 72 | + $wps_current_db_version = get_option('wpshop_db_options', 0); |
|
| 73 | + $wps_current_db_version['installation_state'] = 'completed'; |
|
| 74 | + $wps_current_db_version['installation_date'] = current_time('mysql', 0); |
|
| 75 | + update_option('wpshop_db_options', $wps_current_db_version); |
|
| 76 | 76 | break; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if ( !empty( $the_step_to_save ) ) { |
|
| 80 | - update_option( 'wps-installation-current-step', ( WPSINSTALLER_STEPS_COUNT != $the_step_to_save ? $the_step_to_save + 1 : WPSINSTALLER_STEPS_COUNT ) ); |
|
| 79 | + if (!empty($the_step_to_save)) { |
|
| 80 | + update_option('wps-installation-current-step', (WPSINSTALLER_STEPS_COUNT != $the_step_to_save ? $the_step_to_save + 1 : WPSINSTALLER_STEPS_COUNT)); |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
@@ -87,16 +87,16 @@ discard block |
||
| 87 | 87 | * @param string $setted_state A parameter setted for saving the state of installation ( in progress, completed, ignored ) |
| 88 | 88 | * @param array $current_db_version The current value for database version option |
| 89 | 89 | */ |
| 90 | - function installer_state_saver( $setted_state, $current_db_version ) { |
|
| 90 | + function installer_state_saver($setted_state, $current_db_version) { |
|
| 91 | 91 | $current_db_version['installation_state'] = $setted_state; |
| 92 | - $current_db_version[ 'installation_date' ] = current_time( 'mysql', 0 ); |
|
| 92 | + $current_db_version['installation_date'] = current_time('mysql', 0); |
|
| 93 | 93 | update_option('wpshop_db_options', $current_db_version); |
| 94 | 94 | |
| 95 | - if ( "ignored" == $current_db_version['installation_state'] ) { |
|
| 95 | + if ("ignored" == $current_db_version['installation_state']) { |
|
| 96 | 96 | /** Create the different pages */ |
| 97 | - if ( 2 >= get_option( 'wps-installation-current-step' ) ) { |
|
| 98 | - update_option( 'wpshop_shop_price_piloting', 'TTC' ); |
|
| 99 | - update_option( 'wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE ); |
|
| 97 | + if (2 >= get_option('wps-installation-current-step')) { |
|
| 98 | + update_option('wpshop_shop_price_piloting', 'TTC'); |
|
| 99 | + update_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); |
|
| 100 | 100 | |
| 101 | 101 | /** Insert default pages */ |
| 102 | 102 | //add_action( 'init', array( 'wpshop_install', 'wpshop_insert_default_pages' ) ); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** Save the crrent step to 4 in order to consider that installation is done */ |
| 108 | - update_option( 'wps-installation-current-step', WPSINSTALLER_STEPS_COUNT ); |
|
| 108 | + update_option('wps-installation-current-step', WPSINSTALLER_STEPS_COUNT); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | return $current_db_version; |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | /** |
| 71 | 71 | * Get product Complete Sheet |
| 72 | 72 | * @param integer $pid |
| 73 | - * @return Ambigous <string, string> |
|
| 73 | + * @return string <string, string> |
|
| 74 | 74 | */ |
| 75 | 75 | public static function get_product_complete_sheet_galery( $pid ) { |
| 76 | 76 | $output = ''; |
@@ -157,6 +157,9 @@ discard block |
||
| 157 | 157 | return $output; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | + /** |
|
| 161 | + * @param integer $product_id |
|
| 162 | + */ |
|
| 160 | 163 | public static function get_product_complete_sheet_attachments( $product_id ) { |
| 161 | 164 | $output = ''; |
| 162 | 165 | |
@@ -1,15 +1,15 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_media_manager_frontend_ctr { |
| 3 | 3 | |
| 4 | - public static function get_attachments( $pid, $type = 'gallery' ) { |
|
| 4 | + public static function get_attachments($pid, $type = 'gallery') { |
|
| 5 | 5 | $attachments = array(); |
| 6 | - $media_id_data = get_post_meta( $pid, '_wps_product_media', true ); |
|
| 7 | - if( !empty($media_id_data) ) { |
|
| 8 | - $media_id = explode( ',', $media_id_data ); |
|
| 9 | - foreach($media_id as $id) { |
|
| 10 | - if( ( ( wp_attachment_is_image( $id ) && $type == 'gallery' ) || ( !empty( $id ) && !wp_attachment_is_image( $id ) && $type == 'attachments' ) ) ) { |
|
| 11 | - $attachment_data = get_post( $id ); |
|
| 12 | - if( !empty( $attachment_data ) && !empty($attachment_data->ID) ) { |
|
| 6 | + $media_id_data = get_post_meta($pid, '_wps_product_media', true); |
|
| 7 | + if (!empty($media_id_data)) { |
|
| 8 | + $media_id = explode(',', $media_id_data); |
|
| 9 | + foreach ($media_id as $id) { |
|
| 10 | + if (((wp_attachment_is_image($id) && $type == 'gallery') || (!empty($id) && !wp_attachment_is_image($id) && $type == 'attachments'))) { |
|
| 11 | + $attachment_data = get_post($id); |
|
| 12 | + if (!empty($attachment_data) && !empty($attachment_data->ID)) { |
|
| 13 | 13 | $attachments[] = $attachment_data; |
| 14 | 14 | } |
| 15 | 15 | } |
@@ -26,13 +26,13 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return string The attachement gallery output |
| 28 | 28 | */ |
| 29 | - public static function display_attachment_gallery( $attachement_type, $content ) { |
|
| 29 | + public static function display_attachment_gallery($attachement_type, $content) { |
|
| 30 | 30 | $galery_output = ''; |
| 31 | 31 | |
| 32 | 32 | /* |
| 33 | 33 | * Get the template part for given galery type |
| 34 | 34 | */ |
| 35 | - switch ( $attachement_type ) { |
|
| 35 | + switch ($attachement_type) { |
|
| 36 | 36 | case 'picture': |
| 37 | 37 | $template_part = 'product_attachment_picture_galery'; |
| 38 | 38 | break; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * Build template |
| 53 | 53 | */ |
| 54 | 54 | $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
| 55 | - if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) { |
|
| 55 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 56 | 56 | /* Include the old way template part */ |
| 57 | 57 | ob_start(); |
| 58 | 58 | require(wpshop_display::get_template_file($tpl_way_to_take[1])); |
@@ -72,81 +72,81 @@ discard block |
||
| 72 | 72 | * @param integer $pid |
| 73 | 73 | * @return Ambigous <string, string> |
| 74 | 74 | */ |
| 75 | - public static function get_product_complete_sheet_galery( $pid ) { |
|
| 75 | + public static function get_product_complete_sheet_galery($pid) { |
|
| 76 | 76 | $output = ''; |
| 77 | - if( !empty($pid) ) { |
|
| 77 | + if (!empty($pid)) { |
|
| 78 | 78 | $tpl_component = $sub_tpl_component = array(); |
| 79 | 79 | $attachments = array(); |
| 80 | 80 | $tpl_component['THUMBNAILS'] = ''; |
| 81 | 81 | $tpl_component['SLIDER_CONTENT'] = ''; |
| 82 | 82 | |
| 83 | 83 | /** Check and get the product thumbnail */ |
| 84 | - $principal_thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true); |
|
| 85 | - if( !empty($principal_thumbnail_id) ) { |
|
| 86 | - $attachments[0] = get_post( $principal_thumbnail_id ); |
|
| 84 | + $principal_thumbnail_id = get_post_meta($pid, '_thumbnail_id', true); |
|
| 85 | + if (!empty($principal_thumbnail_id)) { |
|
| 86 | + $attachments[0] = get_post($principal_thumbnail_id); |
|
| 87 | 87 | } |
| 88 | 88 | else { |
| 89 | 89 | $sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL'] = ''; |
| 90 | - $sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
|
| 91 | - $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
|
| 90 | + $sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />'; |
|
| 91 | + $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />'; |
|
| 92 | 92 | $sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL_ID'] = ''; |
| 93 | 93 | |
| 94 | - $tpl_component[ 'SLIDER_CONTENT' ] .= wpshop_display::display_template_element( 'wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component ); |
|
| 95 | - $tpl_component[ 'THUMBNAILS' ] = ''; |
|
| 94 | + $tpl_component['SLIDER_CONTENT'] .= wpshop_display::display_template_element('wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component); |
|
| 95 | + $tpl_component['THUMBNAILS'] = ''; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** Get product associated pictures */ |
| 99 | 99 | $allowed_mime_type = get_allowed_mime_types(); |
| 100 | 100 | |
| 101 | - $attachments = array_merge( $attachments, (array)self::get_attachments( $pid ) ); |
|
| 101 | + $attachments = array_merge($attachments, (array)self::get_attachments($pid)); |
|
| 102 | 102 | |
| 103 | 103 | /** In case there are picture read and display them into product sheet */ |
| 104 | - if ( !empty($attachments) ) { |
|
| 105 | - foreach( $attachments as $attachment) { |
|
| 106 | - if( !empty($attachment) && !empty($attachment->post_mime_type) && in_array( $attachment->post_mime_type, $allowed_mime_type ) ) { |
|
| 104 | + if (!empty($attachments)) { |
|
| 105 | + foreach ($attachments as $attachment) { |
|
| 106 | + if (!empty($attachment) && !empty($attachment->post_mime_type) && in_array($attachment->post_mime_type, $allowed_mime_type)) { |
|
| 107 | 107 | //IMAGE SLIDER |
| 108 | - $image_attributes = wp_get_attachment_metadata( $attachment->ID ); |
|
| 108 | + $image_attributes = wp_get_attachment_metadata($attachment->ID); |
|
| 109 | 109 | $sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL'] = ''; |
| 110 | 110 | $sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL_ID'] = $attachment->ID; |
| 111 | - if ( !empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes']) ) { |
|
| 112 | - foreach ( $image_attributes['sizes'] as $size_name => $size_def) { |
|
| 113 | - $p = wp_get_attachment_image( $attachment->ID, $size_name); |
|
| 114 | - $src = wp_get_attachment_image_src( $attachment->ID, $size_name ); |
|
| 111 | + if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 112 | + foreach ($image_attributes['sizes'] as $size_name => $size_def) { |
|
| 113 | + $p = wp_get_attachment_image($attachment->ID, $size_name); |
|
| 114 | + $src = wp_get_attachment_image_src($attachment->ID, $size_name); |
|
| 115 | 115 | $sub_tpl_component['THUMBNAIL_GALLERY_' . strtoupper($size_name)] = ''; |
| 116 | 116 | $sub_tpl_component['IMAGE_SLIDER_' . strtoupper($size_name)] = ''; |
| 117 | - if( !empty($p) ) { |
|
| 118 | - $sub_tpl_component['SRC_IMAGE_SLIDER_' . strtoupper($size_name)] = ( !empty($src) ) ? $src[0] : ''; |
|
| 119 | - $sub_tpl_component['IMAGE_SLIDER_' . strtoupper($size_name)] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
|
| 120 | - $sub_tpl_component['THUMBNAIL_GALLERY_' . strtoupper($size_name)] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
|
| 117 | + if (!empty($p)) { |
|
| 118 | + $sub_tpl_component['SRC_IMAGE_SLIDER_' . strtoupper($size_name)] = (!empty($src)) ? $src[0] : ''; |
|
| 119 | + $sub_tpl_component['IMAGE_SLIDER_' . strtoupper($size_name)] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />'; |
|
| 120 | + $sub_tpl_component['THUMBNAIL_GALLERY_' . strtoupper($size_name)] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />'; |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | - $p = wp_get_attachment_image( $attachment->ID, 'full'); |
|
| 124 | - $src = wp_get_attachment_image_src( $attachment->ID, 'full' ); |
|
| 125 | - if( !empty($p) ) { |
|
| 126 | - $sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ( !empty($src) ) ? $src[0] : ''; |
|
| 127 | - $sub_tpl_component['IMAGE_SLIDER_FULL'] = ( !empty($p) ) ? $p : ''; |
|
| 128 | - $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = ( !empty($p) ) ? $p : ''; |
|
| 123 | + $p = wp_get_attachment_image($attachment->ID, 'full'); |
|
| 124 | + $src = wp_get_attachment_image_src($attachment->ID, 'full'); |
|
| 125 | + if (!empty($p)) { |
|
| 126 | + $sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = (!empty($src)) ? $src[0] : ''; |
|
| 127 | + $sub_tpl_component['IMAGE_SLIDER_FULL'] = (!empty($p)) ? $p : ''; |
|
| 128 | + $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = (!empty($p)) ? $p : ''; |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | else { |
| 132 | - $p = wp_get_attachment_image( $attachment->ID, 'full' ); |
|
| 133 | - $src = wp_get_attachment_image_src( $attachment->ID, 'full' ); |
|
| 134 | - $sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ( !empty($src) ) ? $src[0] : ''; |
|
| 135 | - $sub_tpl_component['IMAGE_SLIDER_FULL'] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
|
| 136 | - $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = ( !empty( $p ) ) ? $p : '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
|
| 132 | + $p = wp_get_attachment_image($attachment->ID, 'full'); |
|
| 133 | + $src = wp_get_attachment_image_src($attachment->ID, 'full'); |
|
| 134 | + $sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = (!empty($src)) ? $src[0] : ''; |
|
| 135 | + $sub_tpl_component['IMAGE_SLIDER_FULL'] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />'; |
|
| 136 | + $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = (!empty($p)) ? $p : '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />'; |
|
| 137 | 137 | } |
| 138 | - if ( !empty( $sub_tpl_component['IMAGE_SLIDER_FULL'] ) ) { |
|
| 139 | - $tpl_component[ 'SLIDER_CONTENT' ] .= wpshop_display::display_template_element( 'wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component ); |
|
| 140 | - if ( ( 1 < count( $attachments ) ) || ( ( 1 == count( $attachments ) ) && empty( $principal_thumbnail_id ) ) ) { |
|
| 141 | - $tpl_component[ 'THUMBNAILS' ] .= wpshop_display::display_template_element( 'wps_product_complete_sheet_gallery_thumbnail_element', $sub_tpl_component ); |
|
| 138 | + if (!empty($sub_tpl_component['IMAGE_SLIDER_FULL'])) { |
|
| 139 | + $tpl_component['SLIDER_CONTENT'] .= wpshop_display::display_template_element('wps_product_complete_sheet_gallery_slider_element', $sub_tpl_component); |
|
| 140 | + if ((1 < count($attachments)) || ((1 == count($attachments)) && empty($principal_thumbnail_id))) { |
|
| 141 | + $tpl_component['THUMBNAILS'] .= wpshop_display::display_template_element('wps_product_complete_sheet_gallery_thumbnail_element', $sub_tpl_component); |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | - unset( $sub_tpl_component ); |
|
| 144 | + unset($sub_tpl_component); |
|
| 145 | 145 | } |
| 146 | 146 | else { |
| 147 | 147 | $sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ''; |
| 148 | - $sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
|
| 149 | - $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
|
| 148 | + $sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />'; |
|
| 149 | + $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' . WPSHOP_DEFAULT_PRODUCT_PICTURE . '" alt="" />'; |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -157,35 +157,35 @@ discard block |
||
| 157 | 157 | return $output; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public static function get_product_complete_sheet_attachments( $product_id ) { |
|
| 160 | + public static function get_product_complete_sheet_attachments($product_id) { |
|
| 161 | 161 | $output = ''; |
| 162 | 162 | |
| 163 | 163 | /** Get attachement file for the current product */ |
| 164 | 164 | $product_picture_galery_content = $product_document_galery_content = ''; |
| 165 | 165 | $picture_number = $document_number = $index_li = 0; |
| 166 | 166 | |
| 167 | - $attachments = self::get_attachments( $product_id, 'attachments' ); |
|
| 167 | + $attachments = self::get_attachments($product_id, 'attachments'); |
|
| 168 | 168 | |
| 169 | - if ( is_array($attachments) && (count($attachments) > 0) ) { |
|
| 169 | + if (is_array($attachments) && (count($attachments) > 0)) { |
|
| 170 | 170 | $picture_increment = $document_increment = 1; |
| 171 | 171 | foreach ($attachments as $attachment) { |
| 172 | 172 | $tpl_component = array(); |
| 173 | - $attachment_url = wp_get_attachment_url( $attachment->ID ); |
|
| 173 | + $attachment_url = wp_get_attachment_url($attachment->ID); |
|
| 174 | 174 | $attachment_extension = explode('.', $attachment_url); |
| 175 | 175 | $attachment_extension = $attachment_extension[1]; |
| 176 | 176 | $tpl_component['ATTACHMENT_ITEM_GUID'] = $attachment_url; |
| 177 | 177 | $tpl_component['ATTACHMENT_ITEM_TITLE'] = $attachment->post_title; |
| 178 | 178 | $tpl_component['ATTACHMENT_ITEM_EXTENSION'] = $attachment_extension; |
| 179 | - if(is_int(strpos($attachment->post_mime_type, 'application/')) || is_int(strpos($attachment->post_mime_type, 'text/'))) { |
|
| 179 | + if (is_int(strpos($attachment->post_mime_type, 'application/')) || is_int(strpos($attachment->post_mime_type, 'text/'))) { |
|
| 180 | 180 | $tpl_component['ATTACHMENT_ITEM_TYPE'] = 'document'; |
| 181 | - $tpl_component['ATTACHMENT_ITEM_SPECIFIC_CLASS'] = (!($document_increment%WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE)) ? 'wpshop_gallery_document_last' : ''; |
|
| 181 | + $tpl_component['ATTACHMENT_ITEM_SPECIFIC_CLASS'] = (!($document_increment % WPSHOP_DISPLAY_GALLERY_ELEMENT_NUMBER_PER_LINE)) ? 'wpshop_gallery_document_last' : ''; |
|
| 182 | 182 | /** Template parameters */ |
| 183 | 183 | $template_part = 'product_attachment_item_document'; |
| 184 | 184 | $tpl_component['PRODUCT_ID'] = $product_id; |
| 185 | 185 | |
| 186 | 186 | /** Build template */ |
| 187 | 187 | $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
| 188 | - if ( $tpl_way_to_take[0] && !empty($tpl_way_to_take[1]) ) { |
|
| 188 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 189 | 189 | /* Include the old way template part */ |
| 190 | 190 | |
| 191 | 191 | ob_start(); |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | ob_start(); |
| 207 | - require( wpshop_tools::get_template_part( WPS_MEDIA_MANAGER_DIR, WPS_MEDIA_MANAGER_TEMPLATE_DIR, 'frontend', 'associated', 'document' ) ); |
|
| 207 | + require(wpshop_tools::get_template_part(WPS_MEDIA_MANAGER_DIR, WPS_MEDIA_MANAGER_TEMPLATE_DIR, 'frontend', 'associated', 'document')); |
|
| 208 | 208 | $output = ob_get_contents(); |
| 209 | 209 | ob_end_clean(); |
| 210 | 210 | } |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_media_manager_frontend_ctr { |
| 3 | 5 | |
| 4 | 6 | public static function get_attachments( $pid, $type = 'gallery' ) { |
@@ -58,8 +60,7 @@ discard block |
||
| 58 | 60 | require(wpshop_display::get_template_file($tpl_way_to_take[1])); |
| 59 | 61 | $galery_output = ob_get_contents(); |
| 60 | 62 | ob_end_clean(); |
| 61 | - } |
|
| 62 | - else { |
|
| 63 | + } else { |
|
| 63 | 64 | $galery_output = wpshop_display::display_template_element($template_part, $tpl_component); |
| 64 | 65 | } |
| 65 | 66 | unset($tpl_component); |
@@ -84,8 +85,7 @@ discard block |
||
| 84 | 85 | $principal_thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true); |
| 85 | 86 | if( !empty($principal_thumbnail_id) ) { |
| 86 | 87 | $attachments[0] = get_post( $principal_thumbnail_id ); |
| 87 | - } |
|
| 88 | - else { |
|
| 88 | + } else { |
|
| 89 | 89 | $sub_tpl_component['THUMBNAIL_GALLERY_THUMBNAIL'] = ''; |
| 90 | 90 | $sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
| 91 | 91 | $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
@@ -127,8 +127,7 @@ discard block |
||
| 127 | 127 | $sub_tpl_component['IMAGE_SLIDER_FULL'] = ( !empty($p) ) ? $p : ''; |
| 128 | 128 | $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = ( !empty($p) ) ? $p : ''; |
| 129 | 129 | } |
| 130 | - } |
|
| 131 | - else { |
|
| 130 | + } else { |
|
| 132 | 131 | $p = wp_get_attachment_image( $attachment->ID, 'full' ); |
| 133 | 132 | $src = wp_get_attachment_image_src( $attachment->ID, 'full' ); |
| 134 | 133 | $sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ( !empty($src) ) ? $src[0] : ''; |
@@ -142,8 +141,7 @@ discard block |
||
| 142 | 141 | } |
| 143 | 142 | } |
| 144 | 143 | unset( $sub_tpl_component ); |
| 145 | - } |
|
| 146 | - else { |
|
| 144 | + } else { |
|
| 147 | 145 | $sub_tpl_component['SRC_IMAGE_SLIDER_FULL'] = ''; |
| 148 | 146 | $sub_tpl_component['IMAGE_SLIDER_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
| 149 | 147 | $sub_tpl_component['THUMBNAIL_GALLERY_FULL'] = '<img src="' .WPSHOP_DEFAULT_PRODUCT_PICTURE. '" alt="" />'; |
@@ -192,8 +190,7 @@ discard block |
||
| 192 | 190 | require(wpshop_display::get_template_file($tpl_way_to_take[1])); |
| 193 | 191 | $product_document_galery_content .= ob_get_contents(); |
| 194 | 192 | ob_end_clean(); |
| 195 | - } |
|
| 196 | - else { |
|
| 193 | + } else { |
|
| 197 | 194 | $product_document_galery_content .= wpshop_display::display_template_element($template_part, $tpl_component); |
| 198 | 195 | } |
| 199 | 196 | |
@@ -30,7 +30,6 @@ |
||
| 30 | 30 | * of the number of corrected product and the template of the method : ajax_checking_products_values if inconsistent product |
| 31 | 31 | * already present. |
| 32 | 32 | * |
| 33 | - * @param array $_POST['product_price'] List of the new price for the product like array( $id_product => $new_price ) |
|
| 34 | 33 | * @return JSON Response |
| 35 | 34 | */ |
| 36 | 35 | public function ajax_save_product_price() { |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_product_ajax_ctr_01 { |
| 3 | 3 | public function __construct() { |
| 4 | - add_action( 'wp_ajax_checking_products_values', array( &$this, 'ajax_render_inconsistent_product_price' ) ); |
|
| 5 | - add_action( 'wp_ajax_save_products_prices', array( &$this, 'ajax_save_product_price' ) ); |
|
| 4 | + add_action('wp_ajax_checking_products_values', array(&$this, 'ajax_render_inconsistent_product_price')); |
|
| 5 | + add_action('wp_ajax_save_products_prices', array(&$this, 'ajax_save_product_price')); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -12,16 +12,16 @@ discard block |
||
| 12 | 12 | * list. Then display the template product_check_data |
| 13 | 13 | */ |
| 14 | 14 | public function ajax_render_inconsistent_product_price() { |
| 15 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 15 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 16 | 16 | |
| 17 | - if ( !wp_verify_nonce( $_wpnonce, 'ajax_render_inconsistent_product_price' ) ) |
|
| 17 | + if (!wp_verify_nonce($_wpnonce, 'ajax_render_inconsistent_product_price')) |
|
| 18 | 18 | wp_die(); |
| 19 | 19 | |
| 20 | 20 | $list_product = wps_product_ctr::get_inconsistent_product(); |
| 21 | 21 | |
| 22 | 22 | $inconsistent_product_number = count($list_product); |
| 23 | 23 | |
| 24 | - require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data") ); |
|
| 24 | + require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data")); |
|
| 25 | 25 | wp_die(); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -39,39 +39,39 @@ discard block |
||
| 39 | 39 | * @return JSON Response |
| 40 | 40 | */ |
| 41 | 41 | public function ajax_save_product_price() { |
| 42 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 42 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 43 | 43 | |
| 44 | - if ( !wp_verify_nonce( $_wpnonce, 'ajax_save_product_price' ) ) |
|
| 44 | + if (!wp_verify_nonce($_wpnonce, 'ajax_save_product_price')) |
|
| 45 | 45 | wp_die(); |
| 46 | 46 | |
| 47 | - header( 'Content-Type: application/json' ); |
|
| 47 | + header('Content-Type: application/json'); |
|
| 48 | 48 | $response = array(); |
| 49 | 49 | |
| 50 | - $price_piloting_option = get_option( 'wpshop_shop_price_piloting' ); |
|
| 50 | + $price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 51 | 51 | |
| 52 | - $inconsistent_product_number = !empty( $_POST['product_price'] ) ? (int) count( $_POST['product_price'] ) : 0; |
|
| 53 | - $consistent_product_number = 0; |
|
| 52 | + $inconsistent_product_number = !empty($_POST['product_price']) ? (int)count($_POST['product_price']) : 0; |
|
| 53 | + $consistent_product_number = 0; |
|
| 54 | 54 | |
| 55 | - $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 56 | - $language = WPSHOP_CURRENT_LOCALE; |
|
| 57 | - $icl_language = !empty( $_REQUEST['icl_post_language'] ) ? sanitize_text_field( $_REQUEST['icl_post_language'] ) : ''; |
|
| 55 | + $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 56 | + $language = WPSHOP_CURRENT_LOCALE; |
|
| 57 | + $icl_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : ''; |
|
| 58 | 58 | |
| 59 | - if ( !empty($icl_language) ) { |
|
| 60 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_language ); |
|
| 59 | + if (!empty($icl_language)) { |
|
| 60 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_language); |
|
| 61 | 61 | $language = $wpdb->get_var($query); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $product_price = !empty( $_POST['product_price'] ) ? (array) $_POST['product_price'] : array(); |
|
| 64 | + $product_price = !empty($_POST['product_price']) ? (array)$_POST['product_price'] : array(); |
|
| 65 | 65 | |
| 66 | - if( !empty( $product_price ) ) { |
|
| 67 | - foreach( $product_price as $product_id => $price ) { |
|
| 66 | + if (!empty($product_price)) { |
|
| 67 | + foreach ($product_price as $product_id => $price) { |
|
| 68 | 68 | try { |
| 69 | - if( $price_piloting_option == 'TTC' ) |
|
| 70 | - wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'product_price' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_products' ); |
|
| 69 | + if ($price_piloting_option == 'TTC') |
|
| 70 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => sanitize_text_field($price))), $entity_type_id, (int)$product_id, $language, 'wpshop_products'); |
|
| 71 | 71 | else |
| 72 | - wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'price_ht' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_product' ); |
|
| 72 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => sanitize_text_field($price))), $entity_type_id, (int)$product_id, $language, 'wpshop_product'); |
|
| 73 | 73 | |
| 74 | - wpshop_products::calculate_price( $product_id ); |
|
| 74 | + wpshop_products::calculate_price($product_id); |
|
| 75 | 75 | $consistent_product_number++; |
| 76 | 76 | |
| 77 | 77 | } catch (Exception $e) { |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - $response['template_number'] = __( sprintf( 'Number of processed product : %d/%d', $consistent_product_number, $inconsistent_product_number ), 'wps-product' ); |
|
| 82 | + $response['template_number'] = __(sprintf('Number of processed product : %d/%d', $consistent_product_number, $inconsistent_product_number), 'wps-product'); |
|
| 83 | 83 | |
| 84 | 84 | $list_product = wps_product_ctr::get_inconsistent_product(); |
| 85 | 85 | ob_start(); |
| 86 | - require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data") ); |
|
| 86 | + require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "backend", "product_check_data")); |
|
| 87 | 87 | $response['template'] = ob_get_clean(); |
| 88 | 88 | |
| 89 | - wp_die( json_encode( $response ) ); |
|
| 89 | + wp_die(json_encode($response)); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_product_ajax_ctr_01 { |
| 3 | 5 | public function __construct() { |
| 4 | 6 | add_action( 'wp_ajax_checking_products_values', array( &$this, 'ajax_render_inconsistent_product_price' ) ); |
@@ -14,8 +16,9 @@ discard block |
||
| 14 | 16 | public function ajax_render_inconsistent_product_price() { |
| 15 | 17 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 16 | 18 | |
| 17 | - if ( !wp_verify_nonce( $_wpnonce, 'ajax_render_inconsistent_product_price' ) ) |
|
| 18 | - wp_die(); |
|
| 19 | + if ( !wp_verify_nonce( $_wpnonce, 'ajax_render_inconsistent_product_price' ) ) { |
|
| 20 | + wp_die(); |
|
| 21 | + } |
|
| 19 | 22 | |
| 20 | 23 | $list_product = wps_product_ctr::get_inconsistent_product(); |
| 21 | 24 | |
@@ -41,8 +44,9 @@ discard block |
||
| 41 | 44 | public function ajax_save_product_price() { |
| 42 | 45 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 43 | 46 | |
| 44 | - if ( !wp_verify_nonce( $_wpnonce, 'ajax_save_product_price' ) ) |
|
| 45 | - wp_die(); |
|
| 47 | + if ( !wp_verify_nonce( $_wpnonce, 'ajax_save_product_price' ) ) { |
|
| 48 | + wp_die(); |
|
| 49 | + } |
|
| 46 | 50 | |
| 47 | 51 | header( 'Content-Type: application/json' ); |
| 48 | 52 | $response = array(); |
@@ -66,10 +70,11 @@ discard block |
||
| 66 | 70 | if( !empty( $product_price ) ) { |
| 67 | 71 | foreach( $product_price as $product_id => $price ) { |
| 68 | 72 | try { |
| 69 | - if( $price_piloting_option == 'TTC' ) |
|
| 70 | - wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'product_price' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_products' ); |
|
| 71 | - else |
|
| 72 | - wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'price_ht' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_product' ); |
|
| 73 | + if( $price_piloting_option == 'TTC' ) { |
|
| 74 | + wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'product_price' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_products' ); |
|
| 75 | + } else { |
|
| 76 | + wpshop_attributes::saveAttributeForEntity( array( 'decimal' => array( 'price_ht' => sanitize_text_field( $price ) )), $entity_type_id, (int)$product_id, $language, 'wpshop_product' ); |
|
| 77 | + } |
|
| 73 | 78 | |
| 74 | 79 | wpshop_products::calculate_price( $product_id ); |
| 75 | 80 | $consistent_product_number++; |
@@ -257,8 +257,6 @@ |
||
| 257 | 257 | * |
| 258 | 258 | * @param int $product_id L'id du produit |
| 259 | 259 | * @param string $type Peut être varchar, integer, text, options, decimal, datetime |
| 260 | - * @param string $attribute_name Le code d'un attribut |
|
| 261 | - * @param string $attribute_value La valeur à mêttre à jour |
|
| 262 | 260 | */ |
| 263 | 261 | public function update_the_attribute_for_product($product_id, $type, $name_attribute, $value_attribute) { |
| 264 | 262 | global $wpdb; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_product_ctr { |
| 3 | 3 | |
| 4 | 4 | /** |
@@ -8,19 +8,19 @@ discard block |
||
| 8 | 8 | * @return void |
| 9 | 9 | */ |
| 10 | 10 | function __construct() { |
| 11 | - add_action( 'admin_enqueue_scripts', array( &$this, 'callback_admin_enqueue_scripts' ) ); |
|
| 11 | + add_action('admin_enqueue_scripts', array(&$this, 'callback_admin_enqueue_scripts')); |
|
| 12 | 12 | |
| 13 | - add_shortcode( 'wps_product_caracteristics', array( $this, 'display_product_caracteristics_tab' ) ); |
|
| 14 | - add_shortcode( 'wpshop_product_caracteristics', array( $this, 'display_product_caracteristics_tab' ) ); |
|
| 15 | - add_shortcode( 'wps_product_discount_chip', array( $this, 'display_discount_chip' ) ); |
|
| 16 | - add_shortcode( 'wpshop_product_discount_chip', array( $this, 'display_discount_chip' ) ); |
|
| 13 | + add_shortcode('wps_product_caracteristics', array($this, 'display_product_caracteristics_tab')); |
|
| 14 | + add_shortcode('wpshop_product_caracteristics', array($this, 'display_product_caracteristics_tab')); |
|
| 15 | + add_shortcode('wps_product_discount_chip', array($this, 'display_discount_chip')); |
|
| 16 | + add_shortcode('wpshop_product_discount_chip', array($this, 'display_discount_chip')); |
|
| 17 | 17 | |
| 18 | - add_shortcode( 'wpshop_product_title', array( $this, 'wpshop_product_title' ) ); |
|
| 19 | - add_shortcode( 'wpshop_product_content', array( $this, 'wpshop_product_content' ) ); |
|
| 20 | - add_shortcode( 'wpshop_product_thumbnail', array( $this, 'wpshop_product_thumbnail' ) ); |
|
| 18 | + add_shortcode('wpshop_product_title', array($this, 'wpshop_product_title')); |
|
| 19 | + add_shortcode('wpshop_product_content', array($this, 'wpshop_product_content')); |
|
| 20 | + add_shortcode('wpshop_product_thumbnail', array($this, 'wpshop_product_thumbnail')); |
|
| 21 | 21 | |
| 22 | 22 | /** Product sheet Page **/ |
| 23 | - add_action( 'admin_post_wps_product_sheet', array( $this, 'wpshop_product_sheet_output' ) ); |
|
| 23 | + add_action('admin_post_wps_product_sheet', array($this, 'wpshop_product_sheet_output')); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -31,25 +31,25 @@ discard block |
||
| 31 | 31 | $module_folder = WPS_PRODUCT_PATH . '/modules/'; |
| 32 | 32 | |
| 33 | 33 | /** Check if the defined directory exists for reading and including the different modules */ |
| 34 | - if( is_dir( $module_folder ) ) { |
|
| 35 | - $parent_folder_content = scandir( $module_folder ); |
|
| 36 | - foreach ( $parent_folder_content as $folder ) { |
|
| 37 | - if ( $folder && substr( $folder, 0, 1) != '.' && is_dir( $module_folder . $folder ) ) { |
|
| 38 | - $child_folder_content = scandir( $module_folder . $folder ); |
|
| 39 | - if ( file_exists( $module_folder . $folder . '/' . $folder . '.php') ) { |
|
| 40 | - $f = $module_folder . $folder . '/' . $folder . '.php'; |
|
| 41 | - include( $f ); |
|
| 34 | + if (is_dir($module_folder)) { |
|
| 35 | + $parent_folder_content = scandir($module_folder); |
|
| 36 | + foreach ($parent_folder_content as $folder) { |
|
| 37 | + if ($folder && substr($folder, 0, 1) != '.' && is_dir($module_folder . $folder)) { |
|
| 38 | + $child_folder_content = scandir($module_folder . $folder); |
|
| 39 | + if (file_exists($module_folder . $folder . '/' . $folder . '.php')) { |
|
| 40 | + $f = $module_folder . $folder . '/' . $folder . '.php'; |
|
| 41 | + include($f); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function callback_admin_enqueue_scripts( $hook ) { |
|
| 49 | - if( $hook != 'tools_page_wpshop_tools' ) |
|
| 48 | + public function callback_admin_enqueue_scripts($hook) { |
|
| 49 | + if ($hook != 'tools_page_wpshop_tools') |
|
| 50 | 50 | return; |
| 51 | 51 | |
| 52 | - wp_enqueue_script( 'wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array( "jquery", "jquery-form" ), WPS_PRODUCT_VERSION ); |
|
| 52 | + wp_enqueue_script('wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array("jquery", "jquery-form"), WPS_PRODUCT_VERSION); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -57,14 +57,14 @@ discard block |
||
| 57 | 57 | * @param array $args |
| 58 | 58 | * @return string |
| 59 | 59 | */ |
| 60 | - function display_product_caracteristics_tab( $args ) { |
|
| 60 | + function display_product_caracteristics_tab($args) { |
|
| 61 | 61 | $output = ''; |
| 62 | - if( !empty($args) && !empty($args['pid']) ) { |
|
| 62 | + if (!empty($args) && !empty($args['pid'])) { |
|
| 63 | 63 | $wps_product_mdl = new wps_product_mdl(); |
| 64 | - $product_atts_def = $wps_product_mdl->get_product_atts_def( $args['pid'] ); |
|
| 65 | - if( !empty($product_atts_def) ) { |
|
| 64 | + $product_atts_def = $wps_product_mdl->get_product_atts_def($args['pid']); |
|
| 65 | + if (!empty($product_atts_def)) { |
|
| 66 | 66 | ob_start(); |
| 67 | - require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_caracteristics_tab") ); |
|
| 67 | + require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_caracteristics_tab")); |
|
| 68 | 68 | $output = ob_get_contents(); |
| 69 | 69 | ob_end_clean(); |
| 70 | 70 | } |
@@ -77,14 +77,14 @@ discard block |
||
| 77 | 77 | * @param array $args |
| 78 | 78 | * @return string |
| 79 | 79 | */ |
| 80 | - function display_discount_chip( $args ) { |
|
| 80 | + function display_discount_chip($args) { |
|
| 81 | 81 | $output = ''; |
| 82 | - if( !empty($args) && !empty($args['pid']) ) { |
|
| 82 | + if (!empty($args) && !empty($args['pid'])) { |
|
| 83 | 83 | $wps_price = new wpshop_prices(); |
| 84 | - $discount_data = wpshop_prices::check_discount_for_product( $args['pid'] ); |
|
| 85 | - if( !empty($discount_data) ) { |
|
| 84 | + $discount_data = wpshop_prices::check_discount_for_product($args['pid']); |
|
| 85 | + if (!empty($discount_data)) { |
|
| 86 | 86 | ob_start(); |
| 87 | - require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_discount_chip") ); |
|
| 87 | + require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_discount_chip")); |
|
| 88 | 88 | $output = ob_get_contents(); |
| 89 | 89 | ob_end_clean(); |
| 90 | 90 | } |
@@ -102,39 +102,39 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | function check_stock($product_id, $cart_asked_quantity, $combined_variation_id = '') { |
| 104 | 104 | // Checking if combined variation ID exist and it is a simple option |
| 105 | - if( !empty($combined_variation_id) && ( strpos($combined_variation_id, '__') !== false ) ) { |
|
| 106 | - $var_id = explode( '__', $combined_variation_id); |
|
| 105 | + if (!empty($combined_variation_id) && (strpos($combined_variation_id, '__') !== false)) { |
|
| 106 | + $var_id = explode('__', $combined_variation_id); |
|
| 107 | 107 | $combined_variation_id = $var_id[1]; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | |
| 111 | - if ( !empty($combined_variation_id) ) { |
|
| 111 | + if (!empty($combined_variation_id)) { |
|
| 112 | 112 | |
| 113 | - $variation_metadata = get_post_meta( $combined_variation_id, '_wpshop_product_metadata', true ); |
|
| 114 | - if ( isset($variation_metadata['product_stock']) ) { |
|
| 113 | + $variation_metadata = get_post_meta($combined_variation_id, '_wpshop_product_metadata', true); |
|
| 114 | + if (isset($variation_metadata['product_stock'])) { |
|
| 115 | 115 | $product_id = $combined_variation_id; |
| 116 | 116 | } else { |
| 117 | - $product_id = wp_get_post_parent_id( $combined_variation_id ); |
|
| 118 | - $product_id = ( $product_id ) ? $product_id : $combined_variation_id; |
|
| 117 | + $product_id = wp_get_post_parent_id($combined_variation_id); |
|
| 118 | + $product_id = ($product_id) ? $product_id : $combined_variation_id; |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | $product_data = wpshop_products::get_product_data($product_id, false, '"publish", "free_product"'); |
| 122 | 122 | |
| 123 | - if(!empty($product_data)) { |
|
| 123 | + if (!empty($product_data)) { |
|
| 124 | 124 | $manage_stock = !empty($product_data['manage_stock']) ? $product_data['manage_stock'] : ''; |
| 125 | 125 | |
| 126 | - $product_post_type = get_post_type( $product_id ); |
|
| 126 | + $product_post_type = get_post_type($product_id); |
|
| 127 | 127 | |
| 128 | - if ( $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) { |
|
| 129 | - $parent_def = wpshop_products::get_parent_variation( $product_id ); |
|
| 130 | - if ( !empty($parent_def) && !empty($parent_def['parent_post']) ) { |
|
| 128 | + if ($product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 129 | + $parent_def = wpshop_products::get_parent_variation($product_id); |
|
| 130 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 131 | 131 | $parent_post = $parent_def['parent_post']; |
| 132 | 132 | $parent_product_data = wpshop_products::get_product_data($parent_post->ID); |
| 133 | - $manage_stock = empty( $manage_stock ) ? $parent_product_data['manage_stock'] : $manage_stock; |
|
| 133 | + $manage_stock = empty($manage_stock) ? $parent_product_data['manage_stock'] : $manage_stock; |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | - $manage_stock_is_activated = (!empty($manage_stock) && ( strtolower(__($manage_stock, 'wpshop')) == strtolower(__('Yes', 'wpshop')) )) ? true : false; |
|
| 137 | - $the_qty_is_in_stock = ( !empty($product_data['product_stock']) && $product_data['product_stock'] >= $cart_asked_quantity ) ? true : false ; |
|
| 136 | + $manage_stock_is_activated = (!empty($manage_stock) && (strtolower(__($manage_stock, 'wpshop')) == strtolower(__('Yes', 'wpshop')))) ? true : false; |
|
| 137 | + $the_qty_is_in_stock = (!empty($product_data['product_stock']) && $product_data['product_stock'] >= $cart_asked_quantity) ? true : false; |
|
| 138 | 138 | |
| 139 | 139 | if (($manage_stock_is_activated && $the_qty_is_in_stock) OR !$manage_stock_is_activated) { |
| 140 | 140 | return true; |
@@ -147,18 +147,18 @@ discard block |
||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | public static function get_inconsistent_product() { |
| 150 | - $price_piloting_option = get_option( 'wpshop_shop_price_piloting' ); |
|
| 150 | + $price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 151 | 151 | |
| 152 | - $entity_id = wpshop_entities::get_entity_identifier_from_code( 'wpshop_product' ); |
|
| 152 | + $entity_id = wpshop_entities::get_entity_identifier_from_code('wpshop_product'); |
|
| 153 | 153 | |
| 154 | - $attribute_def = wpshop_attributes::getElement( ( $price_piloting_option == 'TTC' ) ? 'product_price' : 'price_ht', "'valid'", 'code' ); |
|
| 155 | - $attribute_id = $attribute_def->id; |
|
| 154 | + $attribute_def = wpshop_attributes::getElement(($price_piloting_option == 'TTC') ? 'product_price' : 'price_ht', "'valid'", 'code'); |
|
| 155 | + $attribute_id = $attribute_def->id; |
|
| 156 | 156 | |
| 157 | 157 | global $wpdb; |
| 158 | 158 | |
| 159 | 159 | $wpdb->query('SET SESSION group_concat_max_len = 10000'); |
| 160 | 160 | |
| 161 | - $query = " |
|
| 161 | + $query = " |
|
| 162 | 162 | SELECT post.ID, post.post_title, attr_val_dec.value as price_attribute, GROUP_CONCAT(postmeta.meta_key, '&sep&', postmeta.meta_value, '&&' ORDER BY postmeta.meta_key) as price |
| 163 | 163 | FROM $wpdb->posts as post |
| 164 | 164 | JOIN $wpdb->postmeta as postmeta |
@@ -171,15 +171,15 @@ discard block |
||
| 171 | 171 | AND postmeta.meta_key IN( '_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata' ) |
| 172 | 172 | GROUP BY post.ID"; |
| 173 | 173 | |
| 174 | - $list_product = $wpdb->get_results( $wpdb->prepare( $query, array( $entity_id, $attribute_id ) ) ); |
|
| 174 | + $list_product = $wpdb->get_results($wpdb->prepare($query, array($entity_id, $attribute_id))); |
|
| 175 | 175 | |
| 176 | - if( !empty( $list_product ) ) { |
|
| 177 | - foreach( $list_product as $key_product => &$product ) { |
|
| 176 | + if (!empty($list_product)) { |
|
| 177 | + foreach ($list_product as $key_product => &$product) { |
|
| 178 | 178 | $product->price = explode('&&,', $product->price); |
| 179 | - if(!empty($product->price) && is_array($product->price)) { |
|
| 179 | + if (!empty($product->price) && is_array($product->price)) { |
|
| 180 | 180 | $array_price = array(); |
| 181 | - foreach($product->price as &$price) { |
|
| 182 | - if(strpos( $price, '&&' )) |
|
| 181 | + foreach ($product->price as &$price) { |
|
| 182 | + if (strpos($price, '&&')) |
|
| 183 | 183 | $price = substr($price, 0, -2); |
| 184 | 184 | |
| 185 | 185 | $tmp_price = explode('&sep&', $price); |
@@ -187,35 +187,35 @@ discard block |
||
| 187 | 187 | $price = maybe_unserialize($tmp_price[1]); |
| 188 | 188 | |
| 189 | 189 | /** _wpshop_product_metadata */ |
| 190 | - if( $key == '_wpshop_product_metadata' ) { |
|
| 191 | - $array_price[$key] = ( $price_piloting_option == 'TTC' ) ? $price['product_price'] : $price['price_ht']; |
|
| 190 | + if ($key == '_wpshop_product_metadata') { |
|
| 191 | + $array_price[$key] = ($price_piloting_option == 'TTC') ? $price['product_price'] : $price['price_ht']; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** _wps_price_infos */ |
| 195 | - if( $key == '_wps_price_infos' ) { |
|
| 196 | - $array_price[$key] = !empty( $price['PRODUCT_PRICE'] ) ? $price['PRODUCT_PRICE'] : '-'; |
|
| 195 | + if ($key == '_wps_price_infos') { |
|
| 196 | + $array_price[$key] = !empty($price['PRODUCT_PRICE']) ? $price['PRODUCT_PRICE'] : '-'; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if( $key == '_product_price' ) { |
|
| 200 | - $array_price[$key] = ( $price_piloting_option == 'TTC' ) ? $price : '-'; |
|
| 199 | + if ($key == '_product_price') { |
|
| 200 | + $array_price[$key] = ($price_piloting_option == 'TTC') ? $price : '-'; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if ( $key == '_wpshop_displayed_price' ) { |
|
| 203 | + if ($key == '_wpshop_displayed_price') { |
|
| 204 | 204 | $array_price[$key] = $price; |
| 205 | 205 | } |
| 206 | 206 | unset($price); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - $array_meta_list = array( '_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata', ); |
|
| 209 | + $array_meta_list = array('_product_price', '_wps_price_infos', '_wpshop_displayed_price', '_wpshop_product_metadata',); |
|
| 210 | 210 | |
| 211 | - foreach( $array_meta_list as $meta_list ) { |
|
| 212 | - if( !array_key_exists( $meta_list, $array_price ) ) { |
|
| 211 | + foreach ($array_meta_list as $meta_list) { |
|
| 212 | + if (!array_key_exists($meta_list, $array_price)) { |
|
| 213 | 213 | $array_price[$meta_list] = 0; |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | $product->price = $array_price; |
| 218 | - if( $product->price_attribute === $product->price['_wpshop_product_metadata'] ) { |
|
| 218 | + if ($product->price_attribute === $product->price['_wpshop_product_metadata']) { |
|
| 219 | 219 | unset($list_product[$key_product]); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | * @param int $pid L'id du produit |
| 234 | 234 | * @return WP_Post |
| 235 | 235 | */ |
| 236 | - public function get_thumbnail ( $pid ) { |
|
| 237 | - if( empty( $pid ) ) |
|
| 236 | + public function get_thumbnail($pid) { |
|
| 237 | + if (empty($pid)) |
|
| 238 | 238 | return null; |
| 239 | 239 | |
| 240 | - $thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true ); |
|
| 240 | + $thumbnail_id = get_post_meta($pid, '_thumbnail_id', true); |
|
| 241 | 241 | |
| 242 | - if( empty( $thumbnail_id ) ) |
|
| 242 | + if (empty($thumbnail_id)) |
|
| 243 | 243 | return null; |
| 244 | 244 | |
| 245 | 245 | return $thumbnail_id; |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | * @param array $array_data The array data [integer][barcode] = 0111100001 |
| 253 | 253 | */ |
| 254 | 254 | public function update_attributes_for_product($product_id, $array_data) { |
| 255 | - if(!empty($array_data)) { |
|
| 256 | - foreach($array_data as $type => $array) { |
|
| 257 | - foreach($array as $name_attribute => $value_attribute) { |
|
| 255 | + if (!empty($array_data)) { |
|
| 256 | + foreach ($array_data as $type => $array) { |
|
| 257 | + foreach ($array as $name_attribute => $value_attribute) { |
|
| 258 | 258 | $this->update_the_attribute_for_product($product_id, $type, $name_attribute, $value_attribute); |
| 259 | 259 | } |
| 260 | 260 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | $attribute_id = $wpdb->get_var($wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s"', array($name_attribute))); |
| 279 | 279 | |
| 280 | 280 | /** On vérifie s'il existe si c'est le cas, on update sinon on insert */ |
| 281 | - if(count($wpdb->get_row($wpdb->prepare('SELECT value_id FROM ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' WHERE entity_id=%d AND attribute_id IN(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s")', array($product_id, $name_attribute)))) > 0) { |
|
| 281 | + if (count($wpdb->get_row($wpdb->prepare('SELECT value_id FROM ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' WHERE entity_id=%d AND attribute_id IN(SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code="%s")', array($product_id, $name_attribute)))) > 0) { |
|
| 282 | 282 | $wpdb->query( |
| 283 | 283 | $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . '_value_' . $type . ' SET value="%s" WHERE entity_id=%d AND attribute_id=%d', |
| 284 | 284 | array($value_attribute, $product_id, $attribute_id) |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | * @param array $args [ 'id' ] L'id du produit |
| 305 | 305 | * @return string |
| 306 | 306 | */ |
| 307 | - public function wpshop_product_title( $args ) { |
|
| 308 | - $output = __( 'No product has been found.', 'wpshop' ); |
|
| 307 | + public function wpshop_product_title($args) { |
|
| 308 | + $output = __('No product has been found.', 'wpshop'); |
|
| 309 | 309 | |
| 310 | - if ( !empty( $args ) && !empty( $args['pid'] ) ) { |
|
| 310 | + if (!empty($args) && !empty($args['pid'])) { |
|
| 311 | 311 | global $wpdb; |
| 312 | 312 | $query = "SELECT post_title FROM {$wpdb->posts} WHERE ID = %d"; |
| 313 | - $output = $wpdb->get_var( $wpdb->prepare( $query, $args['pid'] ) ); |
|
| 313 | + $output = $wpdb->get_var($wpdb->prepare($query, $args['pid'])); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | return $output; |
@@ -321,16 +321,16 @@ discard block |
||
| 321 | 321 | * @param array $args [ 'id' ] L'id du produit |
| 322 | 322 | * @return string |
| 323 | 323 | */ |
| 324 | - public function wpshop_product_content( $args ) { |
|
| 325 | - $output = __( 'No product has been found.', 'wpshop' ); |
|
| 324 | + public function wpshop_product_content($args) { |
|
| 325 | + $output = __('No product has been found.', 'wpshop'); |
|
| 326 | 326 | |
| 327 | - if ( !empty( $args ) && !empty( $args['pid'] ) ) { |
|
| 327 | + if (!empty($args) && !empty($args['pid'])) { |
|
| 328 | 328 | global $wpdb; |
| 329 | 329 | $query = "SELECT post_content FROM {$wpdb->posts} WHERE ID = %d"; |
| 330 | - $output = $wpdb->get_var( $wpdb->prepare( $query, $args['pid'] ) ); |
|
| 330 | + $output = $wpdb->get_var($wpdb->prepare($query, $args['pid'])); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - return nl2br( $output ); |
|
| 333 | + return nl2br($output); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -340,12 +340,12 @@ discard block |
||
| 340 | 340 | * [ size ] La taille de l'image. Peut être défini comme : small, medium ou full |
| 341 | 341 | * @return string |
| 342 | 342 | */ |
| 343 | - public function wpshop_product_thumbnail( $args ) { |
|
| 343 | + public function wpshop_product_thumbnail($args) { |
|
| 344 | 344 | $url_thumbnail = WPSHOP_DEFAULT_PRODUCT_PICTURE; |
| 345 | 345 | $size = '20%'; |
| 346 | 346 | |
| 347 | - if ( !empty( $args ) && !empty( $args['size'] ) ) { |
|
| 348 | - switch ( $args['size'] ) { |
|
| 347 | + if (!empty($args) && !empty($args['size'])) { |
|
| 348 | + switch ($args['size']) { |
|
| 349 | 349 | case 'small': |
| 350 | 350 | $size = '20%'; |
| 351 | 351 | break; |
@@ -360,20 +360,20 @@ discard block |
||
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if ( !empty( $args ) && !empty( $args['pid'] ) ) { |
|
| 364 | - $thumbnail_id = $this->get_thumbnail( $args['pid'] ); |
|
| 363 | + if (!empty($args) && !empty($args['pid'])) { |
|
| 364 | + $thumbnail_id = $this->get_thumbnail($args['pid']); |
|
| 365 | 365 | |
| 366 | - if( !empty( $thumbnail_id ) ) { |
|
| 367 | - $attachment = get_post( $thumbnail_id ); |
|
| 366 | + if (!empty($thumbnail_id)) { |
|
| 367 | + $attachment = get_post($thumbnail_id); |
|
| 368 | 368 | |
| 369 | - if( !empty( $attachment ) && !empty( $attachment->guid ) ) { |
|
| 369 | + if (!empty($attachment) && !empty($attachment->guid)) { |
|
| 370 | 370 | $url_thumbnail = $attachment->guid; |
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | ob_start(); |
| 376 | - require( wpshop_tools::get_template_part( WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_thumbnail" ) ); |
|
| 376 | + require(wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, "frontend", "product_thumbnail")); |
|
| 377 | 377 | $output = ob_get_clean(); |
| 378 | 378 | |
| 379 | 379 | return $output; |
@@ -383,19 +383,19 @@ discard block |
||
| 383 | 383 | * Output product sheet to PDF |
| 384 | 384 | */ |
| 385 | 385 | public function wpshop_product_sheet_output() { |
| 386 | - $product_id = ( !empty($_GET['pid']) ) ? (int) $_GET['pid'] : null; |
|
| 386 | + $product_id = (!empty($_GET['pid'])) ? (int)$_GET['pid'] : null; |
|
| 387 | 387 | $user_id = get_current_user_id(); |
| 388 | - if( !empty($product_id) && get_post_type( $product_id ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT && $user_id != 0 && current_user_can( 'manage_options' ) ) { |
|
| 388 | + if (!empty($product_id) && get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT && $user_id != 0 && current_user_can('manage_options')) { |
|
| 389 | 389 | $wps_product_administration_ctr = new wps_product_administration_ctr(); |
| 390 | - $html_content = $wps_product_administration_ctr->generate_product_sheet_datas( $product_id ); |
|
| 391 | - $product_post = get_post( $product_id ); |
|
| 392 | - require_once(WPSHOP_LIBRAIRIES_DIR.'HTML2PDF/html2pdf.class.php'); |
|
| 390 | + $html_content = $wps_product_administration_ctr->generate_product_sheet_datas($product_id); |
|
| 391 | + $product_post = get_post($product_id); |
|
| 392 | + require_once(WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php'); |
|
| 393 | 393 | try { |
| 394 | 394 | $html2pdf = new HTML2PDF('P', 'A4', 'fr'); |
| 395 | 395 | $html2pdf->pdf->SetDisplayMode('fullpage'); |
| 396 | 396 | $html2pdf->setDefaultFont('Arial'); |
| 397 | 397 | $html2pdf->writeHTML($html_content); |
| 398 | - $html2pdf->Output('product-' .$product_id.'-'.$product_post->post_name.'.pdf', 'D'); |
|
| 398 | + $html2pdf->Output('product-' . $product_id . '-' . $product_post->post_name . '.pdf', 'D'); |
|
| 399 | 399 | } |
| 400 | 400 | catch (HTML2PDF_exception $e) { |
| 401 | 401 | echo $e; |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_product_ctr { |
| 3 | 5 | |
| 4 | 6 | /** |
@@ -46,8 +48,9 @@ discard block |
||
| 46 | 48 | } |
| 47 | 49 | |
| 48 | 50 | public function callback_admin_enqueue_scripts( $hook ) { |
| 49 | - if( $hook != 'tools_page_wpshop_tools' ) |
|
| 50 | - return; |
|
| 51 | + if( $hook != 'tools_page_wpshop_tools' ) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | wp_enqueue_script( 'wps_product_js', WPS_PRODUCT_URL . '/asset/js/backend.js', array( "jquery", "jquery-form" ), WPS_PRODUCT_VERSION ); |
| 53 | 56 | } |
@@ -138,8 +141,7 @@ discard block |
||
| 138 | 141 | |
| 139 | 142 | if (($manage_stock_is_activated && $the_qty_is_in_stock) OR !$manage_stock_is_activated) { |
| 140 | 143 | return true; |
| 141 | - } |
|
| 142 | - else { |
|
| 144 | + } else { |
|
| 143 | 145 | return __('You cannot add that amount to the cart since there is not enough stock.', 'wpshop'); |
| 144 | 146 | } |
| 145 | 147 | } |
@@ -179,8 +181,9 @@ discard block |
||
| 179 | 181 | if(!empty($product->price) && is_array($product->price)) { |
| 180 | 182 | $array_price = array(); |
| 181 | 183 | foreach($product->price as &$price) { |
| 182 | - if(strpos( $price, '&&' )) |
|
| 183 | - $price = substr($price, 0, -2); |
|
| 184 | + if(strpos( $price, '&&' )) { |
|
| 185 | + $price = substr($price, 0, -2); |
|
| 186 | + } |
|
| 184 | 187 | |
| 185 | 188 | $tmp_price = explode('&sep&', $price); |
| 186 | 189 | $key = $tmp_price[0]; |
@@ -234,13 +237,15 @@ discard block |
||
| 234 | 237 | * @return WP_Post |
| 235 | 238 | */ |
| 236 | 239 | public function get_thumbnail ( $pid ) { |
| 237 | - if( empty( $pid ) ) |
|
| 238 | - return null; |
|
| 240 | + if( empty( $pid ) ) { |
|
| 241 | + return null; |
|
| 242 | + } |
|
| 239 | 243 | |
| 240 | 244 | $thumbnail_id = get_post_meta( $pid, '_thumbnail_id', true ); |
| 241 | 245 | |
| 242 | - if( empty( $thumbnail_id ) ) |
|
| 243 | - return null; |
|
| 246 | + if( empty( $thumbnail_id ) ) { |
|
| 247 | + return null; |
|
| 248 | + } |
|
| 244 | 249 | |
| 245 | 250 | return $thumbnail_id; |
| 246 | 251 | } |
@@ -284,8 +289,7 @@ discard block |
||
| 284 | 289 | array($value_attribute, $product_id, $attribute_id) |
| 285 | 290 | ) |
| 286 | 291 | ); |
| 287 | - } |
|
| 288 | - else { |
|
| 292 | + } else { |
|
| 289 | 293 | /** Insert avec toutes les informations requise */ |
| 290 | 294 | $wpdb->insert(WPSHOP_DBT_ATTRIBUTE . '_value_' . $type, array( |
| 291 | 295 | 'attribute_id' => $attribute_id, |
@@ -396,8 +400,7 @@ discard block |
||
| 396 | 400 | $html2pdf->setDefaultFont('Arial'); |
| 397 | 401 | $html2pdf->writeHTML($html_content); |
| 398 | 402 | $html2pdf->Output('product-' .$product_id.'-'.$product_post->post_name.'.pdf', 'D'); |
| 399 | - } |
|
| 400 | - catch (HTML2PDF_exception $e) { |
|
| 403 | + } catch (HTML2PDF_exception $e) { |
|
| 401 | 404 | echo $e; |
| 402 | 405 | } |
| 403 | 406 | } |
@@ -158,6 +158,7 @@ discard block |
||
| 158 | 158 | /** |
| 159 | 159 | * Display pagination |
| 160 | 160 | * |
| 161 | + * @param integer $current_page |
|
| 161 | 162 | * @return string |
| 162 | 163 | */ |
| 163 | 164 | function get_products_pagination( $current_page, $attribute_set_id = 1 ) { |
@@ -201,6 +202,9 @@ discard block |
||
| 201 | 202 | return $output; |
| 202 | 203 | } |
| 203 | 204 | |
| 205 | + /** |
|
| 206 | + * @param integer $product_id |
|
| 207 | + */ |
|
| 204 | 208 | function wps_product_attached_files( $product_id ) { |
| 205 | 209 | global $wpdb; |
| 206 | 210 | $output = ''; |
@@ -370,8 +370,8 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | - * Delete product list |
|
| 374 | - **/ |
|
| 373 | + * Delete product list |
|
| 374 | + **/ |
|
| 375 | 375 | function wps_mass_delete_file() { |
| 376 | 376 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 377 | 377 | |
@@ -389,8 +389,8 @@ discard block |
||
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /** |
| 392 | - * Update product files list |
|
| 393 | - */ |
|
| 392 | + * Update product files list |
|
| 393 | + */ |
|
| 394 | 394 | function wps_mass_edit_update_files_list() { |
| 395 | 395 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 396 | 396 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Main controller file for product mass modification module |
| 4 | 6 | * |
@@ -222,8 +224,9 @@ discard block |
||
| 222 | 224 | function wps_mass_edit_change_page() { |
| 223 | 225 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 224 | 226 | |
| 225 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) ) |
|
| 226 | - wp_die(); |
|
| 227 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) ) { |
|
| 228 | + wp_die(); |
|
| 229 | + } |
|
| 227 | 230 | |
| 228 | 231 | $status = false; $response = ''; |
| 229 | 232 | $page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0; |
@@ -246,8 +249,9 @@ discard block |
||
| 246 | 249 | function wps_mass_interface_new_product_creation() { |
| 247 | 250 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 248 | 251 | |
| 249 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) ) |
|
| 250 | - wp_die(); |
|
| 252 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) ) { |
|
| 253 | + wp_die(); |
|
| 254 | + } |
|
| 251 | 255 | |
| 252 | 256 | global $wpdb; |
| 253 | 257 | $output = $pagination = ''; |
@@ -277,8 +281,9 @@ discard block |
||
| 277 | 281 | function wps_save_product_quick_interface() { |
| 278 | 282 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 279 | 283 | |
| 280 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) ) |
|
| 281 | - wp_die(); |
|
| 284 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) ) { |
|
| 285 | + wp_die(); |
|
| 286 | + } |
|
| 282 | 287 | |
| 283 | 288 | global $wpdb; |
| 284 | 289 | $response = ''; $status = false; |
@@ -306,8 +311,7 @@ discard block |
||
| 306 | 311 | if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') { |
| 307 | 312 | wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) ); |
| 308 | 313 | update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] ); |
| 309 | - } |
|
| 310 | - elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 314 | + } elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 311 | 315 | delete_post_meta( $updated_post, '_thumbnail_id' ); |
| 312 | 316 | } |
| 313 | 317 | } |
@@ -355,12 +359,10 @@ discard block |
||
| 355 | 359 | |
| 356 | 360 | if( $status ) { |
| 357 | 361 | $response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products ); |
| 358 | - } |
|
| 359 | - else { |
|
| 362 | + } else { |
|
| 360 | 363 | if( !empty($total_updated_products) ) { |
| 361 | 364 | $response = sprintf( __( 'All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update ); |
| 362 | - } |
|
| 363 | - else { |
|
| 365 | + } else { |
|
| 364 | 366 | $response = __( 'No product have been updated', 'wpshop'); |
| 365 | 367 | } |
| 366 | 368 | } |
@@ -375,8 +377,9 @@ discard block |
||
| 375 | 377 | function wps_mass_delete_file() { |
| 376 | 378 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 377 | 379 | |
| 378 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) ) |
|
| 379 | - wp_die(); |
|
| 380 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) ) { |
|
| 381 | + wp_die(); |
|
| 382 | + } |
|
| 380 | 383 | |
| 381 | 384 | $status = false; |
| 382 | 385 | $file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null; |
@@ -394,8 +397,9 @@ discard block |
||
| 394 | 397 | function wps_mass_edit_update_files_list() { |
| 395 | 398 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 396 | 399 | |
| 397 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) ) |
|
| 398 | - wp_die(); |
|
| 400 | + if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) ) { |
|
| 401 | + wp_die(); |
|
| 402 | + } |
|
| 399 | 403 | |
| 400 | 404 | $status = false; $response = ''; |
| 401 | 405 | $product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | /** |
| 3 | 3 | * Main controller file for product mass modification module |
| 4 | 4 | * |
@@ -21,29 +21,29 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | function __construct() { |
| 23 | 23 | // Add submenu |
| 24 | - add_action('admin_menu', array( $this, 'register_mass_products_edit_submenu' ), 350 ); |
|
| 24 | + add_action('admin_menu', array($this, 'register_mass_products_edit_submenu'), 350); |
|
| 25 | 25 | |
| 26 | 26 | // Trigger ajax action |
| 27 | - add_action( 'wp_ajax_wps_mass_edit_change_page', array( $this, 'wps_mass_edit_change_page') ); |
|
| 28 | - add_action( 'wp_ajax_wps_mass_edit_product_save_action', array( $this, 'wps_save_product_quick_interface') ); |
|
| 29 | - add_action( 'wp_ajax_wps_mass_interface_new_product_creation', array( $this, 'wps_mass_interface_new_product_creation' ) ); |
|
| 30 | - add_action( 'wp_ajax_wps_mass_delete_file', array( $this, 'wps_mass_delete_file' ) ); |
|
| 31 | - add_action( 'wp_ajax_wps_mass_edit_update_files_list', array( $this, 'wps_mass_edit_update_files_list' ) ); |
|
| 27 | + add_action('wp_ajax_wps_mass_edit_change_page', array($this, 'wps_mass_edit_change_page')); |
|
| 28 | + add_action('wp_ajax_wps_mass_edit_product_save_action', array($this, 'wps_save_product_quick_interface')); |
|
| 29 | + add_action('wp_ajax_wps_mass_interface_new_product_creation', array($this, 'wps_mass_interface_new_product_creation')); |
|
| 30 | + add_action('wp_ajax_wps_mass_delete_file', array($this, 'wps_mass_delete_file')); |
|
| 31 | + add_action('wp_ajax_wps_mass_edit_update_files_list', array($this, 'wps_mass_edit_update_files_list')); |
|
| 32 | 32 | // add_action( 'wap_ajax_wps_mass_delete_post', array( $this, 'wps_mass_delete_post' ) ); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | function register_mass_products_edit_submenu() { |
| 36 | - $this->submenu = add_submenu_page( 'edit.php?post_type=wpshop_product', __( 'Mass product edit', 'wpshop' ), __( 'Mass product edit', 'wpshop' ), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface' ) ); |
|
| 36 | + $this->submenu = add_submenu_page('edit.php?post_type=wpshop_product', __('Mass product edit', 'wpshop'), __('Mass product edit', 'wpshop'), 'manage_options', 'mass_edit_interface', array($this, 'wps_display_mass_edit_interface')); |
|
| 37 | 37 | // Declare Styles and JS Files. |
| 38 | - add_action( 'admin_print_styles-' . $this->submenu, array( $this, 'admin_print_styles' ) ); |
|
| 39 | - add_action( 'admin_print_scripts-' . $this->submenu, array( $this, 'admin_print_scripts' ) ); |
|
| 38 | + add_action('admin_print_styles-' . $this->submenu, array($this, 'admin_print_styles')); |
|
| 39 | + add_action('admin_print_scripts-' . $this->submenu, array($this, 'admin_print_scripts')); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Add css to administration |
| 44 | 44 | */ |
| 45 | 45 | function admin_print_styles() { |
| 46 | - wp_enqueue_style( 'wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css' ); |
|
| 46 | + wp_enqueue_style('wps-mass-product-update', WPS_PDCT_MASS_URL . '/assets/css/backend.css'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function admin_print_scripts() { |
| 53 | 53 | wp_enqueue_media(); |
| 54 | - wp_enqueue_script( 'admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true ); |
|
| 54 | + wp_enqueue_script('admin_product_js', WPS_PDCT_MASS_URL . '/assets/js/backend.js', '', WPS_PDCT_MASS_VERSION, true); |
|
| 55 | 55 | $output = '<script type="text/javascript">'; |
| 56 | - $output .= 'var WPS_MASS_ERROR_INIT = "' .__( 'An error has occured, the page cannot be initialized', 'wpshop' ). '";'; |
|
| 57 | - $output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' .__( 'An error was occured, the new product cannot be created', 'wpshop' ). '";'; |
|
| 58 | - $output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' .__( 'You must select product to save', 'wpshop' ). '";'; |
|
| 59 | - $output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' .__( 'You will save selected products, are you sure to continue ?', 'wpshop' ). '";'; |
|
| 56 | + $output .= 'var WPS_MASS_ERROR_INIT = "' . __('An error has occured, the page cannot be initialized', 'wpshop') . '";'; |
|
| 57 | + $output .= 'var WPS_MASS_ERROR_PRODUCT_CREATION = "' . __('An error was occured, the new product cannot be created', 'wpshop') . '";'; |
|
| 58 | + $output .= 'var WPS_MASS_ERROR_PRODUCT_SAVE = "' . __('You must select product to save', 'wpshop') . '";'; |
|
| 59 | + $output .= 'var WPS_MASS_CONFIRMATION_NEW_PRODUCT = "' . __('You will save selected products, are you sure to continue ?', 'wpshop') . '";'; |
|
| 60 | 60 | $output .= '</script>'; |
| 61 | 61 | echo $output; |
| 62 | 62 | } |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | - function check_attribute_to_display_for_quick_add( $attribute_list, $quick_add_form_attributes = array() ) { |
|
| 72 | - |
|
| 73 | - if ( !empty( $attribute_list ) ) { |
|
| 74 | - foreach( $attribute_list as $attributes_group ) { |
|
| 75 | - foreach( $attributes_group as $attributes_sections ) { |
|
| 76 | - if( !empty($attributes_sections) && !empty($attributes_sections['attributes']) ) { |
|
| 77 | - foreach( $attributes_sections['attributes'] as $attribute_id => $att_def ) { |
|
| 78 | - if( !empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes' ) { |
|
| 79 | - $quick_add_form_attributes[ $attribute_id ] = $att_def; |
|
| 71 | + function check_attribute_to_display_for_quick_add($attribute_list, $quick_add_form_attributes = array()) { |
|
| 72 | + |
|
| 73 | + if (!empty($attribute_list)) { |
|
| 74 | + foreach ($attribute_list as $attributes_group) { |
|
| 75 | + foreach ($attributes_group as $attributes_sections) { |
|
| 76 | + if (!empty($attributes_sections) && !empty($attributes_sections['attributes'])) { |
|
| 77 | + foreach ($attributes_sections['attributes'] as $attribute_id => $att_def) { |
|
| 78 | + if (!empty($att_def) && !empty($att_def['is_used_in_quick_add_form']) && $att_def['is_used_in_quick_add_form'] == 'yes') { |
|
| 79 | + $quick_add_form_attributes[$attribute_id] = $att_def; |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -93,29 +93,29 @@ discard block |
||
| 93 | 93 | * @param integer $page |
| 94 | 94 | * @return string |
| 95 | 95 | */ |
| 96 | - function display_products_list( $default = 1, $page = 0, $order_by = 'date', $order = 'ASC' ) { |
|
| 96 | + function display_products_list($default = 1, $page = 0, $order_by = 'date', $order = 'ASC') { |
|
| 97 | 97 | global $wpdb; |
| 98 | 98 | // Product entity |
| 99 | - $product_entity_id = wpshop_entities::get_entity_identifier_from_code( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); |
|
| 99 | + $product_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 100 | 100 | |
| 101 | 101 | $user_id = get_current_user_id(); |
| 102 | 102 | // Check product limit |
| 103 | - $product_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true ); |
|
| 104 | - $product_limit = ( !empty($product_limit) ) ? $product_limit : 20; |
|
| 103 | + $product_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true); |
|
| 104 | + $product_limit = (!empty($product_limit)) ? $product_limit : 20; |
|
| 105 | 105 | |
| 106 | 106 | // Get products for the current page |
| 107 | 107 | $wps_product_mass_interface_mdl = new wps_product_mass_interface_mdl(); |
| 108 | - $products = $wps_product_mass_interface_mdl->get_quick_interface_products( $default, $page, $product_limit ); |
|
| 108 | + $products = $wps_product_mass_interface_mdl->get_quick_interface_products($default, $page, $product_limit); |
|
| 109 | 109 | |
| 110 | 110 | // Construct Table Head Data |
| 111 | 111 | $quick_add_form_attributes = array(); |
| 112 | 112 | $get_attributes_quick_add_form = $wps_product_mass_interface_mdl->get_attributes_quick_add_form(); |
| 113 | - foreach( $get_attributes_quick_add_form as $quick_add_form_attribute ) { |
|
| 113 | + foreach ($get_attributes_quick_add_form as $quick_add_form_attribute) { |
|
| 114 | 114 | $quick_add_form_attributes[$quick_add_form_attribute['id']] = $quick_add_form_attribute; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | ob_start(); |
| 118 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list" ) ); |
|
| 118 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "product_list")); |
|
| 119 | 119 | $output = ob_get_contents(); |
| 120 | 120 | ob_end_clean(); |
| 121 | 121 | return $output; |
@@ -131,27 +131,27 @@ discard block |
||
| 131 | 131 | $products_attributes_groups = $wps_product_mass_interface_mdl->get_product_attributes_sets(); |
| 132 | 132 | |
| 133 | 133 | $default = ''; |
| 134 | - if( !empty($products_attributes_groups) ) { |
|
| 135 | - foreach( $products_attributes_groups as $key => $products_attributes_group ) { |
|
| 136 | - if( $products_attributes_group->slug == 'free_product' ) { |
|
| 137 | - unset( $products_attributes_groups[$key] ); |
|
| 134 | + if (!empty($products_attributes_groups)) { |
|
| 135 | + foreach ($products_attributes_groups as $key => $products_attributes_group) { |
|
| 136 | + if ($products_attributes_group->slug == 'free_product') { |
|
| 137 | + unset($products_attributes_groups[$key]); |
|
| 138 | 138 | } |
| 139 | - if( !empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes' ) { |
|
| 139 | + if (!empty($products_attributes_group->default_set) && $products_attributes_group->default_set == 'yes') { |
|
| 140 | 140 | $default = $products_attributes_group->id; |
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | // Check page |
| 145 | - $page = ( !empty( $_GET[ 'page' ] ) && is_int( (int)$_GET[ 'page' ] ) && $_GET[ 'page' ] > 0 ) ? (int)($_GET[ 'page' ] - 1) : 0; |
|
| 145 | + $page = (!empty($_GET['page']) && is_int((int)$_GET['page']) && $_GET['page'] > 0) ? (int)($_GET['page'] - 1) : 0; |
|
| 146 | 146 | // Display product tab |
| 147 | - $order_by = !empty( $_GET[ 'order_by' ] ) ? sanitize_title( $_GET[ 'order_by' ] ) : 'date'; |
|
| 148 | - $order = !empty( $_GET[ 'order' ] ) ? sanitize_title( $_GET[ 'order' ] ) : 'ASC'; |
|
| 149 | - $product_list_interface = $this->display_products_list( $default, $page, $order_by, $order ); |
|
| 147 | + $order_by = !empty($_GET['order_by']) ? sanitize_title($_GET['order_by']) : 'date'; |
|
| 148 | + $order = !empty($_GET['order']) ? sanitize_title($_GET['order']) : 'ASC'; |
|
| 149 | + $product_list_interface = $this->display_products_list($default, $page, $order_by, $order); |
|
| 150 | 150 | |
| 151 | 151 | // Get pagination |
| 152 | - $pagination = $this->get_products_pagination( $page, $default ); |
|
| 152 | + $pagination = $this->get_products_pagination($page, $default); |
|
| 153 | 153 | |
| 154 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface" ) ); |
|
| 154 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface")); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return string |
| 161 | 161 | */ |
| 162 | - function get_products_pagination( $current_page, $attribute_set_id = 1 ) { |
|
| 162 | + function get_products_pagination($current_page, $attribute_set_id = 1) { |
|
| 163 | 163 | global $wpdb; |
| 164 | 164 | $user_id = get_current_user_id(); |
| 165 | 165 | $output = ''; |
| 166 | 166 | /** Define the element number per page. If the user change the default value, take this value */ |
| 167 | - $one_page_limit = get_user_meta( $user_id, 'edit_wpshop_product_per_page', true ); |
|
| 168 | - $one_page_limit = ( !empty($one_page_limit) ) ? $one_page_limit : 20; |
|
| 167 | + $one_page_limit = get_user_meta($user_id, 'edit_wpshop_product_per_page', true); |
|
| 168 | + $one_page_limit = (!empty($one_page_limit)) ? $one_page_limit : 20; |
|
| 169 | 169 | |
| 170 | 170 | /** Count the number of product existing in the shop */ |
| 171 | 171 | $query = $wpdb->prepare( |
@@ -177,37 +177,37 @@ discard block |
||
| 177 | 177 | AND meta_value = %s |
| 178 | 178 | AND post_status IN ( 'publish', 'draft' )", |
| 179 | 179 | WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, '_wpshop_product_attribute_set_id', $attribute_set_id); |
| 180 | - $products = $wpdb->get_var( $query ); |
|
| 180 | + $products = $wpdb->get_var($query); |
|
| 181 | 181 | |
| 182 | - if( !empty($products) ) { |
|
| 182 | + if (!empty($products)) { |
|
| 183 | 183 | $args = array( |
| 184 | 184 | 'base' => '%_%', |
| 185 | - 'format' => admin_url( 'admin-ajax.php?action=wps_add_quick_interface&page=%#%' ), |
|
| 186 | - 'current' => ( $current_page + 1 ), |
|
| 187 | - 'total' => ceil( $products / $one_page_limit ), |
|
| 185 | + 'format' => admin_url('admin-ajax.php?action=wps_add_quick_interface&page=%#%'), |
|
| 186 | + 'current' => ($current_page + 1), |
|
| 187 | + 'total' => ceil($products / $one_page_limit), |
|
| 188 | 188 | 'type' => 'array', |
| 189 | 189 | 'prev_next' => false, |
| 190 | 190 | 'show_all' => true, |
| 191 | 191 | ); |
| 192 | - $paginate = paginate_links( $args ); |
|
| 192 | + $paginate = paginate_links($args); |
|
| 193 | 193 | |
| 194 | 194 | $wps_product_ctr = new wps_product_ctr(); |
| 195 | 195 | ob_start(); |
| 196 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination" ) ); |
|
| 196 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface_pagination")); |
|
| 197 | 197 | $output = ob_get_contents(); |
| 198 | 198 | ob_end_clean(); |
| 199 | 199 | } |
| 200 | 200 | return $output; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - function wps_product_attached_files( $product_id ) { |
|
| 203 | + function wps_product_attached_files($product_id) { |
|
| 204 | 204 | global $wpdb; |
| 205 | 205 | $output = ''; |
| 206 | - $query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%' ); |
|
| 207 | - $files = $wpdb->get_results( $query ); |
|
| 208 | - if( !empty($files) ) { |
|
| 206 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_parent = %d AND post_type = %s AND post_mime_type LIKE %s', $product_id, 'attachment', 'application%'); |
|
| 207 | + $files = $wpdb->get_results($query); |
|
| 208 | + if (!empty($files)) { |
|
| 209 | 209 | ob_start(); |
| 210 | - require( wpshop_tools::get_template_part( WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list" ) ); |
|
| 210 | + require(wpshop_tools::get_template_part(WPS_PDCT_MASS_DIR, WPS_PDCT_MASS_TEMPLATES_MAIN_DIR, "backend", "quick_add_interface", "attached_files_list")); |
|
| 211 | 211 | $output = ob_get_contents(); |
| 212 | 212 | ob_end_clean(); |
| 213 | 213 | } |
@@ -219,23 +219,23 @@ discard block |
||
| 219 | 219 | * AJAX - Change page action on mass edit product interface |
| 220 | 220 | */ |
| 221 | 221 | function wps_mass_edit_change_page() { |
| 222 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 222 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 223 | 223 | |
| 224 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_change_page' ) ) |
|
| 224 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_change_page')) |
|
| 225 | 225 | wp_die(); |
| 226 | 226 | |
| 227 | 227 | $status = false; $response = ''; |
| 228 | - $page = ( !empty($_POST['page_id']) ) ? intval( $_POST['page_id'] ) - 1 : 0; |
|
| 229 | - $attribute_set_id = ( !empty($_POST['att_set_id']) ) ? intval( $_POST['att_set_id'] ) : 1; |
|
| 230 | - if( !empty($attribute_set_id) ) { |
|
| 228 | + $page = (!empty($_POST['page_id'])) ? intval($_POST['page_id']) - 1 : 0; |
|
| 229 | + $attribute_set_id = (!empty($_POST['att_set_id'])) ? intval($_POST['att_set_id']) : 1; |
|
| 230 | + if (!empty($attribute_set_id)) { |
|
| 231 | 231 | // Get tab |
| 232 | - $response = $this->display_products_list( $attribute_set_id, $page ); |
|
| 233 | - $pagination = $this->get_products_pagination( $page, $attribute_set_id ); |
|
| 234 | - if( !empty($response) ) { |
|
| 232 | + $response = $this->display_products_list($attribute_set_id, $page); |
|
| 233 | + $pagination = $this->get_products_pagination($page, $attribute_set_id); |
|
| 234 | + if (!empty($response)) { |
|
| 235 | 235 | $status = true; |
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | - echo json_encode( array( 'status' => $status, 'response' => $response, 'pagination' => $pagination ) ); |
|
| 238 | + echo json_encode(array('status' => $status, 'response' => $response, 'pagination' => $pagination)); |
|
| 239 | 239 | wp_die(); |
| 240 | 240 | } |
| 241 | 241 | |
@@ -243,30 +243,30 @@ discard block |
||
| 243 | 243 | * AJAX - Create a draft product and display the line allowing to edit informations for this product |
| 244 | 244 | */ |
| 245 | 245 | function wps_mass_interface_new_product_creation() { |
| 246 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 246 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 247 | 247 | |
| 248 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_interface_new_product_creation' ) ) |
|
| 248 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_interface_new_product_creation')) |
|
| 249 | 249 | wp_die(); |
| 250 | 250 | |
| 251 | 251 | global $wpdb; |
| 252 | 252 | $output = $pagination = ''; |
| 253 | 253 | $status = false; |
| 254 | 254 | |
| 255 | - $new_product_id = wp_insert_post( array( |
|
| 255 | + $new_product_id = wp_insert_post(array( |
|
| 256 | 256 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
| 257 | 257 | 'post_status' => 'publish', |
| 258 | - 'post_title' => __( 'New product', 'wpshop' ), |
|
| 259 | - ) ); |
|
| 258 | + 'post_title' => __('New product', 'wpshop'), |
|
| 259 | + )); |
|
| 260 | 260 | |
| 261 | - if( !is_object($new_product_id) ) { |
|
| 261 | + if (!is_object($new_product_id)) { |
|
| 262 | 262 | $status = true; |
| 263 | 263 | } |
| 264 | - if ( !empty( $new_product_id ) ) { |
|
| 265 | - $product_attribute_set_id = ( !empty($_POST['attributes_set']) ) ? intval( $_POST['attributes_set'] ) : 1; |
|
| 266 | - update_post_meta( $new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id ); |
|
| 264 | + if (!empty($new_product_id)) { |
|
| 265 | + $product_attribute_set_id = (!empty($_POST['attributes_set'])) ? intval($_POST['attributes_set']) : 1; |
|
| 266 | + update_post_meta($new_product_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id', $product_attribute_set_id); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - echo json_encode( array( 'status' => $status, 'response' => $output, 'pagination' => $pagination ) ); |
|
| 269 | + echo json_encode(array('status' => $status, 'response' => $output, 'pagination' => $pagination)); |
|
| 270 | 270 | wp_die(); |
| 271 | 271 | } |
| 272 | 272 | |
@@ -274,32 +274,32 @@ discard block |
||
| 274 | 274 | * AJAX - Save datas |
| 275 | 275 | */ |
| 276 | 276 | function wps_save_product_quick_interface() { |
| 277 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 277 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 278 | 278 | |
| 279 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_save_product_quick_interface' ) ) |
|
| 279 | + if (!wp_verify_nonce($_wpnonce, 'wps_save_product_quick_interface')) |
|
| 280 | 280 | wp_die(); |
| 281 | 281 | |
| 282 | 282 | global $wpdb; |
| 283 | 283 | $response = ''; $status = false; |
| 284 | 284 | $count_products_to_update = 0; $total_updated_products = 0; |
| 285 | 285 | |
| 286 | - $wps_product_quick_save = !empty( $_REQUEST['wps_product_quick_save'] ) ? (array) $_REQUEST['wps_product_quick_save'] : array(); |
|
| 287 | - $wps_mass_interface = !empty( $_REQUEST['wps_mass_interface'] ) ? (array) $_REQUEST['wps_mass_interface'] : array(); |
|
| 288 | - $wpshop_product_attribute = !empty( $_REQUEST['wpshop_product_attribute'] ) ? (array) $_REQUEST['wpshop_product_attribute'] : array(); |
|
| 286 | + $wps_product_quick_save = !empty($_REQUEST['wps_product_quick_save']) ? (array)$_REQUEST['wps_product_quick_save'] : array(); |
|
| 287 | + $wps_mass_interface = !empty($_REQUEST['wps_mass_interface']) ? (array)$_REQUEST['wps_mass_interface'] : array(); |
|
| 288 | + $wpshop_product_attribute = !empty($_REQUEST['wpshop_product_attribute']) ? (array)$_REQUEST['wpshop_product_attribute'] : array(); |
|
| 289 | 289 | |
| 290 | 290 | // ------------------------------------------------------------------------------------------------------ |
| 291 | 291 | |
| 292 | - foreach( $_REQUEST['concur'] as $post_id => $columns ) { |
|
| 292 | + foreach ($_REQUEST['concur'] as $post_id => $columns) { |
|
| 293 | 293 | $concur = array(); |
| 294 | - for( $i = $count = 0; $i <= $count; $i++ ) { |
|
| 295 | - foreach( $columns as $key => $rows ) { |
|
| 296 | - $count = count( $rows )-1; |
|
| 294 | + for ($i = $count = 0; $i <= $count; $i++) { |
|
| 295 | + foreach ($columns as $key => $rows) { |
|
| 296 | + $count = count($rows) - 1; |
|
| 297 | 297 | $concur[$i][$key] = $rows[$i]; |
| 298 | 298 | } |
| 299 | - if( empty( $concur[$i]['is_row'] ) ) { |
|
| 300 | - unset( $concur[$i] ); |
|
| 299 | + if (empty($concur[$i]['is_row'])) { |
|
| 300 | + unset($concur[$i]); |
|
| 301 | 301 | } else { |
| 302 | - unset( $concur[$i]['is_row'] ); |
|
| 302 | + unset($concur[$i]['is_row']); |
|
| 303 | 303 | |
| 304 | 304 | $dotPos = strrpos($concur[$i]['price'], '.'); |
| 305 | 305 | $commaPos = strrpos($concur[$i]['price'], ','); |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | } else { |
| 310 | 310 | $concur[$i]['price'] = floatval( |
| 311 | 311 | preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], 0, $sep)) . '.' . |
| 312 | - preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep+1, strlen($concur[$i]['price']))) |
|
| 312 | + preg_replace("/[^0-9]/", "", substr($concur[$i]['price'], $sep + 1, strlen($concur[$i]['price']))) |
|
| 313 | 313 | ); |
| 314 | 314 | } |
| 315 | 315 | |
@@ -317,51 +317,51 @@ discard block |
||
| 317 | 317 | $concur[$i]['price'] = $concur[$i]['price']; |
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | - update_post_meta( $post_id, '_concur', $concur ); |
|
| 320 | + update_post_meta($post_id, '_concur', $concur); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // ------------------------------------------------------------------------------------------------------ |
| 324 | 324 | |
| 325 | - if( !empty($wps_product_quick_save) ) { |
|
| 326 | - $count_products_to_update = count( $wps_product_quick_save ); |
|
| 327 | - foreach( $wps_product_quick_save as $product_to_save ) { |
|
| 325 | + if (!empty($wps_product_quick_save)) { |
|
| 326 | + $count_products_to_update = count($wps_product_quick_save); |
|
| 327 | + foreach ($wps_product_quick_save as $product_to_save) { |
|
| 328 | 328 | $data_to_save = array(); |
| 329 | 329 | // Update post |
| 330 | - $updated_post = wp_update_post( array( 'ID' => $product_to_save, |
|
| 331 | - 'post_title' => sanitize_text_field( $wps_mass_interface[$product_to_save]['post_title'] ), |
|
| 332 | - 'post_content' => wp_kses_post( $wps_mass_interface[$product_to_save]['post_content'] ), |
|
| 330 | + $updated_post = wp_update_post(array('ID' => $product_to_save, |
|
| 331 | + 'post_title' => sanitize_text_field($wps_mass_interface[$product_to_save]['post_title']), |
|
| 332 | + 'post_content' => wp_kses_post($wps_mass_interface[$product_to_save]['post_content']), |
|
| 333 | 333 | ) |
| 334 | 334 | ); |
| 335 | 335 | // Update attributes |
| 336 | - if( !empty($updated_post) ) { |
|
| 336 | + if (!empty($updated_post)) { |
|
| 337 | 337 | // Update Featured picture |
| 338 | - if( !empty($wps_mass_interface[$product_to_save]['picture']) ) { |
|
| 339 | - $thumbnail_exist = get_post_meta( $updated_post, '_thumbnail_id', true ); |
|
| 340 | - if($wps_mass_interface[$product_to_save]['picture'] != 'deleted') { |
|
| 341 | - wp_update_post( array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post) ); |
|
| 342 | - update_post_meta( $updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture'] ); |
|
| 338 | + if (!empty($wps_mass_interface[$product_to_save]['picture'])) { |
|
| 339 | + $thumbnail_exist = get_post_meta($updated_post, '_thumbnail_id', true); |
|
| 340 | + if ($wps_mass_interface[$product_to_save]['picture'] != 'deleted') { |
|
| 341 | + wp_update_post(array('ID' => (int)$wps_mass_interface[$product_to_save]['picture'], 'post_parent' => $updated_post)); |
|
| 342 | + update_post_meta($updated_post, '_thumbnail_id', (int)$wps_mass_interface[$product_to_save]['picture']); |
|
| 343 | 343 | } |
| 344 | - elseif($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 345 | - delete_post_meta( $updated_post, '_thumbnail_id' ); |
|
| 344 | + elseif ($wps_mass_interface[$product_to_save]['picture'] == 'deleted' && !empty($thumbnail_exist)) { |
|
| 345 | + delete_post_meta($updated_post, '_thumbnail_id'); |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | // Update files datas |
| 350 | - if( !empty($wps_mass_interface[$product_to_save]['files']) ) { |
|
| 351 | - $files_data = explode( ',', sanitize_text_field( $_REQUEST['wps_mass_interface'][$product_to_save]['files'] ) ); |
|
| 352 | - if( !empty($files_data) && is_array($files_data) ) { |
|
| 353 | - foreach( $files_data as $file_id ) { |
|
| 354 | - if( !empty($file_id) ) { |
|
| 355 | - wp_update_post( array('ID' => $file_id, 'post_parent' => $updated_post) ); |
|
| 350 | + if (!empty($wps_mass_interface[$product_to_save]['files'])) { |
|
| 351 | + $files_data = explode(',', sanitize_text_field($_REQUEST['wps_mass_interface'][$product_to_save]['files'])); |
|
| 352 | + if (!empty($files_data) && is_array($files_data)) { |
|
| 353 | + foreach ($files_data as $file_id) { |
|
| 354 | + if (!empty($file_id)) { |
|
| 355 | + wp_update_post(array('ID' => $file_id, 'post_parent' => $updated_post)); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - $data_to_save['post_ID'] = $data_to_save['product_id'] = intval( $product_to_save ); |
|
| 362 | - $data_to_save['wpshop_product_attribute'] = ( !empty($wpshop_product_attribute[ $product_to_save ]) ) ? $wpshop_product_attribute[ $product_to_save ] : array(); |
|
| 361 | + $data_to_save['post_ID'] = $data_to_save['product_id'] = intval($product_to_save); |
|
| 362 | + $data_to_save['wpshop_product_attribute'] = (!empty($wpshop_product_attribute[$product_to_save])) ? $wpshop_product_attribute[$product_to_save] : array(); |
|
| 363 | 363 | |
| 364 | - if(empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) { |
|
| 364 | + if (empty($data_to_save['wpshop_product_attribute']['varchar']['barcode'])) { |
|
| 365 | 365 | // Get current barcode |
| 366 | 366 | $wps_product_mdl = new wps_product_mdl(); |
| 367 | 367 | $attid = wpshop_attributes::getElement('barcode', "'valid'", 'code')->id; |
@@ -372,34 +372,34 @@ discard block |
||
| 372 | 372 | $data_to_save['user_ID'] = get_current_user_id(); |
| 373 | 373 | $data_to_save['action'] = 'editpost'; |
| 374 | 374 | |
| 375 | - if( !empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true" ) { |
|
| 376 | - wp_trash_post( $product_to_save ); |
|
| 375 | + if (!empty($wps_mass_interface[$product_to_save]['post_delete']) && $wps_mass_interface[$product_to_save]['post_delete'] == "true") { |
|
| 376 | + wp_trash_post($product_to_save); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if( !empty($product_to_save) && !empty( $data_to_save['user_ID'] ) ) { |
|
| 379 | + if (!empty($product_to_save) && !empty($data_to_save['user_ID'])) { |
|
| 380 | 380 | $product_class = new wpshop_products(); |
| 381 | - $product_class->save_product_custom_informations( $product_to_save, $data_to_save ); |
|
| 381 | + $product_class->save_product_custom_informations($product_to_save, $data_to_save); |
|
| 382 | 382 | $total_updated_products++; |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | // Checking status |
| 388 | - $status = ( $total_updated_products == $count_products_to_update ) ? true : false; |
|
| 388 | + $status = ($total_updated_products == $count_products_to_update) ? true : false; |
|
| 389 | 389 | |
| 390 | - if( $status ) { |
|
| 391 | - $response = sprintf( __( '%d products have been successfully updated', 'wpshop'), $total_updated_products ); |
|
| 390 | + if ($status) { |
|
| 391 | + $response = sprintf(__('%d products have been successfully updated', 'wpshop'), $total_updated_products); |
|
| 392 | 392 | } |
| 393 | 393 | else { |
| 394 | - if( !empty($total_updated_products) ) { |
|
| 395 | - $response = sprintf( __( 'All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update ); |
|
| 394 | + if (!empty($total_updated_products)) { |
|
| 395 | + $response = sprintf(__('All selected products do not be updated. %d on %d products have been successfully updated', 'wpshop'), $total_updated_products, $count_products_to_update); |
|
| 396 | 396 | } |
| 397 | 397 | else { |
| 398 | - $response = __( 'No product have been updated', 'wpshop'); |
|
| 398 | + $response = __('No product have been updated', 'wpshop'); |
|
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - echo json_encode( array('status' => $status, 'response' => $response ) ); |
|
| 402 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 403 | 403 | wp_die(); |
| 404 | 404 | } |
| 405 | 405 | |
@@ -407,18 +407,18 @@ discard block |
||
| 407 | 407 | * Delete product list |
| 408 | 408 | **/ |
| 409 | 409 | function wps_mass_delete_file() { |
| 410 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 410 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 411 | 411 | |
| 412 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_delete_file' ) ) |
|
| 412 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_delete_file')) |
|
| 413 | 413 | wp_die(); |
| 414 | 414 | |
| 415 | 415 | $status = false; |
| 416 | - $file_id = (!empty($_POST['file_id']) ) ? intval($_POST['file_id']) : null; |
|
| 417 | - if( !empty($file_id) ) { |
|
| 418 | - wp_update_post( array('ID' => $file_id, 'post_parent' => 0) ); |
|
| 416 | + $file_id = (!empty($_POST['file_id'])) ? intval($_POST['file_id']) : null; |
|
| 417 | + if (!empty($file_id)) { |
|
| 418 | + wp_update_post(array('ID' => $file_id, 'post_parent' => 0)); |
|
| 419 | 419 | $status = true; |
| 420 | 420 | } |
| 421 | - echo json_encode( array( 'status' => $status ) ); |
|
| 421 | + echo json_encode(array('status' => $status)); |
|
| 422 | 422 | wp_die(); |
| 423 | 423 | } |
| 424 | 424 | |
@@ -426,32 +426,32 @@ discard block |
||
| 426 | 426 | * Update product files list |
| 427 | 427 | */ |
| 428 | 428 | function wps_mass_edit_update_files_list() { |
| 429 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 429 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 430 | 430 | |
| 431 | - if ( !wp_verify_nonce( $_wpnonce, 'wps_mass_edit_update_files_list' ) ) |
|
| 431 | + if (!wp_verify_nonce($_wpnonce, 'wps_mass_edit_update_files_list')) |
|
| 432 | 432 | wp_die(); |
| 433 | 433 | |
| 434 | 434 | $status = false; $response = ''; |
| 435 | - $product_id = ( !empty($_POST['product_id']) ) ? intval($_POST['product_id']) : null; |
|
| 436 | - $files = ( !empty($_POST['files']) ) ? intval($_POST['files']) : null; |
|
| 437 | - if( !empty($product_id ) ) { |
|
| 435 | + $product_id = (!empty($_POST['product_id'])) ? intval($_POST['product_id']) : null; |
|
| 436 | + $files = (!empty($_POST['files'])) ? intval($_POST['files']) : null; |
|
| 437 | + if (!empty($product_id)) { |
|
| 438 | 438 | // Update files datas |
| 439 | - if( !empty($files) ) { |
|
| 440 | - $files_data = explode( ',', $files ); |
|
| 441 | - if( !empty($files_data) && is_array($files_data) ) { |
|
| 442 | - foreach( $files_data as $file_id ) { |
|
| 443 | - if( !empty($file_id) ) { |
|
| 444 | - wp_update_post( array('ID' => $file_id, 'post_parent' => $product_id) ); |
|
| 439 | + if (!empty($files)) { |
|
| 440 | + $files_data = explode(',', $files); |
|
| 441 | + if (!empty($files_data) && is_array($files_data)) { |
|
| 442 | + foreach ($files_data as $file_id) { |
|
| 443 | + if (!empty($file_id)) { |
|
| 444 | + wp_update_post(array('ID' => $file_id, 'post_parent' => $product_id)); |
|
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
| 451 | - $response = $this->wps_product_attached_files( $product_id ); |
|
| 451 | + $response = $this->wps_product_attached_files($product_id); |
|
| 452 | 452 | $status = true; |
| 453 | 453 | } |
| 454 | - echo json_encode( array( 'status' => $status, 'response' => $response ) ); |
|
| 454 | + echo json_encode(array('status' => $status, 'response' => $response)); |
|
| 455 | 455 | wp_die(); |
| 456 | 456 | } |
| 457 | 457 | |
@@ -78,6 +78,11 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param string $slug |
|
| 84 | + * @param string $separator |
|
| 85 | + */ |
|
| 81 | 86 | private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) { |
| 82 | 87 | $childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) ); |
| 83 | 88 | foreach( $childs as $child ) { |
@@ -115,6 +120,11 @@ discard block |
||
| 115 | 120 | } |
| 116 | 121 | return $permalink; |
| 117 | 122 | } |
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param string $permalink |
|
| 126 | + * @param string $separator |
|
| 127 | + */ |
|
| 118 | 128 | private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) { |
| 119 | 129 | if( $term->parent == 0 ) { |
| 120 | 130 | $permalink = $term->slug . $separator . $permalink; |
@@ -220,6 +230,11 @@ discard block |
||
| 220 | 230 | } |
| 221 | 231 | } |
| 222 | 232 | } |
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @param string $slug |
|
| 236 | + * @param string $separator |
|
| 237 | + */ |
|
| 223 | 238 | private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) { |
| 224 | 239 | $rewrite[] = $slug . $parent->slug . $separator; |
| 225 | 240 | $childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) ); |
@@ -281,6 +296,11 @@ discard block |
||
| 281 | 296 | } |
| 282 | 297 | return $permalink; |
| 283 | 298 | } |
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param string $permalink |
|
| 302 | + * @param string $separator |
|
| 303 | + */ |
|
| 284 | 304 | private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) { |
| 285 | 305 | if( $term->parent == 0 ) { |
| 286 | 306 | $permalink = $term->slug . $separator . $permalink; |
@@ -1,15 +1,15 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | |
| 3 | 3 | // Rewrite wpshop_categories |
| 4 | -$options = get_option( 'wpshop_catalog_categories_option', null ); |
|
| 4 | +$options = get_option('wpshop_catalog_categories_option', null); |
|
| 5 | 5 | $slug = !empty($options['wpshop_catalog_categories_slug']) ? $options['wpshop_catalog_categories_slug'] : WPSHOP_CATALOG_PRODUCT_NO_CATEGORY; |
| 6 | -( empty( $options['wpshop_catalog_categories_slug'] ) || $options['wpshop_catalog_categories_slug'] == '/' ) ? new Custom_Taxonomy_Rewrite( WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $slug, false ) : false; |
|
| 6 | +(empty($options['wpshop_catalog_categories_slug']) || $options['wpshop_catalog_categories_slug'] == '/') ? new Custom_Taxonomy_Rewrite(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $slug, false) : false; |
|
| 7 | 7 | |
| 8 | 8 | // Rewrite wpshop_products |
| 9 | -$options = get_option( 'wpshop_catalog_product_option', null ); |
|
| 10 | -$slug = !empty( $options['wpshop_catalog_product_slug'] ) ? $options['wpshop_catalog_product_slug'] : '/'; |
|
| 11 | -$categories = !empty( $options['wpshop_catalog_product_slug_with_category'] ); |
|
| 12 | -( empty( $options['wpshop_catalog_product_slug'] ) || $options['wpshop_catalog_product_slug'] == '/' ) ? new Custom_Post_Type_Rewrite( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, $slug, $categories ) : false; |
|
| 9 | +$options = get_option('wpshop_catalog_product_option', null); |
|
| 10 | +$slug = !empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : '/'; |
|
| 11 | +$categories = !empty($options['wpshop_catalog_product_slug_with_category']); |
|
| 12 | +(empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') ? new Custom_Post_Type_Rewrite(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, $slug, $categories) : false; |
|
| 13 | 13 | |
| 14 | 14 | class Custom_Taxonomy_Rewrite { |
| 15 | 15 | private $post_type; |
@@ -17,95 +17,95 @@ discard block |
||
| 17 | 17 | private $enable_rewrites; |
| 18 | 18 | private $use_slug; |
| 19 | 19 | private $use_hierarchy_cat_slug; |
| 20 | - public function __construct( $taxonomy, $post_type, $slug = '/', $hierarchy = false ) { |
|
| 20 | + public function __construct($taxonomy, $post_type, $slug = '/', $hierarchy = false) { |
|
| 21 | 21 | $this->post_type = $post_type; |
| 22 | 22 | $this->taxonomy = $taxonomy; |
| 23 | 23 | $this->use_slug = $slug; |
| 24 | 24 | $this->use_hierarchy_cat_slug = $hierarchy; |
| 25 | - add_action( 'init', array( $this, 'rewrite' ), 11 ); |
|
| 26 | - add_action( 'created_' . $this->taxonomy, array( $this, 'flush_rewrite' ) ); |
|
| 27 | - add_action( 'edited_' . $this->taxonomy, array( $this, 'flush_rewrite' ) ); |
|
| 28 | - add_action( 'delete_' . $this->taxonomy, array( $this, 'flush_rewrite' ) ); |
|
| 29 | - add_filter( 'term_link', array( $this, 'permalink' ), 10, 3 ); |
|
| 25 | + add_action('init', array($this, 'rewrite'), 11); |
|
| 26 | + add_action('created_' . $this->taxonomy, array($this, 'flush_rewrite')); |
|
| 27 | + add_action('edited_' . $this->taxonomy, array($this, 'flush_rewrite')); |
|
| 28 | + add_action('delete_' . $this->taxonomy, array($this, 'flush_rewrite')); |
|
| 29 | + add_filter('term_link', array($this, 'permalink'), 10, 3); |
|
| 30 | 30 | } |
| 31 | 31 | public function rewrite() { |
| 32 | 32 | global $wp_rewrite; |
| 33 | 33 | $this->enable_rewrites = $wp_rewrite->use_trailing_slashes; |
| 34 | - if( $this->enable_rewrites ) { |
|
| 35 | - if( empty( $this->use_slug ) || $this->use_slug == '/' ) { |
|
| 36 | - if( $this->use_hierarchy_cat_slug ) { |
|
| 34 | + if ($this->enable_rewrites) { |
|
| 35 | + if (empty($this->use_slug) || $this->use_slug == '/') { |
|
| 36 | + if ($this->use_hierarchy_cat_slug) { |
|
| 37 | 37 | $slug = ''; |
| 38 | 38 | $rewrite = array(); |
| 39 | - $terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) ); |
|
| 40 | - foreach( $terms as $term ) { |
|
| 41 | - $this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' ); |
|
| 39 | + $terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false)); |
|
| 40 | + foreach ($terms as $term) { |
|
| 41 | + $this->rewrite_term_hierarchy($term, $rewrite, $slug, '/'); |
|
| 42 | 42 | } |
| 43 | - foreach( $rewrite as $way ) { |
|
| 44 | - add_rewrite_rule( $way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 45 | - add_rewrite_rule( $way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 46 | - add_rewrite_rule( $way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' ); |
|
| 47 | - add_rewrite_rule( $way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' ); |
|
| 43 | + foreach ($rewrite as $way) { |
|
| 44 | + add_rewrite_rule($way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 45 | + add_rewrite_rule($way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 46 | + add_rewrite_rule($way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top'); |
|
| 47 | + add_rewrite_rule($way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top'); |
|
| 48 | 48 | } |
| 49 | 49 | } else { |
| 50 | - $terms = get_terms( $this->taxonomy, array( 'fields' => 'id=>slug', 'hide_empty' => false ) ); |
|
| 51 | - foreach( $terms as $term ) { |
|
| 52 | - add_rewrite_rule( '(' . $term . ')/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 53 | - add_rewrite_rule( '(' . $term . ')/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 54 | - add_rewrite_rule( '(' . $term . ')/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' ); |
|
| 55 | - add_rewrite_rule( '(' . $term . ')/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' ); |
|
| 50 | + $terms = get_terms($this->taxonomy, array('fields' => 'id=>slug', 'hide_empty' => false)); |
|
| 51 | + foreach ($terms as $term) { |
|
| 52 | + add_rewrite_rule('(' . $term . ')/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 53 | + add_rewrite_rule('(' . $term . ')/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 54 | + add_rewrite_rule('(' . $term . ')/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top'); |
|
| 55 | + add_rewrite_rule('(' . $term . ')/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top'); |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | } else { |
| 59 | - if( $this->use_hierarchy_cat_slug ) { |
|
| 59 | + if ($this->use_hierarchy_cat_slug) { |
|
| 60 | 60 | $slug = '/'; |
| 61 | 61 | $rewrite = array(); |
| 62 | - $terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) ); |
|
| 63 | - foreach( $terms as $term ) { |
|
| 64 | - $this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' ); |
|
| 62 | + $terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false)); |
|
| 63 | + foreach ($terms as $term) { |
|
| 64 | + $this->rewrite_term_hierarchy($term, $rewrite, $slug, '/'); |
|
| 65 | 65 | } |
| 66 | - foreach( $rewrite as $way ) { |
|
| 67 | - add_rewrite_rule( $this->use_slug . $way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 68 | - add_rewrite_rule( $this->use_slug . $way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 69 | - add_rewrite_rule( $this->use_slug . $way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' ); |
|
| 70 | - add_rewrite_rule( $this->use_slug . $way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' ); |
|
| 66 | + foreach ($rewrite as $way) { |
|
| 67 | + add_rewrite_rule($this->use_slug . $way . 'feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 68 | + add_rewrite_rule($this->use_slug . $way . '(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 69 | + add_rewrite_rule($this->use_slug . $way . 'page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top'); |
|
| 70 | + add_rewrite_rule($this->use_slug . $way . '?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top'); |
|
| 71 | 71 | } |
| 72 | 72 | } else { |
| 73 | - add_rewrite_rule( $this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 74 | - add_rewrite_rule( $this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 75 | - add_rewrite_rule( $this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top' ); |
|
| 76 | - add_rewrite_rule( $this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top' ); |
|
| 73 | + add_rewrite_rule($this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 74 | + add_rewrite_rule($this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 75 | + add_rewrite_rule($this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->taxonomy . '=$matches[1]&paged=$matches[2]', 'top'); |
|
| 76 | + add_rewrite_rule($this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->taxonomy . '=$matches[1]', 'top'); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | - private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) { |
|
| 82 | - $childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) ); |
|
| 83 | - foreach( $childs as $child ) { |
|
| 84 | - $this->rewrite_term_hierarchy( $child, $rewrite, $slug . $parent->slug . $separator, $separator ); |
|
| 81 | + private function rewrite_term_hierarchy($parent, &$rewrite, $slug, $separator) { |
|
| 82 | + $childs = get_terms($this->taxonomy, array('parent' => $parent->term_id, 'hide_empty' => false)); |
|
| 83 | + foreach ($childs as $child) { |
|
| 84 | + $this->rewrite_term_hierarchy($child, $rewrite, $slug . $parent->slug . $separator, $separator); |
|
| 85 | 85 | } |
| 86 | 86 | $rewrite[] = $slug . '(' . $parent->slug . ')' . $separator; |
| 87 | 87 | } |
| 88 | 88 | public function flush_rewrite() { |
| 89 | - if( $this->enable_rewrites ) { |
|
| 89 | + if ($this->enable_rewrites) { |
|
| 90 | 90 | $this->rewrite(); |
| 91 | 91 | flush_rewrite_rules(); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | - public function permalink( $permalink, $term, $taxonomy ) { |
|
| 95 | - if( $this->enable_rewrites ) { |
|
| 96 | - if( $taxonomy === $this->taxonomy ) { |
|
| 97 | - if( empty( $this->use_slug ) || $this->use_slug == '/' ) { |
|
| 98 | - if( $this->use_hierarchy_cat_slug ) { |
|
| 94 | + public function permalink($permalink, $term, $taxonomy) { |
|
| 95 | + if ($this->enable_rewrites) { |
|
| 96 | + if ($taxonomy === $this->taxonomy) { |
|
| 97 | + if (empty($this->use_slug) || $this->use_slug == '/') { |
|
| 98 | + if ($this->use_hierarchy_cat_slug) { |
|
| 99 | 99 | $term_permalink = ''; |
| 100 | - $this->permalink_term_hierarchy( $term, $term_permalink, $taxonomy, '/' ); |
|
| 100 | + $this->permalink_term_hierarchy($term, $term_permalink, $taxonomy, '/'); |
|
| 101 | 101 | $permalink = get_site_url() . '/' . $term_permalink; |
| 102 | 102 | } else { |
| 103 | 103 | $permalink = get_site_url() . '/' . $term->slug; |
| 104 | 104 | } |
| 105 | 105 | } else { |
| 106 | - if( $this->use_hierarchy_cat_slug ) { |
|
| 106 | + if ($this->use_hierarchy_cat_slug) { |
|
| 107 | 107 | $term_permalink = ''; |
| 108 | - $this->permalink_term_hierarchy( $term, $term_permalink, $taxonomy, '/' ); |
|
| 108 | + $this->permalink_term_hierarchy($term, $term_permalink, $taxonomy, '/'); |
|
| 109 | 109 | $permalink = get_site_url() . '/' . $this->use_slug . '/' . $term_permalink; |
| 110 | 110 | } else { |
| 111 | 111 | $permalink = get_site_url() . '/' . $this->use_slug . '/' . $term->slug; |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | return $permalink; |
| 117 | 117 | } |
| 118 | - private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) { |
|
| 119 | - if( $term->parent == 0 ) { |
|
| 118 | + private function permalink_term_hierarchy($term, &$permalink, $taxonomy, $separator) { |
|
| 119 | + if ($term->parent == 0) { |
|
| 120 | 120 | $permalink = $term->slug . $separator . $permalink; |
| 121 | 121 | } else { |
| 122 | 122 | $permalink = $term->slug . $separator . $permalink; |
| 123 | - $term_parent = get_term( $term->parent, $taxonomy ); |
|
| 124 | - $this->permalink_term_hierarchy( $term_parent, $permalink, $taxonomy, $separator ); |
|
| 123 | + $term_parent = get_term($term->parent, $taxonomy); |
|
| 124 | + $this->permalink_term_hierarchy($term_parent, $permalink, $taxonomy, $separator); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -133,122 +133,122 @@ discard block |
||
| 133 | 133 | private $use_slug; |
| 134 | 134 | private $use_cat_slug; |
| 135 | 135 | private $use_hierarchy_cat_slug; |
| 136 | - public function __construct( $post_type, $taxonomy, $slug = '/', $categories = false ) { |
|
| 136 | + public function __construct($post_type, $taxonomy, $slug = '/', $categories = false) { |
|
| 137 | 137 | $this->post_type = $post_type; |
| 138 | 138 | $this->taxonomy = $taxonomy; |
| 139 | 139 | $this->use_slug = $slug; |
| 140 | - if( is_bool( $categories ) ) { |
|
| 140 | + if (is_bool($categories)) { |
|
| 141 | 141 | $this->use_cat_slug = $categories; |
| 142 | 142 | $this->use_hierarchy_cat_slug = false; |
| 143 | - } elseif( $categories == 'hierarchy' ) { |
|
| 143 | + } elseif ($categories == 'hierarchy') { |
|
| 144 | 144 | $this->use_cat_slug = true; |
| 145 | 145 | $this->use_hierarchy_cat_slug = true; |
| 146 | 146 | } |
| 147 | - add_action( 'init', array( $this, 'rewrite' ), 11 ); |
|
| 148 | - add_action( 'created_' . $this->taxonomy, array( $this, 'flush_rewrite' ) ); |
|
| 149 | - add_action( 'edited_' . $this->taxonomy, array( $this, 'flush_rewrite' ) ); |
|
| 150 | - add_action( 'delete_' . $this->taxonomy, array( $this, 'flush_rewrite' ) ); |
|
| 151 | - add_filter( 'post_type_link', array( $this, 'permalink' ), 10, 3 ); |
|
| 152 | - add_action( 'pre_get_posts', array( $this, 'query' ) ); |
|
| 147 | + add_action('init', array($this, 'rewrite'), 11); |
|
| 148 | + add_action('created_' . $this->taxonomy, array($this, 'flush_rewrite')); |
|
| 149 | + add_action('edited_' . $this->taxonomy, array($this, 'flush_rewrite')); |
|
| 150 | + add_action('delete_' . $this->taxonomy, array($this, 'flush_rewrite')); |
|
| 151 | + add_filter('post_type_link', array($this, 'permalink'), 10, 3); |
|
| 152 | + add_action('pre_get_posts', array($this, 'query')); |
|
| 153 | 153 | } |
| 154 | 154 | public function rewrite() { |
| 155 | 155 | global $wp_rewrite; |
| 156 | 156 | $this->enable_rewrites = $wp_rewrite->use_trailing_slashes; |
| 157 | - if( $this->enable_rewrites ) { |
|
| 158 | - if( empty( $this->use_slug ) || $this->use_slug == '/' ) { |
|
| 159 | - if( $this->use_cat_slug ) { |
|
| 160 | - if( $this->use_hierarchy_cat_slug ) { |
|
| 157 | + if ($this->enable_rewrites) { |
|
| 158 | + if (empty($this->use_slug) || $this->use_slug == '/') { |
|
| 159 | + if ($this->use_cat_slug) { |
|
| 160 | + if ($this->use_hierarchy_cat_slug) { |
|
| 161 | 161 | add_rewrite_tag('%taxonomies%', '(.*)'); |
| 162 | 162 | $slug = '('; |
| 163 | 163 | $rewrite = array(); |
| 164 | - $terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) ); |
|
| 165 | - foreach( $terms as $term ) { |
|
| 166 | - $this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' ); |
|
| 164 | + $terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false)); |
|
| 165 | + foreach ($terms as $term) { |
|
| 166 | + $this->rewrite_term_hierarchy($term, $rewrite, $slug, '/'); |
|
| 167 | 167 | } |
| 168 | - foreach( array_reverse( $rewrite ) as $way ) { |
|
| 169 | - add_rewrite_rule( $way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' ); |
|
| 170 | - add_rewrite_rule( $way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' ); |
|
| 171 | - add_rewrite_rule( $way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' ); |
|
| 172 | - add_rewrite_rule( $way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' ); |
|
| 168 | + foreach (array_reverse($rewrite) as $way) { |
|
| 169 | + add_rewrite_rule($way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top'); |
|
| 170 | + add_rewrite_rule($way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top'); |
|
| 171 | + add_rewrite_rule($way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top'); |
|
| 172 | + add_rewrite_rule($way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top'); |
|
| 173 | 173 | } |
| 174 | 174 | } else { |
| 175 | 175 | add_rewrite_tag('%taxonomies%', '(.*)'); |
| 176 | - $terms = get_terms( $this->taxonomy, array( 'fields' => 'id=>slug', 'hide_empty' => false ) ); |
|
| 177 | - foreach( $terms as $term ) { |
|
| 178 | - add_rewrite_rule( '(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' ); |
|
| 179 | - add_rewrite_rule( '(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' ); |
|
| 180 | - add_rewrite_rule( '(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' ); |
|
| 181 | - add_rewrite_rule( '(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' ); |
|
| 176 | + $terms = get_terms($this->taxonomy, array('fields' => 'id=>slug', 'hide_empty' => false)); |
|
| 177 | + foreach ($terms as $term) { |
|
| 178 | + add_rewrite_rule('(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top'); |
|
| 179 | + add_rewrite_rule('(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top'); |
|
| 180 | + add_rewrite_rule('(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top'); |
|
| 181 | + add_rewrite_rule('(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top'); |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | } /*else { |
| 185 | 185 | Only in the query func |
| 186 | 186 | } */ |
| 187 | 187 | } else { |
| 188 | - if( $this->use_cat_slug ) { |
|
| 189 | - if( $this->use_hierarchy_cat_slug ) { |
|
| 188 | + if ($this->use_cat_slug) { |
|
| 189 | + if ($this->use_hierarchy_cat_slug) { |
|
| 190 | 190 | add_rewrite_tag('%taxonomies%', '(.*)'); |
| 191 | 191 | $slug = '/('; |
| 192 | 192 | $rewrite = array(); |
| 193 | - $terms = get_terms( $this->taxonomy, array( 'parent' => 0, 'hide_empty' => false ) ); |
|
| 194 | - foreach( $terms as $term ) { |
|
| 195 | - $this->rewrite_term_hierarchy( $term, $rewrite, $slug, '/' ); |
|
| 193 | + $terms = get_terms($this->taxonomy, array('parent' => 0, 'hide_empty' => false)); |
|
| 194 | + foreach ($terms as $term) { |
|
| 195 | + $this->rewrite_term_hierarchy($term, $rewrite, $slug, '/'); |
|
| 196 | 196 | } |
| 197 | - foreach( array_reverse( $rewrite ) as $way ) { |
|
| 198 | - add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' ); |
|
| 199 | - add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' ); |
|
| 200 | - add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' ); |
|
| 201 | - add_rewrite_rule( $this->use_slug . $way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' ); |
|
| 197 | + foreach (array_reverse($rewrite) as $way) { |
|
| 198 | + add_rewrite_rule($this->use_slug . $way . ')([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top'); |
|
| 199 | + add_rewrite_rule($this->use_slug . $way . ')([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top'); |
|
| 200 | + add_rewrite_rule($this->use_slug . $way . ')([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top'); |
|
| 201 | + add_rewrite_rule($this->use_slug . $way . ')([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top'); |
|
| 202 | 202 | } |
| 203 | 203 | } else { |
| 204 | 204 | add_rewrite_tag('%taxonomies%', '(.*)'); |
| 205 | - $terms = get_terms( $this->taxonomy, array( 'fields' => 'id=>slug', 'hide_empty' => false ) ); |
|
| 206 | - foreach( $terms as $term ) { |
|
| 207 | - add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' ); |
|
| 208 | - add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top' ); |
|
| 209 | - add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top' ); |
|
| 210 | - add_rewrite_rule( $this->use_slug . '/(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top' ); |
|
| 205 | + $terms = get_terms($this->taxonomy, array('fields' => 'id=>slug', 'hide_empty' => false)); |
|
| 206 | + foreach ($terms as $term) { |
|
| 207 | + add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top'); |
|
| 208 | + add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&feed=$matches[3]', 'top'); |
|
| 209 | + add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]&paged=$matches[3]', 'top'); |
|
| 210 | + add_rewrite_rule($this->use_slug . '/(' . $term . ')/([^/]+)/?$', 'index.php?taxonomies=$matches[1]&' . $this->post_type . '=$matches[2]', 'top'); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | } else { |
| 214 | - add_rewrite_rule( $this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 215 | - add_rewrite_rule( $this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top' ); |
|
| 216 | - add_rewrite_rule( $this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->post_type . '=$matches[1]&paged=$matches[2]', 'top' ); |
|
| 217 | - add_rewrite_rule( $this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->post_type . '=$matches[1]', 'top' ); |
|
| 214 | + add_rewrite_rule($this->use_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 215 | + add_rewrite_rule($this->use_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $this->post_type . '=$matches[1]&feed=$matches[2]', 'top'); |
|
| 216 | + add_rewrite_rule($this->use_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?' . $this->post_type . '=$matches[1]&paged=$matches[2]', 'top'); |
|
| 217 | + add_rewrite_rule($this->use_slug . '/([^/]+)/?$', 'index.php?' . $this->post_type . '=$matches[1]', 'top'); |
|
| 218 | 218 | //'rewrite' => array( 'slug' => $this->post_type ) || true |
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | - private function rewrite_term_hierarchy( $parent, &$rewrite, $slug, $separator ) { |
|
| 223 | + private function rewrite_term_hierarchy($parent, &$rewrite, $slug, $separator) { |
|
| 224 | 224 | $rewrite[] = $slug . $parent->slug . $separator; |
| 225 | - $childs = get_terms( $this->taxonomy, array( 'parent' => $parent->term_id, 'hide_empty' => false ) ); |
|
| 226 | - foreach( $childs as $child ) { |
|
| 227 | - $this->rewrite_term_hierarchy( $child, $rewrite, $slug . $parent->slug . $separator, $separator ); |
|
| 225 | + $childs = get_terms($this->taxonomy, array('parent' => $parent->term_id, 'hide_empty' => false)); |
|
| 226 | + foreach ($childs as $child) { |
|
| 227 | + $this->rewrite_term_hierarchy($child, $rewrite, $slug . $parent->slug . $separator, $separator); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | public function flush_rewrite() { |
| 231 | - if( $this->enable_rewrites ) { |
|
| 231 | + if ($this->enable_rewrites) { |
|
| 232 | 232 | $this->rewrite(); |
| 233 | 233 | flush_rewrite_rules(); |
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | - public function permalink( $permalink, $post, $leavename ) { |
|
| 237 | - if( $this->enable_rewrites ) { |
|
| 238 | - if( $post->post_type == $this->post_type ) { |
|
| 239 | - if( empty( $this->use_slug ) || $this->use_slug == '/' ) { |
|
| 240 | - if( $this->use_cat_slug ) { |
|
| 241 | - if( $this->use_hierarchy_cat_slug ) { |
|
| 242 | - $terms = get_the_terms( $post->ID, $this->taxonomy ); |
|
| 243 | - if( !empty( $terms ) ) { |
|
| 236 | + public function permalink($permalink, $post, $leavename) { |
|
| 237 | + if ($this->enable_rewrites) { |
|
| 238 | + if ($post->post_type == $this->post_type) { |
|
| 239 | + if (empty($this->use_slug) || $this->use_slug == '/') { |
|
| 240 | + if ($this->use_cat_slug) { |
|
| 241 | + if ($this->use_hierarchy_cat_slug) { |
|
| 242 | + $terms = get_the_terms($post->ID, $this->taxonomy); |
|
| 243 | + if (!empty($terms)) { |
|
| 244 | 244 | $term = $terms[0]; |
| 245 | 245 | $post_permalink = ''; |
| 246 | - $this->permalink_term_hierarchy( $term, $post_permalink, $this->taxonomy, '/' ); |
|
| 246 | + $this->permalink_term_hierarchy($term, $post_permalink, $this->taxonomy, '/'); |
|
| 247 | 247 | $permalink = get_site_url() . '/' . $post_permalink . $post->post_name . '/'; |
| 248 | 248 | } |
| 249 | 249 | } else { |
| 250 | - $terms = get_the_terms( $post->ID, $this->taxonomy ); |
|
| 251 | - if( !empty( $terms ) ) { |
|
| 250 | + $terms = get_the_terms($post->ID, $this->taxonomy); |
|
| 251 | + if (!empty($terms)) { |
|
| 252 | 252 | $term = $terms[0]; |
| 253 | 253 | $permalink = get_site_url() . '/' . $term->slug . '/' . $post->post_name . '/'; |
| 254 | 254 | } |
@@ -257,18 +257,18 @@ discard block |
||
| 257 | 257 | $permalink = get_site_url() . '/' . $post->post_name . '/'; |
| 258 | 258 | } |
| 259 | 259 | } else { |
| 260 | - if( $this->use_cat_slug ) { |
|
| 261 | - if( $this->use_hierarchy_cat_slug ) { |
|
| 262 | - $terms = get_the_terms( $post->ID, $this->taxonomy ); |
|
| 263 | - if( !empty( $terms ) ) { |
|
| 260 | + if ($this->use_cat_slug) { |
|
| 261 | + if ($this->use_hierarchy_cat_slug) { |
|
| 262 | + $terms = get_the_terms($post->ID, $this->taxonomy); |
|
| 263 | + if (!empty($terms)) { |
|
| 264 | 264 | $term = $terms[0]; |
| 265 | 265 | $post_permalink = ''; |
| 266 | - $this->permalink_term_hierarchy( $term, $post_permalink, $this->taxonomy, '/' ); |
|
| 266 | + $this->permalink_term_hierarchy($term, $post_permalink, $this->taxonomy, '/'); |
|
| 267 | 267 | $permalink = get_site_url() . '/' . $this->use_slug . '/' . $post_permalink . $post->post_name . '/'; |
| 268 | 268 | } |
| 269 | 269 | } else { |
| 270 | - $terms = get_the_terms( $post->ID, $this->taxonomy ); |
|
| 271 | - if( !empty( $terms ) ) { |
|
| 270 | + $terms = get_the_terms($post->ID, $this->taxonomy); |
|
| 271 | + if (!empty($terms)) { |
|
| 272 | 272 | $term = $terms[0]; |
| 273 | 273 | $permalink = get_site_url() . '/' . $this->use_slug . '/' . $term->slug . '/' . $post->post_name . '/'; |
| 274 | 274 | } |
@@ -281,20 +281,20 @@ discard block |
||
| 281 | 281 | } |
| 282 | 282 | return $permalink; |
| 283 | 283 | } |
| 284 | - private function permalink_term_hierarchy( $term, &$permalink, $taxonomy, $separator ) { |
|
| 285 | - if( $term->parent == 0 ) { |
|
| 284 | + private function permalink_term_hierarchy($term, &$permalink, $taxonomy, $separator) { |
|
| 285 | + if ($term->parent == 0) { |
|
| 286 | 286 | $permalink = $term->slug . $separator . $permalink; |
| 287 | 287 | } else { |
| 288 | 288 | $permalink = $term->slug . $separator . $permalink; |
| 289 | - $term_parent = get_term( $term->parent, $taxonomy ); |
|
| 290 | - $this->permalink_term_hierarchy( $term_parent, $permalink, $taxonomy, $separator ); |
|
| 289 | + $term_parent = get_term($term->parent, $taxonomy); |
|
| 290 | + $this->permalink_term_hierarchy($term_parent, $permalink, $taxonomy, $separator); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | - public function query( $query ) { |
|
| 294 | - if( $this->enable_rewrites ) { |
|
| 295 | - if ( empty( $this->use_slug ) || $this->use_slug == '/' && !$this->use_cat_slug ) { |
|
| 296 | - if ( !is_admin() && $query->is_main_query() && !isset( $query->page ) && count( $query->query ) == 2 ) { |
|
| 297 | - $query->set('post_type', array( 'page', 'post', $this->post_type ) ); |
|
| 293 | + public function query($query) { |
|
| 294 | + if ($this->enable_rewrites) { |
|
| 295 | + if (empty($this->use_slug) || $this->use_slug == '/' && !$this->use_cat_slug) { |
|
| 296 | + if (!is_admin() && $query->is_main_query() && !isset($query->page) && count($query->query) == 2) { |
|
| 297 | + $query->set('post_type', array('page', 'post', $this->post_type)); |
|
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | } |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | |
| 3 | 5 | // Rewrite wpshop_categories |
| 4 | 6 | $options = get_option( 'wpshop_catalog_categories_option', null ); |
@@ -131,6 +131,7 @@ discard block |
||
| 131 | 131 | /** |
| 132 | 132 | * Construct the element when it's a text Data |
| 133 | 133 | * @param StdObject $attribute_def |
| 134 | + * @param integer $category_id |
|
| 134 | 135 | * @return string |
| 135 | 136 | */ |
| 136 | 137 | function get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_child ) { |
@@ -155,6 +156,7 @@ discard block |
||
| 155 | 156 | /** |
| 156 | 157 | * Construct the element when it's a list Data |
| 157 | 158 | * @param StdObject $attribute_def |
| 159 | + * @param integer $category_id |
|
| 158 | 160 | * @return string |
| 159 | 161 | */ |
| 160 | 162 | function get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_child, $field_type, $type = 'select') { |
@@ -241,6 +243,7 @@ discard block |
||
| 241 | 243 | /** |
| 242 | 244 | * Construct the element when it's a decimal Data |
| 243 | 245 | * @param StdObject $attribute_def |
| 246 | + * @param integer $category_id |
|
| 244 | 247 | * @return string |
| 245 | 248 | */ |
| 246 | 249 | function get_filter_element_for_integer_data ( $attribute_def, $category_id, $current_category_children ) { |
@@ -268,7 +271,7 @@ discard block |
||
| 268 | 271 | * Save Products attribute values for List attribute data for a products category |
| 269 | 272 | * @param integer $category_id |
| 270 | 273 | * @param std_object $attribute_def |
| 271 | - * @param array $current_category_child |
|
| 274 | + * @param array $current_category_children |
|
| 272 | 275 | */ |
| 273 | 276 | function save_values_for_list_filterable_attribute( $category_id, $attribute_def, $current_category_children ) { |
| 274 | 277 | global $wpdb; |
@@ -462,7 +465,6 @@ discard block |
||
| 462 | 465 | |
| 463 | 466 | /** |
| 464 | 467 | * Save values for attributes |
| 465 | - * @param unknown_type $values |
|
| 466 | 468 | */ |
| 467 | 469 | function stock_values_for_attribute( $categories_id = array() ) { |
| 468 | 470 | @set_time_limit( 900 ); |
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | class wps_filter_search { |
| 3 | 3 | |
| 4 | 4 | /** Define the main directory containing the template for the current plugin |
| 5 | - * @var string |
|
| 6 | - */ |
|
| 5 | + * @var string |
|
| 6 | + */ |
|
| 7 | 7 | private $template_dir; |
| 8 | 8 | /** |
| 9 | 9 | * Define the directory name for the module in order to check into frontend |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_filter_search { |
| 3 | 3 | |
| 4 | 4 | /** Define the main directory containing the template for the current plugin |
@@ -16,24 +16,24 @@ discard block |
||
| 16 | 16 | // Template Load |
| 17 | 17 | $this->template_dir = WPS_SEARCH_PATH . WPS_SEARCH_DIR . "/templates/"; |
| 18 | 18 | // Display Filter search |
| 19 | - add_shortcode('wpshop_filter_search', array( $this, 'display_filter_search')); |
|
| 19 | + add_shortcode('wpshop_filter_search', array($this, 'display_filter_search')); |
|
| 20 | 20 | |
| 21 | 21 | // WP General actions |
| 22 | 22 | add_action('save_post', 'wps_filter_search::save_displayed_price_meta'); |
| 23 | 23 | add_action('save_post', array(&$this, 'stock_values_for_attribute')); |
| 24 | 24 | |
| 25 | 25 | // Add scripts |
| 26 | - add_action( 'wp_enqueue_scripts', array( &$this, 'add_frontend_scripts' ) ); |
|
| 26 | + add_action('wp_enqueue_scripts', array(&$this, 'add_frontend_scripts')); |
|
| 27 | 27 | |
| 28 | 28 | // Ajax Actions |
| 29 | - add_action('wp_ajax_filter_search_action',array(&$this, 'wpshop_ajax_filter_search_action')); |
|
| 30 | - add_action('wp_ajax_nopriv_filter_search_action',array(&$this, 'wpshop_ajax_filter_search_action')); |
|
| 29 | + add_action('wp_ajax_filter_search_action', array(&$this, 'wpshop_ajax_filter_search_action')); |
|
| 30 | + add_action('wp_ajax_nopriv_filter_search_action', array(&$this, 'wpshop_ajax_filter_search_action')); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
| 34 | 34 | function add_frontend_scripts() { |
| 35 | - wp_enqueue_script( 'wpshop_filter_search_chosen', WPSHOP_JS_URL.'jquery-libs/chosen.jquery.min.js' ); |
|
| 36 | - wp_enqueue_script( 'wpshop_filter_search_js', WPS_SEARCH_URL.WPS_SEARCH_DIR.'/assets/filter_search/js/wpshop_filter_search.js' ); |
|
| 35 | + wp_enqueue_script('wpshop_filter_search_chosen', WPSHOP_JS_URL . 'jquery-libs/chosen.jquery.min.js'); |
|
| 36 | + wp_enqueue_script('wpshop_filter_search_js', WPS_SEARCH_URL . WPS_SEARCH_DIR . '/assets/filter_search/js/wpshop_filter_search.js'); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * Display Filter search interface |
| 42 | 42 | * @return string |
| 43 | 43 | */ |
| 44 | - function display_filter_search () { |
|
| 44 | + function display_filter_search() { |
|
| 45 | 45 | global $wp_query; |
| 46 | 46 | $output = ''; |
| 47 | - if ( !empty($wp_query) && !empty($wp_query->queried_object_id) ) { |
|
| 47 | + if (!empty($wp_query) && !empty($wp_query->queried_object_id)) { |
|
| 48 | 48 | $category_id = $wp_query->queried_object_id; |
| 49 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
| 50 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) ) { |
|
| 51 | - $output = $this->construct_wpshop_filter_search_interface( $category_id ); |
|
| 49 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
| 50 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes'])) { |
|
| 51 | + $output = $this->construct_wpshop_filter_search_interface($category_id); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | return $output; |
@@ -59,19 +59,19 @@ discard block |
||
| 59 | 59 | * @param integer $category_id |
| 60 | 60 | * @return string |
| 61 | 61 | */ |
| 62 | - function construct_wpshop_filter_search_interface ( $category_id ) { |
|
| 62 | + function construct_wpshop_filter_search_interface($category_id) { |
|
| 63 | 63 | global $wpdb; |
| 64 | 64 | $filter_elements = ''; |
| 65 | - if ( !empty($category_id) ) { |
|
| 66 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
| 67 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes']) ) { |
|
| 68 | - foreach ( $category_option['wpshop_category_filterable_attributes'] as $k => $attribute ) { |
|
| 65 | + if (!empty($category_id)) { |
|
| 66 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
| 67 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes'])) { |
|
| 68 | + foreach ($category_option['wpshop_category_filterable_attributes'] as $k => $attribute) { |
|
| 69 | 69 | $attribute_def = wpshop_attributes::getElement($k); |
| 70 | - $filter_elements .= $this->construct_element( $attribute_def, $category_id ); |
|
| 70 | + $filter_elements .= $this->construct_element($attribute_def, $category_id); |
|
| 71 | 71 | $unity = ''; |
| 72 | - if ( !empty($attribute_def->_default_unit) ) { |
|
| 73 | - $query = $wpdb->prepare('SELECT unit FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE id= %d', $attribute_def->_default_unit); |
|
| 74 | - $unity = $wpdb->get_var( $query ); |
|
| 72 | + if (!empty($attribute_def->_default_unit)) { |
|
| 73 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id= %d', $attribute_def->_default_unit); |
|
| 74 | + $unity = $wpdb->get_var($query); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | //$tpl_component['DEFAULT_UNITY'.'_'.$attribute_def->code] = $unity; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | ob_start(); |
| 82 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_search_interface") ); |
|
| 82 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_search_interface")); |
|
| 83 | 83 | $filter_search_interface = ob_get_contents(); |
| 84 | 84 | ob_end_clean(); |
| 85 | 85 | return $filter_search_interface; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @param integer $category_id |
| 92 | 92 | * @return string |
| 93 | 93 | */ |
| 94 | - function construct_element ( $attribute_def, $category_id ) { |
|
| 94 | + function construct_element($attribute_def, $category_id) { |
|
| 95 | 95 | global $wpdb; |
| 96 | 96 | $current_category_children = array(); |
| 97 | 97 | $args = array( |
@@ -101,27 +101,27 @@ discard block |
||
| 101 | 101 | ); |
| 102 | 102 | $current_category_children = get_categories($args); |
| 103 | 103 | |
| 104 | - if ( !empty( $attribute_def ) ) { |
|
| 105 | - switch ( $attribute_def->frontend_input ) { |
|
| 104 | + if (!empty($attribute_def)) { |
|
| 105 | + switch ($attribute_def->frontend_input) { |
|
| 106 | 106 | case 'text' : |
| 107 | - if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
|
| 108 | - return $this->get_filter_element_for_integer_data( $attribute_def, $category_id, $current_category_children ); |
|
| 107 | + if ($attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
|
| 108 | + return $this->get_filter_element_for_integer_data($attribute_def, $category_id, $current_category_children); |
|
| 109 | 109 | } |
| 110 | 110 | else { |
| 111 | - return $this->get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_children ); |
|
| 111 | + return $this->get_filter_element_for_text_data($attribute_def, $category_id, $current_category_children); |
|
| 112 | 112 | } |
| 113 | 113 | break; |
| 114 | 114 | |
| 115 | 115 | case 'select' : case 'multiple-select' : |
| 116 | - return $this->get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'select'); |
|
| 116 | + return $this->get_filter_element_for_list_data($attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'select'); |
|
| 117 | 117 | break; |
| 118 | 118 | |
| 119 | 119 | case 'checkbox' : |
| 120 | - return $this->get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'checkbox'); |
|
| 120 | + return $this->get_filter_element_for_list_data($attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'checkbox'); |
|
| 121 | 121 | break; |
| 122 | 122 | |
| 123 | 123 | case 'radio' : |
| 124 | - return $this->get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'radio' ); |
|
| 124 | + return $this->get_filter_element_for_list_data($attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'radio'); |
|
| 125 | 125 | break; |
| 126 | 126 | |
| 127 | 127 | } |
@@ -133,20 +133,20 @@ discard block |
||
| 133 | 133 | * @param StdObject $attribute_def |
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | - function get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_child ) { |
|
| 136 | + function get_filter_element_for_text_data($attribute_def, $category_id, $current_category_child) { |
|
| 137 | 137 | global $wpdb; |
| 138 | 138 | $output = ''; |
| 139 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
| 139 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
| 140 | 140 | $list_values = ''; |
| 141 | 141 | |
| 142 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) && is_array($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
| 143 | - foreach( $category_option['wpshop_category_filterable_attributes'][$attribute_def->id] as $attribute_value ) { |
|
| 144 | - $list_values .= '<option value="' .$attribute_value. '">' .$attribute_value. '</option>'; |
|
| 142 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) && is_array($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
| 143 | + foreach ($category_option['wpshop_category_filterable_attributes'][$attribute_def->id] as $attribute_value) { |
|
| 144 | + $list_values .= '<option value="' . $attribute_value . '">' . $attribute_value . '</option>'; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | } |
| 148 | 148 | ob_start(); |
| 149 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox") ); |
|
| 149 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox")); |
|
| 150 | 150 | $output = ob_get_contents(); |
| 151 | 151 | ob_end_clean(); |
| 152 | 152 | return $output; |
@@ -157,77 +157,77 @@ discard block |
||
| 157 | 157 | * @param StdObject $attribute_def |
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | - function get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_child, $field_type, $type = 'select') { |
|
| 160 | + function get_filter_element_for_list_data($attribute_def, $category_id, $current_category_child, $field_type, $type = 'select') { |
|
| 161 | 161 | global $wpdb; |
| 162 | 162 | $output = $list_values = ''; |
| 163 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
| 164 | - if ( !empty( $attribute_def) ){ |
|
| 163 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
| 164 | + if (!empty($attribute_def)) { |
|
| 165 | 165 | // Recovery values |
| 166 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
| 166 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
| 167 | 167 | $available_attribute_values = $category_option['wpshop_category_filterable_attributes'][$attribute_def->id]; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // Store options for attribute |
| 171 | 171 | $stored_available_attribute_values = array(); |
| 172 | - $query = $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS .' WHERE attribute_id = %d ORDER BY position ASC', $attribute_def->id); |
|
| 173 | - $attributes_options = $wpdb->get_results( $query ); |
|
| 174 | - if ( $attribute_def->data_type_to_use == 'internal') { |
|
| 175 | - if ( !empty( $attribute_def->default_value ) ) { |
|
| 172 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d ORDER BY position ASC', $attribute_def->id); |
|
| 173 | + $attributes_options = $wpdb->get_results($query); |
|
| 174 | + if ($attribute_def->data_type_to_use == 'internal') { |
|
| 175 | + if (!empty($attribute_def->default_value)) { |
|
| 176 | 176 | $attribute_default_value = $attribute_def->default_value; |
| 177 | 177 | $attribute_default_value = unserialize($attribute_default_value); |
| 178 | 178 | |
| 179 | - $query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_type = %s ORDER BY menu_order ASC', $attribute_default_value['default_value']); |
|
| 180 | - $elements = $wpdb->get_results( $query ); |
|
| 179 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s ORDER BY menu_order ASC', $attribute_default_value['default_value']); |
|
| 180 | + $elements = $wpdb->get_results($query); |
|
| 181 | 181 | |
| 182 | - if ( !empty( $elements) ) { |
|
| 183 | - foreach ( $elements as $element ) { |
|
| 184 | - if ( array_key_exists($element->ID,$available_attribute_values ) ) { |
|
| 185 | - $stored_available_attribute_values[] = array( 'option_id' => $element->ID, 'option_label' => $element->post_title ); |
|
| 182 | + if (!empty($elements)) { |
|
| 183 | + foreach ($elements as $element) { |
|
| 184 | + if (array_key_exists($element->ID, $available_attribute_values)) { |
|
| 185 | + $stored_available_attribute_values[] = array('option_id' => $element->ID, 'option_label' => $element->post_title); |
|
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | else { |
| 192 | - foreach ( $attributes_options as $attributes_option ) { |
|
| 193 | - if ( in_array($attributes_option->label, $available_attribute_values) ) { |
|
| 194 | - $key_value = array_search( $attributes_option->label, $available_attribute_values); |
|
| 195 | - $stored_available_attribute_values[] = array('option_id' => $key_value, 'option_label' => $attributes_option->label ); |
|
| 192 | + foreach ($attributes_options as $attributes_option) { |
|
| 193 | + if (in_array($attributes_option->label, $available_attribute_values)) { |
|
| 194 | + $key_value = array_search($attributes_option->label, $available_attribute_values); |
|
| 195 | + $stored_available_attribute_values[] = array('option_id' => $key_value, 'option_label' => $attributes_option->label); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | // Sort Stored values |
| 200 | - ksort( $stored_available_attribute_values); |
|
| 201 | - if ( !empty($stored_available_attribute_values) && is_array($stored_available_attribute_values) ) { |
|
| 200 | + ksort($stored_available_attribute_values); |
|
| 201 | + if (!empty($stored_available_attribute_values) && is_array($stored_available_attribute_values)) { |
|
| 202 | 202 | // Construct List values |
| 203 | - foreach( $stored_available_attribute_values as $stored_available_attribute_value ) { |
|
| 204 | - $list_values .= '<option value="' .$stored_available_attribute_value['option_id']. '">' .$stored_available_attribute_value['option_label']. '</option>'; |
|
| 203 | + foreach ($stored_available_attribute_values as $stored_available_attribute_value) { |
|
| 204 | + $list_values .= '<option value="' . $stored_available_attribute_value['option_id'] . '">' . $stored_available_attribute_value['option_label'] . '</option>'; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | // Display the good template file |
| 208 | - switch( $type ) { |
|
| 208 | + switch ($type) { |
|
| 209 | 209 | case 'radio' : |
| 210 | 210 | ob_start(); |
| 211 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_radiobox") ); |
|
| 211 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_radiobox")); |
|
| 212 | 212 | $output = ob_get_contents(); |
| 213 | 213 | ob_end_clean(); |
| 214 | 214 | break; |
| 215 | 215 | case 'checkbox' : |
| 216 | 216 | ob_start(); |
| 217 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_checkbox") ); |
|
| 217 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_checkbox")); |
|
| 218 | 218 | $output = ob_get_contents(); |
| 219 | 219 | ob_end_clean(); |
| 220 | 220 | break; |
| 221 | 221 | default : |
| 222 | - if ( $field_type == 'multiple-select' ) { |
|
| 222 | + if ($field_type == 'multiple-select') { |
|
| 223 | 223 | ob_start(); |
| 224 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_multiple_select") ); |
|
| 224 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_multiple_select")); |
|
| 225 | 225 | $output = ob_get_contents(); |
| 226 | 226 | ob_end_clean(); |
| 227 | 227 | } |
| 228 | 228 | else { |
| 229 | 229 | ob_start(); |
| 230 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox") ); |
|
| 230 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox")); |
|
| 231 | 231 | $output = ob_get_contents(); |
| 232 | 232 | ob_end_clean(); |
| 233 | 233 | } |
@@ -243,20 +243,20 @@ discard block |
||
| 243 | 243 | * @param StdObject $attribute_def |
| 244 | 244 | * @return string |
| 245 | 245 | */ |
| 246 | - function get_filter_element_for_integer_data ( $attribute_def, $category_id, $current_category_children ) { |
|
| 246 | + function get_filter_element_for_integer_data($attribute_def, $category_id, $current_category_children) { |
|
| 247 | 247 | $min_value = $max_value = 0; |
| 248 | 248 | $sub_tpl_component = array(); |
| 249 | 249 | $output = ''; |
| 250 | 250 | $first = true; |
| 251 | 251 | /** Get allproducts of category **/ |
| 252 | - $category_product_ids = wpshop_categories::get_product_of_category( $category_id ); |
|
| 253 | - $category_option = get_option('wpshop_product_category_'.$category_id ); |
|
| 254 | - $amount_min = ( !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min']) ) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min'],2, '.', '') : 0; |
|
| 255 | - $amount_max = ( !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max']) ) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max'],2, '.', '') : 0; |
|
| 252 | + $category_product_ids = wpshop_categories::get_product_of_category($category_id); |
|
| 253 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
| 254 | + $amount_min = (!empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min'])) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min'], 2, '.', '') : 0; |
|
| 255 | + $amount_max = (!empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max'])) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max'], 2, '.', '') : 0; |
|
| 256 | 256 | |
| 257 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
| 257 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
| 258 | 258 | ob_start(); |
| 259 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_slider") ); |
|
| 259 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_slider")); |
|
| 260 | 260 | $output = ob_get_contents(); |
| 261 | 261 | ob_end_clean(); |
| 262 | 262 | |
@@ -270,17 +270,17 @@ discard block |
||
| 270 | 270 | * @param std_object $attribute_def |
| 271 | 271 | * @param array $current_category_child |
| 272 | 272 | */ |
| 273 | - function save_values_for_list_filterable_attribute( $category_id, $attribute_def, $current_category_children ) { |
|
| 273 | + function save_values_for_list_filterable_attribute($category_id, $attribute_def, $current_category_children) { |
|
| 274 | 274 | global $wpdb; |
| 275 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
| 276 | - $products = wpshop_categories::get_product_of_category( $category_id ); |
|
| 275 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
| 276 | + $products = wpshop_categories::get_product_of_category($category_id); |
|
| 277 | 277 | /** If there are sub-categories take all products of sub-categories **/ |
| 278 | - if ( !empty($current_category_children) ) { |
|
| 279 | - foreach ( $current_category_children as $current_category_child ) { |
|
| 280 | - $sub_categories_product_ids = wpshop_categories::get_product_of_category( $current_category_child->term_taxonomy_id ); |
|
| 281 | - if ( !empty($sub_categories_product_ids) ) { |
|
| 282 | - foreach ( $sub_categories_product_ids as $sub_categories_product_id ) { |
|
| 283 | - if ( !in_array($sub_categories_product_id, $products) ) { |
|
| 278 | + if (!empty($current_category_children)) { |
|
| 279 | + foreach ($current_category_children as $current_category_child) { |
|
| 280 | + $sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id); |
|
| 281 | + if (!empty($sub_categories_product_ids)) { |
|
| 282 | + foreach ($sub_categories_product_ids as $sub_categories_product_id) { |
|
| 283 | + if (!in_array($sub_categories_product_id, $products)) { |
|
| 284 | 284 | $products[] = $sub_categories_product_id; |
| 285 | 285 | } |
| 286 | 286 | } |
@@ -289,33 +289,33 @@ discard block |
||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
| 292 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
| 292 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
| 293 | 293 | $category_option['wpshop_category_filterable_attributes'][$attribute_def->id] = array(); |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
| 297 | - if ( !empty( $attribute_def) ){ |
|
| 297 | + if (!empty($attribute_def)) { |
|
| 298 | 298 | $available_attribute_values = array(); |
| 299 | 299 | $test = array(); |
| 300 | - foreach ( $products as $product ) { |
|
| 301 | - $available_attribute_values = array_merge( $available_attribute_values, wpshop_attributes::get_affected_value_for_list( $attribute_def->code, $product, $attribute_def->data_type_to_use) ) ; |
|
| 300 | + foreach ($products as $product) { |
|
| 301 | + $available_attribute_values = array_merge($available_attribute_values, wpshop_attributes::get_affected_value_for_list($attribute_def->code, $product, $attribute_def->data_type_to_use)); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | $available_attribute_values = array_flip($available_attribute_values); |
| 305 | 305 | $data_to_save = array(); |
| 306 | - if ( !empty($available_attribute_values) ) { |
|
| 306 | + if (!empty($available_attribute_values)) { |
|
| 307 | 307 | $data_to_save = array(); |
| 308 | - foreach( $available_attribute_values as $k => $available_attribute_value ) { |
|
| 309 | - if ( $attribute_def->data_type_to_use == 'internal' ) { |
|
| 310 | - $attribute_name = get_the_title( $k ); |
|
| 308 | + foreach ($available_attribute_values as $k => $available_attribute_value) { |
|
| 309 | + if ($attribute_def->data_type_to_use == 'internal') { |
|
| 310 | + $attribute_name = get_the_title($k); |
|
| 311 | 311 | } |
| 312 | 312 | else { |
| 313 | - $query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE attribute_id = %d AND id = %d', $attribute_def->id, $k); |
|
| 313 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND id = %d', $attribute_def->id, $k); |
|
| 314 | 314 | |
| 315 | - $attribute_name = $wpdb->get_var( $query ); |
|
| 315 | + $attribute_name = $wpdb->get_var($query); |
|
| 316 | 316 | } |
| 317 | - if (!empty($attribute_name) && !empty($k) ) { |
|
| 318 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
| 317 | + if (!empty($attribute_name) && !empty($k)) { |
|
| 318 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
| 319 | 319 | $data_to_save[$k] = $attribute_name; |
| 320 | 320 | $category_option['wpshop_category_filterable_attributes'][$attribute_def->id] = $data_to_save; |
| 321 | 321 | } |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | - update_option('wpshop_product_category_'.$category_id, $category_option); |
|
| 326 | + update_option('wpshop_product_category_' . $category_id, $category_option); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -332,18 +332,18 @@ discard block |
||
| 332 | 332 | * @param std_object $attribute_def |
| 333 | 333 | * @param array $current_category_child |
| 334 | 334 | */ |
| 335 | - function save_values_for_integer_filterable_attribute ( $category_id, $attribute_def, $current_category_child ) { |
|
| 335 | + function save_values_for_integer_filterable_attribute($category_id, $attribute_def, $current_category_child) { |
|
| 336 | 336 | $first = true; |
| 337 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
| 338 | - $category_product_ids = wpshop_categories::get_product_of_category( $category_id ); |
|
| 337 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
| 338 | + $category_product_ids = wpshop_categories::get_product_of_category($category_id); |
|
| 339 | 339 | $min_value = $max_value = 0; |
| 340 | 340 | /** If there are sub-categories take all products of sub-categories **/ |
| 341 | - if ( !empty($current_category_children) ) { |
|
| 342 | - foreach ( $current_category_children as $current_category_child ) { |
|
| 343 | - $sub_categories_product_ids = wpshop_categories::get_product_of_category( $current_category_child->term_taxonomy_id ); |
|
| 344 | - if ( !empty($sub_categories_product_ids) ) { |
|
| 345 | - foreach ( $sub_categories_product_ids as $sub_categories_product_id ) { |
|
| 346 | - if ( !in_array($sub_categories_product_id, $category_product_ids) ) { |
|
| 341 | + if (!empty($current_category_children)) { |
|
| 342 | + foreach ($current_category_children as $current_category_child) { |
|
| 343 | + $sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id); |
|
| 344 | + if (!empty($sub_categories_product_ids)) { |
|
| 345 | + foreach ($sub_categories_product_ids as $sub_categories_product_id) { |
|
| 346 | + if (!in_array($sub_categories_product_id, $category_product_ids)) { |
|
| 347 | 347 | $category_product_ids[] = $sub_categories_product_id; |
| 348 | 348 | } |
| 349 | 349 | } |
@@ -352,45 +352,45 @@ discard block |
||
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** For each product of category check the value **/ |
| 355 | - if ( !empty( $category_product_ids ) ) { |
|
| 355 | + if (!empty($category_product_ids)) { |
|
| 356 | 356 | $price_piloting_option = get_option('wpshop_shop_price_piloting'); |
| 357 | 357 | foreach ($category_product_ids as $category_product_id) { |
| 358 | 358 | |
| 359 | - if ( $attribute_def->code == WPSHOP_PRODUCT_PRICE_TTC || $attribute_def->code == WPSHOP_PRODUCT_PRICE_HT ) { |
|
| 359 | + if ($attribute_def->code == WPSHOP_PRODUCT_PRICE_TTC || $attribute_def->code == WPSHOP_PRODUCT_PRICE_HT) { |
|
| 360 | 360 | |
| 361 | 361 | $product_infos = wpshop_products::get_product_data($category_product_id); |
| 362 | 362 | $product_price_infos = wpshop_prices::check_product_price($product_infos); |
| 363 | - if (!empty($product_price_infos) && !empty($product_price_infos['fork_price']) && !empty($product_price_infos['fork_price']['have_fork_price']) && $product_price_infos['fork_price']['have_fork_price'] ) { |
|
| 363 | + if (!empty($product_price_infos) && !empty($product_price_infos['fork_price']) && !empty($product_price_infos['fork_price']['have_fork_price']) && $product_price_infos['fork_price']['have_fork_price']) { |
|
| 364 | 364 | |
| 365 | 365 | |
| 366 | - $max_value = ( !empty($product_price_infos['fork_price']['max_product_price']) && $product_price_infos['fork_price']['max_product_price'] > $max_value ) ? $product_price_infos['fork_price']['max_product_price'] : $max_value; |
|
| 367 | - $min_value = (!empty($product_price_infos['fork_price']['min_product_price']) && ( ( $product_price_infos['fork_price']['min_product_price'] < $min_value) || $first ) ) ? $product_price_infos['fork_price']['min_product_price'] : $min_value; |
|
| 366 | + $max_value = (!empty($product_price_infos['fork_price']['max_product_price']) && $product_price_infos['fork_price']['max_product_price'] > $max_value) ? $product_price_infos['fork_price']['max_product_price'] : $max_value; |
|
| 367 | + $min_value = (!empty($product_price_infos['fork_price']['min_product_price']) && (($product_price_infos['fork_price']['min_product_price'] < $min_value) || $first)) ? $product_price_infos['fork_price']['min_product_price'] : $min_value; |
|
| 368 | 368 | } |
| 369 | 369 | else { |
| 370 | - if (!empty($product_price_infos) && !empty($product_price_infos['discount']) && !empty($product_price_infos['discount']['discount_exist'] ) && $product_price_infos['discount']['discount_exist'] ) { |
|
| 371 | - $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['discount']['discount_et_price'] : $product_price_infos['discount']['discount_ati_price']; |
|
| 370 | + if (!empty($product_price_infos) && !empty($product_price_infos['discount']) && !empty($product_price_infos['discount']['discount_exist']) && $product_price_infos['discount']['discount_exist']) { |
|
| 371 | + $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['discount']['discount_et_price'] : $product_price_infos['discount']['discount_ati_price']; |
|
| 372 | 372 | |
| 373 | 373 | } |
| 374 | 374 | else { |
| 375 | 375 | |
| 376 | - $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['et'] : $product_price_infos['ati']; |
|
| 376 | + $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['et'] : $product_price_infos['ati']; |
|
| 377 | 377 | } |
| 378 | - $max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value; |
|
| 379 | - $min_value = (!empty($product_data) && ( ( $product_data < $min_value) || $first ) ) ? $product_data : $min_value; |
|
| 378 | + $max_value = (!empty($product_data) && $product_data > $max_value) ? $product_data : $max_value; |
|
| 379 | + $min_value = (!empty($product_data) && (($product_data < $min_value) || $first)) ? $product_data : $min_value; |
|
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | else { |
| 383 | 383 | $product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
| 384 | 384 | $product_data = $product_postmeta[$attribute_def->code]; |
| 385 | - $max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value; |
|
| 386 | - $min_value = (!empty($product_data) && ( ( $product_data < $min_value) || $first ) ) ? $product_data : $min_value; |
|
| 385 | + $max_value = (!empty($product_data) && $product_data > $max_value) ? $product_data : $max_value; |
|
| 386 | + $min_value = (!empty($product_data) && (($product_data < $min_value) || $first)) ? $product_data : $min_value; |
|
| 387 | 387 | } |
| 388 | 388 | $first = false; |
| 389 | 389 | } |
| 390 | 390 | $category_option['wpshop_category_filterable_attributes'][$attribute_def->id] = array('min' => $min_value, 'max' => $max_value); |
| 391 | 391 | } |
| 392 | 392 | /** Update the category option **/ |
| 393 | - update_option('wpshop_product_category_'.$category_id, $category_option); |
|
| 393 | + update_option('wpshop_product_category_' . $category_id, $category_option); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -399,66 +399,66 @@ discard block |
||
| 399 | 399 | * @param std_object $attribute_def |
| 400 | 400 | * @param array $current_category_child |
| 401 | 401 | */ |
| 402 | - function save_values_for_text_filterable_attribute ( $category_id, $attribute_def, $current_category_child ) { |
|
| 403 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
| 404 | - $category_product_ids = wpshop_categories::get_product_of_category( $category_id ); |
|
| 402 | + function save_values_for_text_filterable_attribute($category_id, $attribute_def, $current_category_child) { |
|
| 403 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
| 404 | + $category_product_ids = wpshop_categories::get_product_of_category($category_id); |
|
| 405 | 405 | /** If there are sub-categories take all products of sub-categories **/ |
| 406 | 406 | $list_values = array(); |
| 407 | - if ( !empty($current_category_children) ) { |
|
| 408 | - foreach ( $current_category_children as $current_category_child ) { |
|
| 409 | - $sub_categories_product_ids = wpshop_categories::get_product_of_category( $current_category_child->term_taxonomy_id ); |
|
| 410 | - if ( !empty($sub_categories_product_ids) ) { |
|
| 411 | - foreach ( $sub_categories_product_ids as $sub_categories_product_id ) { |
|
| 412 | - if ( !in_array($sub_categories_product_id, $category_product_ids) ) { |
|
| 407 | + if (!empty($current_category_children)) { |
|
| 408 | + foreach ($current_category_children as $current_category_child) { |
|
| 409 | + $sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id); |
|
| 410 | + if (!empty($sub_categories_product_ids)) { |
|
| 411 | + foreach ($sub_categories_product_ids as $sub_categories_product_id) { |
|
| 412 | + if (!in_array($sub_categories_product_id, $category_product_ids)) { |
|
| 413 | 413 | $category_product_ids[] = $sub_categories_product_id; |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
| 420 | - if ( !empty( $category_product_ids ) ) { |
|
| 419 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
| 420 | + if (!empty($category_product_ids)) { |
|
| 421 | 421 | $product_data = ''; |
| 422 | - foreach ( $category_product_ids as $category_product_id ) { |
|
| 422 | + foreach ($category_product_ids as $category_product_id) { |
|
| 423 | 423 | $product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
| 424 | - $product_data = ( !empty($product_postmeta[$attribute_def->code]) ) ? $product_postmeta[$attribute_def->code] : ''; |
|
| 425 | - if ( !in_array( $product_data, $list_values) ) { |
|
| 424 | + $product_data = (!empty($product_postmeta[$attribute_def->code])) ? $product_postmeta[$attribute_def->code] : ''; |
|
| 425 | + if (!in_array($product_data, $list_values)) { |
|
| 426 | 426 | $list_values[] = $product_data; |
| 427 | - if ( !empty($product_data) ) { |
|
| 427 | + if (!empty($product_data)) { |
|
| 428 | 428 | $category_option['wpshop_category_filterable_attributes'][$attribute_def->id][] = $product_data; |
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | - update_option('wpshop_product_category_'.$category_id, $category_option); |
|
| 434 | + update_option('wpshop_product_category_' . $category_id, $category_option); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
| 438 | 438 | * Save the price which is displayed on website |
| 439 | 439 | */ |
| 440 | - public static function save_displayed_price_meta( $product_id = 0 ) { |
|
| 441 | - $ID = !empty( $_POST['ID'] ) ? (int) $_POST['ID'] : 0; |
|
| 442 | - $post_type = !empty( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : ''; |
|
| 440 | + public static function save_displayed_price_meta($product_id = 0) { |
|
| 441 | + $ID = !empty($_POST['ID']) ? (int)$_POST['ID'] : 0; |
|
| 442 | + $post_type = !empty($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : ''; |
|
| 443 | 443 | |
| 444 | - if ( !empty( $product_id ) || ( !empty( $ID ) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) ) { |
|
| 445 | - $product_id = !empty( $product_id ) ? $product_id : $ID; |
|
| 444 | + if (!empty($product_id) || (!empty($ID) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)) { |
|
| 445 | + $product_id = !empty($product_id) ? $product_id : $ID; |
|
| 446 | 446 | |
| 447 | 447 | $price_piloting = get_option('wpshop_shop_price_piloting'); |
| 448 | 448 | $product_data = wpshop_products::get_product_data($product_id); |
| 449 | 449 | $price_infos = wpshop_prices::check_product_price($product_data); |
| 450 | 450 | |
| 451 | - if ( !empty($price_infos) ) { |
|
| 452 | - if ( !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) ) { |
|
| 453 | - $displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price']; |
|
| 451 | + if (!empty($price_infos)) { |
|
| 452 | + if (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist'])) { |
|
| 453 | + $displayed_price = (!empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price']; |
|
| 454 | 454 | } |
| 455 | - else if( !empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price']) ) { |
|
| 455 | + else if (!empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price'])) { |
|
| 456 | 456 | $displayed_price = $price_infos['fork_price']['min_product_price']; |
| 457 | 457 | } |
| 458 | 458 | else { |
| 459 | - $displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
|
| 459 | + $displayed_price = (!empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
|
| 460 | 460 | } |
| 461 | - update_post_meta($product_id, '_wpshop_displayed_price', number_format($displayed_price,2, '.','') ); |
|
| 461 | + update_post_meta($product_id, '_wpshop_displayed_price', number_format($displayed_price, 2, '.', '')); |
|
| 462 | 462 | } |
| 463 | 463 | } |
| 464 | 464 | } |
@@ -467,19 +467,19 @@ discard block |
||
| 467 | 467 | * Save values for attributes |
| 468 | 468 | * @param unknown_type $values |
| 469 | 469 | */ |
| 470 | - function stock_values_for_attribute( $categories_id = array() ) { |
|
| 471 | - @set_time_limit( 900 ); |
|
| 470 | + function stock_values_for_attribute($categories_id = array()) { |
|
| 471 | + @set_time_limit(900); |
|
| 472 | 472 | |
| 473 | - $tax_input = ( !empty( $_POST['tax_input'] ) && !empty( $_POST['tax_input']['wpshop_product_category'] ) ) ? (int) $_POST['tax_input']['wpshop_product_category'] : ''; |
|
| 474 | - $post_type = !empty( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : ''; |
|
| 475 | - if ( !empty( $tax_input ) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) { |
|
| 473 | + $tax_input = (!empty($_POST['tax_input']) && !empty($_POST['tax_input']['wpshop_product_category'])) ? (int)$_POST['tax_input']['wpshop_product_category'] : ''; |
|
| 474 | + $post_type = !empty($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : ''; |
|
| 475 | + if (!empty($tax_input) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 476 | 476 | $categories_id = $tax_input; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - if ( !empty( $categories_id ) ) { |
|
| 480 | - if ( $categories_id && is_array($categories_id) ) { |
|
| 481 | - foreach( $categories_id as $taxonomy_id ) { |
|
| 482 | - if ( $taxonomy_id != 0 ) { |
|
| 479 | + if (!empty($categories_id)) { |
|
| 480 | + if ($categories_id && is_array($categories_id)) { |
|
| 481 | + foreach ($categories_id as $taxonomy_id) { |
|
| 482 | + if ($taxonomy_id != 0) { |
|
| 483 | 483 | $current_category_children = array(); |
| 484 | 484 | $args = array( |
| 485 | 485 | 'type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
@@ -488,23 +488,23 @@ discard block |
||
| 488 | 488 | ); |
| 489 | 489 | $current_category_children = get_categories($args); |
| 490 | 490 | |
| 491 | - $category_option = get_option('wpshop_product_category_'.$taxonomy_id); |
|
| 492 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes']) ) { |
|
| 493 | - foreach ( $category_option['wpshop_category_filterable_attributes'] as $k => $filterable_attribute ) { |
|
| 491 | + $category_option = get_option('wpshop_product_category_' . $taxonomy_id); |
|
| 492 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes'])) { |
|
| 493 | + foreach ($category_option['wpshop_category_filterable_attributes'] as $k => $filterable_attribute) { |
|
| 494 | 494 | $attribute_def = wpshop_attributes::getElement($k); |
| 495 | - if ( !empty( $attribute_def) ) { |
|
| 496 | - switch ( $attribute_def->frontend_input ) { |
|
| 495 | + if (!empty($attribute_def)) { |
|
| 496 | + switch ($attribute_def->frontend_input) { |
|
| 497 | 497 | case 'text' : |
| 498 | - if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
|
| 499 | - $this->save_values_for_integer_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
|
| 498 | + if ($attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
|
| 499 | + $this->save_values_for_integer_filterable_attribute($taxonomy_id, $attribute_def, $current_category_children); |
|
| 500 | 500 | } |
| 501 | 501 | else { |
| 502 | - $this->save_values_for_text_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
|
| 502 | + $this->save_values_for_text_filterable_attribute($taxonomy_id, $attribute_def, $current_category_children); |
|
| 503 | 503 | } |
| 504 | 504 | break; |
| 505 | 505 | |
| 506 | 506 | case 'select' : case 'checkbox' : case 'radio' : case 'multiple-select' : |
| 507 | - $this->save_values_for_list_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
|
| 507 | + $this->save_values_for_list_filterable_attribute($taxonomy_id, $attribute_def, $current_category_children); |
|
| 508 | 508 | break; |
| 509 | 509 | |
| 510 | 510 | } |
@@ -522,22 +522,22 @@ discard block |
||
| 522 | 522 | * @param integer $category_id |
| 523 | 523 | * @return array |
| 524 | 524 | */ |
| 525 | - function pick_up_filter_search_elements_type ( $category_id ) { |
|
| 525 | + function pick_up_filter_search_elements_type($category_id) { |
|
| 526 | 526 | $filter_search_elements = array(); |
| 527 | - if ( !empty($category_id) ) { |
|
| 528 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
| 529 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) ) { |
|
| 530 | - foreach ( $category_option['wpshop_category_filterable_attributes'] as $k => $attribute ) { |
|
| 527 | + if (!empty($category_id)) { |
|
| 528 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
| 529 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes'])) { |
|
| 530 | + foreach ($category_option['wpshop_category_filterable_attributes'] as $k => $attribute) { |
|
| 531 | 531 | $attribute_def = wpshop_attributes::getElement($k); |
| 532 | - if ( !empty($attribute_def) ) { |
|
| 533 | - if ( $attribute_def->frontend_input == 'text' ) { |
|
| 534 | - $filter_search_elements['_'.$attribute_def->code] = array('type' => 'fork_values'); |
|
| 532 | + if (!empty($attribute_def)) { |
|
| 533 | + if ($attribute_def->frontend_input == 'text') { |
|
| 534 | + $filter_search_elements['_' . $attribute_def->code] = array('type' => 'fork_values'); |
|
| 535 | 535 | } |
| 536 | - elseif( in_array( $attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select') ) ) { |
|
| 537 | - $filter_search_elements['_'.$attribute_def->code] = array('type' => 'multiple_select_value'); |
|
| 536 | + elseif (in_array($attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select'))) { |
|
| 537 | + $filter_search_elements['_' . $attribute_def->code] = array('type' => 'multiple_select_value'); |
|
| 538 | 538 | } |
| 539 | - elseif ( !in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password') ) ) { |
|
| 540 | - $filter_search_elements['_'.$attribute_def->code] = array('type' => 'select_value'); |
|
| 539 | + elseif (!in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password'))) { |
|
| 540 | + $filter_search_elements['_' . $attribute_def->code] = array('type' => 'select_value'); |
|
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | } |
@@ -549,28 +549,28 @@ discard block |
||
| 549 | 549 | /** |
| 550 | 550 | * AJAX - Action to search with selected attributes values |
| 551 | 551 | */ |
| 552 | - function wpshop_ajax_filter_search_action () { |
|
| 553 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
| 552 | + function wpshop_ajax_filter_search_action() { |
|
| 553 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
| 554 | 554 | |
| 555 | - if ( !wp_verify_nonce( $_wpnonce, 'wpshop_ajax_filter_search_action' ) ) |
|
| 555 | + if (!wp_verify_nonce($_wpnonce, 'wpshop_ajax_filter_search_action')) |
|
| 556 | 556 | wp_die(); |
| 557 | 557 | |
| 558 | 558 | global $wpdb; |
| 559 | - $category_id = !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer( $_POST['wpshop_filter_search_category_id'] ) : 0; |
|
| 559 | + $category_id = !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer($_POST['wpshop_filter_search_category_id']) : 0; |
|
| 560 | 560 | $filter_search_elements = $this->pick_up_filter_search_elements_type($category_id); |
| 561 | - $page_id = ( !empty( $_POST['wpshop_filter_search_current_page_id']) ) ? wpshop_tools::varSanitizer( $_POST['wpshop_filter_search_current_page_id'] ) : 1; |
|
| 561 | + $page_id = (!empty($_POST['wpshop_filter_search_current_page_id'])) ? wpshop_tools::varSanitizer($_POST['wpshop_filter_search_current_page_id']) : 1; |
|
| 562 | 562 | $request_cmd = ''; |
| 563 | 563 | $status = false; |
| 564 | 564 | $data = array(); |
| 565 | - foreach ( $filter_search_elements as $k=>$filter_search_element) { |
|
| 566 | - $search = isset( $_REQUEST['filter_search'.$k] ) ? sanitize_text_field( $_REQUEST['filter_search'.$k] ) : ''; |
|
| 567 | - $amount_min = !isset( $_REQUEST['amount_min'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_min'.$k] ); |
|
| 568 | - $amount_max = !isset( $_REQUEST['amount_max'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_max'.$k] ); |
|
| 569 | - $datatype_element = array( 'select_value', 'multiple_select_value', 'fork_values'); |
|
| 570 | - if ( (in_array($filter_search_element['type'], $datatype_element) && ( isset($search) && $search == 'all_attribute_values' ) ) || |
|
| 571 | - ( ($filter_search_element['type'] == 'select_value' || $filter_search_element['type'] == 'multiple_select_value' ) && $search == '' ) || |
|
| 572 | - ( $filter_search_element['type'] == 'fork_values' && ( $amount_min == 0 || $amount_max == 0 ) ) ) { |
|
| 573 | - unset( $filter_search_elements[$k]); |
|
| 565 | + foreach ($filter_search_elements as $k=>$filter_search_element) { |
|
| 566 | + $search = isset($_REQUEST['filter_search' . $k]) ? sanitize_text_field($_REQUEST['filter_search' . $k]) : ''; |
|
| 567 | + $amount_min = !isset($_REQUEST['amount_min' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_min' . $k]); |
|
| 568 | + $amount_max = !isset($_REQUEST['amount_max' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_max' . $k]); |
|
| 569 | + $datatype_element = array('select_value', 'multiple_select_value', 'fork_values'); |
|
| 570 | + if ((in_array($filter_search_element['type'], $datatype_element) && (isset($search) && $search == 'all_attribute_values')) || |
|
| 571 | + (($filter_search_element['type'] == 'select_value' || $filter_search_element['type'] == 'multiple_select_value') && $search == '') || |
|
| 572 | + ($filter_search_element['type'] == 'fork_values' && ($amount_min == 0 || $amount_max == 0))) { |
|
| 573 | + unset($filter_search_elements[$k]); |
|
| 574 | 574 | } |
| 575 | 575 | } |
| 576 | 576 | $request_cmd = ''; |
@@ -589,8 +589,8 @@ discard block |
||
| 589 | 589 | /** Construct the array for SELECT query IN **/ |
| 590 | 590 | $categories_id = array(); |
| 591 | 591 | $categories_id[] = $category_id; |
| 592 | - if ( !empty($current_category_children) ) { |
|
| 593 | - foreach ( $current_category_children as $current_category_child ) { |
|
| 592 | + if (!empty($current_category_children)) { |
|
| 593 | + foreach ($current_category_children as $current_category_child) { |
|
| 594 | 594 | $categories_id[] = $current_category_child->term_taxonomy_id; |
| 595 | 595 | } |
| 596 | 596 | } |
@@ -599,55 +599,55 @@ discard block |
||
| 599 | 599 | $array_for_query = implode(',', $categories_id); |
| 600 | 600 | |
| 601 | 601 | /** SQL request Construct for pick up all product with one of filter search element value **/ |
| 602 | - if ( !empty( $filter_search_elements ) ) { |
|
| 603 | - foreach ( $filter_search_elements as $k=>$filter_search_element ) { |
|
| 604 | - $search = isset( $_REQUEST['filter_search'.$k] ) ? $_REQUEST['filter_search'.$k] : ''; |
|
| 605 | - $amount_min = !isset( $_REQUEST['amount_min'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_min'.$k] ); |
|
| 606 | - $amount_max = !isset( $_REQUEST['amount_max'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_max'.$k] ); |
|
| 607 | - |
|
| 608 | - if ( !empty($filter_search_element['type']) && !empty($search) && $filter_search_element['type'] == 'select_value' && $search != 'all_attribute_values') { |
|
| 609 | - $request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON post_id = ID WHERE (meta_key = "'.$k.'" AND meta_value = "'.$search.'") AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish" '; |
|
| 610 | - $request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
|
| 602 | + if (!empty($filter_search_elements)) { |
|
| 603 | + foreach ($filter_search_elements as $k=>$filter_search_element) { |
|
| 604 | + $search = isset($_REQUEST['filter_search' . $k]) ? $_REQUEST['filter_search' . $k] : ''; |
|
| 605 | + $amount_min = !isset($_REQUEST['amount_min' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_min' . $k]); |
|
| 606 | + $amount_max = !isset($_REQUEST['amount_max' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_max' . $k]); |
|
| 607 | + |
|
| 608 | + if (!empty($filter_search_element['type']) && !empty($search) && $filter_search_element['type'] == 'select_value' && $search != 'all_attribute_values') { |
|
| 609 | + $request_cmd .= 'SELECT meta_key, post_id FROM ' . $wpdb->postmeta . ' INNER JOIN ' . $wpdb->posts . ' ON post_id = ID WHERE (meta_key = "' . $k . '" AND meta_value = "' . $search . '") AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '" AND post_status = "publish" '; |
|
| 610 | + $request_cmd .= ' AND post_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) '; |
|
| 611 | 611 | } |
| 612 | - else if($filter_search_element['type'] == 'fork_values') { |
|
| 613 | - $request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON post_id = ID WHERE (meta_key = "'.( ( !empty($k) && $k == '_product_price' ) ? '_wpshop_displayed_price' : $k).'" AND meta_value BETWEEN '.$amount_min.' AND '.$amount_max.') AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish"'; |
|
| 614 | - $request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
|
| 612 | + else if ($filter_search_element['type'] == 'fork_values') { |
|
| 613 | + $request_cmd .= 'SELECT meta_key, post_id FROM ' . $wpdb->postmeta . ' INNER JOIN ' . $wpdb->posts . ' ON post_id = ID WHERE (meta_key = "' . ((!empty($k) && $k == '_product_price') ? '_wpshop_displayed_price' : $k) . '" AND meta_value BETWEEN ' . $amount_min . ' AND ' . $amount_max . ') AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '" AND post_status = "publish"'; |
|
| 614 | + $request_cmd .= ' AND post_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) '; |
|
| 615 | 615 | } |
| 616 | - else if( $filter_search_element['type'] == 'multiple_select_value' ) { |
|
| 616 | + else if ($filter_search_element['type'] == 'multiple_select_value') { |
|
| 617 | 617 | /** Check the attribute id **/ |
| 618 | 618 | $attribute_def = wpshop_attributes::getElement(substr($k, 1), "'valid'", 'code'); |
| 619 | - if ( !empty($attribute_def) ) { |
|
| 620 | - $request_cmd .= 'SELECT CONCAT("_", code) AS meta_key, ATT_INT.entity_id AS post_id FROM ' .WPSHOP_DBT_ATTRIBUTE. ', '.WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER.' AS ATT_INT WHERE attribute_id = id AND attribute_id = '.$attribute_def->id; |
|
| 619 | + if (!empty($attribute_def)) { |
|
| 620 | + $request_cmd .= 'SELECT CONCAT("_", code) AS meta_key, ATT_INT.entity_id AS post_id FROM ' . WPSHOP_DBT_ATTRIBUTE . ', ' . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . ' AS ATT_INT WHERE attribute_id = id AND attribute_id = ' . $attribute_def->id; |
|
| 621 | 621 | $first = true; |
| 622 | - if ( !empty($search) && is_array($search) ){ |
|
| 623 | - foreach ( $search as $r ) { |
|
| 624 | - if ( $first) { |
|
| 625 | - $request_cmd .= ' AND (value ="' . $r. '"'; |
|
| 622 | + if (!empty($search) && is_array($search)) { |
|
| 623 | + foreach ($search as $r) { |
|
| 624 | + if ($first) { |
|
| 625 | + $request_cmd .= ' AND (value ="' . $r . '"'; |
|
| 626 | 626 | $first = false; |
| 627 | 627 | } |
| 628 | 628 | else { |
| 629 | - $request_cmd .= ' OR value ="' . $r. '"'; |
|
| 629 | + $request_cmd .= ' OR value ="' . $r . '"'; |
|
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | $request_cmd .= ')'; |
| 633 | 633 | } |
| 634 | - elseif( !empty($search) ) { |
|
| 634 | + elseif (!empty($search)) { |
|
| 635 | 635 | $request_cmd .= ' AND (value ="' . $search . '" )'; |
| 636 | 636 | } |
| 637 | - $request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
|
| 637 | + $request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) '; |
|
| 638 | 638 | |
| 639 | 639 | |
| 640 | 640 | } |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | |
| 644 | - if ($i < count($filter_search_elements) ) { |
|
| 644 | + if ($i < count($filter_search_elements)) { |
|
| 645 | 645 | $request_cmd .= ' UNION '; |
| 646 | 646 | } |
| 647 | 647 | $i++; |
| 648 | 648 | } |
| 649 | 649 | } else { |
| 650 | - $request_cmd .= 'SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.')'; |
|
| 650 | + $request_cmd .= 'SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ')'; |
|
| 651 | 651 | } |
| 652 | 652 | /** SQL Request execution **/ |
| 653 | 653 | $query = $wpdb->prepare($request_cmd, ''); |
@@ -661,9 +661,9 @@ discard block |
||
| 661 | 661 | |
| 662 | 662 | $last = ''; |
| 663 | 663 | /** Transform the query result array **/ |
| 664 | - foreach ( $results as $result ) { |
|
| 665 | - $result->meta_key = ( !empty($result->meta_key) && $result->meta_key == '_wpshop_displayed_price' ) ? '_product_price' : $result->meta_key; |
|
| 666 | - if ( $last != $result->meta_key ){ |
|
| 664 | + foreach ($results as $result) { |
|
| 665 | + $result->meta_key = (!empty($result->meta_key) && $result->meta_key == '_wpshop_displayed_price') ? '_product_price' : $result->meta_key; |
|
| 666 | + if ($last != $result->meta_key) { |
|
| 667 | 667 | $filter_search_elements[$result->meta_key]['count'] = 1; |
| 668 | 668 | $last = $result->meta_key; |
| 669 | 669 | } |
@@ -677,12 +677,12 @@ discard block |
||
| 677 | 677 | /** Check the smaller array of attributes **/ |
| 678 | 678 | $smaller_array = ''; |
| 679 | 679 | $smaller_array_count = -1; |
| 680 | - foreach ( $filter_search_elements as $k=>$filter_search_element ) { |
|
| 681 | - if ( empty($filter_search_element['count']) ) { |
|
| 680 | + foreach ($filter_search_elements as $k=>$filter_search_element) { |
|
| 681 | + if (empty($filter_search_element['count'])) { |
|
| 682 | 682 | $smaller_array_count = 0; |
| 683 | 683 | $smaller_array = $k; |
| 684 | 684 | } |
| 685 | - elseif( $smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count ) { |
|
| 685 | + elseif ($smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count) { |
|
| 686 | 686 | $smaller_array_count = $filter_search_element['count']; |
| 687 | 687 | $smaller_array = $k; |
| 688 | 688 | } |
@@ -690,21 +690,21 @@ discard block |
||
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** Compare the smaller array with the others **/ |
| 693 | - if ( !empty($smaller_array_count) ) { |
|
| 693 | + if (!empty($smaller_array_count)) { |
|
| 694 | 694 | $temp_tab = $filter_search_elements[$smaller_array]['values']; |
| 695 | - foreach ( $filter_search_elements as $filter_search) { |
|
| 696 | - foreach ( $temp_tab as $value ) { |
|
| 697 | - if ( !in_array($value, $filter_search['values']) ) { |
|
| 695 | + foreach ($filter_search_elements as $filter_search) { |
|
| 696 | + foreach ($temp_tab as $value) { |
|
| 697 | + if (!in_array($value, $filter_search['values'])) { |
|
| 698 | 698 | /** If value don't exist in the smaller array, delete it **/ |
| 699 | 699 | $key = array_key_exists($value, $temp_tab); |
| 700 | - if ( $key ) { |
|
| 700 | + if ($key) { |
|
| 701 | 701 | unset($temp_tab[$value]); |
| 702 | 702 | } |
| 703 | 703 | } |
| 704 | 704 | } |
| 705 | 705 | } |
| 706 | 706 | /** Final result to display the products **/ |
| 707 | - if ( !empty( $temp_tab) ) { |
|
| 707 | + if (!empty($temp_tab)) { |
|
| 708 | 708 | $final_result = $temp_tab; |
| 709 | 709 | } |
| 710 | 710 | } |
@@ -713,21 +713,21 @@ discard block |
||
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | $products_count = count($final_result); |
| 716 | - $products_count = sprintf(__('%s products corresponds to your search.', 'wpshop'),$products_count) ; |
|
| 716 | + $products_count = sprintf(__('%s products corresponds to your search.', 'wpshop'), $products_count); |
|
| 717 | 717 | |
| 718 | 718 | /** If there is products for this filter search **/ |
| 719 | 719 | $status = true; |
| 720 | - if ( !empty($final_result) ) { |
|
| 720 | + if (!empty($final_result)) { |
|
| 721 | 721 | $data['status'] = true; |
| 722 | - $data['result'] = do_shortcode( '[wpshop_products pid="' . implode(',', $final_result) . '" cid="' . $category_id . '" container="no" ]' ) ; |
|
| 722 | + $data['result'] = do_shortcode('[wpshop_products pid="' . implode(',', $final_result) . '" cid="' . $category_id . '" container="no" ]'); |
|
| 723 | 723 | $data['products_count'] = $products_count; |
| 724 | 724 | } |
| 725 | 725 | else { |
| 726 | 726 | $data['status'] = false; |
| 727 | - $data['result'] = '<div class="container_product_listing">'.__('There is no product for this filter search.', 'wpshop').'</div>'; |
|
| 727 | + $data['result'] = '<div class="container_product_listing">' . __('There is no product for this filter search.', 'wpshop') . '</div>'; |
|
| 728 | 728 | $data['products_count'] = __('No products corresponds to your search', 'wpshop'); |
| 729 | 729 | } |
| 730 | - echo json_encode( $data ); |
|
| 730 | + echo json_encode($data); |
|
| 731 | 731 | die(); |
| 732 | 732 | } |
| 733 | 733 | } |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
| 2 | + exit; |
|
| 3 | +} |
|
| 2 | 4 | class wps_filter_search { |
| 3 | 5 | |
| 4 | 6 | /** Define the main directory containing the template for the current plugin |
@@ -106,8 +108,7 @@ discard block |
||
| 106 | 108 | case 'text' : |
| 107 | 109 | if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
| 108 | 110 | return $this->get_filter_element_for_integer_data( $attribute_def, $category_id, $current_category_children ); |
| 109 | - } |
|
| 110 | - else { |
|
| 111 | + } else { |
|
| 111 | 112 | return $this->get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_children ); |
| 112 | 113 | } |
| 113 | 114 | break; |
@@ -187,8 +188,7 @@ discard block |
||
| 187 | 188 | } |
| 188 | 189 | } |
| 189 | 190 | } |
| 190 | - } |
|
| 191 | - else { |
|
| 191 | + } else { |
|
| 192 | 192 | foreach ( $attributes_options as $attributes_option ) { |
| 193 | 193 | if ( in_array($attributes_option->label, $available_attribute_values) ) { |
| 194 | 194 | $key_value = array_search( $attributes_option->label, $available_attribute_values); |
@@ -224,8 +224,7 @@ discard block |
||
| 224 | 224 | require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_multiple_select") ); |
| 225 | 225 | $output = ob_get_contents(); |
| 226 | 226 | ob_end_clean(); |
| 227 | - } |
|
| 228 | - else { |
|
| 227 | + } else { |
|
| 229 | 228 | ob_start(); |
| 230 | 229 | require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox") ); |
| 231 | 230 | $output = ob_get_contents(); |
@@ -308,8 +307,7 @@ discard block |
||
| 308 | 307 | foreach( $available_attribute_values as $k => $available_attribute_value ) { |
| 309 | 308 | if ( $attribute_def->data_type_to_use == 'internal' ) { |
| 310 | 309 | $attribute_name = get_the_title( $k ); |
| 311 | - } |
|
| 312 | - else { |
|
| 310 | + } else { |
|
| 313 | 311 | $query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE attribute_id = %d AND id = %d', $attribute_def->id, $k); |
| 314 | 312 | |
| 315 | 313 | $attribute_name = $wpdb->get_var( $query ); |
@@ -365,21 +363,18 @@ discard block |
||
| 365 | 363 | |
| 366 | 364 | $max_value = ( !empty($product_price_infos['fork_price']['max_product_price']) && $product_price_infos['fork_price']['max_product_price'] > $max_value ) ? $product_price_infos['fork_price']['max_product_price'] : $max_value; |
| 367 | 365 | $min_value = (!empty($product_price_infos['fork_price']['min_product_price']) && ( ( $product_price_infos['fork_price']['min_product_price'] < $min_value) || $first ) ) ? $product_price_infos['fork_price']['min_product_price'] : $min_value; |
| 368 | - } |
|
| 369 | - else { |
|
| 366 | + } else { |
|
| 370 | 367 | if (!empty($product_price_infos) && !empty($product_price_infos['discount']) && !empty($product_price_infos['discount']['discount_exist'] ) && $product_price_infos['discount']['discount_exist'] ) { |
| 371 | 368 | $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['discount']['discount_et_price'] : $product_price_infos['discount']['discount_ati_price']; |
| 372 | 369 | |
| 373 | - } |
|
| 374 | - else { |
|
| 370 | + } else { |
|
| 375 | 371 | |
| 376 | 372 | $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['et'] : $product_price_infos['ati']; |
| 377 | 373 | } |
| 378 | 374 | $max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value; |
| 379 | 375 | $min_value = (!empty($product_data) && ( ( $product_data < $min_value) || $first ) ) ? $product_data : $min_value; |
| 380 | 376 | } |
| 381 | - } |
|
| 382 | - else { |
|
| 377 | + } else { |
|
| 383 | 378 | $product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
| 384 | 379 | $product_data = $product_postmeta[$attribute_def->code]; |
| 385 | 380 | $max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value; |
@@ -451,11 +446,9 @@ discard block |
||
| 451 | 446 | if ( !empty($price_infos) ) { |
| 452 | 447 | if ( !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) ) { |
| 453 | 448 | $displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price']; |
| 454 | - } |
|
| 455 | - else if( !empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price']) ) { |
|
| 449 | + } else if( !empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price']) ) { |
|
| 456 | 450 | $displayed_price = $price_infos['fork_price']['min_product_price']; |
| 457 | - } |
|
| 458 | - else { |
|
| 451 | + } else { |
|
| 459 | 452 | $displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
| 460 | 453 | } |
| 461 | 454 | update_post_meta($product_id, '_wpshop_displayed_price', number_format($displayed_price,2, '.','') ); |
@@ -497,8 +490,7 @@ discard block |
||
| 497 | 490 | case 'text' : |
| 498 | 491 | if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
| 499 | 492 | $this->save_values_for_integer_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
| 500 | - } |
|
| 501 | - else { |
|
| 493 | + } else { |
|
| 502 | 494 | $this->save_values_for_text_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
| 503 | 495 | } |
| 504 | 496 | break; |
@@ -532,11 +524,9 @@ discard block |
||
| 532 | 524 | if ( !empty($attribute_def) ) { |
| 533 | 525 | if ( $attribute_def->frontend_input == 'text' ) { |
| 534 | 526 | $filter_search_elements['_'.$attribute_def->code] = array('type' => 'fork_values'); |
| 535 | - } |
|
| 536 | - elseif( in_array( $attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select') ) ) { |
|
| 527 | + } elseif( in_array( $attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select') ) ) { |
|
| 537 | 528 | $filter_search_elements['_'.$attribute_def->code] = array('type' => 'multiple_select_value'); |
| 538 | - } |
|
| 539 | - elseif ( !in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password') ) ) { |
|
| 529 | + } elseif ( !in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password') ) ) { |
|
| 540 | 530 | $filter_search_elements['_'.$attribute_def->code] = array('type' => 'select_value'); |
| 541 | 531 | } |
| 542 | 532 | } |
@@ -552,8 +542,9 @@ discard block |
||
| 552 | 542 | function wpshop_ajax_filter_search_action () { |
| 553 | 543 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
| 554 | 544 | |
| 555 | - if ( !wp_verify_nonce( $_wpnonce, 'wpshop_ajax_filter_search_action' ) ) |
|
| 556 | - wp_die(); |
|
| 545 | + if ( !wp_verify_nonce( $_wpnonce, 'wpshop_ajax_filter_search_action' ) ) { |
|
| 546 | + wp_die(); |
|
| 547 | + } |
|
| 557 | 548 | |
| 558 | 549 | global $wpdb; |
| 559 | 550 | $category_id = !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer( $_POST['wpshop_filter_search_category_id'] ) : 0; |
@@ -608,12 +599,10 @@ discard block |
||
| 608 | 599 | if ( !empty($filter_search_element['type']) && !empty($search) && $filter_search_element['type'] == 'select_value' && $search != 'all_attribute_values') { |
| 609 | 600 | $request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON post_id = ID WHERE (meta_key = "'.$k.'" AND meta_value = "'.$search.'") AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish" '; |
| 610 | 601 | $request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
| 611 | - } |
|
| 612 | - else if($filter_search_element['type'] == 'fork_values') { |
|
| 602 | + } else if($filter_search_element['type'] == 'fork_values') { |
|
| 613 | 603 | $request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON post_id = ID WHERE (meta_key = "'.( ( !empty($k) && $k == '_product_price' ) ? '_wpshop_displayed_price' : $k).'" AND meta_value BETWEEN '.$amount_min.' AND '.$amount_max.') AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish"'; |
| 614 | 604 | $request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
| 615 | - } |
|
| 616 | - else if( $filter_search_element['type'] == 'multiple_select_value' ) { |
|
| 605 | + } else if( $filter_search_element['type'] == 'multiple_select_value' ) { |
|
| 617 | 606 | /** Check the attribute id **/ |
| 618 | 607 | $attribute_def = wpshop_attributes::getElement(substr($k, 1), "'valid'", 'code'); |
| 619 | 608 | if ( !empty($attribute_def) ) { |
@@ -624,14 +613,12 @@ discard block |
||
| 624 | 613 | if ( $first) { |
| 625 | 614 | $request_cmd .= ' AND (value ="' . $r. '"'; |
| 626 | 615 | $first = false; |
| 627 | - } |
|
| 628 | - else { |
|
| 616 | + } else { |
|
| 629 | 617 | $request_cmd .= ' OR value ="' . $r. '"'; |
| 630 | 618 | } |
| 631 | 619 | } |
| 632 | 620 | $request_cmd .= ')'; |
| 633 | - } |
|
| 634 | - elseif( !empty($search) ) { |
|
| 621 | + } elseif( !empty($search) ) { |
|
| 635 | 622 | $request_cmd .= ' AND (value ="' . $search . '" )'; |
| 636 | 623 | } |
| 637 | 624 | $request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
@@ -666,9 +653,9 @@ discard block |
||
| 666 | 653 | if ( $last != $result->meta_key ){ |
| 667 | 654 | $filter_search_elements[$result->meta_key]['count'] = 1; |
| 668 | 655 | $last = $result->meta_key; |
| 656 | + } else { |
|
| 657 | + $filter_search_elements[$result->meta_key]['count']++; |
|
| 669 | 658 | } |
| 670 | - else |
|
| 671 | - $filter_search_elements[$result->meta_key]['count']++; |
|
| 672 | 659 | |
| 673 | 660 | $filter_search_elements[$result->meta_key]['values'][$result->post_id] = $result->post_id; |
| 674 | 661 | } |
@@ -681,8 +668,7 @@ discard block |
||
| 681 | 668 | if ( empty($filter_search_element['count']) ) { |
| 682 | 669 | $smaller_array_count = 0; |
| 683 | 670 | $smaller_array = $k; |
| 684 | - } |
|
| 685 | - elseif( $smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count ) { |
|
| 671 | + } elseif( $smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count ) { |
|
| 686 | 672 | $smaller_array_count = $filter_search_element['count']; |
| 687 | 673 | $smaller_array = $k; |
| 688 | 674 | } |
@@ -707,8 +693,7 @@ discard block |
||
| 707 | 693 | if ( !empty( $temp_tab) ) { |
| 708 | 694 | $final_result = $temp_tab; |
| 709 | 695 | } |
| 710 | - } |
|
| 711 | - else { |
|
| 696 | + } else { |
|
| 712 | 697 | $final_result = array(); |
| 713 | 698 | } |
| 714 | 699 | |
@@ -721,8 +706,7 @@ discard block |
||
| 721 | 706 | $data['status'] = true; |
| 722 | 707 | $data['result'] = do_shortcode( '[wpshop_products pid="' . implode(',', $final_result) . '" cid="' . $category_id . '" container="no" ]' ) ; |
| 723 | 708 | $data['products_count'] = $products_count; |
| 724 | - } |
|
| 725 | - else { |
|
| 709 | + } else { |
|
| 726 | 710 | $data['status'] = false; |
| 727 | 711 | $data['result'] = '<div class="container_product_listing">'.__('There is no product for this filter search.', 'wpshop').'</div>'; |
| 728 | 712 | $data['products_count'] = __('No products corresponds to your search', 'wpshop'); |