| @@ -1,67 +1,90 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Template form search author field for custom post type of course. | |
| 4 | - * | |
| 5 | - * @since 4.2.6.9 | |
| 6 | - * @version 1.0.0 | |
| 7 | - */ | |
| 8 | -$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; | |
| 9 | - | |
| 10 | -// Check condition show field search by author for post. | |
| 11 | -$show_search_author_field = 0; | |
| 12 | -if ( ! $screen instanceof WP_Screen ) { | |
| 13 | - return; | |
| 14 | -} | |
| 15 | -$course_item_types = learn_press_get_course_item_types(); | |
| 16 | -$screens_show_search_author_field = [ | |
| 17 | - 'edit-' . LP_COURSE_CPT, | |
| 18 | - 'edit-' . LP_QUESTION_CPT, | |
| 19 | - 'edit-' . LP_ORDER_CPT, | |
| 20 | -]; | |
| 21 | - | |
| 22 | -foreach ( $course_item_types as $type ) { | |
| 23 | - $screens_show_search_author_field[] = 'edit-' . $type; | |
| 24 | -} | |
| 25 | - | |
| 26 | -$show_search_author_field = in_array( $screen->id, $screens_show_search_author_field ) ? 1 : 0; | |
| 27 | -if ( ! $show_search_author_field ) { | |
| 28 | - return; | |
| 29 | -} | |
| 30 | - | |
| 31 | -/** | |
| 32 | - * @uses WP_List_Table::search_box() | |
| 33 | - * | |
| 34 | - * HTML return same search_box method | |
| 35 | - */ | |
| 36 | -global $typenow; | |
| 37 | -$post_type = $typenow; | |
| 38 | -$post_type_object = get_post_type_object( $post_type ); | |
| 39 | - | |
| 40 | -$input_id = 'post-search-input'; | |
| 41 | - | |
| 42 | -if ( ! empty( $_REQUEST['orderby'] ) ) { | |
| 43 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; | |
| 44 | -} | |
| 45 | -if ( ! empty( $_REQUEST['order'] ) ) { | |
| 46 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; | |
| 47 | -} | |
| 48 | -if ( ! empty( $_REQUEST['post_mime_type'] ) ) { | |
| 49 | - echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />'; | |
| 50 | -} | |
| 51 | -if ( ! empty( $_REQUEST['detached'] ) ) { | |
| 52 | - echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />'; | |
| 53 | -} | |
| 54 | - | |
| 55 | -$value_search = LP_Request::get_param( 's', '' ); | |
| 56 | -?> | |
| 57 | -<p class="search-box"> | |
| 58 | - <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"> | |
| 59 | - <?php echo $post_type_object->labels->search_items; ?>: | |
| 60 | - </label> | |
| 61 | - <input type="search" | |
| 62 | - id="<?php echo esc_attr( $input_id ); ?>" | |
| 63 | - name="s" | |
| 64 | - placeholder="<?php _e( 'Search', 'learnpress' ); ?>" | |
| 65 | - value="<?php echo esc_attr( $value_search ) ?>"/> | |
| 66 | - <?php submit_button( $post_type_object->labels->search_items, '', '', false, array( 'id' => 'search-submit' ) ); ?> | |
| 67 | -</p> | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Template form search author field for custom post type of course. | |
| 4 | + * | |
| 5 | + * @since 4.2.6.9 | |
| 6 | + * @version 1.0.1 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +use LearnPress\Models\CourseModel; | |
| 10 | + | |
| 11 | +$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; | |
| 12 | + | |
| 13 | +// Check condition show field search by author for post. | |
| 14 | +$show_search_author_field = 0; | |
| 15 | +if ( ! $screen instanceof WP_Screen ) { | |
| 16 | + return; | |
| 17 | +} | |
| 18 | +$course_item_types = CourseModel::item_types_support(); | |
| 19 | +$screens_show_search_author_field = [ | |
| 20 | + 'edit-' . LP_COURSE_CPT, | |
| 21 | + 'edit-' . LP_QUESTION_CPT, | |
| 22 | + 'edit-' . LP_ORDER_CPT, | |
| 23 | +]; | |
| 24 | + | |
| 25 | +foreach ( $course_item_types as $type ) { | |
| 26 | + $screens_show_search_author_field[] = 'edit-' . $type; | |
| 27 | +} | |
| 28 | + | |
| 29 | +$show_search_author_field = in_array( $screen->id, $screens_show_search_author_field ) ? 1 : 0; | |
| 30 | +if ( ! $show_search_author_field ) { | |
| 31 | + return; | |
| 32 | +} | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * @uses WP_List_Table::search_box() | |
| 36 | + * | |
| 37 | + * HTML return same search_box method | |
| 38 | + */ | |
| 39 | +global $typenow; | |
| 40 | +$post_type = $typenow; | |
| 41 | +$post_type_object = get_post_type_object( $post_type ); | |
| 42 | + | |
| 43 | +$input_id = 'post-search-input'; | |
| 44 | + | |
| 45 | +if ( ! empty( $_REQUEST['orderby'] ) ) { | |
| 46 | + echo sprintf( | |
| 47 | + '<input type="hidden" name="orderby" value="%s" />', | |
| 48 | + esc_attr( sanitize_key( $_REQUEST['orderby'] ) ) | |
| 49 | + ); | |
| 50 | +} | |
| 51 | +if ( ! empty( $_REQUEST['order'] ) ) { | |
| 52 | + echo sprintf( | |
| 53 | + '<input type="hidden" name="order" value="%s" />', | |
| 54 | + esc_attr( sanitize_key( $_REQUEST['order'] ) ) | |
| 55 | + ); | |
| 56 | +} | |
| 57 | +if ( ! empty( $_REQUEST['post_mime_type'] ) ) { | |
| 58 | + echo sprintf( | |
| 59 | + '<input type="hidden" name="post_mime_type" value="%s" />', | |
| 60 | + esc_attr( $_REQUEST['post_mime_type'] ) | |
| 61 | + ); | |
| 62 | +} | |
| 63 | +if ( ! empty( $_REQUEST['detached'] ) ) { | |
| 64 | + echo sprintf( | |
| 65 | + '<input type="hidden" name="detached" value="%s" />', | |
| 66 | + esc_attr( $_REQUEST['detached'] ) | |
| 67 | + ); | |
| 68 | +} | |
| 69 | + | |
| 70 | +$value_search = LP_Request::get_param( 's', '' ); | |
| 71 | +?> | |
| 72 | +<p class="search-box"> | |
| 73 | + <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"> | |
| 74 | + <?php echo $post_type_object->labels->search_items; ?>: | |
| 75 | + </label> | |
| 76 | + <input type="search" | |
| 77 | + id="<?php echo esc_attr( $input_id ); ?>" | |
| 78 | + name="s" | |
| 79 | + placeholder="<?php _e( 'Search', 'learnpress' ); ?>" | |
| 80 | + value="<?php echo esc_attr( $value_search ); ?>"/> | |
| 81 | + <?php | |
| 82 | + submit_button( | |
| 83 | + $post_type_object->labels->search_items, | |
| 84 | + '', | |
| 85 | + '', | |
| 86 | + false, | |
| 87 | + array( 'id' => 'search-submit' ) | |
| 88 | + ); | |
| 89 | + ?> | |
| 90 | +</p> | |