Skip to content

Instantly share code, notes, and snippets.

View webgurus's full-sized avatar
🏠
Working from home

Gergely Márton webgurus

🏠
Working from home
View GitHub Profile
@webgurus
webgurus / acf-list-value-from-subsites.php
Created August 14, 2015 10:07
Function to return an ACF field value for all the subsites on a network
<?php
function getAllCRMIds() {
global $wpdb;
$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE blog_id != {$wpdb->blogid} AND site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' order by blog_id", ARRAY_A);
// array_unshift($blogs, 1); /*Including parent blog in the array*/
$crm_to_blog = array();
foreach($blogs as $blog) {
switch_to_blog( $blog[ 'blog_id' ] );
@webgurus
webgurus / acf-update-via-json-plus-sync.php
Created August 14, 2015 07:04
Automatically updates ACF field groups with JSON file modification
<?php
/**
* Function that will automatically update ACF field groups via JSON file update.
*
* @link http://www.advancedcustomfields.com/resources/synchronized-json/
*/
function jp_sync_acf_fields() {
// vars
$groups = acf_get_field_groups();
$sync = array();
@webgurus
webgurus / gist:2d2497b7c164039783f3
Last active August 29, 2015 14:25 — forked from kalenjohnson/gist:0e5805894a75bcec0204
Codeship Deploy to WPEngine
REMOTE_REPOSITORY=${REMOTE_REPOSITORY:?'You need to configure the REMOTE_REPOSITORY environment variable!'}
REMOTE_BRANCH=${REMOTE_BRANCH:?'You need to configure the REMOTE_BRANCH environment variable!'}
set -e
git fetch --unshallow || true
git push ${REMOTE_REPOSITORY} ${CI_COMMIT_ID}:${REMOTE_BRANCH}
cd wp-content/themes/<theme>
npm install -g bower gulp
npm install
bower install
gulp --production
@webgurus
webgurus / custom_post_type_in_loop.php
Created March 16, 2015 18:42
Include custom post types in all WordPress loops
function custom_post_type_in_home_loop( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'travel','deals','food_cooking') );
return $query;
}
add_filter( 'pre_get_posts', 'custom_post_type_in_home_loop' );
@webgurus
webgurus / change_post_label.php
Created March 16, 2015 18:41
Change WordPress default Post name and label
function change_post_label() {
global $menu;
global $submenu;
$menu[5][0] = 'News';
$submenu['edit.php'][5][0] = 'News';
$submenu['edit.php'][10][0] = 'Add News';
$submenu['edit.php'][16][0] = 'News Tags';
echo '';
}
function change_post_object() {
@webgurus
webgurus / yaml_nav.php
Created March 2, 2015 08:46
YAML megamenu walker for roots theme
<?php
/**
* Cleaner walker for wp_nav_menu()
*
* Walker_Nav_Menu (WordPress default) example output:
* <li id="menu-item-8" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8"><a href="/">Home</a></li>
* <li id="menu-item-9" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-9"><a href="/sample-page/">Sample Page</a></l
*
* Roots_Nav_Walker example output:
* <li class="menu-home"><a href="/">Home</a></li>
@webgurus
webgurus / custom.php
Created November 24, 2014 09:46
Highlight WP Search results
// HIGHLIGHT SEARCH RESULTS
function wps_highlight_results($text){
if(is_search()){
$sr = get_query_var('s');
$keys = explode(" ",$sr);
$text = preg_replace('/('.implode('|', $keys) .')/iu', '<span class="label label-default">'.$sr.'</span>', $text);
}
return $text;
}
add_filter('the_excerpt', 'wps_highlight_results');
@webgurus
webgurus / single.html
Last active August 29, 2015 14:09
Semantic HTML dummy content for WordPress theme development
<header>
<h1 class="entry-title">One morning, when Gregor Samsa woke from troubled dreams.</h1>
<time class="updated" datetime="2012-08-02T17:14:25+00:00">August 2, 2012</time>
<p class="byline author vcard">
By
<a href="#author-page" rel="author" class="fn">admin</a>
</p>
</header>
<div class="entry-content">
@webgurus
webgurus / woo_hide_standard_when_free_available.php
Last active August 29, 2015 14:05
WooCommerce - hide standard shipping option when free is available
<?php
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_standard_shipping_when_free_is_available( $available_methods ) {
if( isset( $available_methods['free_shipping'] ) AND isset( $available_methods['flat_rate'] ) ) {
<?php
/**
* Hides the 'view' button in the post edit page
*
*/
function hv_hide_view_button() {
$current_screen = get_current_screen();