Forked from ramiabraham/affwp_custom_meta_box_example.php
Last active
August 7, 2019 09:41
-
-
Save gmatta01/416e48f2ebb708b0112cae933db80874 to your computer and use it in GitHub Desktop.
AffWP Custom Meta Box Example
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: 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; | |
use AffWP\Admin\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-meta-box-base.php'; | |
class Custom_Meta_Box_Example extends Meta_Box implements Meta_Box\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`. | |
* Example on Reports page, Referrals tab: "affwp_reports_tab_referrals" | |
* 'affwp_reports_tab_' . $active_tab | |
* | |
* | |
* 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->action = "affwp_overview_meta_boxes"; // default | |
$this->context = 'secondary'; // Options are `primary`,`secondary`, or `tertiary`. | |
} | |
/** | |
* 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment