Skip to content

Instantly share code, notes, and snippets.

View leoloso's full-sized avatar

Leonardo Losoviz leoloso

View GitHub Profile
@leoloso
leoloso / add_audio_url_meta_to_podcast.php
Last active February 14, 2024 03:30
Add audio_url post meta to new podcast
<?php
add_action(
"gatographql__executed_query:ImportPostFromRSSFeed",
function (Response $response) {
/** @var string */
$responseContent = $response->getContent();
/** @var array<string,mixed> */
$responseJSON = json_decode($responseContent, true);
$postID = $responseJSON['data']['createPost']['post']['id'] ?? null;
if ($postID === null) {
@leoloso
leoloso / import-podcast.gql
Last active February 16, 2024 05:10
GraphQL query: Import Podcast
query FetchPodcastRSSData(
$url: URL!
)
@configureWarningsOnExportingDuplicateVariable(enabled: false)
{
_sendHTTPRequest(input: { url: $url, method: GET }) {
body @remove
rssJSON: _strDecodeXMLAsJSON(
xml: $__body
alwaysArrayTagNames: ["itunes:category"]
@leoloso
leoloso / role-capabiliites-table.gql
Created November 6, 2023 09:10
GraphQL query to generate a table in HTML with the roles and capabilities on the WordPress site, and a ✅ or ❌ in each cell
query ExportData {
roles {
capabilities
@export(as: "roleCapabilities", type: DICTIONARY)
}
capabilities
@export(as: "allCapabilities")
@remove
<?php
/*
Plugin Name: Helper Plugin - Disable user edit profile for WP PoP API
Version: 0.1
Description: It removes the edit profile page for all users other than admins
Plugin URI: https://gist.github.com/leoloso/4e367eb8d8014a7aa7580567608bd5b4
Author: Leonardo Losoviz
*/
/**
* @see: https://wordpress.stackexchange.com/a/45892
@leoloso
leoloso / introspection-query.gql
Created November 30, 2020 07:54
GraphiQL introspection query
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
subscriptionType {
name
@leoloso
leoloso / disable-user-edit-profile.php
Last active November 5, 2023 23:29
WordPress plugin - Disable user edit profile
<?php
/*
Plugin Name: Helper Plugin - Disable user edit profile for WP PoP API
Version: 0.1
Description: It removes the edit profile page for all users other than admins
Plugin URI: https://gist.github.com/leoloso/4e367eb8d8014a7aa7580567608bd5b4
Author: Leonardo Losoviz
*/
/**
* @see: https://wordpress.stackexchange.com/a/45892
// This code is the prettyprinted version of a block's `build/index.js` after running `npm run build`
// It works well, by adding this code anywhere in the block:
// const fixIncreadiblyWeirdBug = {
// ...{},
// }
! function(e) {
function t(t) {
for (var r, s, a = t[0], u = t[1], c = t[2], p = 0, d = []; p < a.length; p++) s = a[p], Object.prototype.hasOwnProperty.call(o, s) && o[s] && d.push(o[s][0]), o[s] = 0;
for (r in u) Object.prototype.hasOwnProperty.call(u, r) && (e[r] = u[r]);
for (l && l(t); d.length;) d.shift()();
// Related to https://github.com/WordPress/gutenberg/issues/23607
// This is the prettyprinted code for a block's `build/index.js` after running `npm run build`
// This code doesn't work! It compiles, but the block is not added under `wp.blocks.getBlockTypes()`
// When loading the editor in the browser, the block is not loaded, and it throws this error in the console:
// Uncaught TypeError: e[t] is undefined
! function(e) {
function t(t) {
for (var r, s, a = t[0], u = t[1], c = t[2], p = 0, d = []; p < a.length; p++) s = a[p], Object.prototype.hasOwnProperty.call(o, s) && o[s] && d.push(o[s][0]), o[s] = 0;
for (r in u) Object.prototype.hasOwnProperty.call(u, r) && (e[r] = u[r]);
for (l && l(t); d.length;) d.shift()();
@leoloso
leoloso / newsletter-subscriptions-rest-endpoints.php
Created November 5, 2019 05:47
Create a REST endpoint for WordPress, providing a list of user newsletter subscriptions (email and language for each)
<?php
/*
Plugin Name: Helper Plugin - Newsletter Subscription REST endpoints for WP PoP API
Version: 0.1
Description: It creates a REST endpoint to demonstrate the PoP API
Plugin URI: https://gist.github.com/leoloso/c14f74ca26eced8bc6e71ba161d672c4
Author: Leonardo Losoviz
*/
if (function_exists('add_action')) {
add_action('rest_api_init', 'register_newsletter_subscriptions_endpoint');