return new WP_Error( 'gp_empty_message', 'Wpisz tresc zgloszenia.', [ 'status' => 400 ] ); } $ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : 'unknown'; $rate_key = 'gp_update_report_' . md5( $ip ) . '_' . $restaurant_id; if ( get_transient( $rate_key ) ) { return new WP_Error( 'gp_rate_limited', 'Odczekaj chwile przed kolejnym zgloszeniem.', [ 'status' => 429 ] ); } set_transient( $rate_key, 1, 2 * MINUTE_IN_SECONDS ); $subject = 'Zgloszenie aktualizacji lokalu: ' . get_the_title( $restaurant_id ); $body = [ 'ID lokalu: ' . $restaurant_id, 'Lokal: ' . get_the_title( $restaurant_id ), 'URL: ' . get_permalink( $restaurant_id ), 'Edycja: ' . get_edit_post_link( $restaurant_id, 'raw' ), '', 'Tresc:', $message, ]; $sent = wp_mail( get_option( 'admin_email' ), $subject, implode( "\n", $body ) ); if ( ! $sent ) { return new WP_Error( 'gp_mail_failed', 'Nie udalo sie wyslac maila.', [ 'status' => 500 ] ); } return [ 'success' => true ]; }, ] ); } ); function gp_restaurant_template_media_url( $value ): string { if ( function_exists( 'gastro_norm_v' ) ) { return gastro_norm_v( $value ); } if ( empty( $value ) ) return ''; $first = is_array( $value ) ? reset( $value ) : $value; if ( is_array( $first ) && isset( $first['url'] ) ) return (string) $first['url']; if ( is_numeric( $first ) ) { $url = wp_get_attachment_url( (int) $first ); return $url ?: ''; } return (string) $first; } /* ── Invalidate homepage restaurant cache on save ── Front-page bumps the key suffix (…_v11 currently); clear the base key plus a range of versioned keys so a venue edit/publish shows up immediately instead of waiting out the 5-minute transient. */ add_action( 'save_post_gastronomia', function () { delete_transient( 'gp_homepage_restaurants' ); for ( $i = 2; $i <= 20; $i++ ) { delete_transient( 'gp_homepage_restaurants_v' . $i ); } } ); /* Blokada dostępu do panelu wp-admin dla osób niebędących administratorami */ add_action( 'admin_init', function() { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } if ( ! current_user_can( 'manage_options' ) ) { wp_safe_redirect( home_url( '/' ) ); exit; } } );