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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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, | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
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:
{
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
body { | |
margin: 0; | |
} | |
.card { | |
width: 75px; | |
border:1px solid #ccc; | |
background-color: #eaeaea; | |
height: 75px; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) { |
NewerOlder