Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created January 30, 2018 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/fe4cbdc9eb5e6409fb4f9e3e1784f97d to your computer and use it in GitHub Desktop.
Save tommcfarlin/fe4cbdc9eb5e6409fb4f9e3e1784f97d to your computer and use it in GitHub Desktop.
[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