remove an array element by date [duplicate]

Question

I want to remove an array element if the date expires, but I couldn’t do it. Would you help me?

This is my removing element function

function my_demo_cronjob_action () {
    $present_date = strtotime('today UTC');
    $user = get_user_by('id',26);
    $user_levels = rua_get_user($user)->get_level_ids(false, false, true);

    foreach ($user_levels as $level) {
        $end_time_meta = 'end-time-'.$level;
        $end_time = get_the_author_meta( $end_time_meta, $user);

        $time = strtotime($end_time);

        if ($present_date > $time) {
            rua_get_user($user)->remove_level($level);
        }
    }
}
add_action('my_demo_cronjob_action', 'my_demo_cronjob_action');

This is my add element with date function

add_action( 'show_user_profile', 'crf_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'crf_show_extra_profile_fields' );

function crf_show_extra_profile_fields( $user ) {
  $choices = [
    '+2 week'  => '2 Week',
    '+9 months' => '9 Month',
    '+12 months' => '12 Month',
    '+2 week' => 'Extend',
];

$rua_user = rua_get_user( $user->ID );
$user_levels = $rua_user->get_level_ids();
$current_date = date("d/m/y H:i:s");

  foreach ( $user_levels as $user_level ) {

    $start_time_meta = 'start-time-'.$user_level;
    $start_time = get_the_author_meta( $start_time_meta, $user->ID);

    $end_time_meta = 'end-time-'.$user_level;
    $end_time = get_the_author_meta( $end_time_meta, $user->ID);

    $effectiveDate = strtotime($end_time, strtotime($start_time));
    $time = date("d/m/y H:i:s", $effectiveDate);

    ob_start();

    echo esc_html( get_the_title( $user_level ) ) . ' -> ';
    ?>
    <input type="datetime-local" id="start-time-<?php echo esc_attr( $user_level ); ?>" name="start-time-<?php echo esc_attr( $user_level ); ?>" value="<?php echo esc_attr( $start_time ); ?>"> - 

    <select name='end-time-<?php echo esc_attr( $user_level ); ?>' id='end-time-<?php echo esc_attr( $user_level ); ?>' style='width:180px;'>
        <option value='default'>Süre Seçiniz</option>
        <?php
        foreach ( $choices as $value => $label ) {
            ?>
            <option value="<?php echo esc_attr( $value ); ?>"
                <?php selected( $value, $end_time ); ?>>
                <?php echo esc_html( $label ); ?>
            </option>
            <?php
        }
        ?>
    </select> <?php echo $current_date . ' - ' . $time; ?>
    <br>
    <br>
    <?php
    $html = ob_get_clean();
    $elements[] = $html;
  } ?>
}
0
freedom667 1 month 0 Answers 5 views 0

Leave an answer