First wordpress plugin making - plugins

I am making my very first wordpress plugin in that I want to make table in my database when I activate the plugin. I write the code exactly what wordpress community said but it's not working. I tried the same several times but the results is the same. I also want to know my plugin showing 2 submenus in my main plugin menu, It's like
My Plugin
-- My Plugin
-- My Submenu Page
Please help I am very new to plugin development.
// Registering plugin
register_activation_hook(__FILE__, 'myplugin_activate');
//Deactivate plugin
register_deactivation_hook(__FILE__, 'myplugin_deactivate');
function myplugin_activate() {
global $wpdb, $table_prefix;
global $favoritethis_db_version;
$table_name = $table_prefix.
'my-plugin-table';
$charset_collate = $wpdb - > get_charset_collate();
if ($wpdb - > get_var("show tables like '$table_name'") != $table_name) {
require_once(ABSPATH.
'wp-admin/upgrade-functions.php');
$sql = "CREATE TABLE ".$table_name.
" (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00'
NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url varchar(55) DEFAULT ''
NOT NULL,
UNIQUE KEY id(id)
) $charset_collate;
";
}
require_once(ABSPATH.
'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
function myplugin_deactivate() {
// Deactivation code here...
echo "<script>alert('Ohhh.. no baby the plugin is deactivated now..')</script>";
}

also I found the solution of the problem, I was facing as getting extra sub menu as same name as the main menu is.
Solution
//Main admin menus
add_action('admin_menu', 'add_my_custom_menu');
function add_my_custom_menu() {
//add an item to the menu
add_menu_page(
'My Plugin',
'My Plugin',
10,
plugin_dir_path(__FILE__).
'admin/plugin-form.php',
'',
plugin_dir_url(__FILE__).
'img/contact.png'
);
add_submenu_page(
'my-plugin-name/admin/plugin-form.php',
'Plugin Setting',
'Plugin Setting',
10,
plugin_dir_path(__FILE__).
'admin/plugin-form.php',
'myplugin_options_page'
);
add_submenu_page(
'my-plugin-name/admin/plugin-form.php',
'Plugin Entries',
'Plugin Entries',
10,
plugin_dir_path(__FILE__).
'admin/entries.php',
''
);
}
reason is that every first sub-menu's destination page/function will be the same as main menu destination.

ok I got the answer myself
// Registering plugin
register_activation_hook(__FILE__, 'myplugin_activate');
//Deactivate plugin
register_deactivation_hook(__FILE__, 'myplugin_deactivate');
function myplugin_activate() {
global $wpdb;
$table_name = $wpdb - > prefix.
'my-plugin-table';
//nstalled_ver = get_option('my-voting-version');
if ($wpdb - > get_var("show tables like '$table_name' ") != $table_name) {
require_once(ABSPATH.
'wp-admin/upgrade-functions.php');
$sql = "CREATE TABLE IF NOT EXISTS `".str_replace('`', '', $table_name).
"` (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00'
NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url varchar(55) DEFAULT ''
NOT NULL,
UNIQUE KEY id(id)
);
";
}
require_once(ABSPATH.
'wp-admin/includes/upgrade.php');
dbDelta($sql);
}

Related

Record data from get request to table in apex oracle

i need help with apex oracle. This task is not typical for me, so I ask for help. I have a rest point (get). As a result, I have the answer:
{
"DT_СREATE": "2020-02-05T10:38:11Z",
"DT_UPDATE": "2020-02-05T10:38:11Z",
"ID": 12015,
"sensors": [
{
"name": "SENSOR1",
"temp": "11.91"
},
{
"name": "SENSOR2",
"temp": "9.23"
}
]
}
I also have a TEMPR_SILO table. In which I want to write this answer!
CREATE TABLE "TEMPR_SILO"
( "ID" NUMBER,
"NAME" VARCHAR2(500),
"TEMP" VARCHAR2(500),
"ID_TRANS" NUMBER,
CONSTRAINT "TEMPR_SILO_PK" PRIMARY KEY ("ID")
USING INDEX ENABLE
)
/
but all this should be the result of a dynamic action after pushing a button on the weed. That is, when the button is pressed, I have to record the data from the GET.
I wrote a POST for this. here he is.
BEGIN
v_clob := iot_general.blob_to_clob(p_blob);
apex_json.parse(tv, v_clob);
v_id := apex_json.get_varchar2(p_path => 'id', p_values => tv);
sCount := APEX_JSON.get_count(p_path => 'sensors' , p_values => tv);
IF sCount > 0 THEN
FOR i in 1 .. sCount LOOP
q_temp := apex_json.get_varchar2(p_path => 'sensors['|| i ||'].temp', p_values => tv);
q_name := apex_json.get_varchar2(p_path => 'sensors['|| i ||'].name', p_values => tv);
INSERT INTO TEMPR_SILO ( NAME, TEMP,ID_TRANS)
VALUES ( q_name , q_temp ,v_id);
commit;
END LOOP;
END IF;
But I don't know how to use it in my task! I would appreciate an example or help in this question!
If you have validated that your last snippet is working, it's just a matter of creating the Dynamic Action on the button, with a PL/SQL code true action and putting it there. If you want to follow best practices, you would have that code in a procedure on the DB, and that's what you would call in the DA.

How to add new email template and call/ use that template in prestashop 1.6

I created a module in which I am displaying all the dormant users by combining two tables - customer and order table and now I Want to perform bulk action (mail send action ) to the dormant users , But I want to make a email template in which this template can be edited and used for sending email to the dormant users from the BO.
How to send email using a template in prestashop ? .
I created a email template (created.html and .text file ) in email folder, Also edited classes/Langugae.php
// Added natives mails files
$mFiles = array(
'account.html', 'account.txt',
'backoffice_order.html', 'backoffice_order.txt',
'bankwire.html', 'bankwire.txt',
'cheque.html', 'cheque.txt',
'contact.html', 'contact.txt',
'contact_form.html', 'contact_form.txt',
'credit_slip.html', 'credit_slip.txt',
'download_product.html', 'download_product.txt',
'employee_password.html', 'employee_password.txt',
'forward_msg.html', 'forward_msg.txt',
'guest_to_customer.html', 'guest_to_customer.txt',
'in_transit.html', 'in_transit.txt',
'log_alert.html', 'log_alert.txt',
'newsletter.html', 'newsletter.txt',
'order_canceled.html', 'order_canceled.txt',
'order_conf.html', 'order_conf.txt',
'order_customer_comment.html', 'order_customer_comment.txt',
'order_merchant_comment.html', 'order_merchant_comment.txt',
'order_return_state.html', 'order_return_state.txt',
'outofstock.html', 'outofstock.txt',
'password.html', 'password.txt',
'password_query.html', 'password_query.txt',
'payment.html', 'payment.txt',
'payment_error.html', 'payment_error.txt',
'preparation.html', 'preparation.txt',
'refund.html', 'refund.txt',
'reply_msg.html', 'reply_msg.txt',
'shipped.html', 'shipped.txt',
'test.html', 'test.txt',
'voucher.html', 'voucher.txt',
'voucher_new.html', 'voucher_new.txt',
'order_changed.html', 'order_changed.txt',
'dormant_email.html', 'dormant_email.txt'
);
I added my email template - 'dormant_email.html', 'dormant_email.txt' in mails\en folder
ok I solved this by adding the template file by creating mail.en folder in module folder ( modulename/emails/en/)
and by below code
if (!Mail::Send(
$this->context->language->id,
'dormant_email',
Mail::l('Hello Long Time No See ! Please Visit and Get a Chance to Win'),
$templateVars,
$dormantUserEmailID,
null, null, null, null, null, dirname(__FILE__).'/mails/', true, $this->context->shop->id))
die('0') ;echo "<script type=\"text/javascript\">alert('Email Send');</script>"; return true;
die('1');echo "<script type=\"text/javascript\">alert('Email not Send');</script>"; return false;
I am able to send email and use the template and it is been listing when I click on the
Localization->transalations -->modify transalations
select email template translations and select English and click modify button and in the modules when u expand your module the email template can be seen and can be edited by edit tool .

MYSQLi PHP connect

Is the following a valid mysqli php connect insert statement?
if($mysql_query = $conn->query("INSERT INTO users (username,password,question,securityanswer) VALUES ('$uname','$upass','$selectquestion','$answer')"))
{
?>
<script>alert('successfully registered ');</script>
<?php
}
else
{
?>
<script>alert('error while registering you...');</script>
<?php
}
}
However I am getting error as "error while registering you..."
Thanks
Issue is resolved. There was an issue with the "user_id" column primary key which was being updated duplicate(0 value) with this error "Duplicate entry '0' for key 'PRIMARY'. Upon updating user_id column with auto increment in phpmyadmin, the INSERT query got updated successfully.
Using the below code to check for errors helped.
die(mysqli_error($conn));
A simple example:
<?php
//Create the connection
$con = mysqli_connect("HostName","UserName","password","DBName") or die("Some error occurred during connection " . mysqli_error($con));
// Write query
$strSQL = "SELECT username FROM MyTable";
// Execute the query.
$query = mysqli_query($con, $strSQL);
while($result = mysqli_fetch_array($query))
{
echo $result["username"]."
";
}
// Close the connection
mysqli_close($con);
?>
Can you paste the whole block with connection statement?
Otherwise SQL statement looks fine. Excepct you should escape inputs to MySQL
if($mysql_query = $conn->query("INSERT INTO users (username,password,question,securityanswer) VALUES ('$uname','$upass','$selectquestion','$answer')"))
Why using if($mysql_query = $conn->query ?
better
if($conn->query("INSERT INTO users (username,password,question,securityanswer) VALUES ('$uname','$upass','$selectquestion','$answer')") === TRUE)

There are no housenumbers om OSM map

I successfully installed tile server based on the instruction given in the switch2osm.org/serving-tiles/manually-building-a-tile-server-14-04/. So I have well-working web-server + tile-server. But there are no housenumbers on map. I add my next code in my imposm-mapping.py
buildings = Polygons (
name = 'buildings',
fields = (
('area', PseudoArea()),
('addr:housenumber', String()),
),
mapping = {
'building': (
'__any__',
),
'railway': (
'station',
)
'aeroway': (
'terminal',
),
}
)
In my labels.mss I have:
#housenumber [zoom>=17]{
::label {
text-name: '[addr:housenumber]';
text-face-name:#sans;
text-size: 9;
text-placement: interior;
text-min-dostance: 1;
text-wrap-width: 0;
text-fill: #444;
}
}
In default.style I have node,way addr:housenumber text linear.
I saw question Map won't show building numbers (tileMill + OSM). But I don't understand this tips.
Well, problem solved. I just reload data to database with carto.style, rebuild tile server with swich2osm instructions but with stylesheet from openstreetmap-carto. Not OSMBright

Search field - laravel

My search in laravel doesn't work. I'm trying everything, but I've got error: Class 'Bike' not found.
Index.blade:
{{Form::open(array('url'=>'/'))}}
{{Form::text('keyword', null, array('placeholder'=>'Miasto'))}}
{{Form::submit('search')}}
{{Form::close()}}
route:
Route::post('/',function(){
$keyword = Input::get('keyword');
$bikes = Bike::where('city', 'LIKE', '%'.$keyword.'%')->get();
var_dump('search results');
foreach($bikes as $bike){
var_dump($bike->city);
}
You are not returning anything.
return var_dump($bike->city);