• What is the correct way to cause a wordpress widget to display the most up-to-date info? I am guessing that when the info changes the cache muse be cleared.

    Here is an example of what I mean.

    I have a wordpress widget that displays Hello <first name> <lastname>. It appears on every page. If the user edits their name, the widget still displays the old name until the breeze cache is cleared. (except if the user is an admin, then it seems this problem does not occur).

    If I hook in this command into the routine that processes a user name change
    breeze_clean_cache();
    the function is not found and the php script dies.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author adeelkhan

    (@adeelkhan)

    Hi

    could you please confirm that the user changes its name information from admin OR front end of the site using the widget?

    While update post/page or any widget area from admin. Breeze clears its cache and change will reflect on site.

    Thread Starter JohnChandlerEdmonton

    (@johnchandleredmonton)

    Yes the user edits his name from the front end.

    function my_woocommerce_save_account_details($user_id) {
    $fn = $_POST[‘account_first_name’];
    $ln = $_POST[‘account_last_name’];
    $display_name = trim(trim($fn) . ‘ ‘ . trim($ln));
    $x = wp_update_user( array( ‘ID’ => $user_id, ‘display_name’ => sanitize_text_field(remove_accents($display_name)) ) );
    }
    add_action( ‘woocommerce_save_account_details’, ‘my_woocommerce_save_account_details’, 10, 1 );

    Then when the user visits a page (that has already been cached) it will not show the new display name in a widget in the sidebar of every page.

    I guess I need to put in a command into my code like
    breeze_clean_cache();

    Or alternatively I could do an “insert_post” and then “delete_post” to cause the cache to be cleared.

    Let me know what you would recommend.

    Thanks!

    Thread Starter JohnChandlerEdmonton

    (@johnchandleredmonton)

    P.S. I tried adding this into my name-update code (shown above). It did not force the cache to be cleared.

    // Create post object
    $my_post = array();
    $my_post[‘post_title’] = ‘Temp post’;
    $my_post[‘post_content’] = ‘This is a temp post made to force the cache to clear.’;
    $my_post[‘post_status’] = ‘publish’;
    $my_post[‘post_author’] = 1;
    $my_post[‘post_category’] = array(0);
    $id = wp_insert_post( $my_post );
    wp_delete_post($id);

    Surely there must be a simple command you can give me that will do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Clear Cache with Php Command?’ is closed to new replies.