Skip to content

Instantly share code, notes, and snippets.

View phoopee3's full-sized avatar

Jason Lawton phoopee3

View GitHub Profile
@phoopee3
phoopee3 / Add Category Term.md
Last active December 6, 2022 17:56
Another AI generated WP plugin - this time to add a term to the taxonomy

Prompt

Write a wordpress plugin that will allow a person to add a term to the category taxonomy. The form will ask the user for the name of the category. The form will be presented on a page on the front end of the site. The form should be implemented via a shortcode. The form should submit the data via admin-ajax.

@phoopee3
phoopee3 / category-term-updater.php
Created December 6, 2022 17:21
wordpress plugin for havign a shortcode present a form for adding a term to a taxonomy - generated via openai chatbot
<?php
/*
Plugin Name: Category Term Updater
Prompt given : Write a wordpress plugin that will present a list of category terms,
and allow a person to update them via a form. The form will be presented on a page
on the front end of the site. The form should be implemented via a shortcode.
*/
function category_term_updater_shortcode() {
// Get the current category terms
@phoopee3
phoopee3 / array_merges.php
Created May 31, 2022 02:27
trying to merge arrays in various ways
<?php
function my_merge( $a, $d ) {
foreach ( $d as $name => $default ) {
if ( array_key_exists( $name, $a ) && !is_null($a[ $name ]) ) {
$out[ $name ] = $a[ $name ];
} else {
$out[ $name ] = $default;
}
}
@phoopee3
phoopee3 / functions.php
Created March 16, 2022 21:02 — forked from sirbrillig/functions.php
Post file using wp_remote_post in WordPress
<?php
$local_file = 'file_path'; //path to a local file on your server
$post_fields = array(
'name' => 'value',
);
$boundary = wp_generate_password( 24 );
$headers = array(
'content-type' => 'multipart/form-data; boundary=' . $boundary,
);
@phoopee3
phoopee3 / cpt-nested.php
Created February 10, 2022 02:34 — forked from andreawetzel/cpt-nested.php
CPT Plugin
<?php
/*
Plugin Name: WI Verbs Nested Post Types
Plugin URI: https://wisconsinverbs.com
Description: Display Custom Post Types in a nested menu
Version: 1.0
Author: Andrea Roenning
Author URI: https://andrearoenning.com
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@phoopee3
phoopee3 / GraphQL Starred Repos with Pagination.md
Last active September 14, 2019 04:22 — forked from obahareth/README.md
GitHub GraphQL API Starred Repositories With Pagination

GitHub GraphQL API Starred Repositories Examples With Pagination

You can play with the GraphQL API live here. It's pretty nice and has autocompletion based on the GraphQL schema.

The first example gets your first 3 starred repos, the cursor values can be used for pagination.

Here's an example response from the first query:

{
<style>
body {
margin: 0;
}
.card {
width: 75px;
border:1px solid #ccc;
background-color: #eaeaea;
height: 75px;
@phoopee3
phoopee3 / anonymous function
Created February 16, 2018 19:37
I want to make an anonymous function that is based off a string i get from a database
// so i have two strings i get from a database, an action, and a callback function name
// let's say the action = 'comment_post', and the function name is 'my_comment_post'
// i want to add an action that is basically add_action( 'comment_post', 'my_comment_post' );
// but i want to do this dynamically for any and all entries i have in the database
// how?
// in my plugin init i had this code, but it wasn't working
// $results->callback would be "my_comment_post"
// $results->hook would be 'comment_post'
function updateUserNicename( $user_id, $posted_field_ids, $errors, $old_values, $new_values )
{
$old_nicename = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' );
if ( empty( $errors ) ) {
// update user_nicename
// field 2 = first name
// field 3 = last name
$new_nicename = $new_values[2]['value'] . '-' . $new_values[3]['value'];
// update user_nicename
@phoopee3
phoopee3 / Buddypress-Group-Check.php
Created January 18, 2018 01:59
Check if a user is part of an existing buddypress group
<?php
// check user against an existing buddypress group
// I needed this in a category.php file to see if
// we were looking at a specific category, and if
// so, check if the user is in a buddypress group
// to ensure they should have access
if ( has_category( 'Some Category') && function_exists( 'groups_is_user_member' ) ) {
$group_id = BP_Groups_Group::group_exists('buddypress-group-slug');
$is_member = groups_is_user_member( wp_get_current_user()->id, $group_id );
if ( !$is_member ) {