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;
}

?>

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
}