How to change plugin start dot php to elgg-plugin dot php

I am a retired website design teacher of HTML and CSS who is looking for to help with a open source social networking project. After looking over about 20 options, I think Elgg is currently the best option. To better understand Elgg, I have installed Elgg 3.3.7 as an online test social network which you can view at this site:

https://ourcommunitynetwork.org/

Keep in mind this is merely be a test site and not a real site. In addition to testing Elgg, I am testing several plugins. One problem I am having is that my Error Log in Cpanel gets rapidly filled up with errors from the fact that several of the plugins work – but they are using deprecated code. Here is the warning:

ELGG.WARNING: Deprecated in 3.3: Using a start.php file in your plugin [plugin_installer] is deprecated. Use a elgg-plugin.php for your plugin.

Here are the 8 plugins I am using that all give this warning:

plugin_installer

minimal_hide_search

menu_builder

imgur

blogcoverphoto

elgg_connect

hello (my own Hello World plugin created from the Elgg Manual tutorial)

tidypics (special forked version)

Some of these plugins do not have an active maintainer. I have the time and would like to at least update them so they can be used on a 3.3.7 Elgg site without filling up the Error Log. I have read the entire latest 400 page Elgg manual at this link:

https://learn.elgg.org/_/downloads/en/stable/pdf/

I have also searched through everything I can find on the Internet - but it is still not clear to me how to update Elgg plugins to replace the start.php file with the newer elgg-plugin.php file.

What I am hoping for is one or two simple step by step examples of transferring start.php code to elgg-plugin.php code.

For example, an old plugin that has several problems but that I think is essential and I am willing to fix and update and share with the community is called plugin-installer. Amazingly, it still works. But it was last updated in 2014 and uses start.php. Here is the start.php file:

<?php

elgg_register_event_handler('init', 'system', 'plugin_installer_init');

$plugin = elgg_get_plugins_path().'plugin_installer/';

require_once("{$plugin}/classes/plugin_installer.php");


 

function plugin_installer_init(){

$plugin = elgg_get_plugins_path().'plugin_installer/';

elgg_register_action('plugin/installer/upload', "{$plugin}actions/upload.php", 'admin');

elgg_register_admin_menu_item('administer', 'plugin_installer', 'administer_utilities');

}

How could the above php file be converted into a functioning elgg-plugin.php file?

Give that Elgg 3.3.7 is issuing all of these errors for old plugins, a clearer tutorial on how we can fix this problem would be timely and greatly appreciated.

  • At least the Minimal Hide Search plugin won't need an elgg-plugin.php at all. The start.php was only necessary because Elgg required the presence of this file in earlier versions even if there was no code to be added to it. I've now made a new release for Elgg 3.3 without start.php: https://elgg.org/plugins/1101722/releases/3.3.0.

    A second example - even if not in your list - you might take a look at is the Elggx Fivestar plugin I just made a new release for Elgg 3.3 for: https://elgg.org/plugins/843333/releases/3.3.0. There was not much remaining in start.php as I had tried to move out everything possible for the Elgg 3.0 release. But you might want to study the "Bootstrap" class I made use of now to replace both start.php and activate.php. Of course, it might be better to do everything possible via elgg-plugin.php only. But making use of the Bootstrap class would be necessary if you had an activate.php you can't fully remove. In case of the Fivestar plugin I also had to use the init() function to register a plugin hook (probably failed via elgg-plugin.php due to the "all" keyword not supported there). But in your case the Bootstrap method could be used as an alternative to get rid of the start.php file, if you move the code from its init function to the init function of the Bootstrap class.

    I've not found the Plugin Installer plugin version you probably are referring to (with last version from 2014). With the above code it would be necessary to know if plugin_installer.php in the classes folder is really a class or if it's actually rather a library. In the latter case you could take look at the Fivestar plugin of mine. I used required_once in elgg-plugin.php to register some files ("libraries") that contain functions but are no classes. With plugin_installer being a class I don't think it would be necessary to register it as such as Elgg would do it automatically. But for Elgg being able to do that you would have to name the file corresponding to the class in it (exactly same usage of upper/lower case letters important, too).

    I do hope that I can work on an update for Tidypics for Elgg 3 - 3.3 soon. I did reduce the code in start.php already with the latest Elgg 2 version to make the transition to Elgg 3 easier (though there were some things just not yet possible in Elgg 2 that would now work in Elgg 3 to make start.php obsolete). In principle, the same approach I made with the Fivestar plugin (Bootstrap class) would also work with Tidypics (and if only as kind of a fallback solution before making fully use of elgg-plugin.php wherever possible).

  • Basically you have to use a Bootstrap class and declare it on elgg-plugin.php.

    As a sample you can check the latest release of this plugin https://elgg.org/plugins/1937889.

    Also have a look on the plugins of Coldtrick team at https://github.com/coldtrick. Their latest releases are developed without the start.php file.

  • Thank you both for your suggestions. I will look at the examples you provided and try to learn more about how to use a Bootstrap class and declare it in the elgg-plugin.php file. While I am pretty good at HTML, CSS and writing documentation, I am still learning PHP. 

  • For others interested in learning more about how to move code from start.php to elgg-plugin.php using the bootstrap class, there are a couple of Elgg tutorials that might help:

    http://learn.elgg.org/en/stable/guides/plugins.html

    see also this guide

    http://learn.elgg.org/en/stable/guides/plugins/bootstrap.html

  • You don't have to add a bootstrap class for every plugin. It depends on what's in start.php. You already found the two links I would have added, too. The explanation at the first link contains a full example of a elgg-plugin.php with all possible options in the array. Maybe this help to get an idea which definitions could be moved from start.php to elgg-plugin.php. It's mainly the exceptions (e.g. if-clauses to only add some elements conditionally) that might better be done within a bootstrap class. Also, code beyond the init function in start.php could be moved into another file ("library") to be loaded in elgg-plugin.phg using require_once(). Or it might be possible to move this code into a class of its own.