Skip to content

Instantly share code, notes, and snippets.

@pankamilr
pankamilr / PhpWord.HTML.php
Last active June 11, 2023 18:44
Override PHPOffice\PHPWord class to generate docx file from HTML code. This one generate correct numbers when ordered list occur.
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
@pankamilr
pankamilr / wordpress plugin rewrite media path
Created November 16, 2017 06:55 — forked from mkdizajn/wordpress plugin rewrite media path
wordpress plugin rewrite media path
<?php
/*
Plugin Name: Rewrite Wordpress upload path
Plugin URI: http://mkdizajn.com
Description: Rewrites your image paths.
Version: 2.4
Author: kreso
Author URI: http://mkdizajn.com/
*/
@pankamilr
pankamilr / gist:99175a8caceb1fce8a5c4847c126c7a7
Created October 20, 2017 14:20 — forked from spivurno/gist:6584835
Gravity Forms Cookies // Saves the query string parameters from a users visit to a cookie and allows these values to be populated via Gravity Forms' Dynamic
<?php
/**
Plugin Name: Gravity Forms Cookies
Plugin URI: http://ounceoftalent.com/
Description: Saves the query string parameters from a users visit to a cookie and allows these values to be populated via Gravity Forms' Dynamic Population feature.
Version: 1.5
Author: David Smith
Author URI: http://ounceoftalent.com
License: GPL2
*/
@pankamilr
pankamilr / create_cpt.php
Created June 12, 2015 09:31
Rapid create custom post types and custom taxonomies.
<?php
/*
* Rejestracja niestandardowych rodzajów zawartości
*/
class RegisterCPTS {
/**
* Rodzaje zawartości do stworzenia
@pankamilr
pankamilr / nofollow_to_external.php
Created June 8, 2015 09:18
Add rel nofollow to all external links in given content. $skip contains domain name
public function nofollow($html, $skip = null) {
return preg_replace_callback(
"#(<a[^>]+?)>#is", function ($mach) use ($skip) {
return (
!($skip && strpos($mach[1], $skip) !== false) &&
strpos($mach[1], 'rel=') === false
) ? $mach[1] . ' rel="nofollow">' : $mach[0];
},
$html
);
@pankamilr
pankamilr / count_widgets_in_sidebar.php
Created June 1, 2015 11:06
Check if Wordpress sidebar widget area is empty or not
function count_widgets_in_area($area) {
$widgets = get_option('sidebars_widgets');
if(isset($widgets[$area])) {
return count($widgets[$area]);
}
return null;
}
if(!is_null(count_widgets_in_area("area_id"))) {
// there are some widgets
<?
function MYMODULE_form_node_admin_content_alter(&$form, &$form_state, $form_id) {
$column_alias = 'my_cool_column';
$column_title = 'Header of my cool column';
// Load the nodes. This incurrs very little overhead as
// "$nodes = node_load_multiple($nids);" has already been run on these
// nids in node_admin_nodes(). The static cache will be used instead of
// another db query being invoked
$nodes = node_load_multiple(array_keys($form['admin']['nodes']['#options']));