| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Site Plugin for danix.xyz |
| 4 | Description: Site specific code changes for danix.xyz |
| 5 | Plugin URI: https://danix.xyz |
| 6 | Version: 0.7 |
| 7 | Author: Danilo 'danix' Macri |
| 8 | Author URI: https://danix.xyz |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * Disable admin bar sitewide |
| 13 | */ |
| 14 | show_admin_bar(__return_false()); |
| 15 | |
| 16 | /** |
| 17 | * Allow Shortcodes inside the html widget |
| 18 | */ |
| 19 | //add_filter( 'widget_text', 'do_shortcode' ); |
| 20 | |
| 21 | /** |
| 22 | * make sure the links menu in the admin is visible |
| 23 | */ |
| 24 | add_filter( 'pre_option_link_manager_enabled', '__return_true' ); |
| 25 | |
| 26 | /** |
| 27 | * The gravatar shortcode |
| 28 | * |
| 29 | * @param email $email email address used to retrieve the gravatar image |
| 30 | * @return string HTML the image tag which will display the gravatar image. |
| 31 | * |
| 32 | */ |
| 33 | function danix_gravatar( $atts ) { |
| 34 | extract(shortcode_atts(array( |
| 35 | 'email' => '', |
| 36 | 'size' => '200', |
| 37 | 'default' => '', |
| 38 | 'alt' => '' |
| 39 | ), $atts)); |
| 40 | |
| 41 | if( empty($email) ) |
| 42 | return ''; |
| 43 | |
| 44 | $output = get_avatar($email, $size, $default, $alt); |
| 45 | |
| 46 | return $output; |
| 47 | } |
| 48 | add_shortcode('gravatar', 'danix_gravatar'); |
| 49 | |
| 50 | /** |
| 51 | * The download button shortcode |
| 52 | * |
| 53 | * @param url $link link address. |
| 54 | * @param string $linkname text that will be displayed by the button. |
| 55 | * @return string HTML the link tag that will be rendered to the page. |
| 56 | * |
| 57 | */ |
| 58 | function danix_download_button( $atts ) { |
| 59 | extract(shortcode_atts(array( |
| 60 | 'link' => '', |
| 61 | 'linkname' => '' |
| 62 | ), $atts)); |
| 63 | |
| 64 | if ( empty($link) ) |
| 65 | return ''; |
| 66 | |
| 67 | $output = sprintf( |
| 68 | '<a href="%s" class="download_button">%s</a>', |
| 69 | $link, |
| 70 | $linkname |
| 71 | ); |
| 72 | |
| 73 | return $output; |
| 74 | } |
| 75 | add_shortcode('download', 'danix_download_button'); |
| 76 | |
| 77 | /** |
| 78 | * The google analytics code |
| 79 | * |
| 80 | */ |
| 81 | function danix_google_anal() { |
| 82 | if ( function_exists('cn_cookies_accepted') && cn_cookies_accepted() ) { ?> |
| 83 | <!-- Global site tag (gtag.js) - Google Analytics --> |
| 84 | <script async src="https://www.googletagmanager.com/gtag/js?id=UA-23882460-1"></script> |
| 85 | <script> |
| 86 | window.dataLayer = window.dataLayer || []; |
| 87 | function gtag(){dataLayer.push(arguments);} |
| 88 | gtag('js', new Date()); |
| 89 | |
| 90 | gtag('config', 'UA-23882460-1'); |
| 91 | </script> |
| 92 | <?php } |
| 93 | } |
| 94 | add_action('wp_head', 'danix_google_anal', 10); |
| 95 | |
| 96 | /** |
| 97 | * The googlemaps shortcode |
| 98 | * |
| 99 | * @param width the width of the returned map |
| 100 | * @param height the height of the returned map |
| 101 | * @param src the url of the map you want to display |
| 102 | * @return string HTML the map object |
| 103 | * @since 0.57 |
| 104 | * |
| 105 | */ |
| 106 | function danix_gmaps($atts, $content = null) { |
| 107 | extract(shortcode_atts(array( |
| 108 | "width" => '640', |
| 109 | "height" => '480', |
| 110 | "src" => '' |
| 111 | ), $atts)); |
| 112 | return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&output=embed" ></iframe>'; |
| 113 | } |
| 114 | add_shortcode("googlemaps", "danix_gmaps"); |
| 115 | |
| 116 | /** |
| 117 | * Add Next Page / Page Break button |
| 118 | * inside the WordPress Visual Editor |
| 119 | * |
| 120 | * @link https://shellcreeper.com/?p=889 |
| 121 | * @since 0.9.7 |
| 122 | * |
| 123 | */ |
| 124 | function danix_next_page_button( $buttons, $id ) { |
| 125 | |
| 126 | /* only add this for content editor */ |
| 127 | if ( 'content' != $id ) |
| 128 | return $buttons; |
| 129 | |
| 130 | /* add next page after more tag button */ |
| 131 | array_splice( $buttons, 13, 0, 'wp_page' ); |
| 132 | |
| 133 | return $buttons; |
| 134 | } |
| 135 | /* Add Next Page Button on the First Row */ |
| 136 | add_filter( 'mce_buttons', 'danix_next_page_button', 1, 2 ); // 1st row |