• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

IntelyBlog

A blog site that is intelligent

  • Hosting
  • jQuery
  • Programming

rush-intely

How to convert any full URL path to relative to WordPress installation (root)

April 6, 2022

Post Views: 1

If you want to make a URL relative from the WordPress root, you can use the following WordPress function.

<?php

$full_url = "https://intelyblog.com/how-to-programmatically-add-a-wordpress-admin-user-using-functions-php/";

$relative_to_wordpress = wp_make_link_relative($full_url);

echo $relative_to_wordpress;

?>

Result: /how-to-programmatically-add-a-wordpress-admin-user-using-functions-php/

That’s all! Happy coding!

Filed Under: WordPress Tagged With: PHP, URL, WordPress

How to write if else statement in a single line (compact if else statement) using PHP

April 5, 2022

Post Views: 1

Normal way of writing an if else statement

<?php

$result = '';

$count = 55;
$target = 70;

if($count >= $target) {
   $result = 'High';
} else {
   $result = 'Low';
}

?>

Now let’s see how the above can be written in a single line.

<?php

$result = '';

$count = 55;
$target = 70;

$result = ($count > $target) ? 'High' : 'Low';

?>

That’s it! Happy coding!

Filed Under: PHP Tagged With: if-else, PHP

How to programmatically add a WordPress admin user using functions.php

February 28, 2022

Post Views: 3

Step 1:
Open your theme’s functions.php using a editor.

Step 2:
Paste the following code at the bottom of the functions.php (need to remove once the user is added)

add_action('init', 'create_my_custom_admin_user');

function create_my_custom_admin_user() {
    $username = 'username123';
    $password = 'pasword123';
    $email = 'newadmin@example.com';

    if (username_exists($username) == null && email_exists($email) == false) {

        // Create the new user
        $user_id = wp_create_user($username, $password, $email);

        // Get current user object
        $user = get_user_by('id', $user_id);

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

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

Step 3:
Save the functions.php file and run the site once.

Step 4:
Go to the site’s login page (wp-login.php) and login with the username and password that are used on the functions.php. You should be able to login and see the dashboard.

Note: If the username or email already exists in the dashboard, you will not be able to login and in that case you may have to username and/or password.

Step 5:
Please remove the code block and save the functions.php once the user is added.

Filed Under: WordPress Tagged With: PHP, WordPress

How to check if a file exists on a remote server using CURL

September 11, 2021

Post Views: 12
function checkRemoteFileExists($remoteFile) {
    $ch = curl_init($remoteFile);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if ($code == 400) {
        $status = true;
    } else {
        $status = false;
    }
    curl_close($ch);
    return $status;
}

Filed Under: PHP Tagged With: curl, file

How to create WhatsApp share button in HTML

September 11, 2021

Post Views: 15
<a href="whatsapp://send?text=http://intelyblog.com/" data-action="share/whatsapp/share" target="_blank">
   <span class="fa fa-whatsapp"></span> Share on WhatsApp</a>

Share on WhatsApp

Filed Under: WhatsApp Tagged With: html, link, whatsapp

Create a link for WhatsApp click to chat in HTML

September 11, 2021

Post Views: 8
<a href="https://wa.me/[full phone number in international format]"><i class="fa fa-whatsapp" target="_blank"></i> WhatsApp Me</a>
WhatsApp Me

Filed Under: WhatsApp Tagged With: html, whatsapp

  • Go to page 1
  • Go to page 2
  • Go to Next Page »

Primary Sidebar

Recent Posts

  • How to convert any full URL path to relative to WordPress installation (root)
  • How to write if else statement in a single line (compact if else statement) using PHP
  • How to programmatically add a WordPress admin user using functions.php
  • How to check if a file exists on a remote server using CURL
  • How to create WhatsApp share button in HTML

Recent Comments

No comments to show.

Archives

  • April 2022
  • February 2022
  • September 2021
  • August 2021

Categories

  • Hosting
  • jQuery
  • PHP
  • WhatsApp
  • WordPress

Content

Our team will teach you the art of writing audience-focused content that will help you achieve the success you truly deserve.

Learn more about content.

Copyright © 2021 IntelyBlog

  • html
  • jquery
  • https
  • css
  • slice
  • WhatsApp