Hot answers tagged

114

Add the following to wp-config.php: define( 'FS_METHOD', 'direct' ); Let me know how it works for you.


84

Arriving here exactly 2 years after the original question was asked, there are a few things I want to point out. (Don't ask me to point out a lot of things, ever). Proper hook To instantiate a plugin class, the proper hook should be used. There isn't a general rule for which it is, because it depends on what the class does. Using a very early hook like "...


80

WooCommerce 3.0+ you can get the order items of an order by $order = wc_get_order( $order_id ); $items = $order->get_items(); then if you loop through the items, you can get all the relevant data: foreach ( $items as $item ) { $product_name = $item->get_name(); $product_id = $item->get_product_id(); $product_variation_id = $item->...


73

Yes. When you register your post type you need to set show_in_menu to the page you would like it displayed on. Adding a custom post type as a sub-menu of Posts Here we set the "movies" post type to be included in the sub-menu under Posts. register_post_type( 'movies', array( 'labels' => array( 'name' => __( '...


65

When you visit a frontend page, WordPress will query the database and if your page does not exist in the database, that query is not needed and is just a waste of resources. Luckily, WordPress offers a way to handle frontend requests in a custom way. That is done thanks to the 'do_parse_request' filter. Returning false on that hook, you will be able to ...


41

Hameedullah Khan's answer will throw a PHP warning. Include this if clause to check to make sure it's an object before unsetting the response for that plugin. 'Warning: Attempt to modify property of non-object' Try this to avoid the warnings (code for the plugin file itself): // remove update notice for forked plugins function remove_update_notifications($...


41

Filters and actions are both assigned to hooks. Functions assigned to hooks are stored in global $wp_filter variable. So all you have to do is to print_r it. print_r($GLOBALS['wp_filter']); PS. add_action function makes a add_filter call. And the latter does $wp_filter[$tag][$priority][$idx]. NOTE: you can directly add this code in functions.php, and you ...


40

This is just, how I understood the idea of the WordPress File API. If it is wrong, please downvote :) Okay. If you upload a file, this file has an owner. If you upload your file with FTP, you login and the file will be owned by the FTP user. Since you have the credentials, you can alter these files through FTP. The owner can usually execute, delete, alter ...


38

I fixed this by going through PHPMyAdmin to the table "Options" and then the row active_plugins. I had the following stored there (formatted for readability): a:10:{ i:0;s:49:"1and1-wordpress-wizard/1and1-wordpress-wizard.php"; i:1;s:29:"acf-repeater/acf-repeater.php"; i:2;s:30:"advanced-custom-fields/acf.php"; i:3;s:45:"limit-login-...


33

Updated answer Cleaner and shorter version. function load_movie_template( $template ) { global $post; if ( 'movie' === $post->post_type && locate_template( array( 'single-movie.php' ) ) !== $template ) { /* * This is a 'movie' post * AND a 'single movie template' is not found on * theme or child theme ...


33

Because I had cut and pasted define(’FS_METHOD’,’direct’); from the web, the incorrect quote characters were pasted into the file. should be define('FS_METHOD', 'direct'); The incorrect quote character also changed the encoding of the file somehow. If anyone has deeper knowledge of this issue please let me know in the comments.


31

Same can be done through functions.php in your (child) theme: add_filter("woocommerce_checkout_fields", "order_fields"); function order_fields($fields) { $order = array( "billing_first_name", "billing_last_name", "billing_company", "billing_address_1", "billing_address_2", "billing_postcode", ...


31

Firstly, you can't immediately achieve the goal you described with the code you show in your question. To understand why there isn't a direct approach with that code you have to take a look at what you're using - woocommerce_related_products() - to do what you have done so far. Secondly, you have to understand, because otherwise you are not able to ask a ...


30

To disable user email notification, add this in a plugin or theme: add_filter( 'send_password_change_email', '__return_false' ); FYI wp_password_change_notification() controls admin email notification when a user changes their password


27

Overriding get_page_template() is just a quick hack. It does not allow the template to be selected from the Admin screen and the page slug is hard-coded into the plugin so the user has no way to know where the template is coming from. The preferred solution would be to follow this tutorial which allows you to register a page template in the back-end from ...


27

Most of the following can be found in the Codex: apply_filters The callback functions attached to filter hook $tag are invoked by calling this function. This function can be used to create a new filter hook by simply calling this function with the name of the new hook specified using the $tag parameter. $value = apply_filters( $tag, $value, $var_1, $...


27

##Plugin Necessity## What the necessity of plugins really boils down to is the question, "Am I satisfied that WordPress's core functionality is all that I need?" If all you want is a simple blog with some categories and a number of static pages you're set. But if you want to start integrating interactive maps, calenders with events, maybe a 3rd-...


27

taken from that very same function: // prior to wordpress 4.5.0 $args = array( 'number' => $number, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids ); $product_categories = get_terms( 'product_cat', $args ); // since wordpress 4.5.0 $args = array( 'taxonomy' =&...


26

What's the risk? On a poorly configured shared host, every customer's PHP will execute as the same user (let's say apache for discussion). This setup is surprisingly common. If you're on such a host and use WordPress to install the plugin using direct file access, all of your plugin files will belong to apache. A legitimate user on the same server would ...


25

Ah I just had this problem myself! And while _embed is great, in my experience it is very slow, and the point of JSON is to be fast :D I have the following code in a plugin (used for adding custom post types), but I imagine you could put it in your theme's function.php file. php add_action( 'rest_api_init', 'add_thumbnail_to_JSON' ); function ...


25

You could do this using the WordPress uninstall.php support: <?php if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit(); global $wpdb; $wpdb->query( "DROP TABLE IF EXISTS NestoNovo" ); delete_option("my_plugin_db_version"); ?> This uninstall.php file is called when your plugin is deleted.


25

add_action( 'admin_init', 'do_something_152677' ); function do_something_152677 () { // Global object containing current admin page global $pagenow; // If current page is post.php and post isset than query for its post type // if the post type is 'event' do something if ( 'post.php' === $pagenow && isset($_GET['post']) &&...


25

There's actually a filter that you can use, see abstract-wc-email.php, line 214: return apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object ); you can put the following in your functions.php: add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2); ...


24

To disable Admin email notification when a user resets their own password, create a Plugin (or Must Use Plugin) using the following code snippet: /** * Disable Admin Notification of User Password Change * * @see pluggable.php */ if ( ! function_exists( 'wp_password_change_notification' ) ) { function wp_password_change_notification( $user ) { ...


24

This means that WordPress is having limited permission for making changes in the folder that it was installed. In-order to fix this, all that you need to do is provide necessary permissions for the same. Run the following Command in your Terminal / Putty / Commandline Prompt after connecting to your Server via SSH: sudo chown -R apache:apache /var/www/...


24

If you want to add a add media button to your admin panels: You need to use wp_enqueue_media(); add_action ( 'admin_enqueue_scripts', function () { if (is_admin ()) wp_enqueue_media (); } ); Then use this js: jQuery(document).ready(function() { var $ = jQuery; if ($('.set_custom_images').length > 0) { if ( typeof wp !== '...


24

You can use wp_get_theme: <?php $theme = wp_get_theme(); // gets the current theme if ( 'Twenty Twelve' == $theme->name || 'Twenty Twelve' == $theme->parent_theme ) { // if you're here Twenty Twelve is the active theme or is // the current theme's parent theme } Or, you can simply check if a function in twentytwelve exists -- which is ...


23

Using WP-CLI you can specify this as described in the official documentation. $ wp plugin update <plugin> Using either of the following arguments --minor Only perform updates for minor releases (e.g. from 1.3 to 1.4 instead of 2.0) --patch Only perform updates for patch releases (e.g. from 1.3 to 1.3.3 instead of 1.4) --version=<version&...


23

luckily woocommerce has many hooks, this removes prices and buttons: remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );...


22

is_plugin_active() expects just the base name of the plugin as parameter: So use: is_plugin_active( 'woocommerce/woocommerce.php' ); The function will use the option 'active_plugins' which is a list of plugins paths relative to the plugin directory already. On a multi-site installation it will search in get_site_option( 'active_sitewide_plugins') too. ...


Only top voted, non community-wiki answers of a minimum length are eligible