Disable Elementor on specific page - wordpress

I have a plugin that uses the default woocommerce my account shortcode and displays the page only for a specific role. But, I have customized the My Account page using elementor & crocoblock, and the plugin is not working properly. They did give a workaround for this in the documentation, but I can't seem to make it work. This is the code
add_filter( 'elementor/frontend/the_content', 'wcb2bsa_disable_elementor_on_sales_agents_area' );
function wcb2bsa_disable_elementor_on_sales_agents_area( $content ) {
if ( is_account_page() && is_user_logged_in() && wcb2bsa_has_role( get_current_user_id(), 'sales_agent' ) ) {
return '[woocommerce_my_account]';
}
return $content;
}
Is it because the elementor/frontend/the_content part is changed?

Related

How to disable specific plugin on Wordpress backend / edit product page

I try to find a solution to disable specific plugins on Wordpress admin area. The problem is that for building WooCommerce shops I use Divi Builder, which on product page can sometimes use 50mb of resources when you try to edit it... if I disable some plugins over there then the load time would be much faster. I've found the following code on other topic:
add_filter( 'option_active_plugins', 'lg_disable_cart66_plugin' );
function lg_disable_cart66_plugin($plugins){
if(strpos($_SERVER['REQUEST_URI'], '/store/') === FALSE AND strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === FALSE) {
$key = array_search( 'cart66/cart66.php' , $plugins );
if ( false !== $key ) unset( $plugins[$key] );
}
return $plugins;
}
But don't know how to modify it, so it only disables the chosen plugin on backend. In other words: I don't want the plugin to load when I edit WooCommerce product page.
Some help will be really appreciated.
As ‘option_active_plugins’ is fired before any plugin is loaded we need to drop our code down into mu-plugins directory. Please also remember that those plugins are run before the main query is initialized – that is why we don’t have any access to many functionalities, especially conditional tags which will always return false.
Please paste below code or download gist in mu-plugins folder in your wp-content folder. It would disable the plugin in post & page areas only.
<?php
/*
Plugin Name: Disable Plugin for URl
Plugin URI: https://www.glowlogix.com
Description: Disable plugins for for specific backend pages.
Author: Muhammad Usama M.
Version: 1.0.0
*/
add_filter( 'option_active_plugins', 'disable_plugins_per_page' );
function disable_plugins_per_page( $plugin_list ) {
// Quit immediately if not post edit area.
global $pagenow;
if (( $pagenow == 'post.php' || $pagenow == 'edit.php' )) {
$disable_plugins = array (
// Plugin Name
'hello.php',
'developer/developer.php'
);
$plugins_to_disable = array();
foreach ( $plugin_list as $plugin ) {
if ( true == in_array( $plugin, $disable_plugins ) ) {
//error_log( "Found $plugin in list of active plugins." );
$plugins_to_disable[] = $plugin;
}
}
// If there are plugins to disable then remove them from the list,
// otherwise return the original list.
if ( count( $plugins_to_disable ) ) {
$new_list = array_diff( $plugin_list, $plugins_to_disable );
return $new_list;
}
}
return $plugin_list;
}
You can replace $disable_plugins with the required list of plugins to disable.

How to set homepage based on device with Wordpress?

I need to set a default homepage based on the visitor device (mobile/desktop), I tried the following code in plugin, but did not work.
if ( wp_is_mobile() ) {
$homepage = get_page_by_title( 'mobile' );
}else{
$homepage = get_page_by_title( 'home1' );
}
if ( $homepage ){
update_option( 'page_on_front', $homepage->ID );
update_option( 'show_on_front', 'page' );
}
it keeps loading the home1, which is selected from theme options.
Thanks,
Your current functionality wouldn't work, even if it "worked". You're attempting to set a site-wide option in the database based on the most recent visitor's device.
Using update_option() isn't in your best interest here. What you should be doing is programmatically changing the template that's loaded at run-time based on the user's device, using the template_include filter - that way you're not storing a (semi) permanent change in your database, which would get constantly overwritten countless times by any user and affect all other users.
This would end up looking something like this:
add_filter( 'template_include', 'so_52745088_homepage_template', 99 );
function so_52745088_homepage_template( $template ){
// Only execute on the front page, not pages/posts/cpts
if( is_front_page() ){
// Determine if mobile
if( wp_is_mobile() ){
// Make sure mobile homepage template is found
if( $home_template = locate_template( array( 'homepage-mobile.php' ) ) ){
return $new_template;
}
}
}
return $template;
}
If you don't have a separate page template for mobile, and it's just a regular ol' separate page, then you can look at using wp_safe_redirect() on any number of hooks, a common one being template_redirect, which would end up looking like this:
add_action( 'template_redirect', 'so_52745088_homepage_redirect' );
function so_52745088_homepage_redirect( $template ){
// Only execute on the front page, not pages/posts/cpts
if( is_front_page() ){
// Determine if mobile
if( wp_is_mobile() ){
wp_safe_redirect( 'mobile' );
exit;
}
}
}

hide wordpress posts and categories for not logged in users

Basically I handled this issue by overriding parent theme files in child theme.
i.e., by using
if( is_user_logged_in() ){
...................
wordpress loop
}
I had to do this for every template ( wherever there is wordpress loop )
Though I didn't have to do this for displaying sidebars as if there was category in widget and whenever user clicks on it to view it, it would automatically say you don't have proper privileges to view this content.
So, my question is, is there any better way to hide wordpress content ( this may be anything, like normal posts, custom post types,.. ) from just visitors.
function bt_hide_from_guestes( $content ) {
global $post;
if ( $post->post_type == 'post' ) {
if ( !is_user_logged_in() ) {
$content = 'Please login to view this post';
}
}
return $content;
}
add_filter( 'the_content', 'bt_hide_from_guestes' );
Above code didn't help
It looks like your filter function should work for you. Try setting a priority and the "accepted arg" number:
add_filter( 'the_content', 'bt_hide_from_guestes', 10, 1 );

remove visual composer from one single page wordpress

I am using a paid plugin "Visual Composer". I want to remove the visual composer from one specific page. But I have tried from screen options and from acf too. Still visual composer still appears.
It can be filtered when WP pulls all active plugins. We check if it's admin side and if the current admin page is correct, then check the URL to see if post with ID 2 (Sample Page) is being edited, and finally remove the plugin from the option list:
add_filter( 'option_active_plugins', function ( $option )
{
global $pagenow;
if( 'post.php' !== $pagenow || !is_admin() )
return $option;
if( !isset( $_GET['post'] ) || '2' !== $_GET['post'] )
return $option;
return array_diff( $option, array( 'js_composer/js_composer.php' ) );
});
Can you remove the buttons via javascript or CSS by targeting the .composer-switch class.
.composer-switch {
display:none;
}
This would remove the buttons on that page if you combine it with the PHP at top.
If you mean "remove visual composer" on the front-end view you can use this plugin: Plugin organizer
Just install, activate the option "Selective plugin loading" as on the screen capture
And go thru wordpress admin to the page you want to disable Visual composer, scroll down to find the Plugin organizer options" and disable "visual composer" for that page just dragging and dropping to one side or another. You can do it for any page you want.
You can use the vc_is_valid_post_type_be filter to completely disable the backend and frontend editor like so:
// Disable WPBakery on certain pages
add_filter( 'vc_is_valid_post_type_be', 'disable_wpbakery', 10, 2 );
function disable_wpbakery( $enabled, $post_type ) {
global $post;
// Replace with the condition of your choice
if ( in_array( get_post_meta( $post->ID, '_wp_page_template', true ), [
'my-template.php',
'other-template.php'
] ) ) {
// Optionally disable the classic editor
//remove_post_type_support( 'page', 'editor' );
return false;
}
return $enabled;
}

Disable WooCommerce SKU on Product Page

I have a WooCommerce store and I don't want to display the SKU on any single product page. Looking at their code, I found this filter:
/**
* Returns whether or not SKUS are enabled.
* #return bool
*/
function wc_product_sku_enabled() {
return apply_filters( 'wc_product_sku_enabled', true );
}
and I attempted to override it with this line of code I placed in a custom plugin:
apply_filters( 'wc_product_sku_enabled', false );
I also tried placing the apply_filter inside an action function for woocommerce_product_meta_start which fires right before but it still renders the SKU on the product page. Any ideas?
I think you shoul try with this:
add_filter( 'wc_product_sku_enabled', '__return_false' );
That will remove sku from all woo, back and front end. You can always hide it just by CSS if need it on admin.
The easiest way is with CSS:
.sku_wrapper {
display:none;
}
A more robust approach is to recreate the woocommerce template woocommerce/templates/single-product/meta.php in your own theme and simply comment out the line:
<span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span>.</span>
To recreate a woocommerce template in your own theme, see:
http://docs.woothemes.com/document/template-structure/
Hiding the SKU/UGS by using cSS is not an efficient solution because it will be still part of the HTML code.
In order to hide it from the product single page and keep it in the admin page, you have to add this code in the child (or parent if you don’t have the child) functions.php :
// Remove the Product SKU from Product Single Page
add_filter( 'wc_product_sku_enabled', 'woocustomizer_remove_product_sku' );
function woocustomizer_remove_product_sku( $sku ) {
// Remove only if NOT admin and is product single page
if ( ! is_admin() && is_product() ) {
return false;
}
return $sku;
}
Make sure also in the product php page (it can have a different name depending on the theme you use) to have this condition to show the SKU in the product single page:
if (wc_product_sku_enabled() && $product->get_sku()) { // HTML code that shows the SKU in the product single page}
Make Sure to remove it from the frontend only by using this code on function.php usually you can edit the function file on theme editor
add_filter( 'wc_product_sku_enabled', 'my_remove_sku', 10 );
function my_remove_sku( $return, $product ) {
if ( !is_admin() && is_product() ) {
return false;
} else {
return true;
}
}
If you don’t need to use SKUs at all in your shop, you can disable them completely by using this plugin. simply install this plugin. https://wordpress.org/plugins/woocommerce-remove-sku/

Resources