Using WP_Query within an mu-plugin

I figured it out. I moved the reference to WP Alchemy within a function that fires after init. Everything now works great and I can use WP_Query within the setup files. Here’s a code reference: // WP Alchemy Setup function jd_setup_wp_alchemy() { include_once WPMU_PLUGIN_DIR . ‘/jonathanwold/metaboxes/setup.php’; include_once WPMU_PLUGIN_DIR . ‘/jonathanwold/metaboxes/cpt-spec.php’; } add_action(‘init’, ‘jd_setup_wp_alchemy’);

Get post/page data outside the loop

You’re using non-existent variables in your function, $post_id, $post, $page. Use get_queried_object to get data from the current page. if( is_single() || is_page() ){ $this_page = get_queried_object(); $excerpt = get_post_field( ‘post_excerpt’, $this_page->ID ); }

mu-plugins aren’t loading

The reason plugins in the mu-plugins folder can’t be activated in the plugins page is because that’s not how mu-plugins works. The mu stands for must use. Improtant things to know: mu-plugins load before plugins WP loads PHP files in the mu-plugins folder it does not search subfolders it does not look for plugin headers … Read more

Hide mu-plugins list

The solution to this request is filtering show_advanced_plugins. This filter is called twice, once for mustuse– and once for dropins-plugins. The filter accepts two parameters, the first one being the standard value (true), and the second one being the type of the advanced plugin (Must-Use and Drop-In). So returning false does the trick, if your … Read more

How to send user data in json format to another server when user register on wordpress site in PHP

Sending and receiving data in JSON format using POST method xhr = new XMLHttpRequest(); var url = “url”; xhr.open(“POST”, url, true); xhr.setRequestHeader(“Content-type”, “application/json”); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { var json = JSON.parse(xhr.responseText); console.log(json.email + “, ” + json.password) } } var data = JSON.stringify({“email”:”[email protected]”,”password”:”101010″}); xhr.send(data); Sending … Read more

wp_get_environment_type is undefined

It is a core WP function, but only after WordPress version 5.5.0. If you’re using an older version of WordPress, it won’t exist yet. Do this: add_action(‘admin_init’, function() { if ( ! function_exists( ‘wp_get_environment_type’ ) ) { return; } $environment = wp_get_environment_type(); //… Or, better still, make sure your WordPress installation is up to date.

POEdit with Custom mu-plugins code

I’m not 100% sure this is the only issue that was preventing POEdit from correctly parsing my code (I’m not sure it actually cares about the WordPress side of things), but fixing these (stupid) errors and re-running POEdit from the .pot file below seems to have generated the correct translation strings: define( ‘MY_TEXTDOMAIN’, ‘MY_TEXTDOMAIN’ ); … Read more

register_activation_hook in mu-plugin not triggering

MU plugins don’t ‘activate’, or ‘deactivate’. They’re just present or not present. So you’ll need a different approach. One option would be to just perform your activation functions on init, and store a record in the database to say whether or not it’s already been done: function activate_mjmc_core() { if ( ‘1’ === get_option( ‘mjmc_activated’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)