Get current page URL in PHP

<?php echo curPageURL(); ?>

<?php

function curPageURL() {
$pageURL = ‘http’;
if ($_SERVER[“HTTPS”] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER[“SERVER_PORT”] != “80”) {
$pageURL .= $_SERVER[“SERVER_NAME”].”:”.$_SERVER[“SERVER_PORT”].$_SERVER[“REQUEST_URI”];
} else {
$pageURL .= $_SERVER[“SERVER_NAME”].$_SERVER[“REQUEST_URI”];
}
return $pageURL;
}

?>

Add CSS & JS files in the plugin

function add_my_css_and_my_js_files(){
wp_enqueue_style( 'my-stylesheet-name', plugins_url('/css/style.css', __FILE__));
wp_register_script( 'my-plugin-script', plugins_url( '/js/script.js', __FILE__ ) );
}
add_action('wp_enqueue_scripts', "add_my_css_and_my_js_files");

Create table at the time of plugin activation

register_activation_hook( __FILE__, ‘create_table’ );

function create_table () {
global $wpdb;
$table_name = “table_name”;
$charset_collate = $wpdb->get_charset_collate();
$sql = “CREATE TABLE $table_name (
id int(20) NOT NULL AUTO_INCREMENT,
name text NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;”;

require_once( ABSPATH . ‘wp-admin/includes/upgrade.php’ );
dbDelta( $sql );
add_option( ‘normal_db_version’, $normal_db_version );
}

PHP error reporting

<?php
// Turn off error reporting
error_reporting(0);

// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Report all errors
error_reporting(E_ALL);

// Same as error_reporting(E_ALL);
ini_set(“error_reporting”, E_ALL);

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>

Drupal Articles Author and Date Information Display settings

1. Log-in as Admin and choose Structure, Content types and click edit (under Operations) for the corresponding content type (e.g. Article).
2. Click Display Settings and un-check Display author and date information check box.
3. Save settings by clicking the Save Content Type button.

 

1. Enable Display Settings for the corresponding content type.
2. Edit the node.tpl.php file of the corresponding theme you are using, e.g. themes\bartik\templates\node.tpl.php and located the following command:
print $submitted;

3. Now replace this command with the following code:
// print $submitted;
if ($submitted) {
echo "Posted: " . date( "F j, Y",$node->created);
}

4. Save the file and you should see the submitted information in the desired format. Of course, you can use a different date format or add additional node details.

Drupal basic codes

<?php
$GLOBALS['base_path']; // The base path to the Drupal installation. Usually this is just "/" or "/drupal" if you installed Drupal into a sub-directory.
$GLOBALS['base_url']; // The full URL to the Drupal installation (i.e. "http://example.com" or "http://example.com/drupal")
$site_frontpage = variable_get('site_frontpage', 'node'); // The site's configured frontpage path (i.e. "frontpage" or "node/123"), settable at http:// example.com/admin/settings/site-information 
?>
Is the user logged in?
if ($user->uid == 0) {
//user is not logged in
}

File upload, Number & E-Mail validation in jQuery

var fsize = $(‘.fileTo_Upload’)[0].files[0].size;
if(fsize>2500000){
alert(“Please upload image below 2MB”);
}
if(!/(\.png|\.jpg|\.gig|\.jpeg)$/i.test($(‘.fileTo_Upload’).val()))
{

alert(“Please upload correct file format Photo”);
/* $(“.phh”).html(“Invalid text file type.\n”);*/
err++;
}

  var email = jQuery( “#dummy_email_id” ).val();
          var regexpEmail = /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
         if (regexpEmail.test(email)) {
 alert(“true”)
         }
<script>
jQuery(document).ready(function(){
jQuery(“#phone_num”).blur(function(){
var value = jQuery(“#phone_num”).val();
var test = /^[0-9]+$/.test(value);
if(test==false){
jQuery(“.num_err”).show();
}else{
jQuery(“.num_err”).hide();
}
});
});
</script>

Drupal 7 Modules as Drupal 8 Features

Admin Menu Bar
Replaces Drupal 7 tool bar to one that behaves just like Drupal 8’s and is responsive as well.

Inline Editing
Allows content editors to edit posts inline.

CKEditor
A WYSIWYG editor without the use of the WYSIWYG module.

Responsive Bartik
Core theme, but responsive.

HTML5
HTML5 API.

More HTML5
Replaces Drupal 7 core elements to be HTML5.

Views
Views, not much more to say.

Admin Views
Replaces admin pages with views.

Views Bulk Operations
Apply changes accross multiple selections in an admin view.

Views Responsive Grids
A views plugin that gives you responsive grids.

Responsive Tables
Adds a library to allow tables to function responsively.

Breakpoints
Breakpoints management for responsive web design.

Responsive Images
Utilizes breakpoints and image styles to give you responsive images.

Tours (Joyride)
Allows developers to create tours, joyride was used to create the tour module in Drupal 8.

Module Filter
Dynamically filter the modules page to find the module you are looking for.

Simplified Admin Menu
This module simplifies the core Menu and Shortcut modules by merging the “List links” and “Edit menu” operations into a single administration page.

Back to Site
Adds a ‘Back to site’ button when the user has clicked on an administration URL from a non-administration page.

Captions
This module provides a very simple caption input filter that can be used to attach captions to an image or embeddable object.

Better Block System
Turns blocks into entities giving us block types that are fieldable.

Multiple Instances of a Block
Allows a single block to be used in more than one region at a time.

Entity Reference
Allows one entity to reference another.

Telephone Field
A field formatted for telephone numbers.

Email Field
A field formatted for email addresses.

URL Field
A field formatted for URLs.

Date Field
This is the date module which gives us a date field and much more.

View Modes
Allow administrators to define custom view modes for entities.

Entity Translations
Allows (fieldable) entities to be translated into different languages, by introducing entity/field translation for the new translatable fields capability in Drupal 7.

Title Translations
Translate the title of a node.