| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | 4 | * The public-facing functionality of the plugin. |
| 4 | 5 | * |
| 5 | 6 | * @link http://wpgeodirectory.com |
| @@ -20,106 +21,108 @@ | ||
| 20 | 21 | * @author GeoDirectory Team <[email protected]> |
| 21 | 22 | */ |
| 22 | 23 | class UsersWP_Public { |
| 23 | 24 | |
| 24 | - /** | |
| 25 | - * Register the stylesheets for the public-facing side of the site. | |
| 26 | - * | |
| 27 | - * @since 1.0.0 | |
| 28 | - */ | |
| 29 | - public function enqueue_styles() { | |
| 30 | - // Scripts if user on own profile page. | |
| 31 | - if ( is_uwp_current_user_profile_page() ) { | |
| 32 | - // Include only profile pages | |
| 33 | - wp_enqueue_style( 'jcrop' ); | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * Register the stylesheets for the public-facing side of the site. | |
| 28 | + * | |
| 29 | + * @since 1.0.0 | |
| 30 | + */ | |
| 31 | + public function enqueue_styles() { | |
| 34 | 32 | |
| 35 | - if ( is_user_logged_in() ) { | |
| 36 | - wp_enqueue_media(); | |
| 37 | - } | |
| 38 | - } | |
| 39 | 33 | |
| 40 | - wp_register_style( 'jquery-ui', USERSWP_PLUGIN_URL . 'assets/css/jquery-ui.css' ); | |
| 34 | + // Scripts if user on own profile page. | |
| 35 | + if (is_uwp_current_user_profile_page()) { | |
| 36 | + // include only profile pages | |
| 37 | + wp_enqueue_style( 'jcrop' ); | |
| 41 | 38 | |
| 42 | - // maybe add bootstrap | |
| 43 | - if ( empty( uwp_get_option("design_style", "bootstrap" ) ) ) { | |
| 44 | - wp_enqueue_style( USERSWP_NAME, USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' ); | |
| 45 | - wp_register_style( 'uwp-authorbox', USERSWP_PLUGIN_URL . 'assets/css/authorbox.css', array(), USERSWP_VERSION, 'all' ); | |
| 46 | - } else { | |
| 47 | - //@todo this is not actually being used yet, enable when if it is. | |
| 48 | - //wp_enqueue_style( "uwp", USERSWP_PLUGIN_URL . 'assets/css/bootstrap/uwp.css', array(), USERSWP_VERSION, 'all' ); | |
| 49 | - } | |
| 50 | - } | |
| 39 | + if (is_user_logged_in()) { | |
| 40 | + wp_enqueue_media(); | |
| 41 | + } | |
| 42 | + } | |
| 51 | 43 | |
| 52 | - /** | |
| 53 | - * Register the JavaScript for the public-facing side of the site. | |
| 54 | - * | |
| 55 | - * @since 1.0.0 | |
| 56 | - */ | |
| 57 | - public function enqueue_scripts() { | |
| 58 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 59 | - $in_footer = apply_filters( 'uwp_enqueue_scripts_in_footer', false ); | |
| 60 | 44 | |
| 61 | - // Core UWP JS | |
| 62 | - wp_enqueue_script( USERSWP_NAME, USERSWP_PLUGIN_URL . 'assets/js/users-wp' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, $in_footer ); | |
| 45 | + wp_register_style( 'jquery-ui', USERSWP_PLUGIN_URL . 'assets/css/jquery-ui.css' ); | |
| 63 | 46 | |
| 64 | - // localize | |
| 65 | - $uwp_localize_data = uwp_get_localize_data(); | |
| 66 | - wp_localize_script( USERSWP_NAME, 'uwp_localize_data', $uwp_localize_data ); | |
| 47 | + // maybe add bootstrap | |
| 48 | + if(empty(uwp_get_option("design_style","bootstrap"))){ | |
| 49 | + wp_enqueue_style( USERSWP_NAME, USERSWP_PLUGIN_URL . 'assets/css/users-wp.css', array(), USERSWP_VERSION, 'all' ); | |
| 50 | + wp_register_style( 'uwp-authorbox', USERSWP_PLUGIN_URL . 'assets/css/authorbox.css', array(), USERSWP_VERSION, 'all' ); | |
| 51 | + }else{ | |
| 52 | + //@todo this is not actually being used yet, enable when if it is. | |
| 53 | + //wp_enqueue_style( "uwp", USERSWP_PLUGIN_URL . 'assets/css/bootstrap/uwp.css', array(), USERSWP_VERSION, 'all' ); | |
| 54 | + } | |
| 67 | 55 | |
| 68 | - wp_register_script( "uwp_timepicker", USERSWP_PLUGIN_URL . 'assets/js/jquery.ui.timepicker.min.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-core' ), USERSWP_VERSION, true ); | |
| 56 | + } | |
| 69 | 57 | |
| 70 | - $enable_timepicker_fields = false; | |
| 71 | - $enable_country_fields = false; | |
| 72 | - $fields = $this->get_all_form_fields(); | |
| 58 | + /** | |
| 59 | + * Register the JavaScript for the public-facing side of the site. | |
| 60 | + * | |
| 61 | + * @since 1.0.0 | |
| 62 | + */ | |
| 63 | + public function enqueue_scripts() { | |
| 73 | 64 | |
| 74 | - if ( ! empty( $fields ) ) { | |
| 75 | - foreach ( $fields as $field ) { | |
| 76 | - if ( isset( $field->field_type ) && ( $field->field_type == 'time' || $field->field_type == 'datepicker' ) ) { | |
| 77 | - $enable_timepicker_fields = true; | |
| 78 | - } | |
| 65 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 79 | 66 | |
| 80 | - if ( isset($field->field_type_key ) && ( $field->field_type_key == 'uwp_country' || $field->field_type_key == 'country' ) ) { | |
| 81 | - $enable_country_fields = true; | |
| 82 | - } | |
| 83 | - } | |
| 84 | - } | |
| 67 | + // Core UWP JS | |
| 68 | + wp_enqueue_script( USERSWP_NAME, USERSWP_PLUGIN_URL . 'assets/js/users-wp' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false ); | |
| 85 | 69 | |
| 86 | - if ( $enable_timepicker_fields ) { | |
| 87 | - wp_enqueue_style( 'jquery-ui' ); | |
| 88 | - wp_enqueue_script( "uwp_timepicker" ); | |
| 89 | - } | |
| 70 | + // localize | |
| 71 | + $uwp_localize_data = uwp_get_localize_data(); | |
| 72 | + wp_localize_script(USERSWP_NAME, 'uwp_localize_data', $uwp_localize_data); | |
| 90 | 73 | |
| 91 | - if ( $enable_country_fields ) { | |
| 92 | - //@todo lets find a better solution for this and put it in AUI, maybe SVG files? | |
| 93 | - wp_enqueue_style( "uwp-country-select", USERSWP_PLUGIN_URL . 'assets/css/countryselect.css', array(), USERSWP_VERSION, 'all' ); | |
| 94 | - wp_enqueue_script( "country-select", USERSWP_PLUGIN_URL . 'assets/js/countrySelect' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, $in_footer ); | |
| 95 | - $country_data = uwp_get_country_data(); | |
| 96 | - wp_localize_script( 'country-select', 'uwp_country_data', $country_data ); | |
| 97 | - } | |
| 74 | + wp_register_script( "uwp_timepicker", USERSWP_PLUGIN_URL . 'assets/js/jquery.ui.timepicker.min.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-core' ), USERSWP_VERSION, true ); | |
| 75 | + | |
| 76 | + $enable_timepicker_fields = false; | |
| 77 | + $enable_country_fields = false; | |
| 78 | + | |
| 79 | + $fields = $this->get_all_form_fields(); | |
| 80 | + if (!empty($fields)) { | |
| 81 | + foreach ($fields as $field) { | |
| 82 | + if (isset($field->field_type) && ($field->field_type == 'time' || $field->field_type == 'datepicker')) { | |
| 83 | + $enable_timepicker_fields = true; | |
| 84 | + } | |
| 85 | + if (isset($field->field_type_key) && ($field->field_type_key == 'uwp_country' || $field->field_type_key == 'country')) { | |
| 86 | + $enable_country_fields = true; | |
| 87 | + } | |
| 88 | + } | |
| 89 | + } | |
| 90 | + | |
| 91 | + if($enable_timepicker_fields) { | |
| 92 | + wp_enqueue_style( 'jquery-ui' ); | |
| 93 | + wp_enqueue_script( "uwp_timepicker" ); | |
| 94 | + } | |
| 95 | + | |
| 96 | + if($enable_country_fields) { | |
| 97 | + //@todo lets find a better solution for this and put it in AUI, maybe SVG files? | |
| 98 | + wp_enqueue_style( "uwp-country-select", USERSWP_PLUGIN_URL . 'assets/css/countryselect.css', array(), USERSWP_VERSION, 'all' ); | |
| 99 | + wp_enqueue_script( "country-select", USERSWP_PLUGIN_URL . 'assets/js/countrySelect' . $suffix . '.js', array( 'jquery' ), USERSWP_VERSION, false ); | |
| 100 | + $country_data = uwp_get_country_data(); | |
| 101 | + wp_localize_script( 'country-select', 'uwp_country_data', $country_data ); | |
| 102 | + } | |
| 103 | + | |
| 98 | 104 | } |
| 99 | 105 | |
| 100 | - function get_all_form_fields( $htmlvar_name = '' ) { | |
| 106 | + function get_all_form_fields($htmlvar_name = ''){ | |
| 101 | 107 | global $wpdb; |
| 108 | + $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 109 | + $register_forms = uwp_get_option( 'multiple_registration_forms' ); | |
| 110 | + $custom_fields = array(); | |
| 102 | 111 | |
| 103 | - $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; | |
| 104 | - $register_forms = uwp_get_option( 'multiple_registration_forms' ); | |
| 105 | - $custom_fields = array(); | |
| 112 | + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) { | |
| 113 | + foreach ( $register_forms as $key => $register_form ) { | |
| 114 | + $form_ids[] = (int) $register_form['id']; | |
| 115 | + } | |
| 106 | 116 | |
| 107 | - if ( ! empty( $register_forms ) && is_array( $register_forms ) ) { | |
| 108 | - $form_ids = array(); | |
| 117 | + if ( isset( $form_ids ) && count( $form_ids ) > 0 ) { | |
| 118 | + $form_ids_placeholder = array_fill( 0, count( $form_ids ), '%d' ); | |
| 119 | + $form_ids_placeholder = implode( ', ', $form_ids_placeholder ); | |
| 120 | + $query = $wpdb->prepare("SELECT id,field_type,field_type_key FROM " . $table_name . " WHERE form_type = 'account' AND form_id IN (" . $form_ids_placeholder . ") AND (field_type = 'time' OR field_type = 'datepicker' OR field_type_key = 'uwp_country' OR field_type_key = 'country') ORDER BY sort_order ASC", $form_ids); | |
| 121 | + $custom_fields = $wpdb->get_results( $query); | |
| 122 | + } | |
| 123 | + } | |
| 109 | 124 | |
| 110 | - foreach ( $register_forms as $key => $register_form ) { | |
| 111 | - $form_ids[] = (int) $register_form['id']; | |
| 112 | - } | |
| 113 | - | |
| 114 | - if ( ! empty( $form_ids ) && count( $form_ids ) > 0 ) { | |
| 115 | - $form_ids_placeholder = array_fill( 0, count( $form_ids ), '%d' ); | |
| 116 | - $form_ids_placeholder = implode( ', ', $form_ids_placeholder ); | |
| 117 | - $query = $wpdb->prepare( "SELECT id,field_type,field_type_key FROM " . $table_name . " WHERE form_type = 'account' AND form_id IN (" . $form_ids_placeholder . ") AND (field_type = 'time' OR field_type = 'datepicker' OR field_type_key = 'uwp_country' OR field_type_key = 'country') ORDER BY sort_order ASC", $form_ids ); | |
| 118 | - $custom_fields = $wpdb->get_results( $query ); | |
| 119 | - } | |
| 120 | - } | |
| 121 | - | |
| 122 | - return $custom_fields; | |
| 123 | - } | |
| 125 | + return $custom_fields; | |
| 126 | + } | |
| 124 | 127 | |
| 125 | 128 | } |