Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / before_save.php
Last active February 21, 2024 21:34
How to Limit BuddyPress Activity Messages | https://www.ibenic.com/limit-buddypress-activity-messages
<?php
// .../wp-content/plugins/buddypress/bp-activity/classes/class-bp-activity-activity.php
// ...
/**
* Database interaction class for the BuddyPress activity component.
* Instance methods are available for creating/editing an activity,
* static methods for querying activities.
@igorbenic
igorbenic / answer.js
Last active February 21, 2024 21:34
Building a Quiz with React and WordPress REST API: Question and Answer Components | https://www.ibenic.com/quiz-react-wordpress-question-answer-components
import React, { Component } from 'react';
class Answer extends Component {
constructor(){
super();
// Binding handleChange to 'this'
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
// Using the passed method setAnswer to set the answer.
@igorbenic
igorbenic / plugin-2.php
Last active February 21, 2024 21:34
How to create a Custom WooCommerce Product Type | https://www.ibenic.com/custom-woocommerce-product-type
<?php
// ...
class WC_Product_Type_Plugin {
/**
* Build the instance
*/
public function __construct() {
@igorbenic
igorbenic / abstract-1.php
Last active February 21, 2024 21:34
How to build WordPress Settings API as Framework | ibenic.com
<?php
namespace MySettingsFramework;
abstract class Settings {
/**
* Setting ID. Prefixes all options.
* @var string
*/
/**
* ReactDOM v15.3.0
*
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
@igorbenic
igorbenic / enqueue.php
Last active February 21, 2024 21:32
Building a Quiz with React and WordPress REST API: React WP Scripts Tool | https://www.ibenic.com/quiz-wordpress-rest-api-react-scripts-tool
<?php
class WPQR {
/**
* Enqueue Public Scripts
* @return void
*/
public function enqueue() {
if ( is_singular( array( 'post', 'page' ) ) ) {
global $post;
@igorbenic
igorbenic / installer.php
Last active February 21, 2024 21:32
Upgrade Process Example in WordPress
<?php
/**
* This class can be used as an installer class to install tables and such.
* And it can be also used to make updates.
*/
class My_Plugin_Installer() {
/**
* Update functions for versions.
@igorbenic
igorbenic / code.php
Last active February 21, 2024 21:32
How to create WordPress Metaboxes with OOP
<?php
class IBenic_WordPress_Metabox extends WordPressSettings {
protected $title = '';
protected $slug = '';
protected $post_types = array();
@igorbenic
igorbenic / abstract.php
Last active February 21, 2024 21:32
How to add custom WordPress Profile Fields
<?php
abstract class WordPressSettings {
/**
* ID of the settings
* @var string
*/
public $settings_id = '';
/**
* Tabs for the settings page
@igorbenic
igorbenic / example.php
Last active February 21, 2024 21:32
Taxonomy Rewrite Example
<?php
function rewriting_resources($wp_rewrite) {
$rules = array();
$terms = get_terms( array(
'taxonomy' => 'resource_type',
'hide_empty' => false,
) );
$post_type = 'resources';