Forum Replies Created

Viewing 15 replies - 46 through 60 (of 138 total)
  • PhPCentre

    (@phpcentre)

    Use the isset() check for the post variable like so:

    if ( isset( $_POST['checkbox1']  ) ) {
        // do  stuff
    }

    For the $input_terms variable check whether is empty like so:

    if ( !empty ( $input_terms ) ) {
       // do stuff
    }

    PhPCentre

    (@phpcentre)

    Also if you don’t like the javascript, you can use jquery, so the script can be loaded either in the header or footer, your choice.

    /* script.js */
    jQuery(document).ready(function ($) {
        $('input[name=email]').prop( 'readonly', true );
    });

    Then in your functions.php modify the enqueue_script function slightly

    wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array('jquery') );

    PhPCentre

    (@phpcentre)

    Ok I have a solution for you, to stop the error “Please enter an email”, change the script code to this:

    document.getElementById('email').readOnly = true;

    The letter O in the readOnly should be a capital letter,to ensure that users can’t change their email while they are logged in change the codes in your function.php file to this:

    global $pagenow;
    
    if ( ( $pagenow == 'user-edit.php' ) || ( ( $pagenow == 'profile.php' ) && ( !current_user_can( 'activate_plugins' ) ) ) ){
    
    	wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', '', '',true );
    }

    The reason while we are using the current_user_can check is to make sure the admin can only edit his own email or a user that has privilege to activate plugins, you can change the value to your preference, check here for all possible value the function accepts. Removing that check means no one can edit the email field including the admin. Use the above codes without the plugin and report your results..

    PhPCentre

    (@phpcentre)

    Ok I have a solution for you, to stop the error “Please enter an email”, change the script code to this:

    document.getElementById('email').readOnly = true;

    The letter O in the readOnly should be a capital letter,to ensure that users can’t change their email while they are logged in change the codes in your function.php file to this:

    global $pagenow;
    
    if ( ( $pagenow == 'user-edit.php' ) || ( ( $pagenow == 'profile.php' ) && ( !current_user_can( 'activate_plugins' ) ) ) ){
    
    	wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', '', '',true );
    }

    The reason while we are using the current_user_can check is to make sure the admin can only edit his own email or a user that has privilege to activate plugins, you can change the value to your preference, check here for all possible value the function accepts. Removing that check means no one can edit the email field including the admin. Use the above codes without the plugin and report your results..

    PhPCentre

    (@phpcentre)

    Ok.. use this:

    //Custom field to custom taxonomy script
    $input_terms = array();
    $input_terms[] = sanitize_text_field( $_POST['checkbox1'] );
    $input_terms[] = sanitize_text_field( $_POST['checkbox2'] );
    $input_terms[] = sanitize_text_field( $_POST['checkbox3'] );
    $input_1 = explode( ",", sanitize_text_field( $_POST['customfieldname1'] ));
    $input_terms = array_merge( $input_1, $input_terms );
    $terms = array();

    Also remember to check the value of the post variable by using isset() check,so you don’t run into errors when any of the checkbox is not checked, and when the input field is empty. Also before doing a foreach on the $input_terms variable, also run a check to make sure it’s not empty.

    PhPCentre

    (@phpcentre)

    There is no need to create another js folder, you can use the folder ( library/scripts ) and create a js file and name it to your preference. So let’s assume the name you gave the file is script.js, in your theme functions.php insert this:

    global $pagenow;
    if ( $pagenow == 'user-edit.php' ) {
    	wp_enqueue_script( 'script', get_template_directory_uri() . '/library/scripts/script.js', '', '',true );
      }

    then in your script.js file insert this:

    function my_function() {
    	document.getElementById('email').disabled = true;
    }
    my_function();

    PhPCentre

    (@phpcentre)

    Just disable the email input field the same way the username input field is disabled,so you can either manually add a disabled attribute by hard-coding the input field, the file to check is wp-admin/user-edit.php, or you can use javascript to disable it as well. In your function.php add this:

    //assuming your script.js is located in folder js/ folder of your theme
    global $pagenow;
    if ( $pagenow == 'user-edit.php' ) {
    	wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', '', '',true );
      }

    The script has to be loaded in the footer to work,then in your script.js use a simple code that will disable the input like so: document.getElementById('email').disabled = true; and you should be good.

    PhPCentre

    (@phpcentre)

    PhPCentre

    (@phpcentre)

    You could use the explode function to break up the input value like so:

    $input_1 = explode( ',' ,sanitize_text_field( $_POST['customfieldname1'] );
    $input_2 = explode( ',' ,sanitize_text_field( $_POST['customfieldname2'] );
    $input_terms = array_merge( $input_1 ,$input_2 );

    Forum: Hacks
    In reply to: Post type tree loop
    PhPCentre

    (@phpcentre)

    Use this:

    $loop = new WP_Query( array( 'post_type' => 'your_post_type', 'post_parent' => 0 , 'posts_per_page' => -1 ) );
    while ( $loop->have_posts() ) : $loop->the_post();
        //parent page title
        the_title();
        $parent_page_id = $post->ID;
        $child_pages = get_pages( array( 'child_of' => $parent_page_id , 'post_type' => 'your_post_type', 'posts_per_page' => -1 ) );
        if ( $child_pages != false ) {
            foreach( $child_pages as $page ) {
                 //child page title
                echo  $page->post_title;
            }
         }
    endwhile;

    PhPCentre

    (@phpcentre)

    PhPCentre

    (@phpcentre)

    Try this:

    global $wpdb;
    $current_time = current_time('mysql');
    $author_id = get_current_user_id();
    
    $ereminder_array = $wpdb->get_results( $wpdb->prepare("
    SELECT *
    FROM {$wpdb->posts}
    
    WHERE post_date <= %s
    
    AND post_type ='ereminder'
    AND post_status = 'publish'
    AND post_author = %d
    ORDER BY post_date ASC
    ", $current_time, $author_id ) );

    PhPCentre

    (@phpcentre)

    You could break up the calls into two, make the first ajax call for task 1, on return response update the text “Task 1 finished. Task 2 pending”, then make another ajax call for the second task 2,on return response update the the text also “Both task finished”..

    Forum: Hacks
    In reply to: Watermark without plugins
    PhPCentre

    (@phpcentre)

    Use this wp_generate_attachment_metadata filter, it fires after creating thumbnails.

    PhPCentre

    (@phpcentre)

    The time adjustment should be done on the requesting client( user pc ). Obviously the time on your local system is out of syn with the current time. Sync up your system clock and the problem will go away.

Viewing 15 replies - 46 through 60 (of 138 total)