Skip to content

Instantly share code, notes, and snippets.

add_filter( 'allowed_http_origins', 'add_allowed_origins' );
function add_allowed_origins( $origins ) {
$origins[] = 'https://site1.example.com';
$origins[] = 'https://site2.example.com';
return $origins;
}
@AlkarE
AlkarE / Functions
Created June 25, 2018 07:26 — forked from nusserstudios/Functions
Zurb Foundation Pagination Function for WordPress
<?php
function foundation_pagination($before = '', $after = '') {
global $wpdb, $wp_query;
$request = $wp_query->request;
$posts_per_page = intval(get_query_var('posts_per_page'));
$paged = intval(get_query_var('paged'));
$numposts = $wp_query->found_posts;
$max_page = $wp_query->max_num_pages;
if ( $numposts <= $posts_per_page ) { return; }
if(empty($paged) || $paged == 0) {
@AlkarE
AlkarE / git.migrate
Created March 10, 2018 22:23 — forked from niksumeiko/git.migrate
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
@AlkarE
AlkarE / wp_queries.md
Last active May 4, 2017 14:40
Sql queries for migrating WP to https

Update any embedded attachments/images that use http. This one updates the src attributes that use double quotes:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'src="http://www.yoursite.com', 'src="https://www.yoursite.com') WHERE post_content LIKE '%src="http://www.yoursite.com%';

This one takes care of any src attributes that use single quotes:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'src='http://www.yoursite.com', 'src='https://www.yoursite.com') WHERE post_content LIKE '%src='http://www.yoursite.com%';

-- Change Siteurl & Homeurl
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'home' OR option_name = 'siteurl'
-- Change GUID
UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com')
-- Change URL in Content
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com')
-- Change Image Path Only
@AlkarE
AlkarE / disable_cpt_archive.php
Created January 23, 2017 13:13
Disable cpt archive
function disable_cpt_archive_template(){
if ( is_post_type_archive('cpt') ) {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 ); exit();
}
}
add_filter( 'archive_template', 'disable_cpt_archive_template', -1 );
@AlkarE
AlkarE / gist:2ba020802b50471e62b71eb80f5e1fd4
Created August 3, 2016 13:39
wordpress disable embed
<?php
function disable_embeds_init() {
// Remove the REST API endpoint.
remove_action('rest_api_init', 'wp_oembed_register_route');
// Turn off oEmbed auto discovery.
// Don't filter oEmbed results.
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
@AlkarE
AlkarE / wp_server_test
Created January 22, 2016 20:00
wp_server_info
<?php
echo '<div style="text-align: center">WordPress: '
. round(memory_get_usage()/1024/1024, 2) . 'MB '
.' | MySQL:' . get_num_queries() . ' | ';
timer_stop(1);
echo 'sec</div>';
?>
@AlkarE
AlkarE / retina_images
Created January 16, 2016 19:53
retina-images
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min--moz-device-pixel-ratio: 2),
only screen and (-moz-min-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx) {
/* стили для дисплеев Retina */
}
@AlkarE
AlkarE / ptoduct_cat_taxonomy.php
Created July 20, 2015 08:07
product_category_taxonomy
<?php
/*Plugin Name: Create product Category Taxonomy
Description: This plugin registers the 'product category' taxonomy and applies it to the 'product' post type.
Version: 1.0
License: GPLv2
*/
function product_register_taxonomy() {
// set up labels
$labels = array(