WordPress Plug-in Development

WordPress Plug-in Development

UnitPrice.org

Member
Local time
09:27
Joined
Oct 7, 2019
Messages
39

Has anyone developed their own Wordpress plugin and released it to the public? If so, any good resources or pieces of advice to pass along?

To branch out with my recent projects, I’ve thought about releasing widgets that people can include on their blogs that feature the lowest prices on Amazon for specific product categories they choose. For example, picture a parenting blog that lists the cheapest onesies and binkies and diapers. In this example, I suppose the plugin would only need to load in an RSS feed provided by my site?

 

Adam

Mr. Webwide
Administrator
Local time
14:27
Joined
Sep 24, 2019
Messages
1,257
Pronouns
he/him

Cool idea! Creating a plugin is pretty straightforward, I have made a number for private clients, though I have never actually submitted one to the .org directory. You could effectively create both a widget and a shortcode in one short PHP file and a CSS file, assuming you are just connecting to one of your homemade APIs/reading a JSON feed. It works the exact same way as if you were adding a custom shortcode or widget via functions.php.

Another more universal option might just be to create some embed HTML codes that people can drop in? These usually work with either an iFrame or a small JS script that replaces an empty div. Perhaps that could be your starting point and then you can build a slightly more integrated WordPress plugin that takes that technology in to a shortcode/widget.

 
Last edited:

Pandemix

MD developer
Gold Member
Local time
08:27
Joined
Feb 13, 2020
Messages
28

To add on to @Adam 's first answer:

Cool idea! Creating a plugin is pretty straightforward, I have made a number for private clients, though I have never actually submitted one to the .org directory. You could effectively create both a widget and a shortcode in one short PHP file and a CSS file, assuming you are just connecting to one of your homemade APIs/reading a JSON feed. It works the exact same way as if you were adding a custom shortcode or widget via functions.php.

If you take the JSON approach and want to help performance look into using Transients, which is a neat WordPress API that sets and holds data until it deletes itself after your defined time limit.

This is useful because rather than refreshing the latest data feed on every single page load it will only check itself on one single page load, rebuild itself with the freshest data, and save to the database for blazing fast access through the wp_options table.

In fact, I wrote a simple function that uses Transients to fetch data about the latest posts on my Invision Power forum to show on my WordPress blog which you can take a look at below for an easy illustration:

A simple example of the Transients API:
function ipstowp() {
    // config
    $url   = 'https://myforum.com';
    $key   = 'xxxxxxxxxxxxxxxxxxxx';
    $count = 5
    // end config
    $name      = 'ipstowp';
    $transient = get_transient( $name );
    if ( ! empty( $transient ) )
        return $transient;
    else {
        $save    = array();
        $request = wp_remote_get( "{$url}/api/forums/topics?key={$key}&sortDir=desc&perPage={$count}" );
        if ( is_wp_error( $request ) )
            return;
        $body = wp_remote_retrieve_body( $request );
        $data = json_decode( $body );
        foreach ( $data->results as $id => $fields )
            $save[$id] = array(
                'title' => $fields->title,
                'url'   => $fields->url,
                'name'  => $fields->firstPost->author->formattedName,
                'date'  => $fields->firstPost->date,
                'photo' => $fields->firstPost->author->photoUrl
            );
        set_transient( $name, $save, DAY_IN_SECONDS );
        return $save;
    }
}

 
Top