(2019-08-19, 11:00 AM)Wildcard Wrote: [ -> ]I'm glad it is useful to you.
But, you need to install the setting in _install
instead of _activate
then you don't lose your settings when you uninstall.
Good point, and yes I could do that, though for this simple purpose I install setting on activate, uninstall setting on deactivate in plugin page while turning on or off setting of the active plugin via configuration settings. Yes as you say using _install and _uninstall is better just didn't opt at the time to do so as this way using _activate = to _install and _deactivate = to _uninstall also works for my purpose. Obviously it also works for a ton of other plugins and plugin devs over the years because plenty opt to use activate/deactivate just like install / uninstall, lol, just saying. Perhaps if I spend more than the 5 minutes edit on it at some point I will transition to renaming said functions, but to be perfectly honest , I do mot see the point as the simple edited variant works as intended and while yes, one could spend more time if they desired to do say for simple example sake:
<?php
/**
* Plugin Title: Simple Mode Must Die!
*
* Plugin Description: Disables or re-enables simple mode.
*
* MyBB Version: 1.8
*
* Plugin Version: 1.1
*
*/
// No direct initialization
if( !defined('IN_MYBB') )
{
die('Direct initialization of this file is not allowed.');
}
/**
* Plugin information
*
* @return void
*/
function smmd_info()
{
return array(
'name' => 'Simple Mode Must Die!',
'compatability' => '18*',
'version' => '1.1',
'author' => 'Wildcard & Vintagedaddyo',
);
}
if (defined('IN_ADMINCP')) {
$plugins->add_hook('admin_style_themes_begin', 'smmd_admin_themes_begin');
}
/**
* Plugin installation
*/
function smmd_install()
{
global $db, $mybb;
$smmd_settinggroup = array(
'name' => 'smmd_settinggroup',
'title' => 'Simple Mode Must Die! Plugin Settings',
'description' => 'This plugin disables or re-enables simple mode theme editor',
'disporder' => '1',
'isdefault' => '0'
);
$group['gid'] = $db->insert_query('settinggroups', $smmd_settinggroup);
$gid = $db->insert_id();
$enable_smmd = array(
'name' => 'enable_smmd',
'title' => 'Enable smmd?',
'description' => 'Do you want the smmd turned on?',
'optionscode' => 'yesno',
'value' => '1',
'disporder' => '2',
'gid' => intval($gid)
);
$db->insert_query('settings', $enable_smmd);
rebuild_settings();
}
function smmd_is_installed() {
global $mybb;
if(isset($mybb->settings['enable_smmd']))
{
return true;
}
return false;
}
/**
* Plugin activation
* Activate via plugin listing page
*/
function smmd_activate()
{
global $db, $mybb;
if ($mybb->input['action'] == "edit_stylesheet" && (!isset($mybb->input['mode']) || $mybb->input['mode'] == "simple"))
{
$mybb->input['mode'] = 'advanced';
}
}
/**
* Plugin de-activation
* Deactivate via plugin listing page
*/
function smmd_deactivate()
{
global $db, $mybb;
if ($mybb->input['action'] == "edit_stylesheet" && (!isset($mybb->input['mode']) || $mybb->input['mode'] == "advanced"))
{
$mybb->input['mode'] = 'simple';
}
}
/**
* Plugin uninstall
*/
function smmd_uninstall()
{
global $db;
$db->delete_query('settings', "name IN ('enable_smmd')");
$db->delete_query('settinggroups', "name = 'smmd_settinggroup'");
rebuild_settings();
}
/**
* Disable / re-enable simple mode style sheet editing
* Disable / re-enable via configuration listing
* @return void
*/
function smmd_admin_themes_begin()
{
global $db, $mybb;
if ($mybb->settings['enable_smmd'] == 1)
{
if ($mybb->input['action'] == "edit_stylesheet" && (!isset($mybb->input['mode']) || $mybb->input['mode'] == "simple"))
{
$mybb->input['mode'] = 'advanced';
}
}
if ($mybb->settings['enable_smmd'] == 0)
{
if ($mybb->input['action'] == "edit_stylesheet" && (!isset($mybb->input['mode']) || $mybb->input['mode'] == "advanced"))
{
$mybb->input['mode'] = 'simple';
}
}
}
?>
Whereas the first example I shared does simply what it was intended for with less editing, less time, etc etc,
<?php
/**
* Plugin Title: Simple Mode Must Die!
*
* Plugin Description: Disables or re-enables simple mode.
*
* MyBB Version: 1.8
*
* Plugin Version: 1.0
*
*/
// No direct initialization
if( !defined('IN_MYBB') )
{
die('Direct initialization of this file is not allowed.');
}
/**
* Plugin information
*
* @return void
*/
function smmd_info()
{
return array(
'name' => 'Simple Mode Must Die!',
'compatability' => '18*',
'version' => '1.0',
'author' => 'Wildcard & Vintagedaddyo',
);
}
if (defined('IN_ADMINCP')) {
$plugins->add_hook('admin_style_themes_begin', 'smmd_admin_themes_begin');
}
/**
* Plugin activation
*/
function smmd_activate()
{
global $db, $mybb;
$smmd_settinggroup = array(
'name' => 'smmd_settinggroup',
'title' => 'Simple Mode Must Die! Plugin Settings',
'description' => 'This plugin disables or re-enables simple mode theme editor',
'disporder' => '1',
'isdefault' => '0'
);
$group['gid'] = $db->insert_query('settinggroups', $smmd_settinggroup);
$gid = $db->insert_id();
$enable_smmd = array(
'name' => 'enable_smmd',
'title' => 'Enable smmd?',
'description' => 'Do you want the smmd turned on?',
'optionscode' => 'yesno',
'value' => '1',
'disporder' => '2',
'gid' => intval($gid)
);
$db->insert_query('settings', $enable_smmd);
rebuild_settings();
}
/**
* Plugin de-activation
*/
function smmd_deactivate()
{
global $db;
$db->delete_query('settings', "name IN ('enable_smmd')");
$db->delete_query('settinggroups', "name = 'smmd_settinggroup'");
rebuild_settings();
}
/**
* Disable / re-enable simple mode style sheet editing
*
* @return void
*/
function smmd_admin_themes_begin()
{
global $db, $mybb;
if ($mybb->settings['enable_smmd'] == 1)
{
if ($mybb->input['action'] == "edit_stylesheet" && (!isset($mybb->input['mode']) || $mybb->input['mode'] == "simple"))
{
$mybb->input['mode'] = 'advanced';
}
}
if ($mybb->settings['enable_smmd'] == 0)
{
if ($mybb->input['action'] == "edit_stylesheet" && (!isset($mybb->input['mode']) || $mybb->input['mode'] == "advanced"))
{
$mybb->input['mode'] = 'simple';
}
}
}
?>
For me it makes absolutely no sense to further edit the first example I shared when in the 5 minutes of creating it, it was able to do what I needed it and intended it to do without any such extra time spent editing it regardless if suggestions are made to edit it simply because some logical minds think in terms of uninstall and install being the only way to do such when in reality other logical minds clearly understand that either install / uninstall or activate / deactivate can be used for exactly the same purposes if so desired. Just a thought. Thanks again. :)