init(); } } add_action('plugins_loaded', 'add_anchor_links_plugin_init', 99); /** * Add settings link * * @since 1.0.0 * @param array $links Array of setting links. * @return array */ function add_anchor_links_plugin_action_links($links) { $action_links = [ 'settings' => '' . esc_html__('Settings', 'add-anchor-links') . '', ]; return array_merge($action_links, $links); } /** * Load scripts and styles * * @since 1.0.0 * @since 1.0.1 ADD_ANCHOR_LINKS_DONT_LOAD_CSS */ function add_anchor_links_scripts() { // Don't load scripts if disabled by settings or by constant. global $add_anchor_links_options; if (defined('ADD_ANCHOR_LINKS_DONT_LOAD_CSS') && ADD_ANCHOR_LINKS_DONT_LOAD_CSS || $add_anchor_links_options['own_css']) { return; } if (is_singular(add_anchor_links_post_types(true))) { wp_enqueue_style('add-anchor-links-style', ADD_ANCHOR_LINKS_URL . 'assets/css/add-anchor-links.css', [], ADD_ANCHOR_LINKS_VERSION); } } /** * Default options * * @since 1.0.0 * @return array */ function add_anchor_links_options_defaults() { $default_options = [ 'own_css' => false, 'post_types' => false, ]; $post_types = add_anchor_links_post_types(); foreach ($post_types as $pt) { $default_options[$pt] = false; } return $default_options; } /** * Get post types where the All is enabled * * @since 1.0.0 * @param bool $active Active. * @return array $post_types */ function add_anchor_links_post_types($active = false) { $post_types = get_post_types([ 'public' => true, ]); if ($active) { global $add_anchor_links_options; $_post_types = $post_types; $post_types = []; foreach ($_post_types as $pt) { if (isset($add_anchor_links_options[$pt]) && $add_anchor_links_options[$pt]) { $post_types[] = $pt; } } } return $post_types; } /** * Runs only when the plugin is activated. * * @since 1.0.1 * @return void */ function add_anchor_links_activation_hook() { // Create transient data. set_transient('aal-admin-notice-activation', true, 5); } register_activation_hook(__FILE__, 'add_anchor_links_activation_hook'); /** * Admin Notice on Activation. * * @since 1.0.1 * @return void */ function add_anchor_links_admin_notice_activation() { /* Check transient, if available display notice */ if (get_transient('aal-admin-notice-activation')) { ?>
', '', ''); ?>