/**
  * Wrapper function for the shortcode code.
  * @param $atts array shortcode attributes
  * @param null|string $content shortcode content
  * @return string
  */
 public function handle_shortcode($atts, $content = null)
 {
     if (isset($this->codeItem['capability']) && $this->codeItem['capability'] && !current_user_can($this->codeItem['capability'])) {
         // if a capability is required and the user doesn't have it,
         // then let the short code do nothing.
         return '';
     }
     $buffer = isset($this->codeItem['buffer']) && $this->codeItem['buffer'];
     if ($buffer) {
         ob_start();
     }
     $result = eval($this->codeItem['code']);
     if ($result === FALSE) {
         $url = $this->plugin->getAdminPageUrl() . "&id={$this->codeItem['id']}&action=edit";
         $result = sprintf("<p>%s Plugin: Error in shortcode [<u><a href='%s' target='_blank'>%s</a></u>]</p>", $this->plugin->getPluginDisplayName(), $url, $this->codeItem['name']);
     }
     if ($buffer) {
         $output = ob_get_contents();
         ob_end_clean();
     } else {
         $output = '';
     }
     return $output . $result;
 }
 /**
  * @param $codeItem array
  */
 public function printErrorMessage($codeItem, $msg = null)
 {
     echo '<div style="background-color: white; text-decoration-color: black">';
     echo '<p>&nbsp;</p>';
     // helps prevent header from covering first line of output
     $url = $this->plugin->getAdminPageUrl() . "&id={$codeItem['id']}&action=edit";
     $name = $codeItem['name'] ? $codeItem['name'] : '(unamed)';
     echo '<p>';
     printf("%s Plugin: Error in user-provided code item named \"%s\". ", $this->plugin->getPluginDisplayName(), $name);
     echo '<br/>';
     if ($msg) {
         echo $msg;
         echo '<br/>';
     }
     printf("<u><a href='%s' target='_blank'>%s</a></u>", $url, __('Fix the code here', 'add-actions-and-filters'));
     echo '</p>';
     echo '<p>&nbsp;</p>';
     echo '</div>';
 }
    public function display()
    {
        $optionMetaData = $this->plugin->getOptionMetaData();
        // Save Posted Options
        if ($optionMetaData != null) {
            foreach ($optionMetaData as $aOptionKey => $aOptionMeta) {
                if (isset($_POST[$aOptionKey])) {
                    $this->plugin->updateOption($aOptionKey, $_POST[$aOptionKey]);
                }
            }
        }
        // HTML for the page
        $settingsGroup = get_class($this->plugin) . '-settings-group';
        ?>
        <style type="text/css">
            table.asaf-options-table {
                width: 100%
            }

            table.asaf-options-table tr:nth-child(even) {
                background: #f9f9f9
            }

            table.asaf-options-table tr:nth-child(odd) {
                background: #FFF
            }

            table.asaf-options-table td {
                width: 350px
            }

            table.asaf-options-table td + td {
                width: auto
            }
        </style>
        <div class="wrap">
            <table width="100%">
                <tbody>
                <tr>
                    <td align="left"><h2><?php 
        _e('System Settings', 'add-actions-and-filters');
        ?>
</h2></td>
                    <td align="right">
                        <a href="<?php 
        echo $this->plugin->getAdminPageUrl();
        ?>
">
                        <img width="128" height="50"
                             src="<?php 
        echo $this->plugin->getPluginFileUrl('img/icon-256x100.png');
        ?>
">
                        </a>
                    </td>
                </tr>
                </tbody>
            </table>

            <table class="asaf-options-table">
                <tbody>
                <tr>
                    <td><?php 
        _e('System', 'add-actions-and-filters');
        ?>
</td>
                    <td><?php 
        echo php_uname();
        ?>
</td>
                </tr>
                <tr>
                    <td><?php 
        _e('PHP Version', 'add-actions-and-filters');
        ?>
</td>
                    <td><?php 
        echo phpversion();
        ?>
                        <?php 
        if (version_compare('5.2', phpversion()) > 0) {
            echo '&nbsp;&nbsp;&nbsp;<span style="background-color: #ffcc00;">';
            _e('(WARNING: This plugin may not work properly with versions earlier than PHP 5.2)', 'add-actions-and-filters');
            echo '</span>';
        }
        ?>
                    </td>
                </tr>
                <tr>
                    <td><?php 
        _e('MySQL Version', 'add-actions-and-filters');
        ?>
</td>
                    <td><?php 
        echo $this->getMySqlVersion();
        ?>
                        <?php 
        echo '&nbsp;&nbsp;&nbsp;<span style="background-color: #ffcc00;">';
        if (version_compare('5.0', $this->getMySqlVersion()) > 0) {
            _e('(WARNING: This plugin may not work properly with versions earlier than MySQL 5.0)', 'add-actions-and-filters');
        }
        echo '</span>';
        ?>
                    </td>
                </tr>
                </tbody>
            </table>

            <h2><?php 
        echo $this->plugin->getPluginDisplayName();
        echo ' ';
        _e('Settings', 'add-actions-and-filters');
        ?>
</h2>

            <form method="post" action="">
                <?php 
        settings_fields($settingsGroup);
        ?>
                <table class="asaf-options-table">
                    <tbody>
                    <?php 
        if ($optionMetaData != null) {
            foreach ($optionMetaData as $aOptionKey => $aOptionMeta) {
                $displayText = is_array($aOptionMeta) ? $aOptionMeta[0] : $aOptionMeta;
                ?>
                            <tr valign="top">
                                <th scope="row"><p><label
                                            for="<?php 
                echo $aOptionKey;
                ?>
"><?php 
                echo $displayText;
                ?>
</label></p></th>
                                <td>
                                    <?php 
                $this->createFormControl($aOptionKey, $aOptionMeta, $this->plugin->getOption($aOptionKey));
                ?>
                                </td>
                            </tr>
                            <?php 
            }
        }
        ?>
                    </tbody>
                </table>
                <p class="submit">
                    <input type="submit" class="button-primary"
                           value="<?php 
        _e('Save Settings', 'add-actions-and-filters');
        ?>
"/>
                </p>
            </form>
        </div>
        <?php 
    }