How to register my code as a plugin

Well as it stands your code will not be executed regardless of whether you add it to your functions.php file or you register it as a stand-alone plugin as it makes no call to any of its functions using a WordPress hook.

In order for your code to be recognised as a plugin, there are some preliminaries that you need to follow, namely create a sub-folder in your /wp-content/plugins/ folder installation, save your code in a file and add a header to it.

  1. Create a sub-folder, let’s call it my-first-plugin,
  2. save your code in a file called my-first-plugin.php in that sub-folder, and add the following header to it,

    /*
    Plugin Name: My First Plugin
    Plugin URI: https://developer.wordpress.org/plugins/the-basics/
    Description: Basic WordPress Plugin Header Comment
    Version: 1.0
    Author: You Name Here
    Author URI: https://developer.wordpress.org/
    License: GPL2
    License URI: https://www.gnu.org/licenses/gpl-2.0.html
    Text Domain: my-first-plugin
    */

  3. At the bottom of your file you can then insert the following code to register your plugin,

    register_activation_hook( __FILE__, 'activate_my_first_plugin' );
    function activate_my_first_plugin(){
    new My_Class();
    }

this will activate your plugin and create a My_Class object when your plugin is activated in the dashboard.

So in Summary, this is what your file will look like,

<?php
/*
Plugin Name:  My First Plugin
Plugin URI:   https://developer.wordpress.org/plugins/the-basics/
Description:  Basic WordPress Plugin Header Comment
Version:      1.0
Author:       You Name Here
Author URI:   https://developer.wordpress.org/
License:      GPL2
License URI:  https://www.gnu.org/licenses/gpl-2.0.html
Text Domain:  my-first-plugin
*/

Class My_Class{

/* Constructor for setting values to the propeties. Make sure to select the right breakpoint with the right image*/
public function __construct($imgPath, $landscapeSelectors, $portraitSelectors, $figureClass, $landscapeBreakpoints, $portraitBreakpoints) {
    $this->setImgPath($imgPath);
    $this->setLandscapeSelectors($landscapeSelectors);
    $this->setPortraitSelectors($portraitSelectors);
    $this->setFigureClass($figureClass);
    $this->setLandscapeBreakpoints($landscapeBreakpoints);
    $this->setPortraitBreakpoints($portraitBreakpoints);
}

/* The picture element is build inside here */
public function createHeroImage() {
    /* Set the base of the figure */
    $this->setHeroImage("<figure style="margin-bottom: -7px;" class="".$this->getFigureClass()["figure']."'>
                                <picture class="".$this->getFigureClass()["figure-div']."'>
                        ");

    $this->landscapeImage();

    $this->portraitImage();

    $this->setHeroImage($this->getHeroImage() . "<img id='hero-image' style="object-fit: cover; height: calc((16 / 9) * 100%)" alt="".$this->getImgPath()["landscapeImage']['alt']."' src="".$this->getImgPath()["portraitImage']['sizes'][$this->getLandscapeSelectors()[0]]."'>");

    $this->setHeroImage($this->getHeroImage() . "</picture>
                                            </figure>");

    return $this->getHeroImage();
}
} //ebd My_Class

register_activation_hook( __FILE__, 'activate_my_first_plugin' );
function activate_my_first_plugin(){
  new My_Class();
}

NOTE:

  1. I wrapped your code in My_Class declaration, I am assuming you are creating a php class, since your code exposes a constructor.
  2. Your constructor expects multiple parameters which are not available at the time of plugin activation, the common practice is to register your method calls with various WordPress Hooks inside the constructor. Hence you need to now understand at what point in the WordPress execution cycle you want your code to run. As you have not explained this clearly, I cannot help you any further. You’ll need to do something like,

    public function __construct(){
    add_action(‘init’, array($this, ‘initialise’));
    add_action(some-other-hook, array($this, call-my-method));
    }

    public function initialise(){
    //method called when a front-page request initialises.
    }

  3. Note that you need to wrap your method calls in an array along with your class instance, array($this, method-call), in order for the hook to call the method in your current instance.