Last active
May 11, 2022 04:51
-
-
Save ramiabraham/1a9d8a09e848a677332c28f7271d5f75 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; | |
// 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; |
Hi, please update version. Thank you
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
Doesn't work with v2.8