Site logo

Archived topic

php code conflict with elements module

5 replies · Started by Prabakaran on January 16, 2022

Viewing posts 1–6 of 6

Hello,

I added the shortcode in the Elements [Block - Content Template] module to make the CPT 'job'.
After I added the code below, the element will not let me edit it, but it works. I disabled the code below and checked the element. It works fine and can be edited. I do not know what code is blocking the element from working. Please help me with this problem.

add_shortcode( 'deadline_date_display', function() {
    ob_start();
    
    global $post;
    
    $new_date = rwmb_meta( "deadline_date" ); 
    $new_date_format = date('m/d/Y');
    
    echo '<p style="color:red; font-size:20px; font-weight: bold;">';
    
    if( !empty( $new_date ) ){
        $new_date_format = wp_date('D, d M Y (H:i T)', $new_date);
        echo '<strong>Apply before the Deadline</strong>' . '<br>';
        echo '<span style="color:black;">' . esc_html( $new_date_format ) . '</span>';
    }
    else {
        echo esc_textarea( 'Open until filled' );
    }
    
    echo '</p>';
    
    $old_url_email = rwmb_meta( "j_url_email" );
    
    if( !empty( $old_url_email ) ){
        echo '<a class="btn" href="' . esc_html( $old_url_email ) . '" target="_blank" rel="noopener">Apply Now</a>';
    }
    else{
        $app_details = rwmb_meta( 'app_details' );
        $method = $app_details['method'];
        
        if($method == 'online'){
            $apply_now = $app_details['url'];
            echo '<a class="btn" href="' . esc_html( $apply_now ) . '" target="_blank" rel="noopener">Apply Now</a>' . '<br><strong>' . esc_textarea('Online Application') . '</strong>';
        }
        elseif($method == 'email'){
          $apply_now = $app_details['email'];
          echo '<a class="btn" href="' . 'mailto:' . esc_html( $apply_now ) . '" target="_blank" rel="noopener">Apply Now</a>' . '<br><strong>' . esc_textarea('eMail Application') . '</strong>';
        }
    }
    return ob_get_clean();
}
);

Thanks.

Hello Leo,

I added the code in the functions.php/child theme.

And when that code is added in function.php, you cannot edit a specific element?

If so you will need to go through the code and identify the issue - you can try removing part by part to find the problem.

Unfortunately we cannot go through your custom code for you.

Hello Leo,

Just now, I noticed the error details.

"An error of type E_ERROR was caused in line 318 of the file /var/web/site/public_html/wp-content/themes/generatepress_child/functions.php. Error message: Uncaught TypeError: Cannot access offset of type string on string in /var/web/site/public_html/wp-content/themes/generatepress_child/functions.php:318"

line 318 is $method = $app_details['method'];

I will check with the Metabox team to solve this issue.

Thank you so much for your quick reply.

No problem :)

This archived topic is closed to new replies.