Friday, August 12, 2022
HomeWordPress Developmentcapabilities - Wordpress easy 'Hi there World' plugin - issues

capabilities – WordPress easy ‘Hi there World’ plugin – issues


I’m an old-school embedded C programmer however a WP noob, so please bear with me.

Here’s what I’ve achieved to date:-

  1. My operate prints out ‘Hi there World’ and is registered to a shortcode within the OceanWP theme, and saved right here:

> wp-content / themes / oceanwp / custom-shortcodes.php:

<?php
// [helloworld]
operate helloworld_func( $atts ) {
    return "Hi there World";
}
add_shortcode( 'helloworld', 'helloworld_func' );
  1. I then added the shortcode to the next capabilities.php file:

>wp-content / themes / oceanwp / capabilities.php:

embrace ('custom-shortcodes.php');
  1. I created a brand new WP Publish and dropped the shortcode into it:
[helloworld]
  1. This works BUT:
    if I subsequently add any code which provides an error, the web page is affected, the entire theme is affected, the entire website is affected and even the entire WP Dashboard exhibits the error !

(Jogs my memory of Home windows 3.1 when a driver error crashed the entire OS. For me, the entire WP structure sucks however I’m caught with it.)
/rant

  1. I might create a baby theme, however I favor to:
  1. So, I created a ‘Hi there World’ plugin in the identical approach:

>wp-content / plugins / hello_world / hello_world_plugin.php

/**
 * Plugin Title: HELLO WORLD PLUGIN
 */
// [hello_world_plugin]
operate hello_world_plugin_func( $atts ) {
    return "Hi there World Plugin";
}
add_shortcode( 'hello_world_plugin', 'hello_world_plugin_func' );

  1. Drawback is: I have no idea which capabilities.php file I would like so as to add the next name to:
embrace ('hello_world_plugin.php');

so all I’m seeing on the web page is:

“[hello_world_plugin]”

I discovered the next file, but it surely doesn’t appear to comprise another contains:

>wp-includes / capabilities.php

Not one of the different plugins appear to have a capabilities.php file, so I’m assuming that my plugin doesn’t want its personal both…Is that proper?

  1. Moreover, when I attempt to Activate my plugin, I get the next error on my WP Dashboard and on the entire rattling web page:
The plugin generated 213 characters of sudden output throughout activation. When you discover “headers already despatched” messages, issues with syndication feeds or different points, strive deactivating or eradicating this plugin.

So, listed here are my questions:-

A) Do I have to activate my Hi there World plugin? In that case, do I have to name the next:

register_activation_hook()

On some tutorials, I noticed related plugin code, with none such hook…

B) During which capabilities.php file am I imagined to drop an embrace assertion, in order that the Hi there World shortcode plugin is ‘executable’?

I’m positive the answer goes to be trivial (at all times is), however after studying by means of ALL the WP Dev docs (or what looks as if it), I nonetheless can not see what I’m doing fallacious.

Any concepts?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments