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;
}
@IacopoC
IacopoC / acf-loop-taxonomy.php
Last active March 16, 2019 21:30
ACF loop through news taxonomy
<?php
$terms = get_the_terms( $post->ID, 'area');
$postid = get_the_ID();
foreach ($terms as $term) {
$posts = get_posts(array(
'posts_per_page'=> -1,
@IacopoC
IacopoC / Acf-loop.php
Last active March 16, 2019 21:30
ACF secondary loop news post type
<?php
$posts = get_posts(array(
'posts_per_page' => 3,
'post_type' => 'news'
));
if( $posts ): ?>
<?php capital_P_dangit( $text ); ?>
<?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',