Thursday, 14 April 2022

WP PLUGIN DEVELOPMENT

  1.  Looking method to get data from wp-mysql
  2. create form to adjust wp-mysql from admin side
  3. connect with woocommerce
1. GET DATA FROM MYSQL

add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget('custom_help_widget', 'Custom Plugin', 'custom_dashboard_help');
}

function custom_dashboard_help() {
global $wpdb;

//insert first row as ID so that we can update database later with form
$wpdb->get_row( $wpdb->prepare( "INSERT INTO wp_pluck SET ID=1" ) ); 

//using iframe to connect with backdoor plugin form
echo '<iframe src="http://localhost/optimize/wp-content/plugins/godek/godek-update.php" title="Embed Inside Admin"></iframe>';

// *optional, for display echo or debug
$pluck = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM wp_pluck WHERE ID = 1" ) );
echo $pluck->number; 
}

2. UPDATE WPDB ROW 

$wpdb->get_row( $wpdb->prepare( "UPDATE wp_pluck SET number='3' WHERE id=1" ) );

3. IN PLUGIN FOLDER CREATE PHP FILE

FORM FILE

<?php
//create godek-update.php to update

$produk_id=1;

$servername = "localhost";
$username = "root";
$password = "";
$db = "optimize";

$conn = new mysqli($servername, $username, $password, $db);

if($conn->connect_error){
die("Connection failed ".$conn->connect_error);
}

$sql = "select * from wp_pluck where id='$produk_id'";

$result = $conn->query($sql);

if ($result->num_rows > 0){

$row = $result->fetch_assoc();

$number = $row["number"];
echo

"<html>
<body>

<form action='godek-process.php' method='post'>
Student ID: $produk_id<br>
<input type='hidden' name='produk_id' value='$produk_id'>
Name: <input type='text' name='number' value='$number'><br>
<input type ='submit'>
</form>

</body>
</html>";

} else {
echo "Not Found";
}
$conn->close();

?>



EXECUTE FILE

<?php
//create godek-process.php execute

$produk_id = $_POST["produk_id"];
$number = $_POST["number"];

$servername = "localhost";
$username = "root";
$password = "";
$db = "optimize";

$conn = new mysqli($servername, $username, $password, $db);

if ($conn->connect_error){
die("Connection failed: ". $conn->connect_error);
}

$sql = "update wp_pluck set number='$number' where ID='$produk_id'";

if ($conn->query($sql) === TRUE) {
echo "Records updated: ID ".$produk_id.":".$number;
} else {
echo "Error: ".$sql."<br>".$conn->error;
}

$conn->close();

?>








Tuesday, 12 April 2022

CUSTOM ADMIN DASHBOARD WIDGET SCREEN OPTIONS

 add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');

  
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
 
wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'custom_dashboard_help');
}
 
function custom_dashboard_help() {
echo '<p>Welcome to Custom Blog Theme! Need help? Contact the developer <a href="mailto:yourusername@gmail.com">here</a>. For WordPress Tutorials visit: <a href="https://www.wpbeginner.com" target="_blank">WPBeginner</a></p>';
}

WP FUNCTIONS.PHP TO THE WORDPRESS PLUGIN

 1. You need file manager. Download it on plugin

2. Create new folder name it anything 'my-functions'

3. Create new php file name it 'my-functions.php'

4. paste and edit code below suit with your want


<?php

/*

Plugin Name: my functions

Plugin URI:  https://orkedtouch.com/wp-admin/plugin-editor.php

Description: This is my functions instead on functions.php

Author:      MUHAZA

Author URI:  

Version:     2022.04.13

License:     GPL

*/

// add your functions below



Saturday, 9 April 2022

Fonts with specific Media Query

 <link rel="stylesheet" href="styles.css" media="only screen and (max-device-width: 480px)">

<link rel="stylesheet" href="styles_mobile.css" media="only screen and (min-device-width: 480px)">

Friday, 8 April 2022

HTACCESS SPEED UP OPTIMIZE SETUP

php_value upload_max_filesize 64M
php_value post_max_size 128M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300


# BEGIN DEFLATE COMPRESSION
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
 AddOutputFilterByType DEFLATE application/javascript
 AddOutputFilterByType DEFLATE application/rss+xml
 AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
 AddOutputFilterByType DEFLATE application/x-font
 AddOutputFilterByType DEFLATE application/x-font-opentype
 AddOutputFilterByType DEFLATE application/x-font-otf
 AddOutputFilterByType DEFLATE application/x-font-truetype
 AddOutputFilterByType DEFLATE application/x-font-ttf
 AddOutputFilterByType DEFLATE application/x-javascript
 AddOutputFilterByType DEFLATE application/xhtml+xml
 AddOutputFilterByType DEFLATE application/xml
 AddOutputFilterByType DEFLATE font/opentype
 AddOutputFilterByType DEFLATE font/otf
 AddOutputFilterByType DEFLATE font/ttf
 AddOutputFilterByType DEFLATE image/svg+xml
 AddOutputFilterByType DEFLATE image/x-icon
 AddOutputFilterByType DEFLATE text/css
 AddOutputFilterByType DEFLATE text/html
 AddOutputFilterByType DEFLATE text/javascript
 AddOutputFilterByType DEFLATE text/plain
 AddOutputFilterByType DEFLATE text/xml
</IfModule>
# END DEFLATE COMPRESSION

# BEGIN GZIP COMPRESSION
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
# END GZIP COMPRESSION


# BEGIN GZIP COMPRESSION
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
# END GZIP COMPRESSION

# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
 <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
 Header set Cache-Control "public"
 </filesMatch>
 <filesMatch "\.(css)$">
 Header set Cache-Control "public"
 </filesMatch>
 <filesMatch "\.(js)$">
 Header set Cache-Control "private"
 </filesMatch>
 <filesMatch "\.(x?html?|php)$">
 Header set Cache-Control "private, must-revalidate"
 </filesMatch>
</ifModule>
# END Cache-Control Headers

WOOCOMMERCE FLYCART

When using woofc or woocommerce flycart font icon will interrupt speed of website.

add_action( 'wp_enqueue_scripts', 'woofc_remove_font_icon', 99 );
function woofc_remove_font_icon() {
wp_dequeue_style( 'woofc-fonts' );
}

email mailto: pretext

 <a href="mailto:designoutsourced.com+info@gmail.com?subject=Maklumat%20lanjut%20pakej&body=Hai,%20saya%20berminat%20tahu%20lebi...