How Can I Change the Elementor Popup Location Settings? - wordpress

I have an issue with one of the websites I work on where the "edit_in_content" location setting for Elementor popups is set to FALSE for all popups, and it is preventing the admin from going to the Elementor editor.
This issue presents itself as the common "the_content not found" error message, however, debugging leads to the location settings for popups being the issue. The problem is in the builder_wrapper method of \ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager, which is in /elementor-pro/modules/theme-builder/classes/locations-manager.php.
public function builder_wrapper( $content ) {
$post_id = get_the_ID();
if ( $post_id ) {
$document = Module::instance()->get_document( $post_id );
if ( $document ) {
$document_location = $document->get_location();
$location_settings = $this->get_location( $document_location );
/**
* Custom Modification Begin
* ------------------------------------
*/
if( $document_location == 'popup' )
return $content;
/**
* Custom Modification End
* ------------------------------------
*/
// If is a `content` document or the theme is not support the document location (header/footer and etc.).
if ( $location_settings && ! $location_settings['edit_in_content'] ) {
$content = '<div class="elementor-theme-builder-content-area">' . __( 'Content Area', 'elementor-pro' ) . '</div>';
}
}
}
return $content;
}
I'm aware that this is a plugin hack, and not recommended, but I have found no other way to handle the issue.
I'm not sure why edit_in_content is FALSE for all popups.
I've found no way to ensure that edit_in_content is TRUE so that the admin can work with popups.
To be fair, I should disclose that the theme is custom, but rather minimal. When switching to twentytwenty the issue goes away. ALL plugins have been disabled during testing, and it seems that the popup location setting is somehow being affected by the custom theme.
I've found nothing in twentytwenty that references elementor in any way.
I've been through Elementor's docs related to the_content issues, and nothing noted there leads to success. Ref: https://docs.elementor.com/article/56-content-area-not-found
So, I'm hoping somebody will be able to shed some light on this issue. What can I do so I don't have to hack the plugin?

I'm posting an answer because I found something that I could do to not hack the plugin, although I'm still curious to why it needs to be done. I basically just add a hook/action that reprocesses the popup location after it was initially registered. This could go in the theme's functions.php file:
function fixElementorPopupLocation( $that )
{
$loc = $that->get_location('popup');
if( ! $loc['edit_in_content'] )
{
$args = [
'label' => $loc['label'],
'multiple' => $loc['multiple'],
'public' => $loc['public'],
'edit_in_content' => TRUE,
'hook' => $loc['hook'],
];
$that->register_location('popup', $args);
}
}
add_action(
'elementor/theme/register_locations',
'fixElementorPopupLocation',
93062220
);
If anyone could tell me why I need to do this, and why I don't need this in the twentytwenty theme, I'd be glad to accept that as an answer, provided I can use the advice to "fix" my theme.

Related

Display list of installed plugins in Wordpress admin area

I would like to find a way of displaying a list of all my installed plugin in a neat widget on the home admin area of Wordpress.
Often when I'm doing performance audits on websites I like to clearly see exactly what I'm working with and having a complete list of plugins whereby I can copy and paste into an Google doc or sheet is really handy so I can go through the list and see what plugins I can remove, upgrade, and keep.
This solution is an adaptation of a similar solution found here.
However, that solution only displays active plugins and not a complete list. For example plugins like Easy Updates Manager wouldn't show as it's only admin-based.
The solution below shows a complete list of all installed plugins. Regardless whether they are active or not.
add_action('wp_dashboard_setup', 'wpse_54742_wp_dashboard_setup');
function wpse_54742_wp_dashboard_setup() {
wp_add_dashboard_widget( 'wpse_54742_active_site_plugins', __( 'Installed Plugins' ), 'wpse_54742_active_site_plugins' );
}
function wpse_54742_active_site_plugins() {
$all_plugins = get_plugins();
$active_plugins = get_option('active_plugins');
echo '<ul>';
foreach ( $active_plugins as $index => $plugin ) {
if ( array_key_exists( $plugin, $all_plugins ) ) {
//var_export( $all_plugins[ $plugin ] );
echo '<h4 style="margin-bottom:15px;font-weight:400;font-size:12px">', $all_plugins[ $plugin ][ 'Name' ], ' ('. $all_plugins[ $plugin ][ 'Version' ] .')</h4>';
}
}
echo '</ul>';
}
Unless you have a child theme installed, I wouldn't recommend adding this to your functions.php file. Instead, use a plugin like code snippets if you want to have better control over your code snippets.
Hope this helps some of you as I feel this is pretty handy to have. Equally, if any has a more elegant solution, I'd love to hear about it.

Is it possible not to load theme on a specific page in wordpress?

I have a question about WordPress, I need the current theme installed on my WordPress not to be loaded on a certain page, is it possible?
What I want to do is create a bootstrap dashboard, and I don't want to load the default theme. The idea is to develop a dashboard via plugin and generate all the HTML, header, content, footer.
I thought about using "WP_USE_THEME" and using external files, but I need to use WordPress functions like: add_action, add_shortcode and etc.
You can use function switch_theme() in hook plugins_loaded to switch the theme run time. You can use below code for reference.
Don't forget to add your condition. Also, note that switching theme runtime may cause peformance issue.
// switch_theme('astra');
// switch_theme('automotive-centre');
// switch_theme('blocksy');
// switch_theme('customify');
// switch_theme('generatepress');
// switch_theme('hello-elementor');
// switch_theme('inbox');
// switch_theme('magcess');
// switch_theme('myself');
// switch_theme('newsphere');
// switch_theme('oceanwp');
// switch_theme('page-builder-framework');
// switch_theme('shopical');
// switch_theme('storement');
// switch_theme('twentyfifteen');
// switch_theme('twentynineteen');
// switch_theme('twentyseventeen');
// switch_theme('twentysixteen');
// switch_theme('vw-ecommerce-store');
//
if( isset( $_GET['theme'] ) && ! empty( $_GET['theme'] ) ) {
$theme_slug = sanitize_title( $_GET['theme'] );
$theme_slugs = array_keys(wp_get_themes( ));
if( in_array($theme_slug, $theme_slugs) ) {
switch_theme( $theme_slug );
} else {
wp_die( sprintf( __( 'Theme not found!<br/><b>%s</b> slug! Please try again with right theme slug.', 'woocommerce' ), $theme_slug ) );
}
}
});```

How to Change Wordpress Admin Bar My Account Profile URL

My wordpress admin bar 'My Account' links takes the user to the back end to manage their profile etc. There are also buddypress links on that menu which take the user to manager their profile on the front end. I like the avatar with the 'Howdy' but I don't want users on the back
end; so I need to change the WP links to take them to the front end.
I found how to remove links and add links to the admin bar 'My Account' but I just want to change the url of those top links from /wp-admin/profile to /members/user/profile.
admin-bar.php
/**
* Add the "My Account" item.
*
* #since 3.3.0
*
* #param WP_Admin_Bar $wp_admin_bar
*/
if ( current_user_can( 'read' ) ) {
$profile_url = get_edit_profile_url( $user_id );
Would changing the 'get_edit_profile_url' from a wordpress admin url to the buddypress members url be the simplest way to accomplish my goal? ... and How would I do that to test it?
Thanks to anybody who can help me, I'm not very good with php.
I couldn't find any help with changing the url however this redirect in my functions file keeps the user on the front end.
Thanks to: http://blog.happyplugins.com/redirect-user-profile-page-frontend-page/
add_action ('init' , 'prevent_profile_access');
function prevent_profile_access() {
if (current_user_can('manage_options')) return '';
if (strpos ($_SERVER ['REQUEST_URI'] , 'wp-admin/profile.php' )){
wp_redirect ('/members/' .bp_core_get_username(bp_loggedin_user_id() ));
die();
}
}
I'd still like to know how to change the URL instead of using the redirect, if anyone knows how!
bp_core_get_userlink( $user_id )
add_action('wp_before_admin_bar_render', 'rew_admin_bar_remove_wp_profile', 0);
function rew_admin_bar_remove_wp_profile() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('edit-profile');
}
add_action('admin_bar_menu', 'rew_add_bbp_profile', 999);
function rew_add_bbp_profile($wp_admin_bar) {
$current_user = wp_get_current_user() ;
$user=$current_user->user_nicename ;
$user_slug = get_option( '_bbp_user_slug' ) ;
if (get_option( '_bbp_include_root' ) == true ) {
$forum_slug = get_option( '_bbp_root_slug' ) ;
$slug = $forum_slug.'/'.$user_slug.'/' ;
}
else {
$slug=$user_slug . '/' ;
}
$profilelink = '/' .$slug. $user . '/edit' ;
$wp_admin_bar->add_node( array(
'parent' => 'user-actions',
'id' => 'bbp-edit-profile',
'title' => 'Edit Profile',
'href' => $profilelink,
) );
}
get you to the bbpress user profile

Wordpress Menu not showing

I'm using a theme called hotheme(dot co) which seems not working properly. I added some links to my menu in the backend and linked it to "main menu" but on the frontend the inspector shows an empty
Here's the code for the menu from the header.php
`
global $wpdb;
$tablename = $wpdb->prefix.'terms'; // use always table prefix
// language support
switch ($lang){
case '':
case '1':
$menu_name = 'default';
break;
case '2':
$menu_name = 'secondary';
break;
}
$menu_id = $wpdb->get_results(
"
SELECT term_id
FROM ".$tablename."
WHERE name= '".$menu_name."'
"
);
// Empty check
if($menu_id != null){
// results in array
foreach($menu_id as $menu):
$menu_id = $menu->term_id;
endforeach;
$items = wp_get_nav_menu_items( $menu_id );
$numItems = count($items);
$i = 0;
foreach($items as $item)
{
if(++$i === $numItems) {
echo "<li class='reservation-btn custom-color-btn-back'><a href='".$item->url.$lang_link.$lang."'>".$item->title."<br /><span class='grey'>".$item->description."</span></a></li>";
$_SESSION['reservation_url'] = $item->url;
} else {
echo "<li><a href='".$item->url.$lang_link.$lang."'>".$item->title."<br /><span class='grey'>".$item->description."</span></a></li>";
}
}
} // end: empty check
?>`
Could it be possile, that the code is deprecated?
Any help would be great! Thanks
That seems like a lot of unneeded code. I am going to give you some code (alters slightly) that I wrote for a theme framework that I am working on. You can add it to the theme and see if a menu shows up or not.
Add to functions.php
function ao_register_menus() {
register_nav_menu( 'primary', 'Primary Navigation');
}
add_action( 'init', 'ao_register_menus' );
function ao_primary_nav() {
echo '<nav class="primary-navigation">';
wp_nav_menu(array(
'theme-location' => 'primary',
'container_class' => 'primary-nav-container',
'menu_class' => 'primary-nav',
));
echo '</nav>';
}
add_action('ao-primary-nav', 'ao_primary_nav');
Then after that, you should be able to add the following to replace all of the code that you showed from header.php with this:
do_action('ao-primary-nav');
Warning: Doing this will destroy the styles attached to your theme's navigation. So don't erase the code the is already there, but instead simply use this to check to see if the navigation functionality is still existent. From here we can see if the theme overall is outdated or if there are bigger underlying issues. This is not a permanent solution. However, if this works and you see A NAVIGATION then it is a good sign that we can dig into the theme further to see what exactly is going on.
You could also always check the changelog of the theme to see when it was last updated and that could be a good sign of whether or not you should use it.
Menu is working fine in Hotheme. You have to read the documentation provided in http://www.hotheme.co/page-documentation.php#doc-3-1. In Menu topic they have mentioned, name the menu as "default".

Hide or remove comments box from wordpress pages

I am developing a plugin everything is going fine but there is a problem.
How can I hide or remove the comments box? I lost many hours but could not develop the right script. My current script is this:
add_filter( 'comments_template', 'remove_comments_template_on_pages', 11 );
function remove_comments_template_on_pages( $file ) {
if ( is_page() )
comments_template('', true);
}
I don't know how to develop this script. Any help could lead me to complete my plugin.
Add the below code to you functions.php file.
add_action('init', 'remove_page_feature');
function remove_page_feature() {
remove_post_type_support( 'page', 'comments' );
}
And now provide a check before the comments template is executed, as below:
if ( post_type_supports( 'page', 'comments' ); )
comments_template('', true);
}
Note: Using the above code will disable comments on pages.

Resources