Skip to content

Instantly share code, notes, and snippets.

View IacopoC's full-sized avatar
🎯
Crunch mode

Iacopo C IacopoC

🎯
Crunch mode
View GitHub Profile
@IacopoC
IacopoC / coordinatestoname.js
Created April 7, 2023 10:59 — forked from AmirHossein/coordinatestoname.js
Get City and Country name by coordinates via Google Maps api
// Demo: http://jsfiddle.net/xuyp8qb5/
// Note: You need Google Map API Key to run demo; bit.ly/2pBgToW
var latlng;
latlng = new google.maps.LatLng(40.730885, -73.997383); // New York, US
//latlng = new google.maps.LatLng(37.990849233935194, 23.738339349999933); // Athens, GR
//latlng = new google.maps.LatLng(48.8567, 2.3508); // Paris, FR
//latlng = new google.maps.LatLng(47.98247572667902, -102.49018710000001); // New Town, US
//latlng = new google.maps.LatLng(35.44448406385493, 50.99001635390618); // Parand, Tehran, IR
//latlng = new google.maps.LatLng(34.66431108560504, 50.89113940078118); // Saveh, Markazi, IR
<?php
// Retrieve sites ID and path in WP multisite
$current_id = get_current_blog_id();
$args = array('site__not_in' => $current_id);
$network_sites = get_sites($args);
foreach($network_sites as $network_site) {
echo $network_site->blog_id;
@IacopoC
IacopoC / redirect-custom-page.php
Created September 30, 2019 11:35
Redirect to a custom page when user is logged in based on user role in WP
function hide_the_dashboard()
{
global $current_user;
// is there a user ?
if ( is_array( $current_user->roles ) ) {
// substitute your role(s):
if ( in_array( 'author', $current_user->roles ) ) {
// hide the dashboard:
remove_menu_page( 'index.php' );
@IacopoC
IacopoC / custom-search-acf-wordpress.php
Created January 15, 2019 14:44 — forked from charleslouis/custom-search-acf-wordpress.php
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request
<?php
/**
* [list_searcheable_acf list all the custom fields we want to include in our search query]
* @return [array] [list of custom fields]
*/
function list_searcheable_acf(){
$list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
return $list_searcheable_acf;
}
<?php
// disable for posts
add_filter('use_block_editor_for_post', '__return_false', 10);
// disable for post types
add_filter('use_block_editor_for_post_type', '__return_false', 10);
<?php
// Remove Admin bar
function remove_admin_bar() {
return false;
}
@IacopoC
IacopoC / get-core-update.php
Created February 21, 2018 20:44
Get core update in Rest Api
<?php
function get_wp_core_updates() {
require_once ABSPATH . '/wp-admin/includes/update.php';
return get_core_updates();
}
add_action( 'rest_api_init', function () {
register_rest_route( 'wp/v2', 'wp-version',array(
'methods' => 'GET',
@IacopoC
IacopoC / push-instruction
Created February 4, 2018 20:52
Push files in Repo in Git
# Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/c0ldlimit/vimcolors.git
git push -u origin master
# Push an existing repository from the command line
@IacopoC
IacopoC / enable-dashicons.php
Created January 6, 2018 17:25
Enable Dashicons in the frontend
<?php
// Adding Dashicons in WordPress Front-end
add_action( 'wp_enqueue_scripts', 'load_dashicons_front_end' );
function load_dashicons_front_end() {
wp_enqueue_style( 'dashicons' );
}
@IacopoC
IacopoC / Allow-cpt-in-category-list-archive.php
Last active November 23, 2017 12:07
Allow cpt in category list archive in wordpress
<?php
// Allow cpt in category list
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if( is_category() ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item', 'post', 'name_of_post_type'); // don't forget nav_menu_item to allow menus to work!