Skip to content

Instantly share code, notes, and snippets.

View alinademi's full-sized avatar

Ali Demi alinademi

  • Vancouver
View GitHub Profile
@alinademi
alinademi / remove-visual-composer-shortcodes.md
Last active April 27, 2023 17:03 — forked from gemmadlou/remove-visual-composer-shortcodes.md
Removing Visual Composer & Shortcodes From Wordpress Content

Adding @k1sul1's suggestion from the comments as it's more concise than what I had before:

I just wanted them all gone, so I ran this in the MySQL shell.

UPDATE wp_posts SET post_content = REGEXP_REPLACE(post_content, "\\[\/?vc(.*?)\]", "");

OR You can also do with with WP-CLI:
wp search-replace --regex --verbose "\\[\/?vc(.*?)\]" "" wp_posts

@alinademi
alinademi / ACF Gutenberg get block fields
Created March 18, 2023 04:02 — forked from jenssogaard/ACF Gutenberg get block fields
Helper class for ACF and Gutenberg. Get blocks fields by passing block_id and post_id.
<?php
namespace JensSogaard;
class BlockHelper
{
/**
* Gets ACF fields for a specific block on a given post
* @author Jens Soegaard <[email protected]>
*/
public function getBlockFromPage(string $block_id, int $post_id)
@alinademi
alinademi / dev-note-5.8-block-api.md
Created March 7, 2023 00:51 — forked from gziolo/dev-note-5.8-block-api.md
Block API enhancements in WordPress 5.8

Block API Enhancements

As of WordPress 5.8 release, we encourage using block.json file metadata as the canonical way to register block types. We have been working on Block Metadata specification for a few major WordPress releases, and we reached the point where all planned features are in place.

Example:

notice/block.json

{
	"apiVersion": 2,
@alinademi
alinademi / dev-note-5.8-block-editor.md
Created March 7, 2023 00:50 — forked from gziolo/dev-note-5.8-block-editor.md
Block Editor filter changes in WordPress 5.8

Block Editor Changes

We have reached the first WordPress core release where the post editor is no longer the only screen that uses the block editor. In the middle of the development process, we found out that several WordPress hooks defined on the server depended on the $post object that isn’t present on the updated screen that lets users edit widgets using blocks. Therefore, we decided to deprecate some of the existing filters and introduce their context-aware replacements. This way, we ensure that we can continue iteratively enabling the block-based paradigm on different screens like the navigation editor screen by leveraging the new WP_Block_Editor_Context class that will receive more capabilities over time. There are also new methods introduced that allow code reuse for the functionality that needs to be shared between the screen that uses the block editor.

Related Trac ticket: #52920.

Class

WP_Block_Editor_Context

{
"title": "JSON schema for WordPress blocks",
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"//": {
"reference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/",
"attributesReference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/",
"contextReference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-context/",
"supportsReference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/",
"registerReference": "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/#example-optional"
@alinademi
alinademi / scripts.php
Created March 3, 2023 00:34 — forked from yratof/scripts.php
Add scripts to customizer for wordpress
<?php
/* Customiser script */
add_action( 'customize_register', 'custom_editor' );
function custom_editor( $wp_customize ) {
// Analytics section
$wp_customize->add_section('analytics_section', array(
'title' => __( 'Analytics', 'tuesday' ),
'description' => __( 'Enable tracking and analytics by placing your script tags in the correct location. <small><strong>Note:</strong> All scripts must be self-containing &lt;script&gt;&lt;/script&gt;, otherwise they will just print the code onto the website.</small>', 'tuesday' ),
@alinademi
alinademi / ffmpeg.md
Created March 3, 2023 00:29 — forked from steven2358/ffmpeg.md
FFmpeg cheat sheet
@alinademi
alinademi / remove dashboard widgets
Created February 11, 2023 01:49 — forked from karlazz/remove dashboard widgets
remove dashboard widgets
// https://deluxeblogtips.com/remove-dashboard-widgets-in-wordpress/
add_action('admin_init', 'rw_remove_dashboard_widgets');
function rw_remove_dashboard_widgets() {
remove_meta_box('dashboard_right_now', 'dashboard', 'normal'); // right now
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal'); // recent comments
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); // incoming links
remove_meta_box('dashboard_plugins', 'dashboard', 'normal'); // plugins
remove_meta_box('dashboard_quick_press', 'dashboard', 'normal'); // quick press
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'normal'); // recent drafts
@alinademi
alinademi / get_parent_block_field.php
Created January 22, 2023 23:12 — forked from joseph-farruggio/get_parent_block_field.php
Returns a specified field from the parent ACF block.
<?php
/**
* Returns a specified ACF field from a parent block
* @param string $child_id The ID of the child ACF block
* @param string $child_name The name of the child ACF block
* @param string $parent_name The name of the parent ACF block
* @param string $field The name of the parent's custom field to return
* @param boolean $return_first If $field is an array, optionally return the first item.
*/
function get_field_from_parent($child_id, $child_name, $parent_name, $field, $return_first = false) {
@alinademi
alinademi / bash-script-base.sh
Created January 7, 2023 00:07 — forked from erawhctim/bash-script-base.sh
Bash script starter file - colors, status messages, custom functions, etc
#!/bin/sh
# Originally pulled from: https://robots.thoughtbot.com/shell-script-suggestions-for-speedy-setups
# Exit if any subcommand fails
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'