gutenberg-jalali-calendar.php
1 year ago
lists-fix.php
1 year ago
styles-fix.php
1 year ago
widgets.php
1 year ago
lists-fix.php
123 lines
| 1 | <?php |
| 2 | |
| 3 | defined( 'ABSPATH' ) or exit( 'No direct script access allowed' ); |
| 4 | |
| 5 | /** |
| 6 | * Fixes admin lists for dates |
| 7 | * |
| 8 | * @author Mobin Ghasempoor |
| 9 | * @package WP-Parsidate |
| 10 | * @subpackage Admin/Lists |
| 11 | */ |
| 12 | |
| 13 | /** |
| 14 | * Enqueues admin scripts |
| 15 | * |
| 16 | * @return void |
| 17 | * @author Ehsaan |
| 18 | */ |
| 19 | function wpp_enqueue_admin_scripts() { |
| 20 | global $wpp_months_name; |
| 21 | |
| 22 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || wpp_is_active( 'dev_mode' ) ? '' : '.min'; |
| 23 | |
| 24 | wp_enqueue_script( 'wpp_admin', WP_PARSI_URL . 'assets/js/admin' . $suffix . '.js', false, WP_PARSI_VER ); |
| 25 | wp_localize_script( |
| 26 | 'wpp_admin', |
| 27 | 'WPP_I18N', |
| 28 | array( |
| 29 | 'months' => $wpp_months_name |
| 30 | ) |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | add_action( 'admin_enqueue_scripts', 'wpp_enqueue_admin_scripts' ); |
| 35 | |
| 36 | /** |
| 37 | * Hooks admin functions for restrict posts in edit pages |
| 38 | * |
| 39 | * @return void |
| 40 | */ |
| 41 | function wpp_backend_init() { |
| 42 | add_action( 'restrict_manage_posts', 'wpp_restrict_posts' ); |
| 43 | add_filter( 'posts_where', 'wpp_admin_posts_where' ); |
| 44 | } |
| 45 | |
| 46 | add_action( 'load-edit.php', 'wpp_backend_init' ); |
| 47 | |
| 48 | /** |
| 49 | * Limits posts to a certain date, if date setted |
| 50 | * |
| 51 | * @param string $where Query pointer |
| 52 | * |
| 53 | * @return string New Pointer |
| 54 | */ |
| 55 | function wpp_admin_posts_where( $where ) { |
| 56 | global $wp_query; |
| 57 | |
| 58 | if ( isset( $_GET['mfa'] ) && $_GET['mfa'] != '0' ) { |
| 59 | $wp_query->query_vars['m'] = $_GET['mfa']; |
| 60 | $where = wpp_posts_where( $where, $wp_query ); |
| 61 | } |
| 62 | |
| 63 | return $where; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Restrict posts to given date |
| 68 | * @return void |
| 69 | * @author Parsa Kafi |
| 70 | * @author Mobin Ghasempoor |
| 71 | */ |
| 72 | function wpp_restrict_posts() { |
| 73 | global $post_type, $post_status, $wpdb, $wpp_months_name; |
| 74 | |
| 75 | if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | $post_status_w = "AND post_status <> 'auto-draft'"; |
| 80 | |
| 81 | if ( $post_status != "" ) { |
| 82 | if ( is_string( $post_status ) ) { |
| 83 | $post_status_w .= " AND post_status = '$post_status'"; |
| 84 | } |
| 85 | } else { |
| 86 | $post_status_w .= " AND post_status <> 'trash'"; |
| 87 | } |
| 88 | |
| 89 | $sql = " |
| 90 | SELECT DISTINCT date( post_date ) AS date |
| 91 | FROM $wpdb->posts |
| 92 | WHERE post_type='$post_type' $post_status_w AND date( post_date ) <> '0000-00-00' |
| 93 | ORDER BY post_date |
| 94 | "; |
| 95 | |
| 96 | $list = $wpdb->get_col( $sql ); |
| 97 | |
| 98 | if ( empty( $list ) ) { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | $m = isset( $_GET['mfa'] ) ? (int) $_GET['mfa'] : 0; |
| 103 | $predate = ''; |
| 104 | |
| 105 | echo '<select name="mfa">'; |
| 106 | echo '<option ' . selected( $m, 0, false ) . ' value="0">' . __( 'Show All Dates', 'wp-parsidate' ) . '</option>' . PHP_EOL; |
| 107 | |
| 108 | foreach ( $list as $date ) { |
| 109 | $date = parsidate( 'Ym', $date, 'eng' ); |
| 110 | $year = substr( $date, 0, 4 ); |
| 111 | $month = substr( $date, 4, 2 ); |
| 112 | $month = $wpp_months_name[ (int) $month ]; |
| 113 | |
| 114 | if ( $predate != $date ) { |
| 115 | echo sprintf( '<option %s value="%s">%s</option>', selected( $m, $date, false ), $date, $month . ' ' . fix_number( $year ) ); |
| 116 | } |
| 117 | |
| 118 | $predate = $date; |
| 119 | } |
| 120 | |
| 121 | echo '</select>'; |
| 122 | } |
| 123 |