Skip to content

Instantly share code, notes, and snippets.

@ramiabraham
Last active May 11, 2022 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ramiabraham/1a9d8a09e848a677332c28f7271d5f75 to your computer and use it in GitHub Desktop.
Save ramiabraham/1a9d8a09e848a677332c28f7271d5f75 to your computer and use it in GitHub Desktop.
AffWP Custom Meta Box Example
<?php
/**
* Plugin Name: AffWP Custom Meta Box Example
* Plugin URI: https://affiliatewp.com
* Description: AffWP Custom Meta Box Example
* Author: AffiliateWP, LLC
* Author URI: https://affiliatewp.com
* Version: 1.0
* Text Domain: affwp-custom-meta-box-example
* */
namespace AffWP\Meta_Box;
// Exit if the AffiliateWP plugin directory constant is not defined.
if ( ! defined( 'AFFILIATEWP_PLUGIN_DIR' ) && ! empty( AFFILIATEWP_PLUGIN_DIR ) ) {
$msg = __( "The AffiliateWP constant 'AFFILIATEWP_PLUGIN_DIR' must be defined." );
error_log( $msg );
$notice = '<div class="notice notice-error is-dismissible">';
$notice .= '<p>';
$notice .= $msg;
$notice .= '</p>';
$notice .= '</div>';
echo $notice;
return;
}
require_once AFFILIATEWP_PLUGIN_DIR . 'includes/admin/class-metabox-base.php';
class Custom_Meta_Box_Example extends Base {
/**
* Define the name and id of the custom AffiliateWP meta box here.
*
* Optionally, you may define:
*
* $this->action: The AffiliateWP action on which the meta box loads.
* Defaults to the Overview page action, `affwp_overview_meta_boxes`.
*
* Note that a corresponding `do_metaboxes()` must be called at the
* location where this action fires in order for the meta box to show.
*
* $this->context: Define the context here. Defaults to `primary`.
* Options are `primary`,`secondary`, or `tertiary`.
*/
public function init() {
$this->meta_box_name = __( 'Custom AffWP Meta Box Example', 'affiliate-wp' );
$this->meta_box_id = 'affwp_custom_meta_box_example';
// Optional
$this->context = 'secondary';
}
/**
* Define the content of the custom AffiliateWP metabox here.
*/
public function content() {
$this->my_meta_box_content();
}
public function my_meta_box_content() {
_e( 'Here is some content I\'d like to share with AffiliateWP users!', 'affiliate-wp' );
}
}
new Custom_Meta_Box_Example;
@yatix100
Copy link

Doesn't work with v2.8

@rseales
Copy link

rseales commented May 11, 2022

Hi, please update version. Thank you

@rseales
Copy link

rseales commented May 11, 2022

please, update a new version. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment