theme-compatibility
6 years ago
tutor-general-functions.php
6 years ago
tutor-template-functions.php
6 years ago
tutor-template-hook.php
6 years ago
tutor-general-functions.php
382 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) |
| 4 | exit; |
| 5 | |
| 6 | /** |
| 7 | * Tutor general Functions |
| 8 | */ |
| 9 | |
| 10 | if ( ! function_exists('tutor_withdrawal_methods')){ |
| 11 | function tutor_withdrawal_methods(){ |
| 12 | $withdraw = new \TUTOR\Withdraw(); |
| 13 | |
| 14 | return $withdraw->available_withdraw_methods; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | if ( ! function_exists('tutor_placeholder_img_src')) { |
| 19 | function tutor_placeholder_img_src() { |
| 20 | $src = tutor()->url . 'assets/images/placeholder.jpg'; |
| 21 | return apply_filters( 'tutor_placeholder_img_src', $src ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @return string |
| 27 | * |
| 28 | * Get course categories selecting UI |
| 29 | * |
| 30 | * @since v.1.3.4 |
| 31 | */ |
| 32 | |
| 33 | if ( ! function_exists('tutor_course_categories_dropdown')){ |
| 34 | function tutor_course_categories_dropdown($post_ID = 0, $args = array()){ |
| 35 | |
| 36 | $default = array( |
| 37 | 'classes' => '', |
| 38 | 'name' => 'tax_input[course-category]', |
| 39 | 'multiple' => true, |
| 40 | ); |
| 41 | |
| 42 | $args = apply_filters('tutor_course_categories_dropdown_args', array_merge($default, $args)); |
| 43 | |
| 44 | $multiple_select = ''; |
| 45 | |
| 46 | if (tutor_utils()->array_get('multiple', $args)){ |
| 47 | if (isset($args['name'])){ |
| 48 | $args['name'] = $args['name'].'[]'; |
| 49 | } |
| 50 | $multiple_select = "multiple='multiple'"; |
| 51 | } |
| 52 | |
| 53 | extract($args); |
| 54 | |
| 55 | $classes = (array) $classes; |
| 56 | $classes = implode(' ', $classes); |
| 57 | |
| 58 | $categories = tutor_utils()->get_course_categories(); |
| 59 | |
| 60 | $output = ''; |
| 61 | $output .= "<select name='{$name}' {$multiple_select} class='{$classes}' data-placeholder='". __('Search Course Category. ex. Design, Development, Business', 'tutor') ."'>"; |
| 62 | $output .= "<option value=''>". __('Select a category', 'tutor') ."</option>"; |
| 63 | $output .= _generate_categories_dropdown_option($post_ID, $categories, $args); |
| 64 | $output .= "</select>"; |
| 65 | |
| 66 | return $output; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @param $categories |
| 72 | * @param string $parent_name |
| 73 | * |
| 74 | * @return string |
| 75 | * |
| 76 | * Get selecting options, recursive supports |
| 77 | * |
| 78 | * @since v.1.3.4 |
| 79 | */ |
| 80 | |
| 81 | if ( ! function_exists('_generate_categories_dropdown_option')){ |
| 82 | function _generate_categories_dropdown_option($post_ID = 0, $categories, $args = array(), $depth = 0){ |
| 83 | $output = ''; |
| 84 | |
| 85 | if (tutor_utils()->count($categories)) { |
| 86 | foreach ( $categories as $category_id => $category ) { |
| 87 | if ( ! $category->parent){ |
| 88 | $depth = 0; |
| 89 | } |
| 90 | |
| 91 | $childrens = tutor_utils()->array_get( 'children', $category ); |
| 92 | $has_in_term = has_term( $category->term_id, 'course-category', $post_ID ); |
| 93 | |
| 94 | $depth_seperator = ''; |
| 95 | if ($depth){ |
| 96 | for ($depth_i = 0; $depth_i < $depth; $depth_i++){ |
| 97 | $depth_seperator.='-'; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | $output .= "<option value='{$category->term_id}' ".selected($has_in_term, true, false)." > {$depth_seperator} {$category->name}</option> "; |
| 102 | |
| 103 | if ( tutor_utils()->count( $childrens ) ) { |
| 104 | $depth++; |
| 105 | $output .= _generate_categories_dropdown_option($post_ID,$childrens, $args, $depth); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | return $output; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @param array $args |
| 115 | * |
| 116 | * @return string |
| 117 | * |
| 118 | * Generate course categories checkbox |
| 119 | * @since v.1.3.4 |
| 120 | */ |
| 121 | |
| 122 | if ( ! function_exists('tutor_course_categories_checkbox')){ |
| 123 | function tutor_course_categories_checkbox($post_ID = 0, $args = array()){ |
| 124 | $default = array( |
| 125 | 'name' => 'tax_input[course-category]', |
| 126 | ); |
| 127 | |
| 128 | $args = apply_filters('tutor_course_categories_checkbox_args', array_merge($default, $args)); |
| 129 | |
| 130 | if (isset($args['name'])){ |
| 131 | $args['name'] = $args['name'].'[]'; |
| 132 | } |
| 133 | |
| 134 | extract($args); |
| 135 | |
| 136 | $categories = tutor_utils()->get_course_categories(); |
| 137 | $output = ''; |
| 138 | $output .= __tutor_generate_categories_checkbox($post_ID, $categories, $args); |
| 139 | |
| 140 | return $output; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * @param $categories |
| 146 | * @param string $parent_name |
| 147 | * @param array $args |
| 148 | * |
| 149 | * @return string |
| 150 | * |
| 151 | * Internal function to generate course categories checkbox |
| 152 | * |
| 153 | * @since v.1.3.4 |
| 154 | */ |
| 155 | if ( ! function_exists('__tutor_generate_categories_checkbox')){ |
| 156 | function __tutor_generate_categories_checkbox($post_ID = 0, $categories, $args = array()){ |
| 157 | $output = ''; |
| 158 | $input_name = tutor_utils()->array_get('name', $args); |
| 159 | |
| 160 | if (tutor_utils()->count($categories)) { |
| 161 | $output .= "<ul class='tax-input-course-category'>"; |
| 162 | foreach ( $categories as $category_id => $category ) { |
| 163 | $childrens = tutor_utils()->array_get( 'children', $category ); |
| 164 | $has_in_term = has_term( $category->term_id, 'course-category', $post_ID ); |
| 165 | |
| 166 | $output .= "<li class='tax-input-course-category-item tax-input-course-category-item-{$category->term_id} '><label class='course-category-checkbox'> <input type='checkbox' name='{$input_name}' value='{$category->term_id}' ".checked($has_in_term, true, false)." /> <span>{$category->name}</span> </label>"; |
| 167 | |
| 168 | if ( tutor_utils()->count( $childrens ) ) { |
| 169 | $output .= __tutor_generate_categories_checkbox($post_ID,$childrens, $args); |
| 170 | } |
| 171 | $output .= " </li>"; |
| 172 | } |
| 173 | $output .= "</ul>"; |
| 174 | } |
| 175 | return $output; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @param string $content |
| 181 | * @param string $title |
| 182 | * |
| 183 | * @return string |
| 184 | * |
| 185 | * Wrap course builder sections within div for frontend |
| 186 | * |
| 187 | * @since v.1.3.4 |
| 188 | */ |
| 189 | |
| 190 | if ( ! function_exists('course_builder_section_wrap')) { |
| 191 | function course_builder_section_wrap( $content = '', $title = '', $echo = true ) { |
| 192 | ob_start(); |
| 193 | ?> |
| 194 | <div class="tutor-course-builder-section"> |
| 195 | <div class="tutor-course-builder-section-title"> |
| 196 | <h3><i class="tutor-icon-down"></i> <span><?php echo $title; ?></span></h3> |
| 197 | </div> |
| 198 | <div class="tutor-course-builder-section-content"> |
| 199 | <?php echo $content; ?> |
| 200 | </div> |
| 201 | </div> |
| 202 | <?php |
| 203 | $html = ob_get_clean(); |
| 204 | |
| 205 | if ($echo){ |
| 206 | echo $html; |
| 207 | }else{ |
| 208 | return $html; |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | |
| 214 | if ( ! function_exists('get_tutor_header')){ |
| 215 | function get_tutor_header($fullScreen = false){ |
| 216 | $enable_spotlight_mode = tutor_utils()->get_option('enable_spotlight_mode'); |
| 217 | |
| 218 | if ($enable_spotlight_mode || $fullScreen){ |
| 219 | ?> |
| 220 | <!doctype html> |
| 221 | <html <?php language_attributes(); ?>> |
| 222 | <head> |
| 223 | <meta charset="<?php bloginfo( 'charset' ); ?>" /> |
| 224 | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 225 | <link rel="profile" href="https://gmpg.org/xfn/11" /> |
| 226 | <?php wp_head(); ?> |
| 227 | </head> |
| 228 | <body <?php body_class(); ?>> |
| 229 | <div id="tutor-page-wrap" class="tutor-site-wrap site"> |
| 230 | <?php |
| 231 | }else{ |
| 232 | get_header(); |
| 233 | } |
| 234 | |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if (! function_exists('get_tutor_footer')){ |
| 239 | function get_tutor_footer($fullScreen = false){ |
| 240 | $enable_spotlight_mode = tutor_utils()->get_option('enable_spotlight_mode'); |
| 241 | if ($enable_spotlight_mode || $fullScreen){ |
| 242 | ?> |
| 243 | </div> |
| 244 | <?php wp_footer(); ?> |
| 245 | |
| 246 | </body> |
| 247 | </html> |
| 248 | <?php |
| 249 | }else{ |
| 250 | get_footer(); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * @param int $parent_id |
| 257 | * @param array $level_categories |
| 258 | * |
| 259 | * Generate Courses categories for Paid Memberships Pro |
| 260 | * |
| 261 | * @since v.1.3.6 |
| 262 | */ |
| 263 | if ( ! function_exists('generate_categories_for_pmpro')) { |
| 264 | function generate_categories_for_pmpro( $parent_id = 0, $level_categories = array() ) { |
| 265 | $args = array( |
| 266 | 'taxonomy' => 'course-category', |
| 267 | 'parent' => $parent_id, |
| 268 | 'hide_empty' => false, |
| 269 | ); |
| 270 | $cats = get_categories( apply_filters( 'course_categories_pmpro_args', $args ) ); |
| 271 | if ( $cats ) { |
| 272 | foreach ( $cats as $cat ) { |
| 273 | $name = 'membershipcategory_' . $cat->term_id; |
| 274 | if ( ! empty( $level_categories ) ) { |
| 275 | $checked = checked( in_array( $cat->term_id, $level_categories ), true, false ); |
| 276 | } else { |
| 277 | $checked = ''; |
| 278 | } |
| 279 | echo "<ul><li class=membershipcategory><input type=checkbox name={$name} id={$name} value=yes {$checked}><label for={$name}>{$cat->name}</label>"; |
| 280 | generate_categories_for_pmpro( $cat->term_id, $level_categories ); |
| 281 | echo '</li></ul>'; |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | function generate_categories_select_for_pmpro($level_categories = array(), $args = array()){ |
| 289 | |
| 290 | $default = array( |
| 291 | 'classes' => '', |
| 292 | 'name' => 'tax_input[course-category]', |
| 293 | 'multiple' => true, |
| 294 | ); |
| 295 | |
| 296 | $args = apply_filters('tutor_course_categories_dropdown_args', array_merge($default, $args)); |
| 297 | |
| 298 | $multiple_select = ''; |
| 299 | |
| 300 | if (tutor_utils()->array_get('multiple', $args)){ |
| 301 | if (isset($args['name'])){ |
| 302 | $args['name'] = $args['name'].'[]'; |
| 303 | } |
| 304 | $multiple_select = "multiple='multiple'"; |
| 305 | } |
| 306 | |
| 307 | extract($args); |
| 308 | |
| 309 | $classes = (array) $classes; |
| 310 | $classes = implode(' ', $classes); |
| 311 | |
| 312 | $categories = tutor_utils()->get_course_categories(); |
| 313 | |
| 314 | $output = ''; |
| 315 | $output .= "<select name='{$name}' {$multiple_select} class='{$classes}'>"; |
| 316 | $output .= "<option value=''>". __('Select categories', 'tutor') ."</option>"; |
| 317 | $output .= _generate_categories_select_option_for_pmpro($level_categories, $categories, $args); |
| 318 | $output .= "</select>"; |
| 319 | |
| 320 | return $output; |
| 321 | } |
| 322 | |
| 323 | function _generate_categories_select_option_for_pmpro($level_categories = array(), $categories, $args = array(), $depth = 0){ |
| 324 | $output = ''; |
| 325 | |
| 326 | if (tutor_utils()->count($categories)) { |
| 327 | foreach ( $categories as $category_id => $category ) { |
| 328 | if ( ! $category->parent){ |
| 329 | $depth = 0; |
| 330 | } |
| 331 | |
| 332 | $childrens = tutor_utils()->array_get( 'children', $category ); |
| 333 | $has_in_term = in_array($category->term_id, $level_categories); |
| 334 | |
| 335 | $depth_seperator = ''; |
| 336 | if ($depth){ |
| 337 | for ($depth_i = 0; $depth_i < $depth; $depth_i++){ |
| 338 | $depth_seperator.='-'; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | $output .= "<option value='{$category->term_id}' ".selected($has_in_term, true, false)." >{$depth_seperator} {$category->name}</option> "; |
| 343 | |
| 344 | if ( tutor_utils()->count( $childrens ) ) { |
| 345 | $depth++; |
| 346 | $output .= _generate_categories_select_option_for_pmpro($level_categories,$childrens, $args, $depth); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | return $output; |
| 351 | }*/ |
| 352 | |
| 353 | |
| 354 | /** |
| 355 | * @param null $key |
| 356 | * @param bool $default |
| 357 | * |
| 358 | * @return array|bool|mixed |
| 359 | * |
| 360 | * Get tutor option by this helper function |
| 361 | * |
| 362 | * @since v.1.3.6 |
| 363 | */ |
| 364 | if ( ! function_exists('get_tutor_option')){ |
| 365 | function get_tutor_option($key = null, $default = false){ |
| 366 | return tutils()->get_option($key, $default); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * @param null $key |
| 372 | * @param bool $value |
| 373 | * |
| 374 | * Update tutor option by this helper function |
| 375 | * |
| 376 | * @since v.1.3.6 |
| 377 | */ |
| 378 | if ( ! function_exists('update_tutor_option')){ |
| 379 | function update_tutor_option($key = null, $value = false){ |
| 380 | tutils()->update_option($key, $value); |
| 381 | } |
| 382 | } |