Skip to content

Instantly share code, notes, and snippets.

@cgrymala
cgrymala / sample-tables.md
Created February 19, 2024 22:12
Sample GitHub Markdown Table
@cgrymala
cgrymala / delete-plugin-tables.php
Created July 10, 2015 14:50
Delete Extra Plugin Tables When a Site Is Deleted in WordPress Multisite
<?php
/**
* Add any custom tables that this plugin creates for an individual site to the list
* of tables that get deleted when a site is deleted.
* @see https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-admin/includes/ms.php#L116
*/
add_filter( 'wpmu_drop_tables', 'delete_my_plugin_tables', 10, 2 );
function delete_my_plugin_tables( $tables=array(), $blog_id=null ) {
/**
* Make sure the blog ID parameter was sent, so we don't
@cgrymala
cgrymala / bad-link.html
Created December 9, 2020 19:01
Bad Link
@cgrymala
cgrymala / views-custom-feed-sample.php
Last active June 23, 2019 06:02
Shows an example of the functions used to remove Views wrapper HTML
<?php
/**
* Override the extra HTML that Views uses to wrap its output
*/
remove_shortcode( 'wpv-layout-start' );
remove_shortcode( 'wpv-layout-end' );
add_shortcode( 'wpv-layout-start', array( $this, '__blank' ) );
add_shortcode( 'wpv-layout-end', array( $this, '__blank' ) );
@cgrymala
cgrymala / add-rand-orderby-to-rest.php
Created November 22, 2018 15:15
Allows you to use `rand` as an `orderby` parameter when querying a custom post type through the WordPress REST API
<?php
class Add_Rand_to_OrderBy {
public function __construct() {
add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
}
/**
* Set up any custom REST API handlers
*
* @access public
@cgrymala
cgrymala / pcs-sample-views-content-template.html
Created January 8, 2016 16:38
Example of PCS usage of custom Views Content Template
<article class="[pcs-entry-classes classes='pcs-entry one-fourth' columns=4]">
<header>
<figure class="pcs-featured-image">
[pcs-thumbnail]
</figure>
<h1 class="pcs-post-title">
<a href="[pcs-post-url]">[wpv-post-title]</a>
</h1>
</header>
<footer>
@cgrymala
cgrymala / inheritance.php
Created February 8, 2018 13:32
Showing how PHP handles inheritance
<?php
class A {
function __construct() {
$this->sample_method();
}
private function sample_method() {
echo "<p>I am inside the parent class 'A'</p>";
}
}

Keybase proof

I hereby claim:

  • I am cgrymala on github.
  • I am cgrymala (https://keybase.io/cgrymala) on keybase.
  • I have a public key whose fingerprint is 3B6A D380 4C78 7EF0 F88B FB54 7726 1A30 1ED3 F998

To claim this, I am signing this object:

@cgrymala
cgrymala / jetpack-fluid-video-embed-fix.php
Created July 21, 2015 17:58
Attempt to make JetPack Shortcode Embeds compatible with Fluid Video Embeds plugin
<?php
/**
* Attempts to override the stupid way JetPack short-circuits native oEmbeds
* so that the Fluid Video Embeds plugin can work properly
*/
function fve_jetpack_filter_video_embed( $html, $atts=array() ) {
/**
* Attempt to make sure the Fluid Video Embeds plugin is
* active and that the global $fve object is instantiated
*/
@cgrymala
cgrymala / no-subscriber-admin.php
Created February 12, 2015 20:28
Keep Subscribers Out of the WP Admin Area
<?php
add_action( 'admin_init', 'hide_backend_from_user' );
/**
* Hide the backend from specific user levels
* @uses VFH_User_Controls::$options['login_redirect_to'] to determine where the user should be redirected
* @uses VFH_User_Controls::$user_levels to see if the user needs to be redirected
*/
function hide_backend_from_user( $level='edit_posts' ) {
/**
* Attempt not to short-circuit AJAX requests