Network admin "Sites" page - Wordpress - wordpress

I'm running a Wordpress multisite network, to manage the sites on the network I go to the "sites"page which displays the following headings:
URL - Last Updated - Registered - Users
To make this more useful I'd like to add the name of the site to this table. I have now added a column through using this code:
add_filter('wpmu_blogs_columns', 'add_site_name_column');
function add_site_name_column($site_columns) {
$site_columns['site_name'] = 'Site Name';
return $site_columns;
}
However I cant now work out how to put the site name into the column?

Check in the file wp-admin/includes/class-wp-ms-site-list-table.php, specifically look for the get_columns method.
The key to doing this will be for you to add a filter that works with the columns:
add_filter( 'wpmu_blogs_columns', 'my_custom_blog_columns' );
function my_custom_blog_columns( $sites_columns ) {
// Modify $site_columns here....
return $site_columns;
}
Typically you would add this filter in your theme's functions.php file, or in the plugin file(s) you are developing.

Related

How can I Override the woocommerce_download_file_redirect function?

I was asked to help a friend with virtual product download issues with their WooCommerce site. I solved the problem in the short term by moving them off their Hostgator shared hosting to a dedicated VPS through Digital Ocean (DO). However, I need to take this one step further as storing their files on droplets is going to get expensive really fast.
What I am wanting to do is use DOs Spaces, which are effectively S3 buckets. The tests we have done suggest this will be a really good setup as the storage space is very cheap compared to droplets, and we can use a CDN feature. Unfortunately, I am having issues working out how to best integrate WooCommerce digital downloads with Spaces. WooCommerce provides three download options:
The first two seem to proxy the file through your webserver to hide the origin URL
The third option 'Redirect (insecure)' updates the database to show you've downloaded the product, and then redirects you to a static link.
I want to use the redirect option and override the plugin function woocommerce_download_file_redirect with my own code that would use DOs API to generate a pre-signed download URL for a protected resource that is valid for no more than 60 seconds, thus protecting the download from unauthorized users.
After looking through the documentation, I came across the function which handles the redirect, and on line 25 of the same class the line of code that registered that action. Knowing about these functions I wrote a simple plugin to test overriding that code
<?php
/**
* plugin meta here (name, uri, description etc)
*/
function download_redirect_override() {
var_dump('test to see if my code works');
// Once I get this to work, this method will take the product URL
// explode it on '/' to get the parts required to make an API call to Spaces
// to generate a pre-signed URL with a 60-second life-span
// this URL will then be returned to the user using Header('Location: '.$url); die;
}
add_action( 'init', function() {
global $WC_Download_Handler;
// remove the default action so I can replace it with my one that generates short-life download URLs
remove_action( 'woocommerce_download_file_redirect', array( $WC_Download_Handler, 'download_file_redirect' ), 10, 2 );
add_action( 'woocommerce_download_file_redirect', 'download_redirect_override', 10, 2 );
});
Once my plugin is enabled, I try hitting the download button and WooCommerce ignores my code continuing to use the default function. I know my add_action( 'init', ..) is getting called because I have inserted a var_dump('test'); in the function and that prints to my screen.
I am not a PHP developer so I don't fully understand the nuances of Word Press. I am hoping someone could either point out what I am doing wrong or point me in the right direction. Thanks.
After taking a break for a few days, I spent last night and finally got it working.
While the code below works, I may well be doing it wrong so I am still open to feedback. Here is my code:
The function `spaces_download` is in another file, I have not posted it below as it is not relevant, however, it ends with a Header('Location: '.$Url); Exit();
<?php
/**
* Plugin Name: <redacted>
* Plugin URI: <redacted>
* Description: <redacted>
* Version: 0.0.1
* Author: <redacted>
* Author URI: <redacted>
*/
add_action('plugins_loaded', function() {
// Override the default Woo Commerce function that handles the redirect download
// The third arg, '1', is the priority, we use this to override the default
add_action( 'woocommerce_download_file_redirect', 'spaces_download', 1, 1 );
}

WordPress constant scope using define method

I'm defining plugin path as a constant through constant define method as shown below.
define( 'MY_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
It is accessible within plugin all files and themes. But when I call this constant in another plugin this constant becomes undefined.
How I can get this plugin constant in another plugin? Any help will be appreciated.
Thanks,
Probably your problem is the order that wordpress is calling your plugins: the plugins that sets the constant is loaded after the one who calls it.
A better explanation of how to force your plugin be loaded first can be found here. I'm putting here a quote of the part that matters:
The order that plugins are loaded (as of WP 2.9.1 at least) is determined by the order of an array stored as "active_plugins" in the WP options table. Whenever a plugin is activated, it is added to this array, the array is sorted alphabetically by plugin name, and the array is saved to the DB.
Fortunately, there is a convenient action hook, "activated_plugins", that is called after the active plugins array is saved to the DB. This allows you to manipulate the order of the plugins stored in this array after the array is initially saved.
You'll have to the following PHP code in the plugin who defines the constant, then deactivate and reactivate it (copied from the link I providaded above).
function this_plugin_first() {
// ensure path to this file is via main wp plugin path
$wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", __FILE__);
$this_plugin = plugin_basename(trim($wp_path_to_this_file));
$active_plugins = get_option('active_plugins');
$this_plugin_key = array_search($this_plugin, $active_plugins);
if ($this_plugin_key) { // if it's 0 it's the first plugin already, no need to continue
array_splice($active_plugins, $this_plugin_key, 1);
array_unshift($active_plugins, $this_plugin);
update_option('active_plugins', $active_plugins);
}
}
add_action("activated_plugin", "this_plugin_first");
Hope it helps!

How to change members per page in BuddyPress members directory

In BuddyPress, it shows 20 members per members directory page. I want to list 24 members per page with a pagination and sorting must work perfectly. I tried:
bp_has_members(bp_ajax_querystring('members').'per_page=24'))
It works but pagination and sorting are not working correctly.
For those like me wondering how to do this nowadays and ending here after searching with their fav engine, the proper way is to use a filter in bp-custom.php or the functions.php of your theme.
Cf. https://codex.buddypress.org/developer/using-bp_parse_args-to-filter-buddypress-template-loops/
For the member loop it would be something like :
function my_bp_members_per_page( $retval ) {
$retval['per_page'] = 24;
return $retval;
}
add_filter( 'bp_after_has_members_parse_args', 'my_bp_members_per_page' );
Bonus : this will still work if you use cache like WP Rocket.
Former method doesn't work with cache and logged in user.
You need an '&' for each additional argument.
Try:
bp_has_members(bp_ajax_querystring('members').'&per_page=24'))
To modify this file, you make a copy of it and put it into your child-theme
/your-child-theme/buddypress/members/members-loop.php

Woocommerce display downloadable files with an external url

I need help with this: I need that the url of the downloadable products link with an external url. I´m trying to add a custom field and replace the filters woocommerce_product_file and woocommerce_product_file_download_path but it didn't worked, I think because I can´t call to the product data from the order. Someone did this? Thank you for your help!
The code doesn't works. Now is something like:
*function mostrar_campo_personalizado_en_order($file_id){
global $wpdb, $woocommerce;
echo get_post_meta($file_id, 'downloadable_url', true);
}
add_filter( 'woocommerce_product_file', 'mostrar_campo_personalizado_en_order', 10, 1 );
add_filter( 'woocommerce_product_file_download_path', 'mostrar_campo_personalizado_en_order', 10, 1 );*
I don´t know if I´m working in the correct way, I need to change the url of the downloadable products because woocommerce internally routed. Because I couldn't modify him, I intente removal and display a custom post field. The page is in a test server because the site is on line. The url of the tester server ishttp://lab.jus.raffles.com.ar/my-account/ but you need credential to come in:
user: paula
pass: 5VPeGgAHWzYX1T

Wordpress and Woocmmerce - how to access settings from theme?

Im trying to pull the settings from Woocommerce admin. I found this:
http://oik-plugins.eu/woocommerce-a2z/oik_api/woocommerce_settings_get_option/
$string = woocommerce_settings_get_option( $option_name, $default );
It looks to be a public function but I cannot access from my theme files. It just gives me Fatal error: Call to undefined. Anyone have any idea how you can access the setting from the theme?
I'm trying to get 'woocommerce_frontend_css_primary', $colors['primary'] so can tie them into the rest of the theme. Woocommerce currently just write the values directly to .less file.
Woocommerce docs are a bit misleading, but it turns out there is another function called get_option... as long as you know the name of the option you can use. EG. get array of front end colors:
$woo_styles = get_option( 'woocommerce_frontend_css_colors' );

Resources