MyBB Community Forums

Full Version: Plugin Authoring For Beginners [Part 1] / How to create plugins
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
(2015-03-24, 08:46 PM)Crazycat Wrote: [ -> ]
(2015-03-24, 07:23 PM)MikesPad Wrote: [ -> ]Copied the code and steps exactly. and I get this error message.
"My First Plugin (1.0)
This is my first plugin! Smile
Created by Vernier This plugin is incompatible with MyBB 1.8.3"

Anyone know how to update this plugin so it is compatible? Or is there something i am doing wrong here?

"compatibility" => "18*"

Worked like a charm. Thanks. Is it bad to leave out the number and just say *, like the "hello world" plugin that comes with MyBB?

I am trying to build a plugin, that will allow the user to click a button and have it insert a bunch of text into the body of the post, so they don't have to re-type it everytime.

Any thoughts of a plugin I can start with or if this is even possible?

When a user goes to make a new post i want to have two buttons on the left that say "add this text to the post" so the user can fill it in with their info. http://www.HoneyTrek.com/si/2015-03-20_1045.png


after click the text would be placed in the window on the right and user could fill in their name, address, etc
http://www.HoneyTrek.com/si/2015-03-20_1045.png

Thanks,
Mike
very good explanation
really helpful dude....
I am, currently, sending wave after wave of much love in your direction.

This was, exactly, what I needed to start writing plugins =)!

Well explained and easy to follow steps.
<?php
if(!defined("IN_MYBB"))
{
    die("You Cannot Access This File Directly. Please Make Sure IN_MYBB Is Defined.");
} 

$plugins->add_hook('global_start', 'warcalc_global_start');

function warcalc_info()
{
return array(
        "name"  => "warcalc",
        "description"=> "Calculates War Ranges",
        "website"        => "http://cn-doomkingdom.info",
        "author"        => "Ghost",
        "authorsite"    => "http://cn-doomkingdom.info",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "18*"
    );
} 
function warcalc_activate() {
global $db;

$warcalc_group = array(
        'gid'    => 'NULL',
        'name'  => 'warcalc',
        'title'      => 'War Dec Calc',
        'description'    => 'Calculates War Ranges',
        'disporder'    => "1",
        'isdefault'  => "0",
    ); 
$db->insert_query('settinggroups', $warcalc_group);
 $gid = $db->insert_id(); 
$wardec_setting = array(
        'sid'            => 'NULL',
        'name'        => 'warcalc_enable',
        'title'            => 'Do you want to enable this plugin?',
        'description'    => 'Calculates War Ranges',
        'optionscode'    => 'yesno',
        'value'        => '1',
        'disporder'        => 1,
        'gid'            => intval($gid),
    ); 
$db->insert_query('settings', $warcalc_setting);
  rebuild_settings();
} 
function warcalc_deactivate()
  {
  global $db;
 $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('wardec_enable')");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='wardec'");
rebuild_settings();
 }
  
function wardec_global_start(){
global $mybb;

if ($mybb->settings['wardec_enable'] == 1){
echo '<html>', "\n";
echo '<body>', "\n";
echo '<p> Type your score and hit submit </p>', "\n";
echo '<form action="" method="post">', "\n" ;
echo 'Your Nation Strength: <input name="num1" type="text" /><br>', "\n";
echo '<input type="submit" />', "\n";
echo '</form>', "\n";
echo '</body>', "\n";
echo '</html>', "\n";
$num1 = $_POST['num1'];
$high = $num1 * 1.33;
$low = $num1 * .75;
echo "The highest you can declare on is ". $high;
echo "The lowest you can declare on is ". $low;
}
} 
?>

I'm not sure where the error is, but that's the code I was using

Error: [spoiler]Fatal error: Call to undefined function warcalc_global_start() in /home/gh0s7/cn-doomkingdom.info/inc/class_plugins.php on line 139[/spoiler]
You're adding a hook for warcalc_global_start but the function is called wardec_global_start ...
Original Post: July 2012
Now: September 2015

A tutorial "gift" that keeps on "giving" after three years.

Thanks to such detailed, yet simple instructions, I now know how to write my own plugins. Awesomesauce!
Lightbulb  Simple Newsbars past basic concept from this thread now further completed:

What the end product looks like:

[Image: ephwk2.png]

What the plugin settings look like:

[Image: 16jh3mc.png]

NOTE* you can disable any or all of the news bars and you can opt to display on Index or Portal or not....

Example of one of the newsbars being disabled:

[Image: 2efkjdh.png]


Plugin File:

 <?php
/*
 * MyBB: Simple Newsbars
 *
 * File: simplenewsbars.php
 * 
 * Authors: Vintagedaddyo
 *
 * MyBB Version: 1.8
 *
 * Plugin Version: 1.0
 * 
 */

if (!defined("IN_MYBB")) {
    die("You cannot access this file directly. Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('index_start', 'simplenewsbars_index_start');
$plugins->add_hook('portal_start', 'simplenewsbars_portal_start');

function simplenewsbars_info()
{
    return array(
        "name" => "Simple Newsbars",
        "description" => "Adds simple newsbars to the index and portal page of your forum",
        "website" => "http://community.mybb.com/user-6029.html",
        "author" => "Vintagedaddyo",
        "authorsite" => "http://community.mybb.com/user-6029.html",
        "version" => "1.0",
        "guid" => "",
        "compatability" => "18*"
    );
}

function simplenewsbars_activate()
{
    global $settings, $mybb, $db, $lang;
    
    $simplenewsbars_group = array(
        'gid' => '0',
        'name' => 'simplenewsbars',
        'title' => 'Simple Newsbars',
        'description' => 'Settings for the Simple Newsbars plugin',
        'disporder' => "1",
        'isdefault' => "0"
    );
    
    $db->insert_query('settinggroups', $simplenewsbars_group);
    
    $gid = $db->insert_id();
    
    $simplenewsbars_setting_1 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_index',
        'title' => 'Do you want to enable Simple Newsbars Plugin on Index?',
        'description' => 'If you set this option to yes, this plugin be active on your Index.',
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '1',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_2 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_portal',
        'title' => 'Do you want to enable Simple Newsbars Plugin on Portal?',
        'description' => 'If you set this option to yes, this plugin be active on your Portal.',
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '2',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_3 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_input_1',
        'title' => 'Alert Display',
        'description' => 'Enter the text you want to display in Alert.',
        'optionscode' => 'textarea',
        'value' => '<strong>Latest MyBB Release:</strong> <a href="http://blog.mybb.com/2018/03/15/mybb-1-8-15-released-security-maintenance-release/">MyBB 1.8.15 Released — Security & Maintenance Release</a> <span class="date">(March 15, 2018)</span>',
        'disporder' => '3',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_4 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_input_1',
        'title' => 'Do you want to enable Simple Newsbars Alert?',
        'description' => 'If you set this option to yes, Alert will be active on your board.',
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '4',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_5 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_input_2',
        'title' => 'Notice 1 Display',
        'description' => 'Enter the text you want to display in Notice 1.',
        'optionscode' => 'textarea',
        'value' => '<strong>Latest news from the MyBB Blog:</strong> <a href="http://blog.mybb.com/2018/01/07/mybb-support-policy-changes/">MyBB Support Policy Changes</a> <span class="date">(January 7, 2018)</span>',
        'disporder' => '5',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_6 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_input_2',
        'title' => 'Do you want to enable Simple Newsbars Notice 1?',
        'description' => 'If you set this option to yes, Notice 1 will be active on your board.',
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '6',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_7 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_input_3',
        'title' => 'Notice 2 Display',
        'description' => 'Enter the text you want to display in Notice 2.',
        'optionscode' => 'textarea',
        'value' => '<strong>Are you on the </strong><a href="http://community.mybb.com/member.php?action=register">MyBB Community Forums</a><strong>&nbsp;?</strong> - Sign up for notification of new MyBB releases and updates.',
        'disporder' => '7',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_8 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_input_3',
        'title' => 'Do you want to enable Simple Newsbars Notice 2?',
        'description' => 'If you set this option to yes, Notice 2 will be active on your board.',
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '8',
        'gid' => intval($gid)
    );
    
    $db->insert_query('settings', $simplenewsbars_setting_1);
    $db->insert_query('settings', $simplenewsbars_setting_2);
    $db->insert_query('settings', $simplenewsbars_setting_3);
    $db->insert_query('settings', $simplenewsbars_setting_4);
    $db->insert_query('settings', $simplenewsbars_setting_5);
    $db->insert_query('settings', $simplenewsbars_setting_6);
    $db->insert_query('settings', $simplenewsbars_setting_7);
    $db->insert_query('settings', $simplenewsbars_setting_8);
    
    rebuild_settings();
    
    $insertarray = array(
        "title" => "simplenewsbars_1",
        "template" => "<style>
.alert {
    background: #FFF6BF;
    border-top: 1px solid #FFD324;
    border-left: 1px solid #FFD324;
    border-right: 1px solid #FFD324;
    border-bottom: 1px solid #FFD324;
    text-align: center;
    margin: 10px auto;
    padding: 5px 20px;
    border-radius: 6px;
    color: #404040;
}
</style><div id=\"alert\"><p class=\"alert\">{\$mybb->settings[\'simplenewsbars_input_1\']}</p></div>",
        "sid" => -1,
        "dateline" => TIME_NOW
    );
    
    $db->insert_query("templates", $insertarray);
    
    $insertarray = array(
        "title" => "simplenewsbars_2",
        "template" => "<style>
.notice1 {
    background: #D6ECA6;
    border-top: 1px solid #8DC93E;
    border-left: 1px solid #8DC93E;
    border-right: 1px solid #8DC93E;
    border-bottom: 1px solid #8DC93E;
    text-align: center;
    margin: 10px auto;
    padding: 5px 20px;
    border-radius: 6px;
    color: #404040;
}
</style><div id=\"notice1\"><p class=\"notice1\">{\$mybb->settings[\'simplenewsbars_input_2\']}</p></div>",
        "sid" => -1,
        "dateline" => TIME_NOW
    );
    
    $db->insert_query("templates", $insertarray);
    
    $insertarray = array(
        "title" => "simplenewsbars_3",
        "template" => "<style>
.notice2 {
    background: #ADCBE7;
    border-top: 1px solid #0F5C8E;
    border-left: 1px solid #0F5C8E;
    border-right: 1px solid #0F5C8E;
    border-bottom: 1px solid #0F5C8E;
    text-align: center;
    margin: 10px auto;
    padding: 5px 20px;
    border-radius: 6px;
    color: #404040;
}
</style><div id=\"notice2\"><p class=\"notice2\">{\$mybb->settings[\'simplenewsbars_input_3\']}</p></div>",
        "sid" => -1,
        "dateline" => TIME_NOW
    );
    
    $db->insert_query("templates", $insertarray);
    
    include MYBB_ROOT . "/inc/adminfunctions_templates.php";
    
    // activate on index
    
    find_replace_templatesets("index", "#" . preg_quote("{\$header}") . "#i", "{\$header}\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}");
    
    // activate on portal
    
    find_replace_templatesets("portal", "#" . preg_quote("{\$header}") . "#i", "{\$header}\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}");
}

function simplenewsbars_deactivate()
{
    global $db;
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_index')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_portal')");
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_input_1')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_input_2')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_input_3')");
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_input_1')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_input_2')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_input_3')");
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settinggroups WHERE name='simplenewsbars'");
    
    $db->delete_query("templates", "title = 'simplenewsbars_1'");
    $db->delete_query("templates", "title = 'simplenewsbars_2'");
    $db->delete_query("templates", "title = 'simplenewsbars_3'");
    
    rebuild_settings();
    
    include MYBB_ROOT . "/inc/adminfunctions_templates.php";
    
    // deactivate on index
    
    find_replace_templatesets("index", "#" . preg_quote("\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}") . "#i", "", 0);
    
    // deactivate on portal
    
    find_replace_templatesets("portal", "#" . preg_quote("\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}") . "#i", "", 0);
}

function simplenewsbars_portal_start()
{
    global $db, $mybb, $templates, $simplenewsbars_1, $simplenewsbars_2, $simplenewsbars_3;
    
    if ($mybb->settings['simplenewsbars_enable_portal'] == 1) {
        
        if ($mybb->settings['simplenewsbars_enable_input_1'] == 1) {
            eval("\$simplenewsbars_1 = \"" . $templates->get("simplenewsbars_1") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_2'] == 1) {
            eval("\$simplenewsbars_2 = \"" . $templates->get("simplenewsbars_2") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_3'] == 1) {
            eval("\$simplenewsbars_3 = \"" . $templates->get("simplenewsbars_3") . "\";");
        }
    }
}

function simplenewsbars_index_start()
{
    global $db, $mybb, $templates, $simplenewsbars_1, $simplenewsbars_2, $simplenewsbars_3;
    
    if ($mybb->settings['simplenewsbars_enable_index'] == 1) {
        
        if ($mybb->settings['simplenewsbars_enable_input_1'] == 1) {
            
            eval("\$simplenewsbars_1 = \"" . $templates->get("simplenewsbars_1") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_2'] == 1) {
            eval("\$simplenewsbars_2 = \"" . $templates->get("simplenewsbars_2") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_3'] == 1) {
            eval("\$simplenewsbars_3 = \"" . $templates->get("simplenewsbars_3") . "\";");
        }
    }
}
?>   

Next..., let us add localization support:

Create a file called
simplenewsbars.lang.php

Add this:

 <?php
/*
 * MyBB: Simple Newsbars
 *
 * File: simplenewsbars.lang.php
 * 
 * Authors: Vintagedaddyo
 *
 * MyBB Version: 1.8
 *
 * Plugin Version: 1.0
 * 
 */

// plugin_info

$l['simplenewsbars_name'] = 'Simple Newsbars';
$l['simplenewsbars_desc'] = 'Adds simple newsbars to the index and portal page of your forum.';
$l['simplenewsbars_web'] = 'http://community.mybb.com/user-6029.html';
$l['simplenewsbars_auth'] = 'Vintagedaddyo';
$l['simplenewsbars_authsite'] = 'http://community.mybb.com/user-6029.html';
$l['simplenewsbars_ver'] = '1.0';
$l['simplenewsbars_compat'] = '18*';

// Setting Group

$l['simplenewsbars_title_setting_group'] = 'Simple Newsbars';
$l['simplenewsbars_description_setting_group'] = 'Settings for the Simple Newsbars plugin.';

// Setting 1

$l['simplenewsbars_title_setting_1'] = 'Do you want to enable Simple Newsbars Plugin on Index?';
$l['simplenewsbars_description_setting_1'] = 'If you set this option to yes, this plugin be active on your Index.';

// Setting 2

$l['simplenewsbars_title_setting_2'] = 'Do you want to enable Simple Newsbars Plugin on Portal?';
$l['simplenewsbars_description_setting_2'] = 'If you set this option to yes, this plugin be active on your Portal.';

// Setting 3

$l['simplenewsbars_title_setting_3'] = 'Simple Newsbars Alert Display';
$l['simplenewsbars_description_setting_3'] = 'Enter the text you want to display in Alert.';

// Setting 4

$l['simplenewsbars_title_setting_4'] = 'Do you want to enable Simple Newsbars Alert?';
$l['simplenewsbars_description_setting_4'] = 'If you set this option to yes, Alert will be active on your board.';

// Setting 5

$l['simplenewsbars_title_setting_5'] = 'Simple Newsbars Notice 1 Display';
$l['simplenewsbars_description_setting_5'] = 'Enter the text you want to display in Notice 1.';

// Setting 6

$l['simplenewsbars_title_setting_6'] = 'Do you want to enable Simple Newsbars Notice 1?';
$l['simplenewsbars_description_setting_6'] = 'If you set this option to yes, Notice 1 will be active on your board.';

// Setting 7

$l['simplenewsbars_title_setting_7'] = 'Simple Newsbars Notice 2 Display';
$l['simplenewsbars_description_setting_7'] = 'Enter the text you want to display in Notice 2.';

// Setting 8

$l['simplenewsbars_title_setting_8'] = 'Do you want to enable Simple Newsbars Notice 2?';
$l['simplenewsbars_description_setting_8'] = 'If you set this option to yes, Notice 2 will be active on your board.';

?>


Now lets place that language file simplenewsbars.lang.php in: inc/languages/english/admin

Now lets go back to: inc/plugins

And edit the plugin file simplenewsbars.php so that we can now have localization support:

 <?php
/*
 * MyBB: Simple Newsbars
 *
 * File: simplenewsbars.php
 * 
 * Authors: Vintagedaddyo
 *
 * MyBB Version: 1.8
 *
 * Plugin Version: 1.0
 * 
 */

if (!defined("IN_MYBB")) {
    die("You cannot access this file directly. Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('index_start', 'simplenewsbars_index_start');
$plugins->add_hook('portal_start', 'simplenewsbars_portal_start');

function simplenewsbars_info()
{
    global $lang;

    $lang->load("simplenewsbars");
    
    $lang->simplenewsbars_desc = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:right;">' .
        '<input type="hidden" name="cmd" value="_s-xclick">' . 
        '<input type="hidden" name="hosted_button_id" value="AZE6ZNZPBPVUL">' .
        '<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">' .
        '<img alt="" border="0" src="https://www.paypalobjects.com/pl_PL/i/scr/pixel.gif" width="1" height="1">' .
        '</form>' . $lang->simplenewsbars_desc;

    return Array(
        'name' => $lang->simplenewsbars_name,
        'description' => $lang->simplenewsbars_desc,
        'website' => $lang->simplenewsbars_web,
        'author' => $lang->simplenewsbars_auth,
        'authorsite' => $lang->simplenewsbars_authsite,
        'version' => $lang->simplenewsbars_ver,
        'compatibility' => $lang->simplenewsbars_compat
    );
}

function simplenewsbars_activate()
{
    global $settings, $mybb, $db, $lang;

    $lang->load("simplenewsbars");
    
    $simplenewsbars_group = array(
        'gid' => '0',
        'name' => 'simplenewsbars',
        'title' => $lang->simplenewsbars_title_setting_group,
        'description' => $lang->simplenewsbars_description_setting_group,
        'disporder' => "1",
        'isdefault' => "0"
    );
    
    $db->insert_query('settinggroups', $simplenewsbars_group);
    
    $gid = $db->insert_id();
    
    $simplenewsbars_setting_1 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_index',
        'title' => $lang->simplenewsbars_title_setting_1,
        'description' => $lang->simplenewsbars_description_setting_1,
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '1',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_2 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_portal',
        'title' => $lang->simplenewsbars_title_setting_2,
        'description' => $lang->simplenewsbars_description_setting_2,
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '2',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_3 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_input_1',
        'title' => $lang->simplenewsbars_title_setting_3,
        'description' => $lang->simplenewsbars_description_setting_3,
        'optionscode' => 'textarea',
        'value' => '<strong>Latest MyBB Release:</strong> <a href="http://blog.mybb.com/2018/03/15/mybb-1-8-15-released-security-maintenance-release/">MyBB 1.8.15 Released — Security & Maintenance Release</a> <span class="date">(March 15, 2018)</span>',
        'disporder' => '3',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_4 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_input_1',
        'title' => $lang->simplenewsbars_title_setting_4,
        'description' => $lang->simplenewsbars_description_setting_4,
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '4',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_5 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_input_2',
        'title' => $lang->simplenewsbars_title_setting_5,
        'description' => $lang->simplenewsbars_description_setting_5,
        'optionscode' => 'textarea',
        'value' => '<strong>Latest news from the MyBB Blog:</strong> <a href="http://blog.mybb.com/2018/01/07/mybb-support-policy-changes/">MyBB Support Policy Changes</a> <span class="date">(January 7, 2018)</span>',
        'disporder' => '5',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_6 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_input_2',
        'title' => $lang->simplenewsbars_title_setting_6,
        'description' => $lang->simplenewsbars_description_setting_6,
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '6',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_7 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_input_3',
        'title' => $lang->simplenewsbars_title_setting_7,
        'description' => $lang->simplenewsbars_description_setting_7,
        'optionscode' => 'textarea',
        'value' => '<strong>Are you on the </strong><a href="http://community.mybb.com/member.php?action=register">MyBB Community Forums</a><strong>&nbsp;?</strong> - Sign up for notification of new MyBB releases and updates.',
        'disporder' => '7',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_8 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_input_3',
        'title' => $lang->simplenewsbars_title_setting_8,
        'description' => $lang->simplenewsbars_description_setting_8,
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '8',
        'gid' => intval($gid)
    );
    
    $db->insert_query('settings', $simplenewsbars_setting_1);
    $db->insert_query('settings', $simplenewsbars_setting_2);
    $db->insert_query('settings', $simplenewsbars_setting_3);
    $db->insert_query('settings', $simplenewsbars_setting_4);
    $db->insert_query('settings', $simplenewsbars_setting_5);
    $db->insert_query('settings', $simplenewsbars_setting_6);
    $db->insert_query('settings', $simplenewsbars_setting_7);
    $db->insert_query('settings', $simplenewsbars_setting_8);
    
    rebuild_settings();
    
    $insertarray = array(
        "title" => "simplenewsbars_1",
        "template" => "<style>
.alert {
    background: #FFF6BF;
    border-top: 1px solid #FFD324;
    border-left: 1px solid #FFD324;
    border-right: 1px solid #FFD324;
    border-bottom: 1px solid #FFD324;
    text-align: center;
    margin: 10px auto;
    padding: 5px 20px;
    border-radius: 6px;
    color: #404040;
}
</style><div id=\"alert\"><p class=\"alert\">{\$mybb->settings[\'simplenewsbars_input_1\']}</p></div>",
        "sid" => -1,
        "dateline" => TIME_NOW
    );
    
    $db->insert_query("templates", $insertarray);
    
    $insertarray = array(
        "title" => "simplenewsbars_2",
        "template" => "<style>
.notice1 {
    background: #D6ECA6;
    border-top: 1px solid #8DC93E;
    border-left: 1px solid #8DC93E;
    border-right: 1px solid #8DC93E;
    border-bottom: 1px solid #8DC93E;
    text-align: center;
    margin: 10px auto;
    padding: 5px 20px;
    border-radius: 6px;
    color: #404040;
}
</style><div id=\"notice1\"><p class=\"notice1\">{\$mybb->settings[\'simplenewsbars_input_2\']}</p></div>",
        "sid" => -1,
        "dateline" => TIME_NOW
    );
    
    $db->insert_query("templates", $insertarray);
    
    $insertarray = array(
        "title" => "simplenewsbars_3",
        "template" => "<style>
.notice2 {
    background: #ADCBE7;
    border-top: 1px solid #0F5C8E;
    border-left: 1px solid #0F5C8E;
    border-right: 1px solid #0F5C8E;
    border-bottom: 1px solid #0F5C8E;
    text-align: center;
    margin: 10px auto;
    padding: 5px 20px;
    border-radius: 6px;
    color: #404040;
}
</style><div id=\"notice2\"><p class=\"notice2\">{\$mybb->settings[\'simplenewsbars_input_3\']}</p></div>",
        "sid" => -1,
        "dateline" => TIME_NOW
    );
    
    $db->insert_query("templates", $insertarray);
    
    include MYBB_ROOT . "/inc/adminfunctions_templates.php";
    
    // activate on index
    
    find_replace_templatesets("index", "#" . preg_quote("{\$header}") . "#i", "{\$header}\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}");
    
    // activate on portal
    
    find_replace_templatesets("portal", "#" . preg_quote("{\$header}") . "#i", "{\$header}\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}");
}

function simplenewsbars_deactivate()
{
    global $db;
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_index')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_portal')");
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_input_1')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_input_2')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_input_3')");
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_input_1')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_input_2')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_input_3')");
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settinggroups WHERE name='simplenewsbars'");
    
    $db->delete_query("templates", "title = 'simplenewsbars_1'");
    $db->delete_query("templates", "title = 'simplenewsbars_2'");
    $db->delete_query("templates", "title = 'simplenewsbars_3'");
    
    rebuild_settings();
    
    include MYBB_ROOT . "/inc/adminfunctions_templates.php";
    
    // deactivate on index
    
    find_replace_templatesets("index", "#" . preg_quote("\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}") . "#i", "", 0);
    
    // deactivate on portal
    
    find_replace_templatesets("portal", "#" . preg_quote("\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}") . "#i", "", 0);
}

function simplenewsbars_portal_start()
{
    global $db, $mybb, $templates, $simplenewsbars_1, $simplenewsbars_2, $simplenewsbars_3;
    
    if ($mybb->settings['simplenewsbars_enable_portal'] == 1) {
        
        if ($mybb->settings['simplenewsbars_enable_input_1'] == 1) {
            eval("\$simplenewsbars_1 = \"" . $templates->get("simplenewsbars_1") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_2'] == 1) {
            eval("\$simplenewsbars_2 = \"" . $templates->get("simplenewsbars_2") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_3'] == 1) {
            eval("\$simplenewsbars_3 = \"" . $templates->get("simplenewsbars_3") . "\";");
        }
    }
}

function simplenewsbars_index_start()
{
    global $db, $mybb, $templates, $simplenewsbars_1, $simplenewsbars_2, $simplenewsbars_3;
    
    if ($mybb->settings['simplenewsbars_enable_index'] == 1) {
        
        if ($mybb->settings['simplenewsbars_enable_input_1'] == 1) {
            
            eval("\$simplenewsbars_1 = \"" . $templates->get("simplenewsbars_1") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_2'] == 1) {
            eval("\$simplenewsbars_2 = \"" . $templates->get("simplenewsbars_2") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_3'] == 1) {
            eval("\$simplenewsbars_3 = \"" . $templates->get("simplenewsbars_3") . "\";");
        }
    }
}
?>   


Ok so lets simply explain how you would add another language to the plugin:

Now lets go into for example: inc/languages/espanol/admin

Create a file called
simplenewsbars.lang.php

Add this:
 <?php
/*
 * MyBB: Simple Newsbars
 *
 * File: simplenewsbars.lang.php
 * 
 * Authors: Vintagedaddyo
 *
 * MyBB Version: 1.8
 *
 * Plugin Version: 1.0
 * 
 */

// plugin_info

$l['simplenewsbars_name'] = 'Simple Newsbars';
$l['simplenewsbars_desc'] = 'Agrega barras de noticias simples al índice y a la página del portal de su foro.';
$l['simplenewsbars_web'] = 'http://community.mybb.com/user-6029.html';
$l['simplenewsbars_auth'] = 'Vintagedaddyo';
$l['simplenewsbars_authsite'] = 'http://community.mybb.com/user-6029.html';
$l['simplenewsbars_ver'] = '1.0';
$l['simplenewsbars_compat'] = '18*';

// Grupo de configuración

$l['simplenewsbars_title_setting_group'] = 'Simple Newsbars';
$l['simplenewsbars_description_setting_group'] = 'Configuraciones para el plugin Simple Newsbars.';

// Configuración 1

$l['simplenewsbars_title_setting_1'] = '¿Desea habilitar el plugin Simple Newsbars en el índice?';
$l['simplenewsbars_description_setting_1'] = 'Si configura esta opción en sí, este complemento estará activo en su índice.';

// Configuración 2

$l['simplenewsbars_title_setting_2'] = '¿Desea habilitar el complemento Simple Newsbars en el Portal?';
$l['simplenewsbars_description_setting_2'] = 'Si configura esta opción en yes, este complemento estará activo en su Portal.';

// Configuración 3

$l['simplenewsbars_title_setting_3'] = 'Simple Newsbars Alert Display';
$l['simplenewsbars_description_setting_3'] = 'Ingrese el texto que desea mostrar en Alert.';

// Configuración 4

$l['simplenewsbars_title_setting_4'] = '¿Desea activar Simple Newsbars Alert?';
$l['simplenewsbars_description_setting_4'] = 'Si configura esta opción en sí, Alert estará activo en su tablero.';

// Configuración 5

$l['simplenewsbars_title_setting_5'] = 'Simple Newsbars Notice 1 Display';
$l['simplenewsbars_description_setting_5'] = 'Ingrese el texto que desea mostrar en el Aviso 1.';

// Configuración 6

$l['simplenewsbars_title_setting_6'] = '¿Desea habilitar el aviso 1 de Simple Newsbars?';
$l['simplenewsbars_description_setting_6'] = 'Si establece esta opción en sí, el Aviso 1 estará activo en su tablero.';

// Configuración 7

$l['simplenewsbars_title_setting_7'] = 'Simple Newsbars Notice 2 Display';
$l['simplenewsbars_description_setting_7'] = 'Ingrese el texto que desea mostrar en el Aviso 2.';

// Configuración 8

$l['simplenewsbars_title_setting_8'] = '¿Desea activar Simple Newsbars Notice 2?';
$l['simplenewsbars_description_setting_8'] = 'Si establece esta opción en sí, el Aviso 2 estará activo en su tablero.';

?>



Now lets place that language file simplenewsbars.lang.php in: inc/languages/espanol/admin

Bam! you added another language! Smile


If you want a much more completed version of this plugin that has more features, more languages etc, etc, visit: https://community.mybb.com/mods.php?acti...w&pid=1109
Just got into MyBB so thank you.
How do i make my plugin variable to show on index.php only
(2018-08-02, 02:09 AM)kingsolomon Wrote: [ -> ]How do i make my plugin variable to show on index.php only



Just to give you a rough idea via previously shared code, lets comment out  code to remove portal functionality like so:

Now for example lets look at the non localized simplenewsbars.php that I first shared:
<?php
/*
 * MyBB: Simple Newsbars
 *
 * File: simplenewsbars.php
 * 
 * Authors: Vintagedaddyo
 *
 * MyBB Version: 1.8
 *
 * Plugin Version: 1.0
 * 
 */

if (!defined("IN_MYBB")) {
    die("You cannot access this file directly. Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('index_start', 'simplenewsbars_index_start');
//$plugins->add_hook('portal_start', 'simplenewsbars_portal_start');

function simplenewsbars_info()
{
    return array(
        "name" => "Simple Newsbars",
        "description" => "Adds simple newsbars to the index and portal page of your forum",
        "website" => "http://community.mybb.com/user-6029.html",
        "author" => "Vintagedaddyo",
        "authorsite" => "http://community.mybb.com/user-6029.html",
        "version" => "1.0",
        "guid" => "",
        "compatability" => "18*"
    );
}

function simplenewsbars_activate()
{
    global $settings, $mybb, $db, $lang;
    
    $simplenewsbars_group = array(
        'gid' => '0',
        'name' => 'simplenewsbars',
        'title' => 'Simple Newsbars',
        'description' => 'Settings for the Simple Newsbars plugin',
        'disporder' => "1",
        'isdefault' => "0"
    );
    
    $db->insert_query('settinggroups', $simplenewsbars_group);
    
    $gid = $db->insert_id();
    
    $simplenewsbars_setting_1 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_index',
        'title' => 'Do you want to enable Simple Newsbars Plugin on Index?',
        'description' => 'If you set this option to yes, this plugin be active on your Index.',
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '1',
        'gid' => intval($gid)
    );
    
//    $simplenewsbars_setting_2 = array(
//        'sid' => '0',
//        'name' => 'simplenewsbars_enable_portal',
//        'title' => 'Do you want to enable Simple Newsbars Plugin on Portal?',
//        'description' => 'If you set this option to yes, this plugin be active on your Portal.',
//        'optionscode' => 'yesno',
//        'value' => '1',
//        'disporder' => '2',
//        'gid' => intval($gid)
//    );
    
    $simplenewsbars_setting_3 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_input_1',
        'title' => 'Alert Display',
        'description' => 'Enter the text you want to display in Alert.',
        'optionscode' => 'textarea',
        'value' => '<strong>Latest MyBB Release:</strong> <a href="http://blog.mybb.com/2018/03/15/mybb-1-8-15-released-security-maintenance-release/">MyBB 1.8.15 Released — Security & Maintenance Release</a> <span class="date">(March 15, 2018)</span>',
        'disporder' => '3',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_4 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_input_1',
        'title' => 'Do you want to enable Simple Newsbars Alert?',
        'description' => 'If you set this option to yes, Alert will be active on your board.',
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '4',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_5 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_input_2',
        'title' => 'Notice 1 Display',
        'description' => 'Enter the text you want to display in Notice 1.',
        'optionscode' => 'textarea',
        'value' => '<strong>Latest news from the MyBB Blog:</strong> <a href="http://blog.mybb.com/2018/01/07/mybb-support-policy-changes/">MyBB Support Policy Changes</a> <span class="date">(January 7, 2018)</span>',
        'disporder' => '5',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_6 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_input_2',
        'title' => 'Do you want to enable Simple Newsbars Notice 1?',
        'description' => 'If you set this option to yes, Notice 1 will be active on your board.',
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '6',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_7 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_input_3',
        'title' => 'Notice 2 Display',
        'description' => 'Enter the text you want to display in Notice 2.',
        'optionscode' => 'textarea',
        'value' => '<strong>Are you on the </strong><a href="http://community.mybb.com/member.php?action=register">MyBB Community Forums</a><strong>&nbsp;?</strong> - Sign up for notification of new MyBB releases and updates.',
        'disporder' => '7',
        'gid' => intval($gid)
    );
    
    $simplenewsbars_setting_8 = array(
        'sid' => '0',
        'name' => 'simplenewsbars_enable_input_3',
        'title' => 'Do you want to enable Simple Newsbars Notice 2?',
        'description' => 'If you set this option to yes, Notice 2 will be active on your board.',
        'optionscode' => 'yesno',
        'value' => '1',
        'disporder' => '8',
        'gid' => intval($gid)
    );
    
    $db->insert_query('settings', $simplenewsbars_setting_1);
//    $db->insert_query('settings', $simplenewsbars_setting_2);
    $db->insert_query('settings', $simplenewsbars_setting_3);
    $db->insert_query('settings', $simplenewsbars_setting_4);
    $db->insert_query('settings', $simplenewsbars_setting_5);
    $db->insert_query('settings', $simplenewsbars_setting_6);
    $db->insert_query('settings', $simplenewsbars_setting_7);
    $db->insert_query('settings', $simplenewsbars_setting_8);
    
    rebuild_settings();
    
    $insertarray = array(
        "title" => "simplenewsbars_1",
        "template" => "<style>
.alert {
    background: #FFF6BF;
    border-top: 1px solid #FFD324;
    border-left: 1px solid #FFD324;
    border-right: 1px solid #FFD324;
    border-bottom: 1px solid #FFD324;
    text-align: center;
    margin: 10px auto;
    padding: 5px 20px;
    border-radius: 6px;
    color: #404040;
}
</style><div id=\"alert\"><p class=\"alert\">{\$mybb->settings[\'simplenewsbars_input_1\']}</p></div>",
        "sid" => -1,
        "dateline" => TIME_NOW
    );
    
    $db->insert_query("templates", $insertarray);
    
    $insertarray = array(
        "title" => "simplenewsbars_2",
        "template" => "<style>
.notice1 {
    background: #D6ECA6;
    border-top: 1px solid #8DC93E;
    border-left: 1px solid #8DC93E;
    border-right: 1px solid #8DC93E;
    border-bottom: 1px solid #8DC93E;
    text-align: center;
    margin: 10px auto;
    padding: 5px 20px;
    border-radius: 6px;
    color: #404040;
}
</style><div id=\"notice1\"><p class=\"notice1\">{\$mybb->settings[\'simplenewsbars_input_2\']}</p></div>",
        "sid" => -1,
        "dateline" => TIME_NOW
    );
    
    $db->insert_query("templates", $insertarray);
    
    $insertarray = array(
        "title" => "simplenewsbars_3",
        "template" => "<style>
.notice2 {
    background: #ADCBE7;
    border-top: 1px solid #0F5C8E;
    border-left: 1px solid #0F5C8E;
    border-right: 1px solid #0F5C8E;
    border-bottom: 1px solid #0F5C8E;
    text-align: center;
    margin: 10px auto;
    padding: 5px 20px;
    border-radius: 6px;
    color: #404040;
}
</style><div id=\"notice2\"><p class=\"notice2\">{\$mybb->settings[\'simplenewsbars_input_3\']}</p></div>",
        "sid" => -1,
        "dateline" => TIME_NOW
    );
    
    $db->insert_query("templates", $insertarray);
    
    include MYBB_ROOT . "/inc/adminfunctions_templates.php";
    
    // activate on index
    
    find_replace_templatesets("index", "#" . preg_quote("{\$header}") . "#i", "{\$header}\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}");
    
    // activate on portal
    
//    find_replace_templatesets("portal", "#" . preg_quote("{\$header}") . "#i", "{\$header}\r\n
//        {\$simplenewsbars_1}
//        {\$simplenewsbars_2}
//        {\$simplenewsbars_3}");
}

function simplenewsbars_deactivate()
{
    global $db;
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_index')");
//    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_portal')");
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_input_1')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_input_2')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_enable_input_3')");
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_input_1')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_input_2')");
    $db->query("DELETE FROM " . TABLE_PREFIX . "settings WHERE name IN ('simplenewsbars_input_3')");
    
    $db->query("DELETE FROM " . TABLE_PREFIX . "settinggroups WHERE name='simplenewsbars'");
    
    $db->delete_query("templates", "title = 'simplenewsbars_1'");
    $db->delete_query("templates", "title = 'simplenewsbars_2'");
    $db->delete_query("templates", "title = 'simplenewsbars_3'");
    
    rebuild_settings();
    
    include MYBB_ROOT . "/inc/adminfunctions_templates.php";
    
    // deactivate on index
    
    find_replace_templatesets("index", "#" . preg_quote("\r\n
        {\$simplenewsbars_1}
        {\$simplenewsbars_2}
        {\$simplenewsbars_3}") . "#i", "", 0);
    
    // deactivate on portal
    
//    find_replace_templatesets("portal", "#" . preg_quote("\r\n
//        {\$simplenewsbars_1}
//        {\$simplenewsbars_2}
//        {\$simplenewsbars_3}") . "#i", "", 0);
}

//function simplenewsbars_portal_start()
//{
//    global $db, $mybb, $templates, $simplenewsbars_1, $simplenewsbars_2, $simplenewsbars_3;
//    
//    if ($mybb->settings['simplenewsbars_enable_portal'] == 1) {
//        
//        if ($mybb->settings['simplenewsbars_enable_input_1'] == 1) {
//            eval("\$simplenewsbars_1 = \"" . $templates->get("simplenewsbars_1") . "\";");
//        }
//        
//        if ($mybb->settings['simplenewsbars_enable_input_2'] == 1) {
//            eval("\$simplenewsbars_2 = \"" . $templates->get("simplenewsbars_2") . "\";");
//        }
//        
//        if ($mybb->settings['simplenewsbars_enable_input_3'] == 1) {
//            eval("\$simplenewsbars_3 = \"" . $templates->get("simplenewsbars_3") . "\";");
//        }
//    }
//}

function simplenewsbars_index_start()
{
    global $db, $mybb, $templates, $simplenewsbars_1, $simplenewsbars_2, $simplenewsbars_3;
    
    if ($mybb->settings['simplenewsbars_enable_index'] == 1) {
        
        if ($mybb->settings['simplenewsbars_enable_input_1'] == 1) {
            
            eval("\$simplenewsbars_1 = \"" . $templates->get("simplenewsbars_1") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_2'] == 1) {
            eval("\$simplenewsbars_2 = \"" . $templates->get("simplenewsbars_2") . "\";");
        }
        
        if ($mybb->settings['simplenewsbars_enable_input_3'] == 1) {
            eval("\$simplenewsbars_3 = \"" . $templates->get("simplenewsbars_3") . "\";");
        }
    }
}
?> 

*same can be done on the localized version of the file if that gives you a better working example to get the general idea
Pages: 1 2 3 4 5 6