Skip to content

Instantly share code, notes, and snippets.

View alinademi's full-sized avatar

Ali Demi alinademi

  • Vancouver
View GitHub Profile
@alinademi
alinademi / simple-google-apis.php
Created December 14, 2023 03:07 — forked from kingkool68/simple-google-apis.php
Interacting with Google API's using their PHP libraries is a nightmare. Skip the headache by authorizing a Guzzle client and make raw HTTP requests instead!
<?php
$key_file_path = __DIR__ . '/service-account-credentials.json';
$google_client = new \Google_Client();
$google_client->setAuthConfig( $key_file_path );
// Set the scopes of whatever you need access to
// See https://developers.google.com/identity/protocols/oauth2/scopes
$google_client->setScopes( array( 'https://www.googleapis.com/auth/analytics.readonly' ) );
$http_client = $client->authorize();
<?php
function rh_filter_the_content( $the_content = '' ) {
$blocks = parse_blocks( $the_content );
$new_block = array(
'blockName' => 'core/paragraph',
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '<p>Hello World</p>',
'innerContent' => array(
'<p>Hello World</p>',
<?php
/**
* A function that takes an array of HTML attribute
* key/value pairs and returns a string of HTML attributes.
**/
function unwrap_html_attrs($attrs)
{
$attributes = '';
@alinademi
alinademi / zsh.md
Created August 10, 2023 23:32 — forked from webdevsuperfast/zsh.md
Install ZSH using Homebrew and set as default shell in Linux/WSL

Install ZSH via HomeBrew

brew install zsh

Add ZSH to /etc/shells

echo $(which zsh) | sudo tee -a /etc/shells

Set ZSH as default user shell

sudo chsh -s $(which zsh) $USER

Execute Shell or just restart terminal to take effect

@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 <jens@jenssogaard.com>
*/
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' ),