Toolset forms

Toolset: Update Title and Slug of Post with Custom Field Content when post saves in the WordPress backend

add_filter( 'wp_insert_post_data' , 'set_issue_title' , '10', 3 );
  
function set_issue_title( $data , $postarr ) {
if ( 'my_post_type' != $data['post_type'] )
return $data;
  
$post_title = $data['post_title'];
  
if ( ! $post_title ) {
  
$issue_number = trim( $_POST['wpcf']['single1'] ); 
$issue_type = trim( $_POST['wpcf']['single2']);
  
$issue_title = $issue_type . ' - ' . $issue_number;
$post_slug = sanitize_title_with_dashes ($issue_title,'','save');
$post_slugsan = sanitize_title($post_slug);
  
$data['post_title'] = $issue_title;
$data['post_name'] = $post_slugsan;
  }
  
return $data;
}

Visto en https://toolset.com/forums/topic/use-custom-field-to-set-title-slug/

Revisar este otro post: https://toolset.com/forums/topic/use-custom-fields-to-set-post-title-and-post-slug/

Toolset: Auto Generate Post Title and Name/Slug by Combining Other Fields

add_action('cred_save_data', 'build_post_title', 10, 2);
function build_post_title($post_id, $form_data) {
 
if ($form_data['id']==9999) {
$field1 = get_post_meta($post_id, 'wpcf-street_address', true);
$field2 = get_post_meta($post_id, 'wpcf-city_address', true);
$term_list = wp_get_post_terms($post_id, 'state-address', array("fields" => "names"));
$terms = join("-",$term_list);
$field4 = get_post_meta($post_id, 'wpcf-zip_address', true);
 
$post_title=$field1.'-'.$field2.'-'.$terms.'-'.$field4;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}

Visto en https://toolset.com/forums/topic/auto-generate-post-title-and-nameslug-by-combining-other-fields/

Toolset:. Populate custom field with post title

function tssupp_set_pp_title ( $post_id, $post, $update ) {
  $field_slug = 'practice-point-title';
  $post_type_slug = 'practice-point';
    
  // - bail on wrong post type or on pre-publish auto draft title
  $post_type = get_post_type( $post_id );
  $post_title = get_the_title( $post_id );
  if ( ( $post_type !== $post_type_slug ) || ( $post_title == 'Auto Draft') )  {
    return;
  }
    
  update_post_meta( $post_id, 'wpcf-' . $field_slug, get_the_title( $post_id ) );
}
    
add_action( 'save_post', 'tssupp_set_pp_title', 100, 3);

Visto en https://toolset.com/forums/topic/populate-custom-field-with-post-title/

Custom logout

/** Custom Logout Shortcode
 */
 function custom_logout_link_func() {
            $return = wp_logout_url();?>
            <a href="<?php echo $return; ?>" class="btn btn-primary btn-xs btn-block" role="button" style="margin-bottom: 10px;">Logout</a>
            <?php
        }
         
    add_shortcode('logout_link', 'custom_logout_link_func');
/**
 *Used to redirect after logout 
 */
 
function logout_page() {
    $login_page  = home_url();
    wp_redirect( $login_page . "" );
    exit;
}
add_action('wp_logout','logout_page');

https://toolset.com/forums/topic/create-a-logout-link/

WP-Cred login form: redirects based on different member roles

/**
 * Redirect user after successful login.
 *
 * @param string $redirect_to URL to redirect to.
 * @param string $request URL the user is coming from.
 * @param object $user Logged user's data.
 * @return string
 */
function my_login_redirect( $redirect_to, $request, $user ) {
    //is there a user to check?
    if ( isset( $user->roles ) && is_array( $user->roles ) ) {
        //check for admins
        if ( in_array( 'administrator', $user->roles ) ) {
            // redirect them to the default place
            return $redirect_to;
        } else {
            return home_url();
        }
    } else {
        return $redirect_to;
    }
}
 
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

function my_login_redirect( $redirect_to, $request, $user ) {
    if( !isset( $user->user_login ) ){ // we only want this to run when credentials have been supplied
        return $redirect_to;
    }
    //is there a user to check?
    if (isset($user->roles) && is_array($user->roles)) {
        //check for subscribers
        if (in_array('subscriber', $user->roles)) {
            // redirect them to another URL, in this case, the homepage
            $redirect_to =  '<em><u>hidden link</u></em>';
        }
 
        if (in_array('contributor', $user->roles)) {
            // redirect them to another URL, in this case, the search page
            $redirect_to = '<em><u>hidden link</u></em>';
        }
 
        // copy and paste the block above for each role
    }
 
    return $redirect_to;
}
 
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

https://toolset.com/forums/topic/need-to-have-1-login-form-that-redirects-based-on-wp_user-role/

Ir arriba

We are using cookies on our website

Please confirm, if you accept our tracking cookies. You can also decline the tracking, so you can continue to visit our website without any data sent to third party services.