I'm building a custom wordpress theme.
When the user is attempting to update a custom post type ( Product ), I want to perform some validation before letting them save/upload.
Here is what's going on.
I have a series of "Things".
Each "Thing" has an advanced custom field for img and for text.
So my goal here is, if they upload an image but don't fill in the textbox, to not allow them to save/upload the post. This also works in reverse ( if they provide text but no image ).
So right now I have hooks in 'save_post' that perform the validation and set notices at the top of the screen letting them know what they did wrong. However, this really doesn't work because 'save_post' is called AFTER the post is saved. Even if it wasn't, I still don't have any way of stopping the post from being saved anyways. The most my implementation does it let them know in hindsight that they messed up.
So, how do I accomplish this task?
I think you can do this with the content_save_pre filter.
http://codex.wordpress.org/Plugin_API/Filter_Reference/content_save_pre
The answer ended up being to use Advanced Custom Field's provided filters.
Related
Actually I have changed some code in WordPress Store Locator. I want it to remain when plugin will update. So I want to create a child plugin for that. Any ideas on how I could manage it?
This varies plugin to plugin, and it sometimes isn't even possible, other times plugins have documentation to extend them easily (such as WooCommerce and Gravity Forms). Some of them create Action Hooks with do_action() that let you extend the functionality easily. A common example is updating a post after a Gravity Form is submitted with their gform_after_submission hook.
Effectively, it depends on what you want to do, and how the plugin implements the functionality you want to change. If they add text with a Closure or Anonymous Function, it will be harder to modify said text, and you may have to look at something strange like doing a run-time find and replace using Output Buffering, typically on the template_redirect hook.
If you want to remove something a plugin does, you can often unhook it with remove_action. This can be a bit tricky depending on how the plugin is instantiated, sometimes its as simple as:
remove_action( 'some_hook', 'function_to_remove' );
Other times it's more complicated like:
global $plugin_class_var;
remove_action( 'some_hook', array($plugin_class_var, 'function_to_remove') );
Those are the basics of extending (or even 'shrinking'?) a plugin's functionality, and it's not always doable appropriately. Unfortunately the narrow answer to your question is outside of the scope of what we can provide from StackOverflow.
From here, you'll need to figure out exactly what you want to do with the plugin, and dig through the plugin's files to see if there's an appropriate hook or function you can use. If you're still stuck, you'll need to post a new question (don't update this one) with your exact desired result and anything you've tried, and the relevant code that goes along with it. "I want to change a plugin without editing core files" isn't nearly specific enough. "I want to replace an icon with a custom icon in this plugin, here's what I've tried" is specific enough to possibly answer.
Good luck!
I just went through myself and I had so many changes that I couldn't just override the actions.
I created this tool that allows you to create a child plugin like a child theme. You can make updates to the plugin and still update it without losing your changes.
I'm posting this here because it relates and hopefully becomes useful to the next person who runs into this issue.
https://github.com/ThomasDepole/wordpress-child-plugin-tool
As per WordPress standard, it's called plugin's addon.
if the plugin has provided any action to update that functionality then you can use it with your addon (child plugin).
Here I am sending a link for reference.
https://developer.wordpress.org/reference/functions/add_action/
Even though I change the fields (custom or not) order in the Custom Fields screen in Mautic, that order doesn't reflect in the Contacts screen.
How can I customize the order and position of fields in the Contacts screen?
Since I didn't find a solution ready for this need I decided to customize the leads form myself. After taking a look at the code I noticed it's really easy to change and maintain.
The solution was to order/position the fields directly on the view: app/bundles/LeadBundle/Views/Lead/form.html.php.
I'm completely new to the whole WordPress scene so I kind of don't know the "WordPress way" of doing the desired task:
Create a form where a user would fill in some details (such as name, surname, upload a video or post a youtube iframe link)
Submit it, once it's done - an admin must verify that everything has been filled out correctly and after that the video can be seen on the website.
Should I write a plugin of some sort that would do that or how does it happen?
Thank you.
The Gravity Forms plugin allows you to do exactly what you're looking to do. With it, you can set up a form that creates a post and sets it to be 'Pending Review' in WordPress. This tutorial contains everything you need to know about what you'll need to do.
If you want to create a Custom Post Type (ie. 'User Page') to better separate user submissions, you'll need to employ this special add-on (as mentioned in the tutorial above).
I'm wanting to make an employee page populated from a custom post type called "Employees". It lists http://www.domain.com/employees/joe/ as the permalink but the the actual page shows up as unavailable. Am I missing something on the taxonomy side?
Thanks in advance!
Answering it because I just figured it out, but after quite a bit of googling, nothing came up, so hopefully this helps somebody.
Reset the permalinks!
For some reason, if you create a custom post type after you initially set your permalink structure, it needs to be reset. Go to your settings/permalinks, set them to default, save, and then set them back how you want, save, and you're good to go.
The permalink structure needs resetting because this regenerates the rewrite rules within wordpress, allowing the different URL segment structures to be properly recognised and processed.
Wordpress rewriting works very well, but getting around it for custom post types, custom taxonomies etc. has added an extra set of needs to the system, which are slowly being improved. The custom rewrite system was added, and it's continued development is gradually making it easier to tackle issues like this.
In many cases, a custom taxonomy is the easiest way to go.
I want my users to be able to mark posts as favorite. I tried the wp-favorite-posts plugin, but it doesn't work. I mark posts as favorites and after refreshing the page it's all gone. Furthermore, if I put {{wp-favorite-posts}} to a page, it just shows the text.
So I want to create my own solution, but don't really know how. I have never edited the WP database, but I have plenty of PHP mySQL experience.
Can anyone please point me in the right direction ?
You can use post_meta. You can store the "favourite" aspect as a custom field attached to each post. You don't need to manually edit the database (i.e. via mySQL).
When you want to show the favourited posts, run a custom query that only shows posts with the specific custom field that you've specified.