Skip to content

Instantly share code, notes, and snippets.

@lloc
Last active July 3, 2019 04:43
Show Gist options
  • Save lloc/5f922fc770d818365992 to your computer and use it in GitHub Desktop.
Save lloc/5f922fc770d818365992 to your computer and use it in GitHub Desktop.
Hooks, filters and actions
<?php
/**
* @param string $path
* @return string
*/
function my_msls_admin_icon_get_edit_new( $path ) {
return add_query_arg( array( 'abc' => 'xyz' ), $path );
}
add_filter( 'msls_admin_icon_get_edit_new', 'my_msls_admin_icon_get_edit_new' );
<?php
/**
* @param string $page
* @param string $section
*/
function my_msls_admin_main_section( $page, $section ) {
add_settings_field( 'custom_field', __( 'Custom Field' ), 'custom_field', $page, $section );
}
add_action( 'msls_admin_main_section', 'my_msls_admin_main_section', 10, 2 );
function custom_field() {
printf(
'<input id="custom_field" name="msls[custom_field]" value="%s" size="30"/>',
esc_attr( MslsOptions::instance()->custom_field )
);
}
<?php
/**
* @param string $page
*/
function my_msls_admin_register( $page ) {
add_settings_section( 'custom_section', __( 'Custom Settings' ), 'custom_section', $page );
add_settings_field( 'custom_field', __( 'Custom Field' ), 'custom_field', $page, 'custom_section' );
}
add_action( 'msls_admin_register', 'my_msls_admin_register' );
function custom_section() { }
function custom_field() {
printf(
'<input id="custom_field" name="msls[custom_field]" value="%s" size="30"/>',
esc_attr( MslsOptions::instance()->custom_field )
);
}
<?php
/**
* @param array $arr
* @return array
*/
function my_msls_admin_validate( $arr ) {
$arr['abc'] = ( isset( $arr['abc'] ) ? $arr['abc'] : 'xyz' );
}
add_filter( 'msls_admin_validate', 'my_msls_admin_validate' );
<?php
/**
* @param array $blogs
* @return array
*/
function my_msls_blog_collection_construct( $blogs ) {
if ( isset( $blogs[1] ) ) {
unset( $blogs[1] );
}
return $blogs;
}
add_filter( 'msls_blog_collection_construct', 'my_msls_blog_collection_construct' );
<?php
/**
* @param int $blog_id
* @param string|bool $description
* @return string|bool
*/
function my_msls_blog_collection_description( $blog_id, $description = false ) {
$arr = array( 1 => 'abc', 2 => 'xyz' );
if ( isset( $arr[ $blog_id ] ) ) {
$description = $arr[ $blog_id ];
}
return $description;
}
add_filter( 'msls_blog_collection_description', 'my_msls_blog_collection_description', 10, 2 );
<?php
/**
* @param string $output
* @param array $links
* @return string
*/
function my_msls_filter_string( $output, $links ) {
if ( empty( $links ) ) {
$output = '';
}
else {
$output = sprintf(
'<p>%s</p><ul><li>%s</li></ul>',
__( 'Available Translations' ),
implode( '</li><li>', $links )
);
}
return $output;
}
add_filter( 'msls_filter_string', 'my_msls_filter_string', 10, 2 );
<?php
/**
* @param string $language
* @return string
*/
function my_msls_head_hreflang( $language ) {
if ( 'en' == $language ) {
$language = 'en-gb';
}
return $language;
}
add_filter( 'msls_head_hreflang', 'my_msls_head_hreflang' );
<?php
/**
* @param int $object_id
* @param string $class
*/
function my_msls_main_save( $object_id, $class ) {
// Your code here
}
add_action( 'msls_main_save', 'my_msls_main_save' );
<?php
function my_hide_input_button( $input_button ) {
return '<!-- ' . $input_button . ' -->';
}
add_filter( 'msls_meta_box_render_input_button', 'my_hide_input_button' );
<?php
/**
* @param array $args
* @return array
*/
function my_msls_meta_box_render_select_hierarchical( $args ) {
$args['post_status'] = array( 'publish', 'draft', 'future', 'pending' );
return $args;
}
add_filter( 'msls_meta_box_render_select_hierarchical', 'my_msls_meta_box_render_select_hierarchical' );
<?php
/**
* @param array $args
* @return array
*/
function my_msls_meta_box_suggest_args( $args ) {
$args['posts_per_page'] = 5;
return $args;
}
add_filter( 'msls_meta_box_suggest_args', 'my_msls_meta_box_suggest_args' );
<?php
/**
* @param WP_Post $post
* @return WP_Post
*/
function my_msls_meta_box_suggest_post( $post ) {
$post->post_title .= ' (' . $post->ID . ')';
return $post;
}
add_filter( 'msls_meta_box_suggest_post', 'my_msls_meta_box_suggest_post' );
<?php
/**
* @param array $languages
* @return string
*/
function my_msls_options_get_available_languages( languages ) {
if ( ! isset( $languages['en_GB'] ) ) {
$languages['en_GB'] = 'British English';
}
return $languages;
}
add_filter( 'msls_options_get_available_languages', 'my_msls_options_get_available_languages' );
<?php
/**
* @param string $url
* @return string
*/
function my_msls_options_get_flag_url( $url ) {
return get_stylesheet_directory_uri() . '/images/';
}
add_filter( 'msls_options_get_flag_url', 'my_msls_options_get_flag_url' );
<?php
/**
* @param string $url
* @param MslsLink $link
* @param bool current
* @return string
*/
function my_msls_output_get( $url, $link, $current ) {
return sprintf(
'<a href="%s" title="%s"%s>%s</a>',
$url,
$link->txt,
( $current ? ' class="current"' : '' ),
$link
);
}
add_filter( 'msls_output_get', 'my_msls_output_get', 10, 3 );
<?php
/**
* @param array $tags
* @return array
*/
function my_msls_output_get_tags( $tags ) {
return array(
'before_item' => '<li>',
'after_item' => '</li>',
'before_output' => '<ul>',
'after_output' => '</ul>',
);
}
add_filter( 'msls_output_get_tags', 'my_msls_output_get_tags' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment