Skip to content

Instantly share code, notes, and snippets.

View dnaber-de's full-sized avatar
🏠
Working from home

David Naber dnaber-de

🏠
Working from home
View GitHub Profile
@dnaber-de
dnaber-de / Class_Reflector.php
Created October 1, 2013 10:04
Example of a class reflection to make the availability of this class optional.
<?php
/**
* base reflector class to reflect plugins APIs without using
* plugin classes directly
*
*/
namespace Project\Theme\Reflector;
abstract class Class_Reflector {
@dnaber-de
dnaber-de / not-static-but-static.php
Created November 25, 2013 13:03
Shows the difference between static and dynamic class properties.
<?php
namespace Static_Or_Dynamic;
/**
* a simple property list
*
*/
class Settings_List {
@dnaber-de
dnaber-de / bookmarklet.js
Last active November 9, 2016 13:52
A bookmarklet which brings you directly from a wordpress.org plugin page to the svn repository on plugins.svn.wordpress.org.
(function(){var b=document.location.href,a=document.createElement('a'),path=[],protocol='http';a.href=b;path=a.pathname.split('/');if('https:'==a.protocol){protocol='https'}if('wordpress.org'!=a.hostname||'undefined'==typeof path[1]||''==path[1]||'plugins'!=path[1]||'undefined'==typeof path[2]||''==path[2]){alert('It seems you are not facing a wordpress plugin page. The URL must match: worpress.org/plugins/{PLUGIN_NAME}');return}document.location.href=protocol+'://plugins.svn.wordpress.org/'+path[2]+'/trunk/'})();
@dnaber-de
dnaber-de / readme.md
Last active August 29, 2015 13:56
Hotfix Plugin for WP Colored Coding to disable the early shortcode handling, which can lead into trouble with some other plugins.

WP Colored Coding – Disable early shortcode

Issue #8 of WP Colored Coding describes a interoperability problem with another plugin which parses the_content and didn't expect the occurrence of source code in the text.

This can be fixed by handling the WP-CC Shortcode after the_content which is the normal way.

But this drops the support for in-text codes using the enclosing shortcode:

[cc lang="html"]
<strong>This will not longer be possible</strong>
@dnaber-de
dnaber-de / WP_Plugins_Unit_Tests.md
Last active November 9, 2016 13:55
Short description on how I prepared sucessfully a unit test for wordpress plugin.

Plugin UnitTest – How To

Assuming you have a separate WordPress installation for your project (eg. /var/www/my-project ) with your plugin you want to test in /var/www/my-project/wp-content/plugins/my-plugin. PHPUnit and SVN needs also to be installed on your system.

1. Get the WordPress test environment

Get the WordPress test environment as described here in step 1 and 2. You may want to use a separate directory for those stuff like ( ~/tmp/wordpress-test).

The repository looks like:

@dnaber-de
dnaber-de / copy_table.sql
Created August 20, 2014 09:36
How to copy a table in MySQL
CREATE TABLE IF NOT EXISTS dbname.new_tablename LIKE dbname.old_tablename;
ALTER TABLE dbname.new_tablename DISABLE KEYS;
TRUNCATE TABLE dbname.new_tablename;
INSERT INTO dbname.new_tablename SELECT * FROM dbname.old_tablename;
ALTER TABLE dbname.new_tablename ENABLE KEYS;
@dnaber-de
dnaber-de / dom-dissolve-node.php
Last active December 6, 2021 01:26
Dissolving a DOM Node and moving all child nodes one level up
<?php
$html = <<<HTML
<table>
<tr>
<td>Foo with some <span>makrup</span> inside</td>
<td>Bar also <div>with <em>some</em></div> markup</td>
</tr>
</table>
HTML;
@dnaber-de
dnaber-de / attribute-entiy.php
Created September 29, 2014 08:42
Quick notes about some OOP structure
<?php
interface EntityAttributeInterface {
public function getName();
public function setValue( AttributeValueInterface $value );
public function setUnit( AttributeUnitInterface $unit );
@dnaber-de
dnaber-de / wp-config-sample.php
Last active November 13, 2017 18:05
wp-config.php template
<?php
/**
* WordPress config file template
*
* @link http://wpengineer.com/2382/wordpress-constants-overview/
*/
/**
* MySQL credentials
*/
@dnaber-de
dnaber-de / ReleaseTest.php
Last active August 29, 2015 14:24
Some example on a simple PHPUnit Mock. Meant as answer to this question: https://twitter.com/Rarst/status/618880034145718272
<?php
class ReleaseTest \PHPUnit_Framework_TestCase {
public function testConstructor() {
$splFileInfoMock = $this->getMockBuilder( 'SplFileInfo' )
->disableOriginalConstructor()
->getMock();