Skip to content

Instantly share code, notes, and snippets.

View dirkeinecke's full-sized avatar

Dirk Einecke dirkeinecke

  • Karlsruhe, Germany
View GitHub Profile
<?php
if ($_SERVER['SERVER_NAME'] === 'REMOTE_HOST') {
// remote host data
define('DB_HOST', (string) 'REMOTE_DB_HOST');
define('DB_USER', (string) 'REMOTE_DB_USERNAME');
define('DB_PW', (string) 'REMOTE_DB_PASSWORD');
define('DB_DB', (string) 'REMOTE_DB');
} else {
// local host data
define('DB_HOST', (string) 'LOCAL_DB_HOST');
@dirkeinecke
dirkeinecke / wordpress_sitemap_without_plugin__mamp_pro_remote_publish_host_version.php
Last active August 10, 2018 10:14
Wordpress - Create sitemap.xml without PlugIn (Version for MAMP PRO -> Remote -> Publish Host)
add_action('save_post', 'create_sitemap');
function create_sitemap() {
$items = (array) get_posts(array(
'numberposts' => -1,
'post_type' => (array) array(
(string) 'post',
(string) 'page',
),
'post_status' => (string) 'publish',
@dirkeinecke
dirkeinecke / wordpress_sitemap_without_plugin.php
Last active December 2, 2019 13:24
Wordpress - Create sitemap.xml without PlugIn
add_action('save_post', 'create_sitemap');
function create_sitemap() {
$items = (array) get_posts(array(
'numberposts' => -1,
'post_type' => (array) array(
(string) 'post',
(string) 'page',
),
'post_status' => (string) 'publish',
@dirkeinecke
dirkeinecke / wordpress_remove_height_and_width_attributes_of_images.php
Created August 6, 2018 07:17
WordPress – remove “height” and “width” attributes of images
add_filter('post_thumbnail_html', 'remove_thumbnail_dimensions', 10);
add_filter('image_send_to_editor', 'remove_thumbnail_dimensions', 10);
add_filter('the_content', 'remove_thumbnail_dimensions', 10);
function remove_thumbnail_dimensions($html) {
$html = preg_replace('/(width|height)=\"\d*\"\s/', '', $html);
return $html;
}
@dirkeinecke
dirkeinecke / check-email-address.php
Created July 12, 2018 06:09
This PHP function checks if the email address is syntactically correct.
function check_email_address($email_address) {
if ($email_address !== '') {
$result = filter_var($email_address, FILTER_VALIDATE_EMAIL);
if ($result === FALSE) {
return false; // email address is not valid
} else {
return true; // email address is valid
}
} else {
@dirkeinecke
dirkeinecke / paddle-api-create-coupon.php
Created July 5, 2018 06:37
Paddle API - Create coupon
// Documentation: https://paddle.com/docs/api-generate-coupon/
$url = 'https://vendors.paddle.com/api/2.1/product/create_coupon';
$post = (array) array(
'vendor_id' => (int) 12345,
'vendor_auth_code' => (string) 'abc1234...',
'coupon_prefix' => (string) 'TEST-',
'num_coupons' => (int) 5,
'description' => (string) 'Coupons created via the API.',
@dirkeinecke
dirkeinecke / paypal-tlstest.php
Last active June 27, 2018 10:47
PayPal TLS Tester
<!DOCTYPE html>
<html>
<head>
<title>PayPal TLS Tester</title>
</head>
<body>
<h1>PayPal TLS Tester</h1>
<?php
$curl = curl_init();
@dirkeinecke
dirkeinecke / disable-browser-cache.php
Last active August 29, 2015 14:14
Das folgende Beispiel zeigt, wie man das Caching im Browser serverseitig durch PHP unterbindet.
header('Expires: Mon, 26 Jul 1990 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
@dirkeinecke
dirkeinecke / ios-remove-subviews-from-view.m
Last active November 10, 2017 07:56
Das folgende Beispiel zeigt, wie man unter iOS (Objective-C) alle Subviews einer View entfernt.
for (UIView *view in myView.subviews) {
[view removeFromSuperview];
}