| 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> |
| 91 |
|