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 / 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 / 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
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'] );
@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 / functions.php
Last active November 29, 2017 06:32
Fake Wordpress filter integartion for allow add page template via plugins
<?php
// Spacial Hook! : Add cart page template for cart on admin page options
add_filter( 'theme_page_templates', 'add_cart_page_template_option_select' );
add_filter( 'page_template', 'add_cart_page_template_to_theme', 10, 3 );
function add_cart_page_template_option_select( $post_templates ) {
$post_templates[ 'some-page-name-non-exist-or-uniqe.php' ] = __( 'Page Template Name', 'text-domain' );
return $post_templates;
}
function add_cart_page_template_to_theme( $template, $type, $templates ) {
if( $type === 'page' && $templates[0] === 'some-page-name-non-exist-or-uniqe.php' ) {
@Mosharush
Mosharush / options_ui.php
Created December 7, 2017 06:41
HOTFIX - Rock Theme Wordpress, Azoom theme - Theme options not updates bug
<?php
function rockthemes_to_get_option_length( $array = array() ) {
if ( empty( $array ) ) {
return 0;
}
$array_count = 0;