Skip to content

Instantly share code, notes, and snippets.

View allysonsouza's full-sized avatar
💻
Doing some WordPress stuff...

Allyson Souza allysonsouza

💻
Doing some WordPress stuff...
View GitHub Profile
@allysonsouza
allysonsouza / wp-remove-dashboard-widgets.php
Created August 28, 2021 14:54
Remove WordPress dashboard widgets
<?php
/**
* Remove dashboard widgets.
*/
function remove_dashboard_widgets() {
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
@allysonsouza
allysonsouza / wordpress-create-media-from-filepath.php
Last active May 16, 2021 01:29
Create a WordPress media from file path and attach it to a post.
<?php
/**
* Create media from path.
*
* @param string $file_path
*/
function create_media_from_path( $file_path, $post_id = 0 ) {
// Requires
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
@allysonsouza
allysonsouza / fetch_plugin.js
Created May 14, 2021 04:04 — forked from cwhittl/fetch_plugin.js
Using Fetch with Wordpress Plugins Ajax
fetch(ajax_url, {
method: 'POST',
credentials: 'same-origin',
headers: new Headers({'Content-Type': 'application/x-www-form-urlencoded'}),
body: 'action=zget_profile_user'
})
.then((resp) => resp.json())
.then(function(data) {
if(data.status == "success"){
_this.setState({loaded:true,user:data.user});
@allysonsouza
allysonsouza / install-commands.php
Last active July 21, 2021 21:01
WP Install Command - Copy command to install plugins trough WP-CLI or Composer easily.
<?php
/*
Plugin Name: Install Commands
Plugin URI:
Description: Copy command to install plugins trough WP-CLI or Composer.
Author: Allyson Souza
Version: 1.0
Author URI: https://hastedesign.com.br
Text Domain: install-commands
Domain Path: /languages
@allysonsouza
allysonsouza / about.js
Last active September 11, 2020 17:28
Question: Using inline images in Gatsby markdown
import React from "react";
import "./_about.scss";
import { FormattedMessage, useIntl } from "gatsby-plugin-intl"
import AboutEN from "./about.en.mdx"
import AboutPT from "./about.pt.mdx"
import AboutES from "./about.es.mdx"
export default function Header() {
const intl = useIntl()
@allysonsouza
allysonsouza / packages.config
Last active August 16, 2020 16:12
My Chocolatey packages.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="cmder" />
<package id="nodejs" />
<package id="git" />
<package id="composer" />
<package id="sourcetree" />
<package id="slack" />
<package id="gifcam" />
<package id="paint.net" />
@allysonsouza
allysonsouza / autoset-featured.php
Created March 18, 2019 21:30
Automatically sets the featured image from first <img> in post content in WordPress
## Output posts into post.txt file, only ID
wp post list --post_type=shop_order --field=ID --format=table > posts.txt
## Loop trough each post ID stored in posts.txt then run some wp-cli command, like post meta update
## Change the two %p for %%p if you want to run it in a .bat file (I run it directly on cmd)
FOR /F "tokens=1* delims=" %p IN (posts.txt) DO wp post meta update %p my_meta_key "My Value"
@allysonsouza
allysonsouza / haste-status.bat
Created January 29, 2019 18:05
Script to move projects from folders and search-replace WordPress databases to reflect that change
:: Name: haste status
:: Purpose: move Haste WordPress projects from folders
:: Author: @allysonsouza
:: URL: https://github.com/allysonsouza
:: Version: 0.0.1
:: License: GPL-v2
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
@allysonsouza
allysonsouza / export.php
Created November 28, 2018 21:40
Export WordPress XML content acessing this file. It supports the exports of more posts than it's supported trough the panel with the same server resources.
<?php
include 'wp-config.php';
include 'wp-admin/includes/export.php';
 
ob_start();
export_wp();
$file = ob_get_contents();
ob_end_clean();