Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a check for PMPro constant before querying the data. #10

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 52 additions & 31 deletions admin/class-convertkit-pmp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,39 +110,48 @@ public function register_settings() {
$this->plugin_name
);

// Get all PMP membership levels
$levels = $this->get_pmp_membership_levels();
if ( defined( 'PMPRO_VERSION' ) ) {
// Get all PMP membership levels
$levels = $this->get_pmp_membership_levels();

// Get all tags from ConvertKit
$tags = $this->api->get_tags();
// Get all tags from ConvertKit
$tags = $this->api->get_tags();

// No PMP mappings created yet
if ( empty ( $levels ) ){
// No PMP mappings created yet
if ( empty ( $levels ) ) {

add_settings_field(
'convertkit-empty-mapping',
apply_filters( $this->plugin_name . '-display-convertkit-mapping', __( 'Mapping', 'convertkit-pmp' ) ),
array( $this, 'display_options_empty_mapping' ),
$this->plugin_name,
$this->plugin_name . '-ck-mapping'
);
} else {
foreach ( $levels as $key => $name ) {

add_settings_field(
'convertkit-mapping-' . $key,
apply_filters( $this->plugin_name . '-display-convertkit-mapping-' . $key, $name ),
array( $this, 'display_options_convertkit_mapping' ),
$this->plugin_name,
$this->plugin_name . '-ck-mapping',
array(
'key' => $key,
'name' => $name,
'tags' => $tags,
)
);
}
}
} else {
add_settings_field(
'convertkit-empty-mapping',
apply_filters( $this->plugin_name . '-display-convertkit-mapping', __( 'Mapping', 'convertkit-pmp' ) ),
array( $this, 'display_options_empty_mapping' ),
array( $this, 'plugin_not_active' ),
$this->plugin_name,
$this->plugin_name . '-ck-mapping'
);

} else {
foreach( $levels as $key => $name ) {

add_settings_field(
'convertkit-mapping-' . $key,
apply_filters( $this->plugin_name . '-display-convertkit-mapping-' . $key , $name ),
array( $this, 'display_options_convertkit_mapping' ),
$this->plugin_name,
$this->plugin_name . '-ck-mapping',
array( 'key' => $key,
'name' => $name,
'tags' => $tags,
)
);
}

}

}
Expand Down Expand Up @@ -173,12 +182,13 @@ public function add_menu() {
* @return void
*/
public function options_page() {
?><div class="wrap"><h1><?php echo esc_html( get_admin_page_title() ); ?></h1></div>
<form action="options.php" method="post"><?php
settings_fields( 'convertkit-pmp-options' );
do_settings_sections( $this->plugin_name );
submit_button( 'Save Settings' );
?></form><?php
?>
<div class="wrap"><h1><?php echo esc_html( get_admin_page_title() ); ?></h1></div>
<form action="options.php" method="post"><?php
settings_fields( 'convertkit-pmp-options' );
do_settings_sections( $this->plugin_name );
submit_button( 'Save Settings' );
?></form><?php
}


Expand Down Expand Up @@ -264,6 +274,18 @@ public function display_options_empty_mapping() {
<?php
}

/**
* PMPro plugin not active.
*
* @since 1.0.3
* @return mixed The settings field
*/
public function plugin_not_active() {
?>
<p><?php echo __( 'The PMPro plugin is not active.', 'converkit-pmp'); ?></p>
<?php
}


/**
* Display mapping for the specified key.
Expand Down Expand Up @@ -309,7 +331,6 @@ public function display_options_convertkit_mapping( $args ) {
* @return array
*/
public function get_pmp_membership_levels(){

global $wpdb;

$sqlQuery = "SELECT * FROM $wpdb->pmpro_membership_levels ";
Expand Down