Where to put my global functions?

I currently have a global function in my functions.php file ein_error_log($message) { //push out $message to file... } But I want to start using it in my MU-Plugin directory and it doesn't know it exists. So I assume it's because MU-Plugins folder is read before the theme folder in WordPress's hierarchy, which makes sense. But if the hierarchy is the case, how do I distinguish which MU-Plugin runs first to make sure all other MU-Plugin files can run dependent on …
Category: Web

How can I recompile js file in dist folder?

I'm working on a project that loads a minified js file from my theme into a page <script type='text/javascript' src='http://localhost/mysite/wp-content/themes/mytheme-2021/dist/app.js?ver=5.9' id='app-js'></script> I have a webpack.mix.js file in my theme root directory: let mix = require('laravel-mix'); const dist = `dist` mix .options({ processCssUrls: false }) .copyDirectory('resources/fonts', dist) .copyDirectory('resources/images', dist) .js('resources/js/app.js', dist) .sass('resources/sass/app.sass', dist); and a package.json { "dependencies": { "laravel-mix": "^6.0.6", "normalize-scss": "^7.0.1", "reset-css": "^5.0.1", "sass-mq": "^5.0.1" }, "devDependencies": { "sass": "^1.37.5", "sass-loader": "^12.1.0" } } I've made changes to the …
Category: Web

Check for dependent plugin and if false dont activate plugin

I am creating a plugin for WordPress and this plugin depends on another plugin with a specific version. If I enable my plugin without dependent plugin there are fatal error. Is there a way to check this ? I tried looking at source code but WP do not provide any hook for this. Thanks in advance. --UPDATE-- I am not asking about how to check plugin installed or about plugin data, but I want to know "how to check if …
Category: Web

How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met

I have a plugin which is dependent on another plugin, in this case WooCommerce. How can I stop the activation of my plugin and display an admin notice with download link of the dependent plugin, if the version of the dependent plugin is lower than a certain version? In short, on the activation process my plugin should not be activated and display a notice with download link when any of the following is true: WooCommerce plugin is not activated (I …
Category: Web

Conditionally dequeue dependency of scripts

Please note that, I'm not telling about conditionally enqueue/dequeue scripts, I'm referring to conditionally dequeue certain dependencies from an existing enqueued scripts in front end. And please note the question is not plugin-specific. I want to be enlightened about the general rules. I used Elementor (page builder) for front end. But it's not used in all my pages. So the default lightbox feature enabled in Elementor doesn't work in those pages. That's why I added my own lightbox throughout the …
Category: Web

Wordpress Bedrock breaking plugin links

I recently switched to using WP-Bedrock and I currently like the workflow but there's a huge drawback for me. There are 2 URLs which previously were identical, due to Bedrock's file structure, are different. Site_URL: /wp Home_URL: A huge bunch of plugins are written taking in mind only regular WP installations. A very critical plugin for my site is currently unusable because the links to internal images look like this: https://<domain>/wp/https://<domain>/app/uploads/... I've tried to dig in the plugin files but …
Category: Web

Excess dependencies

I grabbed gallery block from Gutenberg github (Gallery block) and I wanted to modify it in following way: only first image is output to the html, while the rest are sent to lightbox javascript plugin. However, when compiled and used, I am getting a bunch of excess dependencies in the frontend like lodash, react, react.dom and so on. Gutenberg does not output these dependencies in the frontend. How to prevent outputting these dependencies? they are getting outputed in index.asset.php. I …
Category: Web

What dependencies should I load and to use the WP_Filesystem?

I'm building a Wordpress theme which has a WP_Filesystem call in it: <?php $wp_filesystem = new WP_Filesystem_Direct(null); echo $wp_filesystem->get_contents(get_stylesheet_directory() . '/assets/images/Search_Glyph.svg'); ?> I know that the WP_Filesystem needs some dependencies. I load them now like this in functions.php: require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; I don't know if this is the correct way to load the dependencies for the filesystem. I found an other question for plugin development and after some research I made the following code, which …
Category: Web

How to include a mu-plugin as a theme dependency?

I'm going through a tutorial which says that creating new post_types is best handled by creating a new mu-plugin (as opposed to adding it to the functions.php). I understand why, but what I don't understand is how to include this mu-plugin as a dependency of my theme. I want to be able to have my friend upload my theme and have it work right away, without having to tell them to copy the mu-plugin file into their WordPress mu-plugins folder.
Category: Web

Enqueue registered dependencies only when necessary

I'm developing plugin where I want to load my dependency JS libraries only when the setting is enabled. The most correct way is to register all the scripts and styles I have and then enqueue my main script with dependencies, but I can't figure it out how to load them only when setting is enabled. Here's my current code: function registerAssets() { wp_register_script('main', plugins_url('public/assets/js/script-main.js', $this->pluginFile), array('additionaljs', 'additionaljs2'), $this->version, true); wp_register_script('additionaljs', plugins_url('public/assets/js/additionaljs.js', $this->pluginFile), array(), $this->version, true); wp_register_script('additionaljs2', plugins_url('public/assets/js/additionaljs2.js', $this->pluginFile), array(), $this->version, …
Category: Web

RequireJS in custom theme. Working Example

I try to add to my custom wordpress Theme requirejs because I do not want to use wp_enqueue over and over to inject used plugins and on the other side I do not want to mess the DOM from the beginning. I followed a lot of tutorials what I got from google but none of theme is working. Is there a good working example how to use requirejs in a wrodpress theme properly?
Category: Web

How to provide a plugin which requires CMB2 (plugin dependencies)?

Every serious plugin developer probably has to deal with this problem: WordPress is not supporting composer or any dependency management by default. I have written a great plugin which I would like to put into the official repository on WordPress.org. Problem is: I do not want to write all of those options pages (including network options pages) on my own - this is why I am using the CMB2 library. It is actually a well known framework used by a …
Category: Web

Set a parent script presence status true so that child scripts load in wordpress

I didn't know how to write a good title for my problem. I'm trying to integrate some scripts in js file and dequeue them to decrease browser requests. So let's say we have some child scripts which for some reasons I don't want to integrate them and they have dependencies on a parent script that I've dequeued it and integrated into another script file. Now I know I've loaded the parent script (inside the integrated script) and I want to …
Category: Web

Loading jQuery in the footer after removing jQuery migrate?

I am removing jQuery migrate in WordPress in this way: add_filter( 'wp_default_scripts', 'remove_jquery_migrate' ); function remove_jquery_migrate( &$scripts ){ if(!is_admin()){ $scripts->remove( 'jquery'); $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.2.1'); } } I'm confused at how you set the in_footer property with the WP_Dependencies::add function, I tried the below but it didn't work: $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.2.1', ['in_footer' => true]); What is the correct way to do this?
Category: Web

Flexslider won't work with WordPress' jQuery | Dependencies

When I try to use the Flexslider with 'built-in' jquery, the Flexslider won't work. When I use my own myjquery file, It works as if nothing ever. Do I always have to use my own jquery file even wordpress has its own? Wordpress' (built in) jQuery vserion: 1.11.3 Flexbox required jQuery version: 1.7+ myjquery = jquery version: 1.12.0 Summary: flexbox should work with jQuery of WordPress. More Details Flexslider doesn't work when I use Wordpress' jQuery. It works when I …
Category: Web

wp_enqueue_script silently fails

I created a plugin which uses bootstrap datetimepicker. So i load corresponding js setting dependancies like this: wp_enqueue_script('medapp-datetimepicker-js', $medapp_boot_timepicker_js, array( 'jquery', 'jquery-ui', 'moment', 'medapp-twitter-bootstrap-js' )); wp_enqueue_script('medapp-frontend-js', $medapp_script_js, array( 'jquery', // 'medapp-datetimepicker-js', ),'',false); If the line commented is on, of course in my js file i can't access datetimepicker and i have the following error when i try to instanciate the datetimepicker: TypeError: jQuery(...).datetimepicker is not a function So i uncomment the commented line, and then load of scripts silently fails …
Category: Web

PHP includes with AJAX actions

I have the following code in my main plugin file <?php include plugin_dir_path( __FILE__) . 'options.php'; include plugin_dir_path( __FILE__ ) . 'config.php'; include plugin_dir_path( __FILE__ ) . 'front/manage.php'; add_action( 'admin_init', 'restrict_admin', 1 ); //prepare wordpress for ajax this needs to be done early to avoid strange race conditions add_action( 'wp_ajax_devices', 'api_list_devices' ); add_action( 'wp_ajax_profiles', 'api_list_profiles' ); add_action( 'wp_ajax_held_accounts', 'api_list_held_accounts' ); add_action( 'wp_ajax_set_profile', 'api_set_profiles' ); define('AJAX_NONCE_NAME',"title_example"); //... I assume since adding an action just lets admin-ajax.php know it should run some …
Category: Web

Can´t access child theme´s scripts dependencies found in parent

I´ve been struggling with this for nearly a month now and still couldn´t find anything at all on how to do this! Not here, not in Quora, not through many different advanced Google search queries... Here it is: The parent theme has only one script file main.min.js. It contains all the scripts and libraries being used by it, including jQuery, Select2, Parsley and Slick, to name a few. How do I go about making my own scripts use one or …
Category: Web

Identifying the priority of style.css so I can make a small CSS file load last

I have a small bit of hourly-changing css and I want to keep it in a second file (apart from style.css) and load it after my theme's style.css file. I believe I can make it load before style.css by setting its priority to the style.css minus one (e.g. if the main style.css has a priority of 10, my bit of code would have a priority of 9). But here's my problem: apart from trial and error I don't know how …
Category: Web

How to check for dependencies for a specific page and enqueue them

I am creating a one page site where the content of the sections (separate pages) above and under the actual page section are lazy loaded via AJAX. Say in one of the pages a shortcode for a gallery plugin is used and the plugin only enqueues its dependencies on pages where the shortcode is used: How can I check which dependencies would be enqueued if a specific page is loaded? By 'page' I do not only mean actual pages or …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.