Skip to content

Instantly share code, notes, and snippets.

@scofennell
scofennell / p.php
Last active May 12, 2021 15:54
p css
<?php
function paragraph_cb( $attributes, $out ) {
$out = $this -> bottom_whitespaceify( $out );
return $out;
}
@scofennell
scofennell / bq.php
Last active May 12, 2021 15:55
bq style
<?php
function quote_cb( $attributes, $out ) {
$out = wpautop( $out );
$i = new Icon( 'quote-left', FALSE, array( 'block w-6' ) );
$mark = $i -> get();
$out = $this -> css_classify( $out, 'blockquote', array( 'flex', 'flex-col', 'space-y-5' ) );
@scofennell
scofennell / ad_exclude.php
Last active January 21, 2021 17:27
Ad Exclude
<?php
/**
* Determine if a widget should be hidden from QA.
*
* @param string $widget_id The ID for this widget instance.
* @return boolean Returns TRUE if the widget should be hidden from QA, else FALSE.
*/
static function is_widget_hidden_from_qa( $widget_id ) {
@scofennell
scofennell / log.php
Created January 28, 2019 15:00
a wordpress function for logging
<?php
function debug( $bug ) {
ob_start();
var_dump( $bug );
$out = ob_get_clean();
error_log( $out );
}
@scofennell
scofennell / error.php
Created January 28, 2019 14:42
php function for parsing a wp_remote_request into a wp_error
<?php
function call() {
$response = wp_remote_request( $this -> url, $this -> args );
$code = wp_remote_retrieve_response_code( $response );
$first_digit = $code[0];
$good_responses = array( 2, 3 );
if( ! in_array( $first_digit, $good_responses ) {
$body = wp_remote_retrieve_body( $response );
@scofennell
scofennell / delete_transients.php
Last active March 23, 2020 15:55
WordPress function for deleting all transients related to a certain namespace
<?php
// Purge all the transients associated with our plugin.
function purge() {
global $wpdb;
$prefix = esc_sql( $this -> get_transient_prefix() );
$options = $wpdb -> options;
<?php
function agoify( $from_date, $to_date = FALSE ) {
if( ! $to_date ) {
$to_date = current_time( 'timestamp', get_option( 'gmt_offset' ) );
}
$human_time = human_time_diff( $from_date, $to_date );
$out = sprintf( esc_html__( '%s ago', 'boilerplate' ), $human_time );
<?php
function set_is_update() {
$fv = $this -> get_file_version();
$dbv = $this -> get_database_version();
// returns -1 if the first version is lower than the second, 0 if they are equal, and 1 if the second is lower.
$compare = version_compare( $fv, $dbv );
if( $compare === 1 ) {
<?php
class BodyClass extends Base {
public function __construct() {
$this -> conditionals = get_boilerplate() -> conditionals;
add_filter( 'body_class', array( $this, 'has_post_thumbnail' ) );
add_filter( 'body_class', array( $this, 'is_singular' ) );
add_filter( 'body_class', array( $this, 'admin_bar' ) );
<?php
$out = array(
'' => esc_html__( 'Please choose a state.', 'boilerplate' ),
'AL' => esc_html__( 'Alabama', 'boilerplate' ),
'AK' => esc_html__( 'Alaska', 'boilerplate' ),
'AS' => esc_html__( 'American Samoa', 'boilerplate' ),
'AZ' => esc_html__( 'Arizona', 'boilerplate' ),
'AR' => esc_html__( 'Arkansas', 'boilerplate' ),
[...]