/** * Adds help tabs to the plugin pages. * * @since 1.0.0 * @access public */ public function add_help_tabs() { $screen = get_current_screen(); if (!in_array($screen->id, auto_load_next_post_get_screen_ids())) { return; } $screen->add_help_tab(array('id' => 'auto_load_next_post_docs_tab', 'title' => __('Documentation', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), 'content' => '<p>' . sprintf(__('Thank you for using <strong>%s</strong> :) Should you need help using or extending %s please read the documentation.', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), Auto_Load_Next_Post()->name, Auto_Load_Next_Post()->name) . '</p>' . '<p><a href="' . Auto_Load_Next_Post()->doc_url . '" class="button button-primary">' . sprintf(__('%s Documentation', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), Auto_Load_Next_Post()->name) . '</a></p>')); $screen->add_help_tab(array('id' => 'auto_load_next_post_support_tab', 'title' => __('Support', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), 'content' => '<p>' . sprintf(__('After <a href="%s">reading the documentation</a>, for further assistance you can use the <a href="%s">community forum</a>.', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), Auto_Load_Next_Post()->doc_url, Auto_Load_Next_Post()->wp_plugin_support_url) . '</p>' . '<p><a href="' . Auto_Load_Next_Post()->wp_plugin_support_url . '" class="button button-primary">' . __('Community Support', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN) . '</a></p>')); $screen->add_help_tab(array('id' => 'auto_load_next_post_bugs_tab', 'title' => __('Found a bug?', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), 'content' => '<p>' . sprintf(__('If you find a bug within <strong>%s</strong> you can create a ticket via <a href="%s">Github issues</a>. Ensure you read the <a href="%s">contribution guide</a> prior to submitting your report. Be as descriptive as possible. Thank you.', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), Auto_Load_Next_Post()->name, AUTO_LOAD_NEXT_POST_GITHUB_REPO_URI . 'issues?state=open', AUTO_LOAD_NEXT_POST_GITHUB_REPO_URI . 'blob/master/CONTRIBUTING.md') . '</p>' . '<p><a href="' . AUTO_LOAD_NEXT_POST_GITHUB_REPO_URI . 'issues?state=open" class="button button-primary">' . __('Report a bug', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN) . '</a></p>')); $screen->set_help_sidebar('<p><strong>' . __('For more information:', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN) . '</strong></p>' . '<p><a href="' . Auto_Load_Next_Post()->web_url . '" target="_blank">' . sprintf(__('About %s', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), Auto_Load_Next_Post()->name) . '</a></p>' . '<p><a href="' . Auto_Load_Next_Post()->wp_plugin_url . '" target="_blank">' . __('Project on WordPress.org', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN) . '</a></p>' . '<p><a href="' . AUTO_LOAD_NEXT_POST_GITHUB_REPO_URI . '" target="_blank">' . __('Project on Github', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN) . '</a></p>'); }
/** * Add admin notices and styles when needed. * * @since 1.3.2 * @access public */ public function add_notices() { $template = get_option('template'); if (!current_theme_supports('auto-load-next-post')) { if (!empty($_GET['hide_auto_load_next_post_theme_support_check'])) { update_option('auto_load_next_post_theme_support_check', $template); return; } if (get_option('auto_load_next_post_theme_support_check') !== $template) { wp_enqueue_style('auto-load-next-post-activation', Auto_Load_Next_Post()->plugin_url() . '/assets/css/admin/activation.css'); add_action('admin_notices', array($this, 'theme_check_notice')); } } }
/** * When the 'partial' endpoint is used on a post, retrieve only the post content. **/ function auto_load_next_post_template_redirect() { global $wp_query; // if this is not a request for partial or a singular object then bail if (!isset($wp_query->query_vars['partial']) || !is_singular()) { return; } // Load file from theme if one exists. $template_path = get_stylesheet_directory() . '/' . Auto_Load_Next_Post()->template_path(); if (file_exists($template_path . 'content-partial.php')) { include $template_path . 'content-partial.php'; } // If theme does not have the file, load default from plugin. $default_path = Auto_Load_Next_Post()->plugin_path(); if (file_exists($default_path . '/template/content-partial.php')) { include $default_path . '/template/content-partial.php'; } exit; }
/** * Add menu items. * * @since 1.0.0 * @access public * @global $menu * @global $auto_load_next_post * @global $wp_version */ public function admin_menu() { global $menu, $auto_load_next_post, $wp_version; add_options_page(sprintf(__('%s Settings', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), Auto_Load_Next_Post()->title_name), 'Auto Load Next Post', Auto_Load_Next_Post()->manage_plugin, 'auto-load-next-post-settings', array($this, 'settings_page')); register_setting('auto_load_next_post_status_settings_fields', 'auto_load_next_post_status_options'); }
$url = $this->plugin_url() . $file_path; $file = $this->plugin_path() . $file_path; if (file_exists($file)) { if ($is_script) { wp_register_script($name, $url, $support, $version); wp_enqueue_script($name); } else { wp_register_style($name, $url); wp_enqueue_style($name); } // end if } // end if } } // END Auto_Load_Next_Post() } // END class_exists('Auto_Load_Next_Post') /** * Returns the instance of Auto_Load_Next_Post to prevent the need to use globals. * * @since 1.0.0 * @return Auto Load Next Post */ function Auto_Load_Next_Post() { return Auto_Load_Next_Post::instance(); } // Run Plugin Auto_Load_Next_Post();
<?php /** * Admin View: Settings */ if (!defined('ABSPATH')) { exit; } // Exit if accessed directly. ?> <div class="wrap auto-load-next-post"> <form method="post" id="mainform" action="" enctype="multipart/form-data"> <h2 class="nav-tab-wrapper"> <?php echo Auto_Load_Next_Post()->name; ?> <?php foreach ($tabs as $name => $label) { echo '<a href="' . admin_url('options-general.php?page=' . 'auto-load-next-post-settings&tab=' . $name) . '" class="nav-tab ' . ($current_tab == $name ? 'nav-tab-active' : '') . '">' . $label . '</a>'; } do_action('auto_load_next_post_settings_tabs'); ?> </h2> <?php do_action('auto_load_next_post_sections_' . $current_tab); do_action('auto_load_next_post_settings_' . $current_tab); ?> <p class="submit"> <?php if (!isset($GLOBALS['hide_save_button'])) { ?>
/** * Output admin fields. * * Loops though the plugin name options array and outputs each field. * * @since 1.0.0 * @access public static * @param array $options Opens array to output */ public static function output_fields($options) { foreach ($options as $value) { if (!isset($value['type'])) { continue; } if (!isset($value['id'])) { $value['id'] = ''; } if (!isset($value['title'])) { $value['title'] = isset($value['name']) ? $value['name'] : ''; } if (!isset($value['class'])) { $value['class'] = ''; } if (!isset($value['css'])) { $value['css'] = ''; } if (!isset($value['default'])) { $value['default'] = ''; } if (!isset($value['desc'])) { $value['desc'] = ''; } if (!isset($value['desc_tip'])) { $value['desc_tip'] = false; } // Custom attribute handling $custom_attributes = array(); if (!empty($value['custom_attributes']) && is_array($value['custom_attributes'])) { foreach ($value['custom_attributes'] as $attribute => $attribute_value) { $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($attribute_value) . '"'; } } // Description handling if ($value['desc_tip'] === true) { $description = ''; $tip = $value['desc']; } else { if (!empty($value['desc_tip'])) { $description = $value['desc']; $tip = $value['desc_tip']; } else { if (!empty($value['desc'])) { $description = $value['desc']; $tip = ''; } else { $description = $tip = ''; } } } if ($description && in_array($value['type'], array('textarea', 'radio'))) { $description = '<p style="margin-top:0">' . wp_kses_post($description) . '</p>'; } else { if ($description) { $description = '<span class="description">' . wp_kses_post($description) . '</span>'; } } if ($tip && in_array($value['type'], array('checkbox'))) { $tip = '<p class="description">' . $tip . '</p>'; } else { if ($tip) { $tip = '<img class="help_tip" data-tip="' . esc_attr($tip) . '" src="' . Auto_Load_Next_Post()->plugin_url() . '/assets/images/help.png" height="16" width="16" />'; } } // Switch based on type switch ($value['type']) { // Section Titles case 'title': if (!empty($value['title'])) { echo '<h3>' . esc_html($value['title']) . '</h3>'; } if (!empty($value['desc'])) { echo wpautop(wptexturize(wp_kses_post($value['desc']))); } echo '<table class="form-table">' . "\n\n"; if (!empty($value['id'])) { do_action('auto_load_next_post_settings_' . sanitize_title($value['id'])); } break; // Section Ends // Section Ends case 'sectionend': if (!empty($value['id'])) { do_action('auto_load_next_post_settings_' . sanitize_title($value['id']) . '_end'); } echo '</table>'; if (!empty($value['id'])) { do_action('auto_load_next_post_settings_' . sanitize_title($value['id']) . '_after'); } break; // Standard text inputs and subtypes like 'number' // Standard text inputs and subtypes like 'number' case 'text': case 'email': case 'number': case 'color': case 'password': $type = $value['type']; $class = ''; $option_value = self::get_option($value['id'], $value['default']); if ($value['type'] == 'color') { $type = 'text'; $value['class'] .= 'colorpick'; $description .= '<div id="colorPickerDiv_' . esc_attr($value['id']) . '" class="colorpickdiv" style="z-index:100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>'; } ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <input name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($value['id']); ?> " type="<?php echo esc_attr($type); ?> " style="<?php echo esc_attr($value['css']); ?> " value="<?php echo esc_attr($option_value); ?> " class="<?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> /> <?php echo $description; ?> </td> </tr><?php break; // Textarea // Textarea case 'textarea': $option_value = self::get_option($value['id'], $value['default']); ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <?php echo $description; ?> <textarea name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($value['id']); ?> " style="<?php echo esc_attr($value['css']); ?> " class="<?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> ><?php echo esc_textarea($option_value); ?> </textarea> </td> </tr><?php break; // Select boxes // Select boxes case 'select': case 'multiselect': $option_value = self::get_option($value['id'], $value['default']); ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <select name="<?php echo esc_attr($value['id']); if ($value['type'] == 'multiselect') { echo '[]'; } ?> " id="<?php echo esc_attr($value['id']); ?> " style="<?php echo esc_attr($value['css']); ?> " class="<?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> <?php if ($value['type'] == 'multiselect') { echo 'multiple="multiple"'; } ?> > <?php foreach ($value['options'] as $key => $val) { ?> <option value="<?php echo esc_attr($key); ?> " <?php if (is_array($option_value)) { selected(in_array($key, $option_value), true); } else { selected($option_value, $key); } ?> ><?php echo $val; ?> </option> <?php } ?> </select> <?php echo $description; ?> </td> </tr><?php break; // Radio inputs // Radio inputs case 'radio': $option_value = self::get_option($value['id'], $value['default']); ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <fieldset> <?php echo $description; ?> <ul> <?php foreach ($value['options'] as $key => $val) { ?> <li> <label><input name="<?php echo esc_attr($value['id']); ?> " value="<?php echo $key; ?> " type="radio" style="<?php echo esc_attr($value['css']); ?> " class="<?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> <?php checked($key, $option_value); ?> /> <?php echo $val; ?> </label> </li> <?php } ?> </ul> </fieldset> </td> </tr><?php break; // Checkbox input // Checkbox input case 'checkbox': $option_value = self::get_option($value['id'], $value['default']); if (!isset($value['hide_if_checked'])) { $value['hide_if_checked'] = false; } if (!isset($value['show_if_checked'])) { $value['show_if_checked'] = false; } if (!isset($value['checkboxgroup']) || isset($value['checkboxgroup']) && $value['checkboxgroup'] == 'start') { ?> <tr valign="top" class="<?php if ($value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes') { echo 'hidden_option'; } if ($value['hide_if_checked'] == 'option') { echo 'hide_options_if_checked'; } if ($value['show_if_checked'] == 'option') { echo 'show_options_if_checked'; } ?> "> <th scope="row" class="titledesc"><?php echo esc_html($value['title']); ?> </th> <td class="forminp forminp-checkbox"> <fieldset> <?php } else { ?> <fieldset class="<?php if ($value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes') { echo 'hidden_option'; } if ($value['hide_if_checked'] == 'option') { echo 'hide_options_if_checked'; } if ($value['show_if_checked'] == 'option') { echo 'show_options_if_checked'; } ?> "> <?php } ?> <legend class="screen-reader-text"><span><?php echo esc_html($value['title']); ?> </span></legend> <label for="<?php echo $value['id']; ?> "> <input name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($value['id']); ?> " type="checkbox" value="1" <?php checked($option_value, 'yes'); ?> <?php echo implode(' ', $custom_attributes); ?> /> <?php echo wp_kses_post($value['desc']); ?> </label> <?php echo $tip; ?> <?php if (!isset($value['checkboxgroup']) || isset($value['checkboxgroup']) && $value['checkboxgroup'] == 'end') { ?> </fieldset> </td> </tr> <?php } else { ?> </fieldset> <?php } break; // Image width settings // Image width settings case 'image_width': $width = self::get_option($value['id']['width'], $value['default']['width']); $height = self::get_option($value['id']['height'], $value['default']['height']); $crop = checked(1, self::get_option($value['id']['crop'], $value['default']['crop']), false); ?> <tr valign="top"> <th scope="row" class="titledesc"><?php echo esc_html($value['title']); ?> <?php echo $tip; ?> </th> <td class="forminp image_width_settings"> <input name="<?php echo esc_attr($value['id']); ?> [width]" id="<?php echo esc_attr($value['id']); ?> -width" type="text" size="3" value="<?php echo $width; ?> " /> × <input name="<?php echo esc_attr($value['id']); ?> [height]" id="<?php echo esc_attr($value['id']); ?> -height" type="text" size="3" value="<?php echo $height; ?> " />px <label><input name="<?php echo esc_attr($value['id']); ?> [crop]" id="<?php echo esc_attr($value['id']); ?> -crop" type="checkbox" <?php echo $crop; ?> /> <?php _e('Hard Crop?', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN); ?> </label> </td> </tr><?php break; // Single page selects // Single page selects case 'single_select_page': $args = array('name' => $value['id'], 'id' => $value['id'], 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'show_option_none' => ' ', 'class' => $value['class'], 'echo' => false, 'selected' => absint(self::get_option($value['id']))); if (isset($value['args'])) { $args = wp_parse_args($value['args'], $args); } ?> <tr valign="top" class="single_select_page"> <th scope="row" class="titledesc"><?php echo esc_html($value['title']); ?> <?php echo $tip; ?> </th> <td class="forminp"> <?php echo str_replace(' id=', " data-placeholder='" . __('Select a page…', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN) . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages($args)); ?> <?php echo $description; ?> </td> </tr><?php break; // Default: run an action // Default: run an action default: do_action('auto_load_next_post_admin_field_' . $value['type'], $value); break; } // end switch } }
/** * Install Auto Load Next Post * * @since 1.0.0 * @access public */ public function install() { $this->create_options(); // Add plugin version update_option('auto_load_next_post_version', Auto_Load_Next_Post()->version); }
/** * Filters the update footer by placing details * of the plugin and links to contribute or * report issues with the plugin when viewing any * of the plugin pages. * * @since 1.0.0 * @access public * @param $text * @filter auto_load_next_post_update_footer_links * @return string $text */ public function update_footer($text) { $screen = get_current_screen(); if (in_array($screen->id, auto_load_next_post_get_screen_ids())) { $text = '<span class="wrap">'; $links = apply_filters('auto_load_next_post_update_footer_links', array(AUTO_LOAD_NEXT_POST_GITHUB_REPO_URI . 'blob/master/CONTRIBUTING.md?utm_source=wpadmin&utm_campaign=footer' => __('Contribute', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), AUTO_LOAD_NEXT_POST_GITHUB_REPO_URI . 'issues?state=open&utm_source=wpadmin&utm_campaign=footer' => __('Report Bugs', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN))); foreach ($links as $key => $value) { $text .= '<a target="_blank" class="add-new-h2" href="' . $key . '">' . $value . '</a>'; } $text .= '</span>' . '</p>' . '<p class="alignright">' . sprintf(__('%s Version', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN), Auto_Load_Next_Post()->name) . ' : ' . esc_attr(Auto_Load_Next_Post()->version) . '</p>'; return $text; } return $text; }
<?php /** * Admin View: Admin Theme Notice */ if (!defined('ABSPATH')) { exit; } // Exit if accessed directly ?> <div id="message" class="updated auto-load-next-post-message"> <p><?php _e(sprintf('<strong>The theme you are using has not declared support for %s</strong> – please read the integration guide.', Auto_Load_Next_Post()->name), AUTO_LOAD_NEXT_POST_TEXT_DOMAIN); ?> </p> <p class="submit"><a href="<?php echo esc_url(Auto_Load_Next_Post()->doc_url . 'Supporting-your-theme'); ?> " class="button-primary"><?php _e('Supporting your theme', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN); ?> </a> <a class="skip button-primary" href="<?php echo esc_url(add_query_arg('hide_auto_load_next_post_theme_support_check', 'true')); ?> "><?php _e('Hide this notice', AUTO_LOAD_NEXT_POST_TEXT_DOMAIN); ?> </a></p> </div>