Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress] Templating and Conditional Logic with OOP
<div class="wrap">
<!-- Snipping out irrelevant code in this file -->
<form id="yhd-upload-new-item-settings">
<?php if (!$this->hasSecondaryPlugin()) { ?>
<?php include_once 'partials/error-inactive-plugin.php'; ?>
<?php } else { ?>
<h2>Secondary Plugin Settings</h2>
<p class="description">The Secondary Plugin is installed and active.</p>
<form method="post" action="<?php echo esc_html(admin_url('admin-post.php')); ?>">
<label for="acme-secondary-plugin">
<input type="checkbox" name="acme-secondary-plugin" value="true"/>
Would you like to automatically use the secondary plugin?
</label>
<!-- Snipping out irrelevant code in this file -->
</form>
<?php } ?>
</div>
</div>
<?php
/**
* This is the partial displayed when the Secondary Plugin is not active.
*/
?>
<div id="inactive-importer-message" class="error notice is-dismissible">
<p>[The message you want to display here.]</p>
<button type="button" class="notice-dismiss">
<span class="screen-reader-text">Dismiss this notice.</span>
</button>
</div><!-- #inactive-importer-message -->
<?php
/**
* Determines if the Secondary Importer is is activated.
*
* @return bool True if the the pklugin is active; false, otherwise.
*/
private function hasSecondaryPlugin()
{
return in_array(
'secondary-plugin/secondary-plugin.php',
get_option('active_plugins')
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.