Skip to content

Instantly share code, notes, and snippets.

View Jerl92's full-sized avatar

Jérémie Langevin Jerl92

View GitHub Profile
@Jerl92
Jerl92 / Get_post_by_city.php
Last active March 5, 2026 00:42
Get post by city
<?php
$city = null;
$get_city_array = array();
$get_args_emploi = array(
'post_type' => 'emploi',
'posts_per_page' => -1,
'post_status' => array('publish', 'draft', 'future'),
'orderby' => 'date',
@Jerl92
Jerl92 / Geodecode_city.js
Created March 4, 2026 22:35
Geodecode the city with a full address or a code postal
jQuery(document).ready(function($) {
jQuery('.monemploi_add_code_postal_text').on('keydown', function(event) {
geocoder = new google.maps.Geocoder();
var adresse = jQuery('.monemploi_add_code_postal_text').val();
geocoder.geocode({ 'address': adresse }, function(results, status) {
if (results[0]) {
var city = "";
for (var i = 0; i < results[0].address_components.length; i++) {
for (var b = 0; b < results[0].address_components[i].types.length; b++) {
if (results[0].address_components[i].types[b] == "locality") {
@Jerl92
Jerl92 / send_email_on_future_publish.php
Created March 4, 2026 22:32
send email on future publish
<?php
function send_email_on_future_publish( $new_status, $old_status, $post ) {
// Check if the new status is 'publish' and the old status was 'future'
if ( 'publish' === $new_status && 'future' === $old_status ) {
// Ensure it's a 'post' type (can add other post types if needed)
if ( 'post' === $post->post_type ) {
$author = get_userdata( $post->post_author );
$author_email = $author->user_email;
$post_title = get_the_title( $post->ID );
@Jerl92
Jerl92 / scheduled.php
Created February 25, 2026 12:01
Create scheduled post programmatically
<?php
function create_scheduled_post_programmatically() {
// Define the future publication date and time
$schedule_timestamp = strtotime('+1 day 10:00:00'); // Example: Schedule for tomorrow at 10 AM
// Convert the timestamp to the required MySQL datetime format
$publish_date = date('Y-m-d H:i:s', $schedule_timestamp);
// Convert to GMT time for post_date_gmt, accounting for your WordPress site's timezone settings
$publish_date_gmt = get_gmt_from_date($publish_date);
@Jerl92
Jerl92 / jquery-count.js
Created February 6, 2026 10:45 — forked from frankyonnetti/jquery-count.js
jQuery - count clicks #jquery
var count = 0;
$("#update").click(function() {
count++;
$("#counter").html("My current count is: "+count);
});
$("#update").click(function() {
count += 120; // increase by 120
@Jerl92
Jerl92 / Character-count.js
Created February 6, 2026 05:04
How to display real time characters count using jQuery?
// Source - https://stackoverflow.com/a/45591102
// Posted by hallleron
// Retrieved 2026-02-06, License - CC BY-SA 3.0
$('input[name="name"]').on('keyup keydown', updateCount);
function updateCount() {
$('#characters').text($(this).val().length);
}
@Jerl92
Jerl92 / Front-end-upload.php
Created January 24, 2026 03:26
Wordpress front-end media upload
<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post" enctype="multipart/form-data">
<!-- Security field -->
<?php wp_nonce_field( 'media_upload', 'media_upload_nonce' ); ?>
<label for="file_upload">Select File:</label>
<input type="file" name="file_upload" id="file_upload" required />
<input type="hidden" name="action" value="frontend_media_upload">
<input type="submit" name="submit" value="Upload Media" />
</form>
<?php
@Jerl92
Jerl92 / Getdistance.js
Created January 14, 2026 10:08
Get distance from two points
// Source - https://stackoverflow.com/a
// Posted by James
// Retrieved 2026-01-14, License - CC BY-SA 3.0
function getDistance()
{
//Find the distance
var distanceService = new google.maps.DistanceMatrixService();
distanceService.getDistanceMatrix({
origins: [$("#autocompleteDeparture").val()],
@Jerl92
Jerl92 / gist:31bf7684c438672e1ba32f74ea5513db
Created December 26, 2025 15:57
Ultimate member change user role on create
<?php
add_action( 'um_registration_set_extra_data', 'my_custom_after_registration_action', 10, 2 );
function my_custom_after_registration_action( $user_id, $args ) {
if ( empty( $user_id ) || is_wp_error( $user_id ) ) {
return;
}
// Check if the specific radio button field value exists in the submitted data
<?php
function add_custom_item_to_menu( $items, $args ) {
if ( $args->theme_location == 'primary-menu' ) {
$user = wp_get_current_user();
$user_meta = get_userdata($user->ID);
$user_role = $user_meta->roles[0];
if($user_role == 'um_employeur' || $user_role == 'administrator'){
$items .= "<li id='main-menu'><a href='https://monemploi.net/ajouter-un-emploi/'>Ajouter un emploi</a></li>";
}