String not loading when using wp_nonce_url and admin_url function - php

I am trying to modify an existing plugin and one of the modifications that I am trying to do is to correct the way buttons are displayed on a certain page. Currently it's like this http://cl.ly/image/1C1l1H3w0r22 (excuse me for pasting screenshot link, I couldn't paste it on here). I am trying to change it to this http://cl.ly/image/3F2e252y3c41.
The buttons are loaded, that is working. The action is taking place, that is working. The images are loading, that is working. But for some strange reason the $post->ID is not being loaded.
I am getting wp-admin/?print_pip=true&post&type=print_invoice&_wpnonce=e25508b9df when I should be getting wp-admin/?print_pip=true&post=2712&type=print_invoice&_wpnonce=e25508b9df. 2712 being the order number in this case.
I understand that the problem is this: -
wp_nonce_url(admin_url('?print_pip=true&post='.$post->ID.'&type=print_invoice'), 'print-pip');
Would be great if someone can help me figure out what I am doing wrong.

Fixed this problem. I wasn't getting the $post so fixed it by changing top lines with: -
function pip_woocommerce_alter_action_column($order){
global $post;
$order = new WC_Order( $post->ID );

Related

WordPress add_theme_support('post-thumbnails') is not working

I'm new to WordPress development and I saw a video on how to add featured images. For some reason it's not working and I can't really figure out why. The option for Featured Image is not showing at all, so I don't really know how to fix it.
I've tried googling to see if people have experienced the same thing and from what I've seen it's usually syntax errors, however I don't think I have that.
I've tried deleting and adding it on again, but to no avail. I've also tried adding an array as a second argument to add_theme_support() but still nothing. I've also tried having the add_action() function before the custom function, and that hasn't worked either.
Here is the code in the functions.php file:
function Image_theme_setup(){
add_theme_support('post-thumbnails');
}
add_action('after_setup_theme', 'Image_theme_setup');

Using shortcode in HREF in content loaded via functions.PHP

Wordpress | Advanced Custom Fields plugin
I created a new field in the editor where my colleagues can fill in a URL relevant to that specific page. This URL will be used in the button we load on every single job listing page. This button is created within the functions.php file:
function my_editor_content( $content ) {
$content = "<h3>Title</h3><p>text</P>
<a href='[acf field='afas_url']' target='_blank' rel='noopener'><button>Solliciteer Nu</button></a>";
The above is cut off at the 'afas_url' part. So, I think it has something to do with the quotations marks and probably not even hard to fix, but as I'm just starting to figure things out I couldn't find the answer myself yet.
I hope it's a clear enough explanation :)
(And maybe it's not best practice to use functions.php but it was already like this)

Wordpress hooks after a post is saved

I have been searching and found a lot of various answers, however, I have not found a definitive answer.
I need to run a function right after a post is done saving to the database. This includes every aspect of the post including post metas. I have tried to hook into save_post but that seems to run my function before post metas are saved. I have also tried post_updated and updated_postmeta, but my function doesn't seem to run on either of them.
Another thing to note, I need to have access to the post ID inside my function.
Edit, My plugin uses the Advanced Custom Fields plugin and the function I have coded uses update_field to either create new post metas or update existing one based on some stuff. This code works. When I run the function at the post_updated hook the function seems to run but nothing happens. If I add die() to the end of my function my code works, but die kills the page and all I am left with is a blank white page at the url wp-admin/post.php. So adding die allows my function to work and I am not sure why it would not work without die.
I would comment your post, but I cannot because I dont have 50 rep.
Do you mean the_post?
https://codex.wordpress.org/Plugin_API/Action_Reference/the_post
function my_the_post_action( $post_object ) {
// modify post object here
}
add_action( 'the_post', 'my_the_post_action' );
it ought to have the post Id
https://developer.wordpress.org/reference/hooks/the_post/
Okay I found how to make publish_post work.
For custom post type you need to replace the "post" by the post type slug.
Example with the custom post type "Recipe" with "recipe" slug.
add_action('publish_recipe', 'test_publish_post', 10, 2);
function test_publish_post($post_id, $post){
wp_die($post_id);
}
Don't forget to wp_die() or die(); else you will be redirected and you won't see your var_dump();
I was able to
fix my issue. It turns out that save_post does seem to run after post metas are saved. My problem actually came from something else inside my code that I was able to fix by changing how I handled that part of my script.

Redux Framework in Wordpress not working

I don't know what is wrong with me. I just simple generated a file using build.reduxframework.com and then added in my Wordpress theme. Then added the following line to functions.php
if(is_admin()){
require_once(get_template_directory().'/core/admin/admin-init.php');
}
Good thing is the demo stuff is showing up. Now my $opt_name is for_test. In my header.php I am adding the following code.
<h2><?php
global $for_test;
echo $for_test['textarea-example'];
?></h2>
PS: textarea-example is the id of the field which is already added in the files I downloaded. But I don't know why it is not fetching the value in it.
is_admin() means that only admins will load that. So if you're logged out, your redux config will never load.
Best to just include it. Redux will take care of when it should run.

i want to diplay a custom term value but it gives fatal error

i want to display my custom terms from tags, even the code is valid in front of me but it gives the fatal error i use this code
<p style="width:50%;float:left;">
<?php $dataTax = get_the_term_list($post->ID, 'genre', '', ', ', '');
$dataMeta = get_post_meta($postID, 'genre', true);
if ((!empty($dataTax)) || (!empty($dataMeta))){ ?>
<span class="data-info">Genre:<span itemprop="genre"></span></span>
<?php if ($dataTax != ""){
// strip links until we're ready to use the taxonomy pages in the future
echo strip_tags($dataTax);
} else {
echo $dataMeta;
}
} ?>
</p>
"genre" is my taxonmy ,i want to dispaly their values,but it give me this type of error
Genre:
Catchable fatal error: Object of class WP_Error could not be converted to string in
Any help plz
I think that's the problem - something to do with deleting custom taxonomies when there are links in the Nav Menu which link to/are related to those now-missing taxonomies.
I read a post somewhere describing the exact problem, and this guy had spent a considerable amount of time trying to fix the problem without success. In the end he had fixed it by resetting WP back to a clean state (I assume a default database), which will of course result in complete loss of site data.
I would imagine there's a fix by delving into the database, but I've not explored this as the error I had was none-critical (on a localhost test site).
I keep on getting this problem, or related problems. Basically it happens whenever I rename a custom taxonomy or custom posts. I'm using the Custom Post Type UI plugin, and I created a load of custom posts & taxonomies. I then decided to change the name of some of the taxonomies from sentence case to lowercase, and this is where it screwed various plugins (e.g. Query Multiple Taxonomies) and the wp-menu (Appearance / menu). When I changed the name of some of the taxonomies back, everything started working ok again (although had to delete the query multiple taxonomies widget, and add it back in again).
Bottom line seems to be, once you've created your custom posts/taxonomies, don't alter them.
Deleted a menu that you had created in another theme would somehow fix it if you done this.
Kinda lame solution, but works as a charm.
Some solutions from wordpress forums.
http://wordpress.org/support/topic/catchable-fatal-error-object-of-class-wp_error-could-not-be-converted-to-string-11
Replace line
echo strip_tags($dataTax);
with
print_r($dataTax);
and if you get something like: "WP_Error Object ( [errors]......"
check is "genre" a right name of $taxonomy

Categories