Skip to content

Instantly share code, notes, and snippets.

View strsar's full-sized avatar

Scott Trsar strsar

View GitHub Profile
@strsar
strsar / batch.php
Created October 7, 2021 01:32
[WP] Batch update posts
$posts = get_posts( array(
'post_type' => 'post',
'numberposts' => -1
) );
foreach ( $posts as $post ) {
$content = $post->post_content;
if(substr( $content, 0, 4 ) === "<img"){
$content = preg_replace('/<img(.*)>/i','', $content, 1);
@strsar
strsar / .htaccess
Created October 7, 2021 01:31
[htaccess] Load production assets if not on local
## LOAD PRODUCTION ASSET IF NOT LOCAL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^local\.test$
RewriteRule ^uploads/(.*)$ https://production.com/uploads/$1 [NC,L]
@strsar
strsar / admin-user.php
Created October 7, 2021 01:30
[WP] Programmatically create WP admin user
add_action( 'init', function () {
$username = 'user';
$password = 'pass';
$email_address = '[email protected]';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
@strsar
strsar / compress.php
Last active October 1, 2020 14:34
[WP] Wordpress - Clean and minify all markup
<?php defined('ABSPATH') or header('Location: /');
/**
* HTML document compression
*
* Clean and minify all markup
* Wrap `<!--wp-html-compression no compression-->` to skip over content
*/
class WP_HTML_Compression {
protected $compress_css = true; // Compress all inline styles
@strsar
strsar / svg_mime.php
Last active February 8, 2022 10:26
[WP] Wordpress - Add svg mime type to WP file upload
<?php
function add_svg_mime($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'add_svg_mime');
@strsar
strsar / article.php
Created January 30, 2017 17:36
[Joomla!] - Load article by ID and register new set of params
<?php
// Load article
$id = 0;
$article = JTable::getInstance('content');
$article->load($id);
// Register new set of params
$item = $article;
$new_params = new JRegistry();
@strsar
strsar / typeface.scss
Created January 30, 2017 17:35
[SCSS] - @font-face mixin
/**
* Build @font-face
*
* @vars {@family}, {@path}, {@weight}, {@style}
*/
@mixin typeface($family, $path, $weight: normal, $style: normal) {
@font-face {
font-family:$family;
src: url('#{$path}.woff2') format('woff2'),
@strsar
strsar / app.php
Created January 30, 2017 17:34
[Joomla!] - Create standalone application
<?php
/**
* Custom standalone application
*
* @package Joomla.Cli
* @application Stand-alone
*/
define('_JEXEC', 1);
ini_set('magic_quotes_runtime', 0);
ini_set('max_execution_time', 0);
@strsar
strsar / plugin_xml.php
Created January 30, 2017 17:32
[Joomla!] - Extend core component xml fields via System Plugin
<?php defined('_JEXEC') or die;
class plgSystemPlugin extends JPlugin {
public function __construct(&$subject, $config = array()) {
parent::__construct($subject, $config);
}
/**
* @event onContentPrepareForm
*/
function onContentPrepareForm($form, $data) {
@strsar
strsar / plugin_sef.php
Created January 30, 2017 17:30
[Joomla!] - Remove article ID from SEF URL's via System Plugin
<?php defined('_JEXEC') or die;
class plgSystemPlugin extends JPlugin {
public function __construct(&$subject, $config = array()) {
parent::__construct($subject, $config);
}
/**
* @event onAfterInitialise
*/
function onAfterInitialise(){