Im kinda new with wordpress. I wonder where is the code excute the action Update when I hit the button "Update" in wP admin when I edit post ?
Because I want to modify some information before it update to DB.
You don't really need to know where the code is located, Wordpress provides hooks for almost every action we do.
So in your case, when a post is updated there are some hooks that are fired.
pre_post_update Fires immediately before an existing post is updated in the database.
2.transition_post_status Fires when a post is transitioned from one status to another.
The 1st one
do_action( 'pre_post_update', int $post_ID, array $data )
You can run the pre_post_update hook and do whatever you need to do on the post.
https://developer.wordpress.org/reference/hooks/pre_post_update/
https://developer.wordpress.org/reference/hooks/transition_post_status/
https://codex.wordpress.org/Plugin_API/Action_Reference/post_updated
Related
So I'm a little stuck.
I'm a php beginner constantly learning and now I face a new challenge on Wordpress.
There are a few authors on the same site.
When someone writes a new post, it goes in "Pending Review" and it is shown on page only when the "Administrator" approves it.
The point is that I need to call a custom PHP function whenever the "Administrator" approves a post and I'm not really sure how to do this. The function is simple, like update other tables with some of the author's info. The problem is I don't know how exactly to run it on post approval.
Yes, a workaround would be a CRON function to run once an hour or so but it's not really what I need.
Quick update: By "Administrator approves" I mean he checks each post and changed its status from "Pending review" to "Published" and hits the Save button.
You can use the following hook for example:
function on_publish_pending_post( $post ) {
// A function to perform when a pending post is published.
}
add_action( 'pending_to_publish', 'on_publish_pending_post', 10, 1 );
More information on post status transitions.
I want to add an icon near phone_no in phone field. It should have a jQuery click() action. It's necessary to create new module to install or I just have to add new hook to existing field (if hook - where to add it)? I found file /custom/modules/logic_hooks.php but when I changed it (added line):
$hook_array['after_ui_frame'][] = Array(12, 'Description', 'custom/modules/MyModule/mymodule.php','MyModule', 'showIcon');
Some pages fired strange popup (lots of \t\t\t\n\n\n etc). Could someone give me a tip how to do it properly? I'm totally new user of SugarCRM
after_ui_frame logic hook fire every page load. while you render studio the hook is fired and html is not properly render.
apply check for particular module so your hook code execute only for given module.
if(checkmodulename for you module){
//hook code here...
}
Ok, I found the solution. I can add a field or customize existing one by editing the detailviewdefs.php. I made new field and added onclick action in 'custom_code'.
Thank you for your effort, Rupesh.
i have a custom field for source-links. The URL inserted in this custom field should get pinged once the post gets published. I know there is a dedicated trackback field but i want the URL from the custom field automatically added.
As far as i understand, $add_ping is exactly that.
http://codex.wordpress.org/Function_Reference/add_ping
My problem is: i don't know where to add it. I imagine if i'd write this into my theme where i display the source-link, the source gets pinged everytime the post gets visited.
So whats the proper way to add an url to get pinged on publish?
To be clear: it is not a service that i want to get pinged. More like if you'd insert a link to post B into post A's content. Once post A gets published, post B (or its blog) gets pinged. I want to insert the link into a custom field of post A, instead of its content area.
I think Felipe is right. You could try something like this:
function doCustomPing ($post_id) {
$uri_to_ping = get_post_meta($post_id, 'FIELDNAME', true);
add_ping($post_id, $uri_to_ping);
}
add_action ('publish_post', 'doCustomPing');
So every time a post if published (that includes if its edited) then a hook into publish_post will run the doCustomPing function. If you're putting this as part of a theme drop the above code in your functions.php file. Put the name if your custom field where it says FIELDNAME.
I have an meta_box in the post creation screen. As soon a user click on a specific category it will be displayed. For saving the information in the meta_box and post title and post content I use the hook post_updated. All is going to save fine in the database -- post data in wp_posts and the data in the meta_box into a special created table.
But sometimes the user want to edit this post from this 'special 'category. In this case the meta_box with the inserted information should be loaded and be editable. I know that I need to fill in the fields manually, but I need to know which hook is called when the user presses the edit link. An idea was, check for the url and if a parameter edit is found call my edit routine. But it looks like a dirty thing for me.
The codex is not very helpful. I tried the following hooks:
edit post, publish post, save post, wp insert post
But they are called after I pressed the actualize button.
BR,
mybecks
You don't have to use any hook for this, you just need to use following lines where you are generating your meta_box html
global $post;
now you have access the $post object when you are editing
get_post_meta($post_id, $key, $single);
use above function to get the value of particular meta and set it to your html as required.
for reading more about get_post_meta, goto http://codex.wordpress.org/Function_Reference/get_post_meta
I'm using a wordpress theme that allows users to create posts (they don't need to be logged in). The problem is that when the posts are displayed, <?php the_author(); ?> always shows as "admin". The post-creation form has a name field that I can get at in functions.php, but how can I manually change the author of the post to the name that was entered in the form field?
Without seeing the context, I can only offer a step in the right direction. Within a plugin or functions.php in your theme, you can call on the wp_insert_post_data filter to change the data that will be inserted as your post. For instance, if you wanted every post to be attributed to author with ID 5, you could do something like:
function my_change_author( $data , $postarr )
{
$data['post_author'] = 5;
return $data;
}
add_filter('wp_insert_post_data' , 'my_change_author' , '99', 2);
I've done something like this before where I have front end forms that I capture as posts and automatically assign to a predefined author that I call Web Monkey or something like that ;) Check out this page for more: http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data. This filter is really powerful in that you can alter your data that will become your post in anyway before it hits the database.
Have you checked what the_author_meta() contains? WP has to attach a userID to each post, so chances are it's assigning user 1 to those posts regardless of what they're entering into the box. Without seeing the custom function or knowing what theme you're using to test, it'll be pretty difficult to troubleshoot.