Here is the line I am trying to redirect:
'redirect' => get_site_url().'/checkout/order-received/'.$order->id.'/?key='.$order->order_key );
I want to redirect it to my thank you page:
http://website.com/thank-you-order/ I do not want all the order id Key etc. I just want the client to be redirected to the thank you page. Here is what I am thinking
Here is my tryout:
'redirect' => get_site_url().'/thank-you-order/' );
Maybe?
Related
I am trying to create a form that when submitted, adds data to a mysql database and redirects to a success page.
I added this code to the bottom of my functions.php file:
add_action('init', 'form_submit');
function form_submit(){
global $wpdb;
if(isset($_POST['form_sub']))
{
$name= $_POST['name'];
$age= $_POST['age'];
$wpdb->insert(
'mytable',
array(
'name' => $name,
'age' => $age
),
array(
'%s',
'%s'
)
);
header("Location: http://www.google.com");
}
}
and added a form to my page that calls this function when submit is clicked.
When I try this, the data is added to the mysql database, but the redirect doesn't seem to work. Instead of going to google.com, it adds this to the top of the page:
Object Moved
This document may be found here
Where here is a link to google.com. Any idea on how to fix this? Thank you!
You are probably sending the redirect header too late (after the page is rendered).
Check this out: http://shibashake.com/wordpress-theme/wordpress-page-redirect
You can try to put out a javascript redirect if you can't get the header() or wp_redirect() out early enough.
If a user clicks the "update" link in their recurring fees table, then decides not to make any changes and clicks Cancel instead of Update, they get access denied because the cancel link redirects to the admin view of recurring fees, not back to the user view. This is with the authorize.net handler, the URL in question is like the following:
example.com/user/263/recurring/715/cancel/authorizenet_cim?destination=user/263/recurring-fees
This is the code I got when I am doing research, I changed my code according to the mentioned below,but it does't work for me any help!
In uc_recurring.uc_authorizenet.inc around lines 140-147:
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
// '#suffix' => l(t('Cancel'), 'admin/store/orders/recurring/view/fee/' . $rfid),
'#suffix' => l(t('Cancel'), $_SERVER['HTTP_REFERER']), //This is the line I have added
);
It is very easy, you can add the Rules, it will redirect.
I am trying to make a module which generates output at a specific relative path say mysite.com/newcomment/
What I am trying to do:
On client side I have coded JS which makes ajax request to "mysite.com/newcomment/". If there is any new comment, on "mysite.com/newcomment/" output " have done comment on " is generated and same is shown on client side in a pop-up.
What I have done previously:
If I am making a page/article, header and footer code is coming with output.
I have also made a endpoint for it via web service but i don't want that-much complexity.
Am I doing it the right way any pointers or clues will be helpful.
Your question is very confusing but from the title it sounds like your looking for hook_menu
Check out: api.drupal.org
Your custom url will be created with code that looks like:
function my_module_menu() {
$items['example/feed'] = array(
'title' => 'Example RSS feed',
'page callback' => 'my_module_page',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
Then output the code on the page callback:
my_module_page {
return '<h2 class=test>Hello World</h2>';
}
While you normally want html to be generated using theme functions for better caching this should at least get you started.
Edit:
To print only the data such as in an ajax call the function should look like this. Of course only include the code for your version of Drupal:
my_module_page {
// Drupal 7
print 'string';
drupal_exit();;
// Drupal 6
print 'string';
module_invoke_all('exit');
exit;
}
I have a block which displays list of RSS feed from an external site. I want to keep caching other blocks except the mentioned block. Howto do that?
For example, I have blockA, blockB and blockC. I only want to change the blockB's cache settings permamently to DRUPAL_NO_CACHE and leave other blocks as they are and I want to do that programmatically.
You can change the caching roles in the specific module that creates youre block.
In the block info like beneath:
function pref_block_info() {
return array(
'pref_main' => array(
'info' => t('Display flash game for auth. users'),
'cache' => DRUPAL_NO_CACHE,
),
'pref_winner' => array(
'info' => t('Show the winner of the last week.'),
'cache' => DRUPAL_NO_CACHE,
),
'pref_leader' => array(
'info' => t('Show the leader of the current week.'),
'cache' => DRUPAL_NO_CACHE,
),
'pref_top' => array(
'info' => t('Show the top 10 of the current week.'),
'cache' => DRUPAL_NO_CACHE,
),
);
}
The answer given by Jurgo is perfectly right, if you are defining the block within your own module.
In case if you want to change the caching behavior of a block written by some other module then you can use the function mymodule_block_list_alter
function mymodule_block_list_alter(&$blocks, $theme, $code_blocks) {
// Remove the caching on rss feeds block.
// Here rss-feeds is the unique key for the block
$blocks['rss-feeds']['cache'] = DRUPAL_NO_CACHE;
}
Where do the blocks come from? That's important. As Jurgo said, you can specify it in hook_block_info if it's a custom module. If they are views blocks, there is a caching setting per display within views that handles this. If they are blocks provided by some other module, you'd need to directly query the database to change the block's caching setting.
As a general note, to display RSS feeds, just use Feeds and Views. Then you don't write custom code at all for any of this.
This will reduce the work by going to performance settings page (admin/settings/performance) & clicking "cleared cached data" by scrolling down.
But make sure that this page is only accessed by administrator.
For Drupal 7 is same as Drupal 6:
<?php
drupal_flush_all_caches();
drupal_set_message('cache flushed.');
?>
I created a new page which is assigned a custom template. When I visit that page's url I see what appears to be the default page layout (not my template) and the admin toolbar shows options pertaining to media (ex: Edit media).
After some head scratching, I deduced that somehow that url must point to a media item. I edited the page slug and "bingo" the actual page appears just as expected. When I visit the original url (from the first slug) I see the same media item.
Bottom line: It appears that coincidentally the page and the media item share the same name, and this was somehow causing WP's wires to get crossed.
My question: Can someone help me understand how/why this happens? Does wordpress create magic permalinks to everything in the media library (other than their location in wp-content/uploads/...)?
Note: The media item was uploaded normally into the media library (not FTP into the root directory, etc)
Yes, in WordPress you cannot have duplicate slugs/categories/taxonomies/tags. So if your theme allows for media files and permalinks to have their own page and the slug is the same as another one, it will usually append a number to it because the database does not like it.
media slug "example"
page slug "example" will not work since that slug exists already , if done in the admin it will automatically change the slug to "example-1".
I just had this problem and fixed it like this:
$post_s=get_posts('posts_per_page=-1');
foreach($post_s as $p){
$atts = get_posts('post_type=attachment&name='.$p->post_name.'&posts_per_page=-1&post_status=inherit');
foreach($atts as $att){
echo 'found!! '.$p->post_name;
// Update post 37
$my_post = array(
'ID' => $atts->ID,
'post_name' => $att->post_name.'-image'
);
// Update the post into the database
wp_update_post( $my_post );
}
}
This is a late answer, but I wanted to give a cleaner version of the answer that alesub gave.
function wp21418_append_to_post_name() {
// Checks to see if the option images_updated has been set or has a value of true.
if ( get_option( 'images_updated' ) === 'true' ) :
return;
endif;
// get all attachment posts.
$attachments = get_posts([
'post_type' => 'attachment',
'post_status' => 'inherit',
'name' => $p->slug,
'posts_per_page' => -1,
]);
// For each attachment, loop and update the post_name
foreach($attachments as $p){
$attachment = array(
'ID' => $p->ID,
'post_name' => $p->post_name.'-image'
);
// Update the post into the database
wp_update_post( $attachment );
}
// Once everything is looped, add the option to the database.
add_option( 'images_updated', 'true' );
}
add_action( 'after_setup_theme', 'wp21418_append_to_post_name' );
This function runs on an action hook right after the theme has setup. The first line checks to see if there is an option in the database images_updated. If that option exists, we bail on the function and it doesn't do any processing. Otherwise, if the option does not exist, it runs the function and sets the option at the very end.
This makes it so it will only run once. You don't have to remove the function after refresh. If you want to run it again, you can simply remove the if statement at the top. As a caveat: doing this will add another -image at the end of post_names even if they have -image already (e.g. -image-image)
There could be more file name checking for that situation. Will update the answer with that if someone really needs it.
I tried one of the suggested solutions, and ended up having attachment pages like /bob-image-image-image-image/.
I'd suggest that instead of using alesub or disinfor's code blindly, use a better option in the form of "Disable Media Pages" plugin.
https://github.com/joppuyo/disable-media-pages
It automatically sets all attachment slugs to an unique id, and there is the option to mangle any existing attachment slugs so they won't cause any issues in the future.