We are building a fairly dynamic platform with several functions and a wide dynamic of technologies (F#, C#, MVC, Python, etc). For the CMS/Content, we have elected to use Wordpress to cut down on development time. And, "it is so pretty and functional as-is" -CEO.
The challenge: How to get Wordpress to notify an external service/uri that something has changed.
We do not want to write "background threads" from the other services to constantly "ping" the wordpress site/database for changes, aka "Pull". We want this to be a Push model.
With that said, we are looking to pass some json, xml, or something to another url that we can consume the changes and handle internally.
SQL Azure does support triggers, yes; but, did you shudder as much as I did when you read the word "triggers"? Besides, I wouldn't have a clue where to start on what tables for them.
Here are a few changes we'd like to capture:
Post Drafts
Post Published
Post Deleted (and so on)
Tag added, renamed, deleted
Category added, renamed, deleted
And possibly other event such as when a media file gets uploaded (for the CDN).
Random -almost related- thought: I have found some Wordpress plugins for Windows Azure Blog Storage for media, which may help - I'll try to setup a Storage account for the CDN for the media stuff. If there are other related Wordpress plugins for notifying external services for categories, tags, etc, please let me know - I haven't found them (they all just "email" someone).
I found questions such as this:
Wordpress: How to ping URL from custom field on publish
But it doesn't get me all the way there for all post drafts (I think). And, I'm not even sure where to insert that code (haven't modified a wordpress install before).
The cleanest way to do this is create a Wordpress plugin. That way, your code is separate from both the Wordpress Core and the chosen theme.
The plugin could be pretty simple. You'll need one or more functions to do the notifying, and a bunch of add_action statements for the action hooks to fire a function when that action of interest occurs.
function so23600027_notify_external_site( $post_id ) {
//Your notification code here, probably using cURL
}
// Catch when posts saved (should get both draft and published posts)
add_action ( 'save_post', 'so23600027_notify_external_site' );
//Catch when posts deleted
add_action ( 'delete_post', 'so23600027_notify_external_site' );
//etc.
Related
I would like to know what happens when I click on activate on a WordPress-Plugin on "Activate". Which files and functions get Triggered by WordPress.
How I actually think WordPress is working are these steps:
A file and function from WordPress is in a loop which gets triggered like this:
WordPress gets from the main-file the Header-fields and calls a file(which?) with the functions and defines it to the public output with echo or return.
WordPress calls the activation_function. When the user has not defined it then it does nothing.
The main file runs now like each other program.
While the program runs, WordPress has a file/function which gets triggered on "plugin->deactivate" and a function which will look similarly:"
(I am a type of human who likes to play compiler)
(I add a picture because I got only: "Your post appears to contain code that is not properly formatted as code" and could not solve like 10 minutes.)
This "Your post appears to contain code that is not properly formatted as code" is driving me crazy. I had to delete a few things.
I have looked on pages like these but no one goes so deep inside:
https://developer.wordpress.org/plugins/plugin-basics/
I appreciate you are thinking this way.
But before you get any answer to this, may i ask why you are asking this?
Meaning, what you want to understand? Is there any specific thing you want to achieve at plugin activation?
There is not much WordPress does while activating plugin.
WordPress scans each file or top level directory inside plugin directory and looks for header comment
See for more details: https://developer.wordpress.org/plugins/plugin-basics/#getting-started
Once it recognizes a plugin, it offers to activate it.
Here is a ruff sketch what happens once you click activate:
WordPress runs any callback function that is bound with register_activation_hook. Its not required to have an activation hook. If you have a callback function, WordPress runs it, if not, WordPress does not do anything. This callback function is used by plugins to do all sort of stuff like creating default options, creating required database tables, checking for dependent plugins , WordPress and PHP required version compatibility to name a few.
WordPress updates an option in DB to keep track of active plugins. so that these can be loaded for each page call. option id is active_plugins. Screenshot: https://snipboard.io/e7sjB9.jpg
On Next page load, WordPress check this option active_plugins and looks for these active plugins and load/run their header comments file code.
Hope it helps.
Regards,
Rao
P.S. this question belongs to https://wordpress.stackexchange.com/
Before the community dismisses this - this is not a repeat of other issues with the Facebook submission process. Were a non-profit looking for help getting this running.
We have many articles on our website but we are not able to get them to appear in https://childmind.org/feed/instant-articles
I am not able to see where you instruct the FB Instant Articles WordPress plugin which content you want to publish e.g. our articles aren't in /blog but rather in /article e.g. https://childmind.org/article/adhd-behavior-problems/
Everything else is configured seemingly properly. Does anyone have an idea?
After we get articles in the feed, we can submit for review.
NOTE: We have edited and saved articles to "trigger" them being added but has not worked.
Articles sound like a custom post type which you need to manually tell the plugin by using a filter for your CPT.
add_filter( 'instant_articles_post_types', 'add_post_types', 10,1 );
function add_post_types($post_type_array){
array_push($post_type_array,'post'); // Standard post "blog"
array_push($post_type_array,'articles'); // The name of your custom post.
return $post_type_array;
}
This should then get pull the articles for the feed as long as everything else has been set up correctly. Taken from a post on the WP Plugin forum.
Note: Also, Facebook have their own validation process once you get this working before you will start to see them on Facebook.
I have made modifications in several of the plugins in wordpress. But
these plugins are now outdated. I have to submit the project to the
client. The client is asking me to update the plugins. But the problem
is that when I would update plugins, the changes that I made in
plugins would have gone away. So, I want to ask is there any concept
of child plugin in wordpress and if so, how to create it; so that my
changes would remain intact.
I don't know which plugins are you using so I am giving an example of WooCommerce Delivery Date plugin. I have disabled updates for that plugin and I have used below code to achieve it :
/* Function which remove Plugin Update Notices – WooCommerce Delivery Date*/
function disable_plugin_updates( $value ) {
unset( $value->response['woocommerce-delivery-date/woocommerce-delivery-date.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'disable_plugin_updates' );
Just edit the version of the plugin to more than the latest version :
Go to wp-content/plugins/your-plugin/your-plugin.php
generally your-plugin.php is the main file of the plugin and it is having version in the top commented line.
Edit the version of the each plugin
Otherwise install a plugin your admin that will disable updates. Get this plugin from here : https://wordpress.org/plugins/disable-wordpress-updates/
If you're looking to keep a good name, I'd find a way to achieve making the necessary changes without modifying plugins in the first place (this is a bad practice, as I'm sure you know). When people purchase your product or services, they want to know they're not getting a "bad egg" or a "lemon deal"; and that their investment is actually an investment and not a complete waste of effort, money and overall time.
Updates are important! What if they are handling sensitive information on their site? What if their host requires a specific plugin to be a certain version?
Make your change in another way, write your own plugin, include the functionality in a child-theme; you can even handle certain "modifications" by using jQuery to manipulate elements in the DOM (include it in your child theme).
Just don't do something regrettable as some others have suggested. This is only going to last until the next update is released and lead to trouble, a bad reputation, or legal action. Integrity is all a man has. If you throw it away, you're worthless.
What i wanted to do in my WP site is to display pages instead of posts, so i learned that you can do that by using the function query_posts(), and change the post_type parameter to 'page'. But then i read the documentation in the codex web page, and it says that you shouldn't use this function ever, because it runs too many queries unnecessary. They recommend to use the hook pre_get_posts. But when i read its documentation it says:
"pre_get_posts cannot be used to alter the query for Page requests (page templates) because 'is_page', 'is_singular', 'pagename' and other properties (depending if pretty permalinks are used) are already set by the parse_query() method."
I'm not sure if this means that the only way is to use query_posts() and if that implies to run more queries. I'm worried about this because my WP site will have hundreds of pages, maybe more.
I'm trying to add an upload form onto the checkout of my woocommerce website...I have a found a good tutorial here: http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-hooks-and-filters/ which shows how to customize the fields, however within the array there is not an option to create an upload form only (type of field (text, textarea, password, select).
How could I implement this?
Sadly I can't answer about the woocommerce perspective. But as your problem is about upload functionality I recommend you valums / file-uploader. I have use it in all my last WP plugins, both the front and backend.
This plugin uses an XMLHttpRequest (AJAX) for uploading multiple files
with a progress-bar in FF3.6+, Safari4+, Chrome and falls back to
hidden-iframe-based upload in other browsers (namely IE), providing
good user experience everywhere.
It is a little hard to make it work, but once you have accomplished you will love it.So if you want give it a try and need help ask again here in SO. And redirect it to me so I can be informed to help you.
I use a file upload in each of my products - gravity forms allows this - though there is one limitation of the filesize as default being about 8mb - though I'm told this can be increased.
I use woo commerce - and there is an extension for gravity forms - which makes adding these forms to products (or anything else) really easy.
Only downside is no upload bar or showing the uploaded file...
For form, try to use these two hooks:
1) add_action('woocommerce_after_cart_table', 'add_file_to_upcoming_order');
2) add_action('woocommerce_checkout_after_customer_details', 'add_file_to_upcoming_order');
And to receive/get files, you should use hooks like the following:
add_action('woocommerce_init', 'file_during_checkout');
add_action( 'woocommerce_order_status_pending', 'wc_checkout_order_processed');
add_action( 'woocommerce_order_status_on-hold', 'wc_checkout_order_processed');
add_action( 'woocommerce_order_status_processing', 'wc_checkout_order_processed');
add_action( 'woocommerce_order_status_completed', 'wc_checkout_order_processed');
Important:
add_action( 'save_post', 'pre_wc_checkout_order_processed' );
Description:
In fact you can loose your attachments when your hook will be depending on order status. Suppose your order is not completed in anyway so you will loose the PHP session too. Its better that you manage with "save_post" hook and must add some flags to your upload attachments.
You can use this function wp_handle_upload to handle your uploaded files. Once files are uploaded so you can easily get order items from WooCommerce object "WC_Order" & $order->get_items() which were added previously. I tried to make it working last year and a number of people used it too, you can develop an improved solution by using these hooks.