Skip to content

Instantly share code, notes, and snippets.

View Mosharush's full-sized avatar
👨‍💻
Code. Sleep. Repeat.

Moshe Harush Mosharush

👨‍💻
Code. Sleep. Repeat.
View GitHub Profile
@Mosharush
Mosharush / functions.php
Last active July 20, 2017 15:35
Post content partial schedule - Wordpress Shortcode
<?php
// Add Shortcode sc_schedule_content - Post content partial schedule
function sc_schedule_content( $atts , $content = null ) {
// Attributes
$atts = shortcode_atts(
array(
'time' => '',
'date' => '',
),
@Mosharush
Mosharush / .htaccess
Last active July 27, 2017 23:35
Base Clean Project Template - Best HTML index & htaccess file for web optimization browser cache
AddDefaultCharset utf-8
RewriteEngine on
<FilesMatch "\.(jpg|png|css|js|gif|html|htm|gz|xml|ttf|woff|woff2|svg|eot)$">
<ifModule mod_headers.c>
RequestHeader unset Set-Cookie
Header unset Set-Cookie
Header set X-CDN "WebStorm.co.il-CDN"
</ifModule>
</FilesMatch>
@Mosharush
Mosharush / fixImagesNameUnicode.php
Last active August 12, 2018 13:28
Wordpress - Fix images names encoded utf8 (gibberish)
<?php
$it = new RecursiveDirectoryIterator(".");
$extAllow = Array ( 'jpeg', 'jpg' );
foreach( new RecursiveIteratorIterator($it) as $img ){
$ext = explode( '.', $img );
$ext = array_pop( $ext );
if (! in_array( strtolower( $ext ), $extAllow ) ){
continue;
@Mosharush
Mosharush / array2select.function.php
Last active August 9, 2017 23:23
Format php array to HTML select tag
<?php
function array2select( $name, $array, $assoc = false, $selected = null, $addArray = null ) {
if( isset( $addArray ) && is_array( $addArray ) ) {
$array = $addArray + $array;
}
if( ! $assoc ) {
$select = '<select name="' . $name . '"><option>' . implode( '</option><option>', $array ) . '</option></select>';
@Mosharush
Mosharush / procMvc.function.php
Created August 9, 2017 23:44
PHP function to replace MVC Viewer to end result
<?php
function procMvc( $view, $vars = null ) {
$vars = empty( $vars ) ? $GLOBALS : $vars;
/*
* Replace $view
* only var like varname or array value like arrname.varname
* short if like varname==8?hhhh output be hhhh if varname eq to 8
*/
@Mosharush
Mosharush / wp-change-domain.php
Last active October 22, 2017 20:35
WP - StandAlone script to change wordpress url in db - Search & Replace
<?php
if( ! empty( $_GET[ 'done' ] ) ) {
if( unlink( __FILE__ ) ) {
die( 'הקובץ נמחק והאתר שלך מוכן עם הכתובת החדשה!' );
} else {
die( 'עקב בעיית הרשאות לא ניתן למחוק את הקובץ אוטומטית, אנא מחק את הקובץ ידנית.' );
}
}
@Mosharush
Mosharush / email.reader.class.php
Created September 1, 2017 11:19
Read emails from SMTP - PHP
<?php
class Email_reader {
// imap server connection
private $conn;
// inbox storage and inbox message count
public $inbox;
public $msg_cnt;
@Mosharush
Mosharush / functions.php
Created September 18, 2017 23:24
Add target attribute to all links in post
/*** Add target attribute to all links in post ***/
function gt_add_target_attr( $match ){
if( strpos( $match[0], 'target=' ) === false ){
return preg_replace( '#>$#', ' target="_blank">', $match[0] );
} else {
return $match[0];
}
}
@Mosharush
Mosharush / functions.php
Created September 27, 2017 10:48
WordPress PolyLang translate shortcode & function - use in customizer texts
<?php
// If Polylang is active, hook function on the admin pages
if ( function_exists( 'pll_register_string' ) ) add_action( 'admin_init', 'pll_tc_strings_setup' );
function pll_tc_strings_setup() {
// Add text to Polylang's string translation panel
pll_register_string( 'fl-topbar-col1-text', 'Contact_Data', 'wipi', true );
pll_register_string( 'fl-arrow-breadcrumbs', 'arrow_mulilang', 'wipi', true );
}
function polylanguage_shortcode( $atts ) {
@Mosharush
Mosharush / functions.php
Last active September 27, 2017 11:47
Wipi (beaver) builder support for Contact Form 7 DB plugin
<?php
// Code start form here:
// Wipi (beaver) builder support for Contact Form 7 DB plugin
function webstorm_wipi_support_cf7db(){
// Save temp unnecessary post fields and remove untail save to db
$tempPost = $_POST;
unset( $_POST['fields'] );
unset( $_POST['action'] );
unset( $_POST['node_id'] );