Custom Post Type | Fatal Error on register_post_type()

try these changes: 1) To use add_action() when your plugin or theme is built using classes instead of passing just the function name, you need to pass an array with a reference to the class ($this) and the callable function (‘custom_post_type’) function __construct() { add_action(‘init’, array( $this, ‘custom_post_type’ ) ); } 2) The original ‘activate’ … Read more

Limit the number of plugins that can be installed in a WordPress installation

The most performant way to do this is probably by hooking into map_meta_cap to conditionally disallow the install_plugins capability. There are no database calls involved with that. Here’s an (untested) example: add_filter( ‘map_meta_cap’, ‘wpse291964_limit_plugins’, 10, 2 ); function wpse291964_limit_plugins( $caps, $cap ) { if ( ‘install_plugins’ === $cap ) { $plugins = get_plugins(); // Only … Read more

Correct wp-content ownership and permissions

By default, all files added by the Apache itself will be owned by the server’s user, in your case www-data. But since your users use FTP to deploy, those files are owned by them, and it makes the Apache scream for your attention. Changing the ownership of wp-content folder to www-data isn’t insecure at all, … Read more

How to retrieve custom meta term of category taxonomy from WP Rest API?

First you need to tell WordPress to show this custom field in the API response: register_term_meta(‘category’, ‘_category_color’, [‘show_in_rest’ => true]); Then you can filter the category term API endpoint like so: add_filter( ‘rest_prepare_category’,function($response, $item, $request){ $color = get_term_meta( $item->term_id, ‘_category_color’, true ); $response->data[‘color’] = $color ?: ”; return $response; }, 10, 3);

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.

Is there a way to programmatically enable a plugin?

Yes, there’s activate_plugin() defined in wp-admin/includes/plugin.php (which isn’t normally loaded from non-admin code, and note that obviously a PHP plugin file can’t activate itself) wp-cli wp plugin activate if you meant activate from the command line without using the admin site (and at a pinch you could edit the active_plugins value in wp_options in the … Read more

How do you add custom logo to entire themes

If you want this logo to show up across your network sites regardless of the theme I’d advise you to create a new PHP file inside wp-content/mu-plugins (create the directory if it doesn’t exist) and drop that code inside the new file. You can name your file whatever you like – for example my-network-tweaks.php. That … Read more