_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q256800
Papi_Property_String.get_value
test
public function get_value() { $value = $this->format_value( parent::get_value(), $this->get_slug(), papi_get_post_id() ); return $this->get_setting( 'allow_html' ) ? $value : esc_html( $value ); }
php
{ "resource": "" }
q256801
Papi_Core_Data_Handler.decode_property
test
protected function decode_property( $key, $value ) { if ( papi_is_property_type_key( $key ) && is_string( $value ) ) { $value = base64_decode( $value ); $value = papi_maybe_json_decode( $value ); } return $value; }
php
{ "resource": "" }
q256802
Papi_Core_Data_Handler.get_post_data
test
protected function get_post_data( $pattern = '/^papi\_.*/' ) { $data = []; $keys = preg_grep( $pattern, array_keys( $_POST ) ); foreach ( $keys as $key ) { // Remove page type keys with suffix. This should not be saved. if ( strpos( $key, papi_get_page_type_key() ) === 0 && strlen( papi_get_page_type_key() ) !== strlen( $key ) ) { continue; } // Fix for input fields that should be true on `on` value. if ( $_POST[$key] === 'on' ) { $data[$key] = true; } else { $value = $this->decode_property( $key, $_POST[$key] ); $data[$key] = $this->prepare_post_data( $value ); $data[$key] = $this->santize_data( $data[$key] ); } } // Don't wont to save meta nonce field. if ( isset( $data['papi_meta_nonce'] ) ) { unset( $data['papi_meta_nonce'] ); } return $data; }
php
{ "resource": "" }
q256803
Papi_Core_Data_Handler.get_pre_deep_keys_value
test
protected function get_pre_deep_keys_value( array $arr ) { $keys = []; $value = null; foreach ( $arr as $key => $v ) { if ( is_array( $v ) ) { $keys[] = $key; list( $ks, $val ) = $this->get_pre_deep_keys_value( $v ); $keys = array_merge( $keys, $ks ); $value = $val; } else { $keys[] = $key; $value = $v; } } return [$keys, $value]; }
php
{ "resource": "" }
q256804
Papi_Core_Data_Handler.prepare_post_data
test
protected function prepare_post_data( $data ) { if ( ! is_array( $data ) ) { return $data; } foreach ( $data as $key => $value ) { if ( is_array( $value ) ) { $data[$key] = $this->prepare_post_data( $value ); } else { $data[$key] = $this->decode_property( $key, $value ); } } return $data; }
php
{ "resource": "" }
q256805
Papi_Core_Data_Handler.prepare_properties_data
test
protected function prepare_properties_data( array $data = [], $post_id = 0 ) { // Since we are storing witch property it is in the `$data` array // we need to remove that and set the property type to the property // and make a array of the property type and the value. foreach ( $data as $key => $value ) { if ( papi_is_property_type_key( $key ) ) { continue; } $property_type_key = papify( papi_get_property_type_key( $key ) ); // Check if value exists. if ( ! isset( $data[$key] ) || ! isset( $data[$property_type_key] ) ) { continue; } // Pair property value with property type object. $data[$key] = [ 'type' => $data[$property_type_key], 'value' => $value ]; // Remove property type object since it's not needed anymore. unset( $data[$property_type_key] ); } foreach ( $data as $key => $item ) { if ( papi_is_property_type_key( $key ) ) { if ( isset( $data[$key] ) ) { unset( $data[$key] ); } continue; } if ( empty( $item['type'] ) ) { continue; } $property = papi_get_property_type( $item['type'] ); unset( $data[ $key ] ); if ( papi_is_property( $property ) ) { // Run `update_value` method on the property class. $data[$key] = $property->update_value( $item['value'], unpapify( $key ), $post_id ); // Apply `update_value` filter so this can be changed from // the theme for specified property type. $data[$key] = papi_filter_update_value( $item['type']->type, $data[$key], unpapify( $key ), $post_id, papi_get_meta_type() ); if ( $item['type']->overwrite ) { $slug = unpapify( $key ); $this->overwrite[$slug] = $data[$key]; unset( $data[$key] ); } } } return $data; }
php
{ "resource": "" }
q256806
Papi_Core_Data_Handler.santize_data
test
protected function santize_data( $value ) { if ( is_array( $value ) ) { foreach ( $value as $k => $v ) { if ( is_string( $v ) ) { $value[$k] = $this->santize_data( $v ); } } } else if ( is_string( $value ) ) { $value = wp_unslash( $value ); } return $value; }
php
{ "resource": "" }
q256807
Papi_Core_Data.delete
test
public function delete( $id, $slug ) { $fn = $this->get_function( 'delete' ); // Check so the function is callable before using it. if ( ! is_callable( $fn ) ) { return false; } // Delete cached value. papi_cache_delete( $slug, $id, $this->type ); if ( $this->id ) { return call_user_func_array( $fn, [$this->type, $id, unpapify( $slug )] ); } return call_user_func_array( $fn, [unpapify( $slug )] ); }
php
{ "resource": "" }
q256808
Papi_Core_Data.get_function
test
public function get_function( $context = 'get' ) { switch ( $this->type ) { case 'option': return sprintf( '%s_option', $context ); case 'site': case 'network': return sprintf( '%s_site_option', $context ); case 'post': case 'term': return sprintf( '%s_metadata', $context ); default: break; } }
php
{ "resource": "" }
q256809
Papi_Core_Data.get
test
public function get( $id, $slug ) { $fn = $this->get_function( 'get' ); if ( ! is_callable( $fn ) ) { return; } if ( $this->id ) { $value = call_user_func_array( $fn, [$this->type, $id, unpapify( $slug ), true] ); } else { $value = call_user_func_array( $fn, [unpapify( $slug ), null] ); } if ( papi_is_empty( $value ) ) { return; } return $value; }
php
{ "resource": "" }
q256810
Papi_Core_Data.update
test
public function update( $id, $slug, $value ) { $save_value = true; // Get right update function to use. $fn = $this->get_function( 'update' ); if ( ! is_callable( $fn ) ) { return false; } // Check for string keys in the array if any. foreach ( array_keys( papi_to_array( $value ) ) as $key ) { if ( is_string( $key ) ) { $save_value = false; break; } } // If main value shouldn't be saved it should be array. if ( ! $save_value && is_array( $value ) ) { $value = [$value]; } // Delete saved value if empty. if ( papi_is_empty( $value ) ) { return $this->delete( $id, $slug ); } $result = true; foreach ( papi_to_array( $value ) as $key => $val ) { // Delete saved value if value is empty. if ( papi_is_empty( $val ) || $val === '[]' || $val === '{}' ) { return $this->delete( $id, $slug ); } // Delete main value cache. papi_cache_delete( $slug, $id, $this->type ); // If not a array we can save the value. if ( ! is_array( $val ) ) { if ( $save_value ) { $val = $value; } if ( $this->id ) { $out = call_user_func_array( $fn, [$this->type, $id, unpapify( $slug ), $val] ); $result = $out ? $result : $out; } else { $out = call_user_func_array( $fn, [unpapify( $slug ), $val] ); $result = $out ? $result : $out; } continue; } // Clear cache for all child values. $this->update_clear_cache( $id, $value ); // Update metadata or option value for all child values. foreach ( $val as $child_key => $child_value ) { if ( papi_is_empty( $child_value ) ) { $this->delete( $id, $child_key ); } else { if ( $this->id ) { call_user_func_array( $fn, [$this->type, $id, unpapify( $child_key ), $child_value] ); } else { call_user_func_array( $fn, [unpapify( $child_key ), $child_value] ); } } } } return $result; }
php
{ "resource": "" }
q256811
Papi_Core_Data.update_clear_cache
test
public function update_clear_cache( $id, $value ) { $value = is_array( $value ) ? $value : []; foreach ( $value as $child_key => $child_value ) { papi_cache_delete( $child_key, $id, $this->type ); if ( is_array( $child_value ) ) { $this->update_clear_cache( $id, $child_value ); } } }
php
{ "resource": "" }
q256812
Papi_Admin_Entry_Post.get_revision_ui_diff
test
public function get_revision_ui_diff( $return, $compare_from, $compare_to ) { $meta = get_post_meta( $compare_from->ID ); $meta = is_array( $meta ) ? $meta : []; foreach ( $meta as $key => $value ) { if ( $key[0] === '_' && $key !== papi_get_page_type_key() ) { continue; } $content_from = papi_data_get( $compare_from->ID, $key ); $content_to = papi_data_get( $compare_to->ID, $key ); $diff = wp_text_diff( $content_from, $content_to, [ 'show_split_view' => true ] ); if ( $diff ) { $return[] = [ 'id' => $key, 'name' => $key, 'diff' => $diff, ]; } } return $return; }
php
{ "resource": "" }
q256813
Papi_Admin_Entry_Post.hidden_meta_boxes
test
public function hidden_meta_boxes() { global $_wp_post_type_features; if ( isset( $_wp_post_type_features[$this->post_type]['editor'] ) ) { return; } add_meta_box( 'papi-hidden-editor', 'Papi hidden editor', [$this, 'hidden_meta_box_editor'], $this->post_type ); }
php
{ "resource": "" }
q256814
Papi_Admin_Entry_Post.load_post_new
test
public function load_post_new() { $request_uri = $_SERVER['REQUEST_URI']; $post_types = papi_get_post_types(); if ( in_array( $this->post_type, $post_types, true ) && strpos( $request_uri, 'page_type=' ) === false ) { $parsed_url = parse_url( $request_uri ); $only_page_type = papi_filter_settings_only_page_type( $this->post_type ); $page_types = papi_get_all_page_types( $this->post_type ); $show_standard = false; if ( count( $page_types ) === 1 && empty( $only_page_type ) ) { $show_standard = $page_types[0]->standard_type; $show_standard = $show_standard ? papi_filter_settings_show_standard_page_type( $this->post_type ) : $show_standard; $only_page_type = $show_standard ? '' : $page_types[0]->get_id(); } // Check if we should show one post type or not and // create the right url for that. if ( ! empty( $only_page_type ) && ! $show_standard ) { $url = papi_get_page_new_url( $only_page_type, false ); } else { $page = 'page=papi-add-new-page,' . $this->post_type; if ( $this->post_type !== 'post' ) { $page = '&' . $page; } $url = 'edit.php?' . $parsed_url['query'] . $page; } wp_safe_redirect( $url ); papi_is_admin() && exit; } }
php
{ "resource": "" }
q256815
Papi_Admin_Entry_Post.redirect_post_location
test
public function redirect_post_location( $location ) { if ( ! isset( $_SERVER['HTTP_REFERER'] ) ) { return $location; } $referer = $_SERVER['HTTP_REFERER']; $referer = strtolower( $referer ); if ( strpos( $referer, 'papi-iframe-mode' ) === false ) { return $location; } return sprintf( '%s&papi_css[]=papi-iframe-mode', $location ); }
php
{ "resource": "" }
q256816
Papi_Admin_Entry_Post.setup
test
public function setup() { // Preload all page types. foreach ( papi_get_post_types() as $post_type ) { papi_get_all_entry_types( [ 'args' => $post_type ] ); } return ! in_array( $this->post_type, ['revision', 'nav_menu_item'], true ); }
php
{ "resource": "" }
q256817
Papi_CLI_Post_Command.rename
test
public function rename( $args, $assoc_args ) { $type = $args[0]; $old_key = $args[1]; $new_key = $args[2]; $posts = ( new Papi_Query( [ 'entry_type' => $type, 'fields' => 'ids' ] ) )->get_result(); if ( empty( $posts ) ) { WP_CLI::error( 'No posts found' ); } foreach ( $posts as $post ) { $meta = get_post_meta( $post, $old_key, true ); if ( papi_is_empty( $meta ) ) { continue; } if ( delete_post_meta( $post, $old_key ) === false ) { WP_CLI::error( 'Could not delete post meta with key: ' . $old_key ); } if ( update_post_meta( $post, $new_key, $meta ) === false ) { WP_CLI::error( 'Could not update post meta with key: ' . $new_key ); } } WP_CLI::success( 'Done' ); }
php
{ "resource": "" }
q256818
Papi_Core_Conditional_Rule.get_field_slug
test
public function get_field_slug() { if ( preg_match( '/\[|\]/', $this->slug ) ) { $slug = preg_replace( '/\[|\]/', '.', $this->slug ); $slug = str_replace( '..', '.', $slug ); return substr( $slug, 0, -1 ); } return $this->slug; }
php
{ "resource": "" }
q256819
Papi_Core_Conditional_Rule.get_source
test
public function get_source() { if ( is_callable( $this->source ) ) { return call_user_func_array( $this->source, [$this->slug] ); } if ( is_string( $this->source ) && strpos( $this->source, '#' ) !== false ) { $source = explode( '#', $this->source ); if ( empty( $source[0] ) || empty( $source[1] ) ) { return $this->source; } $source[0] = new $source[0](); if ( method_exists( $source[0], $source[1] ) ) { return call_user_func_array( $source, [$this->slug] ); } return; } return $this->source; }
php
{ "resource": "" }
q256820
Papi_Core_Conditional_Rule.setup_source
test
public function setup_source( $value ) { if ( is_array( $value ) && count( $value ) === 2 && is_object( $value[0] ) && is_string( $value[1] ) ) { return sprintf( '%s#%s', get_class( $value[0] ), $value[1] ); } if ( is_string( $value ) && is_callable( $value ) ) { return $value; } // No support for closure. if ( is_object( $value ) && $value instanceof Closure ) { return ''; } return $value; }
php
{ "resource": "" }
q256821
Papi_Core_Conditional_Rule.setup
test
protected function setup( array $rule ) { foreach ( $rule as $key => $value ) { if ( $key === 'operator' ) { $value = strtoupper( $value ); $value = html_entity_decode( $value ); } else if ( $key === 'slug' ) { $value = papify( $value ); } else if ( $key === 'source' ) { $value = $this->setup_source( $value ); } $this->$key = $value; } }
php
{ "resource": "" }
q256822
Papi_Admin.admin_init
test
public function admin_init() { $meta_type = papi_get_meta_type(); $meta_type = ucfirst( $meta_type ); $class_name = 'Papi_Admin_Entry_' . $meta_type; // A custom class is not required, e.g // options don't have one. if ( class_exists( $class_name ) ) { $class = call_user_func( [$class_name, 'instance'] ); if ( ! $class->setup() ) { return; } } // Setup entry type. if ( $entry_type = $this->get_entry_type() ) { $entry_type->setup(); } }
php
{ "resource": "" }
q256823
Papi_Admin.admin_body_class
test
public function admin_body_class( $classes ) { if ( $entry_type = $this->get_entry_type() ) { $classes .= sprintf( ' papi-body papi-meta-type-%s', papi_get_meta_type() ); // Add custom css classes from entry type. $arr = $entry_type->get_body_classes(); $arr = is_string( $arr ) ? [ $arr ] : $arr; $arr = is_array( $arr ) ? $arr : []; $classes .= ' ' . implode( ' ', $arr ); } // Add custom css classes from query string. if ( $css = papi_get_qs( 'papi_css' ) ) { $css = is_array( $css ) ? $css : []; $css = array_map( 'sanitize_text_field', $css ); $classes .= ' ' . implode( ' ', $css ); } return $classes; }
php
{ "resource": "" }
q256824
Papi_Admin.edit_form_after_title
test
public function edit_form_after_title() { wp_nonce_field( 'papi_save_data', 'papi_meta_nonce' ); if ( $value = esc_attr( papi_get_entry_type_id() ) ) { papi_render_html_tag( 'input', [ 'data-papi-page-type-key' => true, 'name' => esc_attr( papi_get_page_type_key() ), 'type' => 'hidden', 'value' => $value ] ); } }
php
{ "resource": "" }
q256825
Papi_Admin.get_entry_type
test
protected function get_entry_type() { if ( $this->entry_type instanceof Papi_Entry_Type ) { return $this->entry_type; } $entry_type_id = papi_get_entry_type_id(); // If the entry type id is empty try to load // the entry type id from `page` query string. // // Example: // /wp-admin/options-general.php?page=papi/option/site-option-type if ( empty( $entry_type_id ) ) { $entry_type_id = preg_replace( '/^papi\/\w+\//', '', papi_get_qs( 'page' ) ); } // Use the default entry type id if empty. if ( empty( $entry_type_id ) ) { $entry_type_id = papi_get_entry_type_id(); } // If no entry type id exists Papi can't setup a entry type. if ( empty( $entry_type_id ) ) { return false; } $entry_type = papi_get_entry_type_by_id( $entry_type_id ); if ( $entry_type instanceof Papi_Entry_Type === false ) { return false; } $this->entry_type = $entry_type; return $entry_type; }
php
{ "resource": "" }
q256826
Papi_Admin.plugin_row_meta
test
public function plugin_row_meta( array $links, $file ) { if ( $file === PAPI_PLUGIN_BASENAME ) { return array_merge( $links, [ 'docs' => '<a href="' . esc_url( 'https://wp-papi.github.io/docs/' ) . '" title="' . esc_attr( __( 'View Papi Documentation', 'papi' ) ) . '">' . __( 'Docs', 'papi' ) . '</a>', ] ); } return $links; }
php
{ "resource": "" }
q256827
Papi_Admin.update_front_page
test
public function update_front_page( $value, $option ) { if ( $option !== 'page_on_front' ) { return $value; } $front_pages = papi_get_all_entry_types( [ 'types' => ['front-page'], ] ); if ( count( $front_pages ) === 0 ) { return $value; } $old_page_type_id = papi_get_page_type_id( $value ); $new_page_type_id = $front_pages[0]->get_id(); // Delete all old fields from old page type if any. if ( strtolower( $old_page_type_id ) !== strtolower( $new_page_type_id ) ) { if ( $page_type = papi_get_entry_type_by_id( $old_page_type_id ) ) { $slugs = array_map( function( $property ) { return $property->get_slug( true ); }, $page_type->get_properties() ); foreach ( $slugs as $slug ) { papi_delete_field( $value, $slug ); } } } papi_set_page_type_id( $value, $new_page_type_id ); return $value; }
php
{ "resource": "" }
q256828
Papi_Admin.wp_link_query
test
public function wp_link_query( array $results ) { foreach ( $results as $index => $value ) { $post_type = papi_get_post_type( $value['ID'] ); $name = papi_get_page_type_name( $value['ID'] ); if ( empty( $name ) ) { $name = papi_filter_settings_standard_page_type_name( $post_type ); } $results[$index]['info'] = esc_html( $name ); } return $results; }
php
{ "resource": "" }
q256829
Papi_Property_Module.get_templates
test
protected function get_templates( $id ) { if ( empty( $id ) && ! is_numeric( $id ) ) { return []; } if ( $data = papi_get_entry_type_by_meta_id( $id ) ) { $templates = papi_to_array( $data->template ); ksort( $templates ); return $templates; } return []; }
php
{ "resource": "" }
q256830
Papi_Post_Store.prepare_load_value
test
protected function prepare_load_value( Papi_Core_Property $property, $value ) { if ( $property->overwrite ) { // Clear post cache to solve issue with cached post objects // when selecting post field. clean_post_cache( $this->id ); $slug = $property->get_slug( true ); $context = papi_is_admin() ? 'edit' : 'display'; $value = get_post_field( $slug, $this->id, $context ); } return $value; }
php
{ "resource": "" }
q256831
Papi_Admin_Option_Handler.save_properties
test
public function save_properties() { if ( $_SERVER ['REQUEST_METHOD'] !== 'POST' || papi_get_meta_type() !== 'option' ) { return; } // Check if our nonce is vailed. if ( ! wp_verify_nonce( papi_get_sanitized_post( 'papi_meta_nonce' ), 'papi_save_data' ) ) { return; } // Get properties data. $data = $this->get_post_data(); // Prepare properties data. $data = $this->prepare_properties_data( $data, 0 ); foreach ( $data as $key => $value ) { papi_data_update( 0, $key, $value, 'option' ); } /** * Fire `save_properties` action when all is done. * * @param int $id * @param string $meta_type */ do_action( 'papi/save_properties', 0, 'option' ); }
php
{ "resource": "" }
q256832
Papi_Admin_Page_Type_Switcher.metabox
test
public function metabox() { $post_type = papi_get_post_type(); $page_type = papi_get_entry_type_by_id( papi_get_page_type_id() ); $page_type_key = papi_get_page_type_key( 'switch' ); $page_types = papi_get_all_page_types( $post_type ); $show_standard = papi_filter_settings_show_standard_page_type( $post_type ); if ( $show_standard ) { $standard_page_type = papi_get_standard_page_type( $post_type ); $page_types[] = $standard_page_type; if ( empty( $page_type ) ) { $page_type = $standard_page_type; } } usort( $page_types, function ( $a, $b ) { return strcmp( $a->name, $b->name ); } ); $page_types = papi_sort_order( array_reverse( $page_types ) ); // Don't do anything without any page types. if ( empty( $page_type ) || empty( $page_types ) ) { return; } ?> <div class="misc-pub-section misc-pub-section-last papi-page-type-switcher"> <label for="<?php echo esc_attr( $page_type_key ); ?>"><?php esc_html_e( 'Page Type:', 'papi' ); ?></label> <span><?php echo esc_html( $page_type->name ); ?></span> <?php if ( papi_current_user_is_allowed( $page_type->capabilities ) && $page_type->switcher ): ?> <a href="#" id="papi-page-type-switcher-edit" class="hide-if-no-js"><?php esc_html_e( 'Edit', 'papi' ); ?></a> <div> <select name="<?php echo esc_attr( $page_type_key ); ?>" id="<?php echo esc_attr( $page_type_key ); ?>"> <?php foreach ( $page_types as $pt ) { if ( ! papi_current_user_is_allowed( $pt->capabilities ) ) { continue; } papi_render_html_tag( 'option', [ 'selected' => $page_type->match_id( $pt->get_id() ), 'value' => esc_attr( $pt->get_id() ), esc_html( $pt->name ) ] ); } ?> </select> <a href="#" id="papi-page-type-switcher-save" class="hide-if-no-js button"><?php esc_html_e( 'OK', 'papi' ); ?></a> <a href="#" id="papi-page-type-switcher-cancel" class="hide-if-no-js"><?php esc_html_e( 'Cancel', 'papi' ); ?></a> </div> <?php endif; ?> </div> <?php }
php
{ "resource": "" }
q256833
Papi_Admin_Page_Type_Switcher.save_post
test
public function save_post( $post_id, $post ) { // Check if post id and post object is empty or not. if ( empty( $post_id ) || empty( $post ) ) { return false; } // Check if our nonce is vailed. if ( ! wp_verify_nonce( papi_get_sanitized_post( 'papi_meta_nonce' ), 'papi_save_data' ) ) { return false; } // Check if so both page type keys exists. if ( empty( $_POST[papi_get_page_type_key()] ) || empty( $_POST[papi_get_page_type_key( 'switch' )] ) ) { return false; } // Page type information. $page_type_id = sanitize_text_field( $_POST[papi_get_page_type_key()] ); $page_type_switch_id = sanitize_text_field( $_POST[papi_get_page_type_key( 'switch' )] ); // Don't update if the same ids. if ( $page_type_id === $page_type_switch_id ) { return false; } // Fetch right page type if standard page type id. if ( papi_get_standard_page_type_id( $post->post_type ) === $page_type_id ) { $page_type = papi_get_standard_page_type( $post->post_type ); } else { $page_type = papi_get_entry_type_by_id( $page_type_id ); } // Fetch right page type switch if standard page type id. if ( papi_get_standard_page_type_id( $post->post_type ) === $page_type_switch_id ) { $page_type_switch = papi_get_standard_page_type( $post->post_type ); $page_type_switch_id = ''; } else { $page_type_switch = papi_get_entry_type_by_id( $page_type_switch_id ); } $post_type_object = get_post_type_object( $post->post_type ); // Check if page type and post type is not empty. if ( empty( $page_type_switch ) || empty( $post_type_object ) ) { return false; } // Check if autosave. if ( wp_is_post_autosave( $post_id ) ) { return false; } // Check if revision. if ( wp_is_post_revision( $post_id ) ) { return false; } // Check if revision post type. if ( in_array( $post->post_type, ['revision', 'nav_menu_item'], true ) ) { return false; } // Check so page type has the post type. if ( ! $page_type->has_post_type( $post->post_type ) || ! $page_type_switch->has_post_type( $post->post_type ) ) { return false; } // Check page type capabilities. if ( ! papi_current_user_is_allowed( $page_type_switch->capabilities ) ) { return false; } // Check so user can edit posts and that the user can publish posts on the post type. if ( ! current_user_can( 'edit_post', $post_id ) || ! current_user_can( $post_type_object->cap->publish_posts ) ) { return false; } // Get properties. $properties = $page_type->get_properties(); $properties_switch = $page_type_switch->get_properties(); // Delete only properties that don't have the same type and slug. foreach ( $properties as $property ) { $delete = true; // Check if the properties are the same or not. foreach ( $properties_switch as $property_switch ) { if ( $property_switch->type === $property->type && $property_switch->match_slug( $property->get_slug() ) ) { $delete = false; break; } } if ( ! $delete ) { continue; } // Delete property values. $property->delete_value( $property->get_slug( true ), $post_id, papi_get_meta_type() ); } // Delete page type switch id. if ( empty( $page_type_switch_id ) ) { return delete_post_meta( $post_id, papi_get_page_type_key() ); } // Update page type id. return papi_set_page_type_id( $post_id, $page_type_switch_id ); }
php
{ "resource": "" }
q256834
Papi_Admin_Meta_Handler.overwrite_post_data
test
protected function overwrite_post_data( $post_id ) { global $wpdb; if ( empty( $post_id ) || empty( $this->overwrite ) ) { return; } $wpdb->update( $wpdb->posts, $this->overwrite, [ 'ID' => $post_id ] ); // Delete cache since it can be cached even if not saved in the database. foreach ( array_keys( $this->overwrite ) as $key ) { papi_cache_delete( $key, $post_id ); } clean_post_cache( $post_id ); }
php
{ "resource": "" }
q256835
Papi_Admin_Meta_Handler.pre_save
test
protected function pre_save( $id ) { if ( empty( $id ) ) { return; } $data = $this->get_pre_data(); foreach ( $data as $key => $value ) { if ( empty( $value ) ) { continue; } if ( is_array( $value ) ) { list( $keys, $value ) = $this->get_pre_deep_keys_value( $value ); $key = sprintf( '%s_%s', $key, implode( '_', $keys ) ); } update_metadata( $this->get_meta_type(), $id, $key, $value ); } }
php
{ "resource": "" }
q256836
Papi_Admin_Meta_Handler.save_meta_boxes
test
public function save_meta_boxes( $id, $post = null ) { // Check if there was a multisite switch before. if ( is_multisite() && ms_is_switched() ) { return; } // Can't proceed without a id. if ( empty( $id ) ) { return; } // Check if our nonce is vailed. if ( ! wp_verify_nonce( papi_get_sanitized_post( 'papi_meta_nonce' ), 'papi_save_data' ) ) { return; } $meta_type = $this->get_meta_type(); $post = is_array( $post ) ? (object) $post : $post; if ( $meta_type === 'post' && $post_type = get_post_type_object( $post->post_type ) ) { // Check so the id is a post id and not a autosave post. if ( ! $this->valid_post_id( $id ) ) { return; } // Check the `edit_posts` capability before we continue. if ( ! current_user_can( $post_type->cap->edit_posts ) ) { return; } // Delete all oEmbed caches. if ( class_exists( 'WP_Embed' ) ) { global $wp_embed; if ( $wp_embed instanceof WP_Embed ) { $wp_embed->delete_oembed_caches( $id ); } } } if ( $meta_type === 'term' && $taxonomy = get_taxonomy( papi_get_taxonomy() ) ) { // Check the `edit_terms` capability before we continue. if ( $taxonomy && ! current_user_can( $taxonomy->cap->edit_terms ) ) { return; } } $this->save_properties( $id ); }
php
{ "resource": "" }
q256837
Papi_Admin_Meta_Handler.save_revision
test
public function save_revision( $revision_id ) { // Check if our nonce is vailed. if ( ! wp_verify_nonce( papi_get_sanitized_post( 'papi_meta_nonce' ), 'papi_save_data' ) ) { return; } // Fetch parent id from revision. if ( ! $parent_id = wp_is_post_revision( $revision_id ) ) { return; } // Bail if a entry type don't exists on parent post. if ( papi_is_empty( papi_get_entry_type_by_meta_id( $parent_id, 'post' ) ) ) { return; } $meta = get_post_meta( $parent_id ); foreach ( $meta as $key => $value ) { if ( $key[0] === '_' && $key !== papi_get_page_type_key() ) { continue; } papi_data_update( $revision_id, $key, array_shift( $value ) ); } }
php
{ "resource": "" }
q256838
Papi_Admin_Meta_Handler.save_properties
test
public function save_properties( $id ) { // Pre save page template, page type and some others dynamic values. $this->pre_save( $id ); // Get properties data. $data = $this->get_post_data(); // Prepare properties data. $data = $this->prepare_properties_data( $data, $id ); // Get meta type. $meta_type = $this->get_meta_type(); // Overwrite post data if any. if ( $meta_type === 'post' ) { $this->overwrite_post_data( $id ); } // Save all properties value foreach ( $data as $key => $value ) { papi_data_update( $id, $key, $value, $this->get_meta_type() ); } /** * Fire `save_properties` action when all is done. * * @param int $id * @param string $meta_type */ do_action( 'papi/save_properties', $id, $meta_type ); }
php
{ "resource": "" }
q256839
Papi_Admin_Meta_Handler.restore_post_revision
test
public function restore_post_revision( $post_id, $revision_id ) { if ( papi_is_empty( papi_get_entry_type_by_meta_id( $post_id, 'post' ) ) ) { return; } $meta = get_post_meta( $revision_id ); foreach ( $meta as $key => $value ) { if ( $key[0] === '_' && $key !== papi_get_page_type_key() ) { continue; } papi_data_update( $post_id, $key, array_shift( $value ) ); } }
php
{ "resource": "" }
q256840
Papi_Admin_Meta_Handler.valid_post_id
test
protected function valid_post_id( $post_id ) { $key = papi_get_sanitized_post( 'action' ) === 'save-attachment-compat' ? 'id' : 'post_ID'; $val = papi_get_sanitized_post( $key ); // When autosave is in place the post id is located deeper in the post data array, the ids should not match. if ( isset( $_POST['data']['wp_autosave'], $_POST['data']['wp_autosave']['post_id'] ) ) { // But if it's a auto draft the ids should match. if ( isset( $_POST['data']['wp_autosave']['auto_draft'] ) && ! empty( $_POST['data']['wp_autosave']['auto_draft'] ) ) { return sanitize_text_field( $_POST['data']['wp_autosave']['post_id'] ) === strval( $post_id ); } return sanitize_text_field( $_POST['data']['wp_autosave']['post_id'] ) !== strval( $post_id ); } // Should not be the same id when `wp-preview` equals `dopreview`. if ( isset( $_POST['wp-preview'] ) && strtolower( $_POST['wp-preview'] ) === 'dopreview' ) { return $val !== strval( $post_id ); } return $val === strval( $post_id ); }
php
{ "resource": "" }
q256841
Papi_Core_Conditional.display
test
public function display( array $rules, $property = null ) { if ( empty( $rules ) ) { return true; } $rules = $this->prepare_rules( $rules, $property ); if ( in_array( $rules['relation'], $this->relations, true ) ) { return $this->display_by_relation( $rules ); } return true; }
php
{ "resource": "" }
q256842
Papi_Core_Conditional.display_by_relation
test
protected function display_by_relation( array $rules ) { if ( $rules['relation'] === 'AND' ) { $display = true; foreach ( $rules as $rule ) { if ( ! $display ) { break; } if ( papi_is_rule( $rule ) ) { /** * Modify rule allowed. * * @param bool $result * @param Papi_Core_Conditional_Rule $rule * * @return bool */ $display = apply_filters( 'papi/conditional/rule_allowed', papi_filter_conditional_rule_allowed( $rule ), $rule ); } } return $display; } $empty = array_filter( $rules, function ( $rule ) { return papi_is_rule( $rule ) ? true : null; } ); if ( empty( $empty ) ) { return true; } $result = []; foreach ( $rules as $rule ) { if ( papi_is_rule( $rule ) ) { /** * Modify rule allowed. * * @param bool $result * @param Papi_Core_Conditional_Rule $rule * * @return bool */ $result[] = apply_filters( 'papi/conditional/rule_allowed', papi_filter_conditional_rule_allowed( $rule ), $rule ); } } $result = array_filter( $result, function ( $res ) { return $res === true ? true : null; } ); return ! empty( $result ); }
php
{ "resource": "" }
q256843
Papi_Core_Conditional.get_rule_slug
test
protected function get_rule_slug( $rule, $property ) { $arr_reg = '/\[\d+\](\[\w+\])$/'; $slug = $property->get_slug(); $page_type = papi_get_entry_type_by_meta_id(); if ( $page_type instanceof Papi_Page_Type === false ) { return $rule->slug; } if ( preg_match( $arr_reg, $slug, $out ) ) { $slug = str_replace( $out[1], '[' . unpapify( $rule->slug ) . ']', $slug ); $property = $page_type->get_property( $slug ); if ( papi_is_property( $property ) ) { return $slug; } } return $rule->slug; }
php
{ "resource": "" }
q256844
Papi_Core_Conditional.prepare_rules
test
public function prepare_rules( array $rules, $property = null ) { if ( ! isset( $rules['relation'] ) ) { $rules['relation'] = 'OR'; } else { $rules['relation'] = strtoupper( $rules['relation'] ); } foreach ( $rules as $index => $value ) { if ( is_string( $index ) ) { continue; } if ( is_array( $value ) ) { $rules[$index] = new Papi_Core_Conditional_Rule( $value ); if ( strpos( $rules[$index]->slug, '.' ) === false && papi_is_property( $property ) ) { $rules[$index]->slug = $this->get_rule_slug( $rules[$index], $property ); } } } return $rules; }
php
{ "resource": "" }
q256845
Papi_Page_Type.allowed
test
public function allowed() { $args = func_get_args(); if ( empty( $args ) ) { return parent::allowed(); } return papi_current_user_is_allowed( $this->capabilities ) && isset( $args[0] ) && in_array( $args[0], $this->post_type, true ); }
php
{ "resource": "" }
q256846
Papi_Page_Type.get_body_classes
test
public function get_body_classes() { $classes = parent::get_body_classes(); if ( ! $this->show_permalink ) { $classes[] = 'papi-hide-edit-slug-box'; } if ( ! $this->show_page_attributes ) { $classes[] = 'papi-hide-pageparentdiv'; } return $classes; }
php
{ "resource": "" }
q256847
Papi_Page_Type.get_child_types
test
public function get_child_types() { $child_types = []; foreach ( papi_to_array( $this->child_types ) as $id ) { $child_type = papi_get_entry_type_by_id( $id ); if ( $child_type instanceof Papi_Page_Type ) { $child_types[] = $child_type; } } return $child_types; }
php
{ "resource": "" }
q256848
Papi_Page_Type.get_labels
test
public function get_labels() { if ( ! $this->fill_labels ) { return $this->labels; } return array_merge( $this->labels, [ 'add_new_item' => sprintf( '%s %s', __( 'Add New', 'papi' ), $this->name ), 'edit_item' => sprintf( '%s %s', __( 'Edit', 'papi' ), $this->name ), 'view_item' => sprintf( '%s %s', __( 'View', 'papi' ), $this->name ) ] ); }
php
{ "resource": "" }
q256849
Papi_Page_Type.get_post_type_supports
test
protected function get_post_type_supports() { $supports = ['custom-fields']; if ( method_exists( $this, 'remove' ) ) { $output = $this->remove(); $output = is_string( $output ) ? [$output] : $output; $output = is_array( $output ) ? $output : []; $output = array_filter( $output, 'is_string' ); $supports = array_merge( $supports, $output ); } $parent_class = get_parent_class( $this ); $parent_remove = method_exists( $parent_class, 'remove' ); while ( $parent_remove ) { $parent = new $parent_class(); $output = $parent->remove(); $output = is_string( $output ) ? [$output] : $output; $output = is_array( $output ) ? $output : []; $output = array_filter( $output, 'is_string' ); $supports = array_merge( $supports, $output ); $parent_class = get_parent_class( $parent_class ); $parent_remove = method_exists( $parent_class, 'remove' ); } return $supports; }
php
{ "resource": "" }
q256850
Papi_Page_Type.remove_post_type_support
test
public function remove_post_type_support() { global $_wp_post_type_features; $post_type = $this->get_post_type(); if ( empty( $post_type ) ) { return; } $post_type_supports = $this->get_post_type_supports(); foreach ( $post_type_supports as $key => $value ) { if ( is_numeric( $key ) ) { $key = $value; $value = ''; } if ( isset( $_wp_post_type_features[$post_type], $_wp_post_type_features[$post_type][$key] ) ) { unset( $_wp_post_type_features[$post_type][$key] ); continue; } if ( in_array( strtolower( $key ), ['all', 'normal', 'side', 'advanced'], true ) ) { $value = strtolower( $key ); } else if ( empty( $value ) ) { $value = 'normal'; } $this->remove_meta_boxes[] = [$key, $value]; } add_action( 'add_meta_boxes', [$this, 'remove_meta_boxes'], 999 ); }
php
{ "resource": "" }
q256851
Papi_Page_Type.remove_meta_boxes
test
public function remove_meta_boxes() { global $wp_meta_boxes; $post_type = $this->get_post_type(); $context = []; foreach ( $this->remove_meta_boxes as $item ) { if ( $item[0] !== $item[1] ) { remove_meta_box( $item[0], $post_type, $item[1] ); continue; } $context = $item[0]; // Our special context. if ( $context === 'all' ) { $context = ['normal', 'side', 'advanced']; } else { $context = [strtolower( $context )]; } foreach ( $context as $ctx ) { if ( ! isset( $wp_meta_boxes[$post_type], $wp_meta_boxes[$post_type][$ctx] ) ) { continue; } $meta_boxes = $wp_meta_boxes[$post_type][$ctx]; if ( ! is_array( $meta_boxes ) ) { continue; } foreach ( $meta_boxes as $level ) { foreach ( $level as $id => $box ) { // Don't allow removing of papi boxes. if ( strpos( $id, '_papi' ) !== false ) { continue; } // Don't allow removing of submitdiv. if ( $id === 'submitdiv' ) { continue; } remove_meta_box( $id, $post_type, $ctx ); } } } } // Special for editor in normal context. if ( in_array( 'normal', $context, true ) ) { remove_post_type_support( 'page', 'editor' ); } }
php
{ "resource": "" }
q256852
Papi_Page_Type.setup
test
public function setup() { parent::setup(); // Remove post type support and meta boxes. $this->remove_post_type_support(); // Add support for displaying information in publish box from a page type. if ( method_exists( $this, 'publish_box' ) ) { add_action( 'post_submitbox_misc_actions', [$this, 'publish_box'] ); } // Hide page template dropdown if it shouldn't be showed. if ( ! $this->show_page_template ) { add_filter( 'theme_page_templates', '__return_empty_array' ); } // Main title input placeholder. if ( ! empty( $this->labels['title_placeholder'] ) ) { add_filter( 'enter_title_here', function () { return $this->labels['title_placeholder']; } ); } }
php
{ "resource": "" }
q256853
Papi_Page_Type.setup_post_types
test
protected function setup_post_types() { $this->post_type = papi_to_array( $this->post_type ); // Set a default value to post types array // if we don't have a array or a empty array. if ( empty( $this->post_type ) ) { $this->post_type = ['page']; } if ( count( $this->post_type ) === 1 && $this->post_type[0] === 'any' ) { $this->post_type = get_post_types( '', 'names' ); $this->post_type = array_values( $this->post_type ); } }
php
{ "resource": "" }
q256854
Papi_Page_Type.setup_page_templates
test
protected function setup_page_templates() { if ( ! is_array( $this->template ) || ! $this->has_post_type( papi_get_post_type() ) ) { return; } $this->show_page_template = true; foreach ( $this->post_type as $post_type ) { // Can't use `theme_templates` filter since it's added in 4.9.6. add_filter( "theme_{$post_type}_templates", function( $templates ) { foreach ( $this->template as $template ) { if ( ! is_array( $template ) || ! isset( $template['template'], $template['label'] ) ) { continue; } $templates[$template['template']] = $template['label']; } return $templates; } ); } }
php
{ "resource": "" }
q256855
Papi_Property_Editor.add_mce_buttons
test
protected function add_mce_buttons() { for ( $i = 0; $i < 4; $i++ ) { $num = $i === 0 ? '' : '_' . ( $i + 1 ); add_filter( 'mce_buttons' . $num, [$this, 'mce_buttons'] ); } }
php
{ "resource": "" }
q256856
Papi_Property_Editor.reove_mce_buttons
test
protected function reove_mce_buttons() { for ( $i = 0; $i < 4; $i++ ) { $num = $i === 0 ? '' : '_' . ( $i + 1 ); remove_filter( 'mce_buttons' . $num, [$this, 'mce_buttons'] ); } }
php
{ "resource": "" }
q256857
Papi_Property_Repeater.get_row_results
test
protected function get_row_results( $dbresults ) { $results = []; $is_option = $this->get_meta_type() === 'option'; foreach ( $dbresults as $meta ) { if ( $is_option ) { preg_match( '/^[^\d]*(\d+)/', $meta->option_name, $matches ); } else { preg_match( '/^[^\d]*(\d+)/', $meta->meta_key, $matches ); } if ( count( $matches ) < 2 ) { continue; } $i = intval( $matches[1] ); if ( ! isset( $results[$i] ) ) { $results[$i] = []; } if ( $is_option ) { $results[$i][$meta->option_name] = (object) [ 'meta_key' => $meta->option_name, 'meta_value' => $meta->option_value ]; } else { $results[$i][$meta->meta_key] = $meta; } } return $results; }
php
{ "resource": "" }
q256858
Papi_Property_Repeater.load_value
test
public function load_value( $value, $repeater_slug, $post_id ) { if ( is_array( $value ) ) { return $value; } list( $results, $trash ) = $this->get_results( $value, $repeater_slug, $post_id ); // Will not need this array. unset( $trash ); $results = papi_from_property_array_slugs( $results, unpapify( $repeater_slug ) ); if ( empty( $results ) ) { return $this->default_value; } return $this->load_child_properties( $results, $this ); }
php
{ "resource": "" }
q256859
Papi_Property_Repeater.prepare_properties
test
protected function prepare_properties( $items ) { $key = isset( $this->layout_key ) && $this->layout_key === '_layout' ? 'flexible' : 'repeater'; $items = array_map( 'papi_property', $items ); $exclude_properties = $this->exclude_properties; $exclude_properties = array_merge( $exclude_properties, apply_filters( 'papi/property/' . $key . '/exclude', [] ) ); return array_filter( $items, function ( $item ) use ( $exclude_properties ) { if ( ! is_object( $item ) ) { return false; } if ( empty( $item->type ) ) { return false; } return ! in_array( $item->type, $exclude_properties, true ); } ); }
php
{ "resource": "" }
q256860
Papi_Property_Repeater.prepare_property_for_json
test
protected function prepare_property_for_json( $property ) { // Only real property objects and not properties that are disabled. if ( ! papi_is_property( $property ) || $property->disabled() ) { return false; } $options = clone $property->get_options(); if ( isset( $options->settings->items ) ) { foreach ( $options->settings->items as $index => $property ) { if ( is_array( $property ) && isset( $property['items'] ) ) { foreach ( $property['items'] as $child_index => $child_property ) { $options->settings->items[$index]['items'][$child_index] = $this->prepare_property_for_json( $child_property ); } } if ( $property = $this->prepare_property_for_json( $property ) ) { $options->settings->items[$index] = $property; } } } return $options; }
php
{ "resource": "" }
q256861
Papi_Property_Repeater.remove_repeater_rows
test
protected function remove_repeater_rows( $post_id, $repeater_slug ) { global $wpdb; $is_option = $this->get_meta_type() === 'option'; $repeater_slug = $repeater_slug . '_%'; if ( $is_option ) { $table = $wpdb->prefix . 'options'; // @codingStandardsIgnoreStart $query = $wpdb->prepare( "SELECT * FROM `$table` WHERE (`option_name` LIKE %s OR `option_name` LIKE %s AND NOT `option_name` = %s)", $repeater_slug, papi_f( $repeater_slug ), papi_get_property_type_key_f( $repeater_slug ) ); // @codingStandardsIgnoreEnd } else { $table = $wpdb->prefix . 'postmeta'; // @codingStandardsIgnoreStart $query = $wpdb->prepare( "SELECT * FROM `$table` WHERE `post_id` = %d AND (`meta_key` LIKE %s OR `meta_key` LIKE %s AND NOT `meta_key` = %s)", $post_id, $repeater_slug, papi_f( $repeater_slug ), papi_get_property_type_key_f( $repeater_slug ) ); // @codingStandardsIgnoreEnd } $results = $wpdb->get_results( $query ); // WPCS: unprepared sql foreach ( $results as $res ) { if ( $is_option ) { $key = $res->option_name; } else { $key = $res->meta_key; } papi_data_delete( $post_id, $key, $this->get_meta_type() ); } }
php
{ "resource": "" }
q256862
Papi_Property_Repeater.render_json_template
test
protected function render_json_template( $slug ) { $options = $this->get_options(); $options->settings->items = papi_to_array( $options->settings->items ); foreach ( $options->settings->items as $key => $value ) { $property = $this->prepare_property_for_json( papi_property( $value ) ); if ( $property === false ) { unset( $options->settings->items[$key] ); continue; } $options->settings->items[$key] = $property; } papi_render_html_tag( 'script', [ 'data-papi-json' => esc_attr( sprintf( '%s_repeater_json', $slug ) ), 'type' => 'application/json', papi_maybe_json_encode( [$options] ) ] ); }
php
{ "resource": "" }
q256863
Papi_Property_Repeater.render_repeater_head
test
protected function render_repeater_head() { $properties = $this->get_settings_properties(); ?> <thead> <?php if ( ! $this->layout( 'row' ) ): ?> <tr> <th></th> <?php foreach ( $properties as $property ): // Don't show the property if it's disabled. if ( $property->disabled() ) { continue; } ?> <th class="repeater-column <?php echo $property->display() ? '' : 'papi-hide'; ?>"> <?php echo esc_html( $property->title ); ?> </th> <?php endforeach; ?> <th class="last"></th> </tr> <?php endif; ?> </thead> <?php }
php
{ "resource": "" }
q256864
Papi_Property_Repeater.render_repeater_rows
test
protected function render_repeater_rows() { $items = $this->get_settings_properties(); $values = $this->get_value(); $values = is_array( $values ) ? $values : []; $slugs = wp_list_pluck( $items, 'slug' ); // Remove values that don't exists in the slugs array. foreach ( $values as $index => $value ) { if ( ! is_array( $value ) ) { continue; } $keys = array_keys( $value ); foreach ( $slugs as $slug ) { if ( in_array( $slug, $keys, true ) ) { continue; } $values[$index][$slug] = ''; } } $values = array_filter( $values ); $closed_rows = $this->get_setting( 'closed_rows', true ); foreach ( $values as $row ): ?> <tr <?php echo $closed_rows ? 'class="closed"' : ''; ?>> <td class="handle"> <span class="toggle"></span> <span class="count"><?php echo esc_html( $this->counter + 1 ); ?></span> </td> <?php $this->render_properties( $items, $row ); $this->counter ++; ?> <td class="last"> <span> <a title="<?php esc_attr_e( 'Remove', 'papi' ); ?>" href="#" class="repeater-remove-item">x</a> </span> </td> </tr> <?php endforeach; }
php
{ "resource": "" }
q256865
Papi_REST_API_Settings.register
test
public function register() { // Fetch all options entries. $this->entries = papi_get_all_entry_types( [ 'types' => 'option' ] ); foreach ( $this->entries as $entry ) { foreach ( $entry->get_properties() as $property ) { $property->register( 'option' ); } } }
php
{ "resource": "" }
q256866
Papi_REST_API_Settings.get_setting
test
public function get_setting( $key, $value ) { $property = null; foreach ( (array) $this->entries as $entry ) { if ( $property = $entry->get_property( $key ) ) { break; } } if ( is_null( $property ) ) { return $value; } $value = papi_get_option( $key ); return $property->rest_prepare_value( $value ); }
php
{ "resource": "" }
q256867
Papi_REST_API_Settings.prepare_response
test
public function prepare_response( $response ) { $response = (array) $response; foreach ( $response as $key => $value ) { $setting = $this->get_setting( $key, $value ); if ( $setting !== $value ) { $response[$key] = $setting; } } return $response; }
php
{ "resource": "" }
q256868
Papi_Property_User.get_value
test
public function get_value() { $user = parent::get_value(); if ( is_object( $user ) && isset( $user->ID ) ) { return $user->ID; } return 0; }
php
{ "resource": "" }
q256869
Papi_Property_User.get_items
test
public function get_items() { $capabilities = papi_to_array( $this->get_setting( 'capabilities' ) ); $users = get_users(); $items = []; foreach ( $users as $user ) { $allcaps = $user->allcaps; if ( count( array_diff( $capabilities, array_keys( $allcaps ) ) ) === 0 ) { $items[$user->display_name] = $user->ID; } } ksort( $items ); return $items; }
php
{ "resource": "" }
q256870
Papi_Loader.init
test
protected function init() { // Fires the before init action. did_action( 'papi/before_init' ) || do_action( 'papi/before_init' ); // Set up localisation. $this->load_textdomain(); // Load all required files. $this->require_files(); // Setup the container. $this->setup_container(); // Fires the init action. did_action( 'papi/init' ) || do_action( 'papi/init' ); }
php
{ "resource": "" }
q256871
Papi_Loader.load_textdomain
test
protected function load_textdomain() { $locale = function_exists( 'get_user_local' ) ? get_user_local() : get_locale(); $locale = apply_filters( 'plugin_locale', $locale, 'papi' ); load_textdomain( 'papi', WP_LANG_DIR . '/papi/papi-' . $locale . '.mo' ); load_textdomain( 'papi', PAPI_PLUGIN_DIR . '../languages/papi-' . $locale . '.mo' ); }
php
{ "resource": "" }
q256872
Papi_Loader.require_files
test
protected function require_files() { // Require the autoload class. require_once __DIR__ . '/core/class-papi-core-autoload.php'; $lib_path = __DIR__ . '/lib/'; $lib_includes = [ 'core/cache.php', 'core/conditional.php', 'core/data.php', 'core/deprecated.php', 'core/meta.php', 'core/store.php', 'core/post.php', 'core/io.php', 'core/property.php', 'core/slug.php', 'core/tabs.php', 'core/taxonomy.php', 'core/template.php', 'core/url.php', 'core/utilities.php', 'hooks/actions.php', 'hooks/filters.php', 'hooks/filters-page-type.php', 'hooks/filters-taxonomy-type.php', 'fields/page.php', 'fields/option.php', 'fields/taxonomy.php', 'types/entry.php', 'types/page.php', 'types/option.php', 'types/taxonomy.php' ]; // Require function files. foreach ( $lib_includes as $file ) { if ( file_exists( $lib_path . $file ) ) { require_once $lib_path . $file; } } unset( $file ); // Require admin classes that should not be loaded by the autoload. require_once __DIR__ . '/admin/class-papi-admin.php'; require_once __DIR__ . '/admin/class-papi-admin-ajax.php'; require_once __DIR__ . '/admin/class-papi-admin-assets.php'; require_once __DIR__ . '/admin/class-papi-admin-menu.php'; // Require conditional rules that should not be loaded by the autoload. require_once __DIR__ . '/core/class-papi-core-conditional-rules.php'; // Require REST API classes. require_once __DIR__ . '/rest-api/class-papi-rest-api.php'; // Load Papi CLI class if WP CLI is used. if ( defined( 'WP_CLI' ) && WP_CLI ) { require_once __DIR__ . '/cli/class-papi-cli.php'; } }
php
{ "resource": "" }
q256873
Papi_Loader.deactivate
test
public static function deactivate() { // Remove Papi from plugins_loaded action. remove_action( 'plugins_loaded', 'papi' ); // Load deactivate_plugins if it don't exists. if ( ! function_exists( 'deactivate_plugins' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } deactivate_plugins( PAPI_PLUGIN_BASENAME ); wp_die( esc_html__( 'WordPress 4.6 and higher required to run Papi! The plugin has now disabled itself.', 'papi' ) ); // Remove instance. self::$instance = null; }
php
{ "resource": "" }
q256874
Papi_Property_Dropdown.is_string_items
test
public function is_string_items() { $items = $this->get_items(); if ( empty( $items ) ) { return false; } $items = array_values( $items ); return is_string( $items[0] ); }
php
{ "resource": "" }
q256875
Papi_Property_Group.prepare_properties
test
protected function prepare_properties( $properties ) { $result = []; $value = $this->get_value(); $value = is_array( $value ) ? $value : []; foreach ( $properties as $property ) { $render_property = clone $property->get_options(); $value_slug = $property->get_slug( true ); if ( array_key_exists( $value_slug, $value ) ) { $render_property->value = $value[$value_slug]; } else { $render_property->value = null; } $render_property->slug = $this->html_name( $property ); $result[] = $render_property; } return $result; }
php
{ "resource": "" }
q256876
Papi_Property_File.get_file
test
public function get_file( $value ) { $meta_key = $this->get_setting( 'meta_key' ); if ( empty( $meta_key ) ) { if ( is_numeric( $value ) && intval( $value ) !== 0 ) { $post = get_post( $value ); } } else if ( ! empty( $value ) ) { $args = [ 'fields' => 'ids', 'meta_key' => $meta_key, 'meta_value' => $value, 'posts_per_page' => 1, 'post_type' => 'attachment', 'post_status' => 'any' ]; $query = new WP_Query( $args ); if ( ! empty( $query->posts ) ) { $post = get_post( $query->posts[0] ); } } if ( empty( $post ) ) { return $value; } return $post->ID; }
php
{ "resource": "" }
q256877
Papi_Property_File.get_file_value
test
protected function get_file_value( $value ) { $meta_key = $this->get_setting( 'meta_key' ); if ( ! is_object( $value ) ) { return 0; } if ( empty( $meta_key ) ) { return $value->id; } if ( $value = get_post_meta( $value->id, $meta_key, true ) ) { return $value; } return 0; }
php
{ "resource": "" }
q256878
Papi_Property_File.update_value
test
public function update_value( $values, $slug, $post_id ) { if ( ! is_array( $values ) ) { $values = $this->get_file_value( (object) [ 'id' => $values ] ); if ( empty( $values ) ) { return; } return $values; } foreach ( $values as $index => $value ) { if ( ! is_numeric( $value ) ) { continue; } $values[$index] = $this->get_file_value( (object) [ 'id' => $value ] ); } return array_filter( $values ); }
php
{ "resource": "" }
q256879
Papi_Core_Container.bind
test
public function bind( $id, $value = null, $singleton = false ) { if ( is_string( $id ) && $this->is_singleton( $id ) ) { throw new Exception( sprintf( 'Identifier `%s` is a singleton and cannot be rebind', $id ) ); } if ( is_object( $id ) && get_class( $id ) !== false ) { $value = $id; $id = $this->get_class_prefix( get_class( $id ), false ); $this->classes[$id] = true; } if ( $value instanceof Closure ) { $closure = $value; } else { $closure = $this->get_closure( $value, $singleton ); } $this->values[$id] = compact( 'closure', 'singleton' ); $this->keys[$id] = true; return $value; }
php
{ "resource": "" }
q256880
Papi_Core_Container.call_closure
test
protected function call_closure( $closure, array $parameters = [] ) { if ( $closure instanceof Closure ) { $rc = new ReflectionFunction( $closure ); $args = $rc->getParameters(); $params = $parameters; $classes = [ $this->get_class_prefix( get_class( $this ) ), get_class( $this ), get_parent_class( $this ) ]; foreach ( $args as $index => $arg ) { if ( $arg->getClass() === null ) { continue; } if ( in_array( $arg->getClass()->name, $classes, true ) ) { $parameters[$index] = $this; } else if ( $this->exists( $arg->getClass()->name ) ) { $parameters[$index] = $this->make( $arg->getClass()->name ); } } if ( ! empty( $args ) && empty( $parameters ) ) { $parameters[0] = $this; } if ( count( $args ) > count( $parameters ) ) { $parameters = array_merge( $parameters, $params ); } return $this->call_closure( call_user_func_array( $closure, $parameters ), $parameters ); } return $closure; }
php
{ "resource": "" }
q256881
Papi_Core_Container.get_class_prefix
test
protected function get_class_prefix( $id, $check = true ) { if ( strpos( $id, '\\' ) !== false && $id[0] !== '\\' ) { $class = '\\' . $id; if ( $check ) { return isset( $this->classes[$class] ) ? $class : $id; } return $class; } return $id; }
php
{ "resource": "" }
q256882
Papi_Core_Container.is_singleton
test
public function is_singleton( $id ) { if ( ! is_string( $id ) ) { throw new InvalidArgumentException( 'Invalid argument. Must be string.' ); } if ( ! $this->exists( $id ) ) { return false; } $id = $this->get_class_prefix( $id ); return $this->values[$id]['singleton'] === true; }
php
{ "resource": "" }
q256883
Papi_Core_Container.once
test
public function once( $key, $callback ) { if ( ! is_string( $key ) && ! is_callable( $callback ) ) { return; } if ( ! $this->exists( $key ) ) { $result = $callback(); $this->singleton( $key, $result ); } return $this->make( $key ); }
php
{ "resource": "" }
q256884
Papi_Core_Container.remove
test
public function remove( $id ) { $id = $this->get_class_prefix( $id ); unset( $this->keys[$id], $this->values[$id] ); }
php
{ "resource": "" }
q256885
Papi_Admin_Menu.override_labels
test
protected function override_labels( Papi_Entry_Type $entry_type ) { global $wp_post_types, $wp_taxonomies; if ( $entry_type->get_type() === 'taxonomy' ) { $meta_type_value = papi_get_taxonomy(); } else { $meta_type_value = papi_get_post_type(); } if ( empty( $meta_type_value ) || ( ! isset( $wp_post_types[$meta_type_value] ) && ! isset( $wp_taxonomies[$meta_type_value] ) ) ) { return; } foreach ( $entry_type->get_labels() as $key => $value ) { if ( empty( $value ) ) { continue; } if ( $entry_type->get_type() === 'taxonomy' && isset( $wp_taxonomies[$meta_type_value]->labels->$key ) ) { $wp_taxonomies[$meta_type_value]->labels->$key = $value; } else if ( isset( $wp_post_types[$meta_type_value]->labels->$key ) ) { $wp_post_types[$meta_type_value]->labels->$key = $value; } } }
php
{ "resource": "" }
q256886
Papi_Admin_Menu.page_items_menu
test
public function page_items_menu() { $entry_types = papi_get_all_entry_types( [ 'mode' => 'exclude', 'types' => 'page' ] ); foreach ( $entry_types as $entry_type ) { if ( empty( $entry_type->get_menu() ) || empty( $entry_type->name ) ) { continue; } $slug = sprintf( 'papi/%s/%s', $entry_type->get_type(), $entry_type->get_id() ); add_submenu_page( $entry_type->get_menu(), $entry_type->name, $entry_type->name, $entry_type->capability, $slug, [$entry_type, 'render'] ); } }
php
{ "resource": "" }
q256887
Papi_Admin_Menu.post_types_menu
test
public function post_types_menu() { global $submenu; $post_types = papi_get_post_types(); foreach ( $post_types as $post_type ) { if ( ! post_type_exists( $post_type ) ) { continue; } if ( $post_type === 'post' ) { $edit_url = 'edit.php'; } else { $edit_url = 'edit.php?post_type=' . $post_type; } if ( ! isset( $submenu[$edit_url], $submenu[$edit_url][10], $submenu[$edit_url][10][2] ) ) { $post_type_object = get_post_type_object( $post_type ); if ( $post_type_object->show_in_menu !== true ) { $submenu[$edit_url] = [ 10 => [ __( 'Add New', 'papi' ), 'edit_posts', 'post-new.php' ] ]; } else { continue; } } $only_page_type = papi_filter_settings_only_page_type( $post_type ); $page_types = papi_get_all_page_types( $post_type ); $show_standard = false; // Don't change menu item when no page types is found. if ( empty( $page_types ) ) { continue; } if ( count( $page_types ) === 1 && empty( $only_page_type ) ) { $show_standard = papi_filter_settings_show_standard_page_type( $post_type ); $only_page_type = $show_standard ? '' : $page_types[0]->get_id(); } if ( ! empty( $only_page_type ) && ! $show_standard ) { $submenu[$edit_url][10][2] = papi_get_page_new_url( $only_page_type, false, $post_type, [ 'post_parent', 'lang' ] ); } else { $page = 'papi-add-new-page,' . $post_type; $start = strpos( $edit_url, 'post_type' ) === false ? '?' : '&'; $submenu[$edit_url][10][2] = sprintf( '%s%spage=%s', $edit_url, $start, $page ); // Add menu item. add_menu_page( __( 'Add New', 'papi' ), __( 'Add New', 'papi' ), 'read', $page, [$this, 'render_view'] ); // Remove the menu item so it's hidden. remove_menu_page( $page ); } } }
php
{ "resource": "" }
q256888
Papi_Admin_Menu.render_view
test
public function render_view() { if ( strpos( papi_get_qs( 'page' ), 'papi' ) !== false ) { $page = str_replace( 'papi-', '', papi_get_qs( 'page' ) ); $res = preg_replace( '/\,.*/', '', $page ); if ( is_string( $res ) ) { $page_view = $res; } } if ( ! isset( $page_view ) ) { $page_view = null; } if ( ! is_null( $page_view ) ) { $view = new Papi_Admin_View; $view->render( $page_view ); } else { echo '<h2>Papi - 404</h2>'; } }
php
{ "resource": "" }
q256889
Papi_Core_Autoload.autoload
test
public function autoload( $class ) { $class = strtolower( $class ); $file = 'class-' . str_replace( '_', '-', strtolower( $class ) ) . '.php'; $path = PAPI_PLUGIN_DIR; if ( strpos( $class, 'papi_admin' ) === 0 ) { $path .= 'admin/'; } else if ( strpos( $class, 'papi_core_' ) === 0 ) { $path .= 'core/'; } else if ( strpos( $class, 'papi_cli_' ) === 0 ) { $path .= 'cli/'; } else if ( preg_match( '/^papi\_\w+\_store$/', $class ) ) { $path .= 'stores/'; } else if ( strpos( $class, 'papi_property' ) === 0 ) { $path .= 'properties/'; } else if ( strpos( $class, 'papi_query' ) === 0 ) { $path .= 'query/'; } else if ( preg_match( '/^papi\_\w+\_type/', $class ) ) { $path .= 'types/'; } if ( is_readable( $path . $file ) ) { require_once $path . $file; } }
php
{ "resource": "" }
q256890
Papi_Property_Sidebar.get_items
test
public function get_items() { global $wp_registered_sidebars; $items = []; foreach ( $wp_registered_sidebars as $item ) { $items[$item['name']] = $item['id']; } ksort( $items ); return $items; }
php
{ "resource": "" }
q256891
Papi_Property_Post.get_labels
test
protected function get_labels() { $results = []; foreach ( $this->get_post_types() as $post_type ) { if ( post_type_exists( $post_type ) ) { $post_type_object = get_post_type_object( $post_type ); $results[$post_type] = $post_type_object->labels->menu_name; } } return $results; }
php
{ "resource": "" }
q256892
Papi_Query.parse_args
test
public function parse_args( array $args ) { $args = array_merge( $this->default_args, $args ); // Since a page type has defined post types we should use them. // With a fallback on `post_type` args or `any` value. if ( $this->type === 'post' ) { $args = $this->parse_post_args( $args ); } else if ( $this->type === 'term' ) { $args = $this->parse_term_args( $args ); } $this->args = $args; }
php
{ "resource": "" }
q256893
Papi_Query.parse_post_args
test
protected function parse_post_args( array $args ) { if ( isset( $args['page_type'] ) ) { $args['entry_type'] = $args['page_type']; unset( $args['page_type'] ); } $entry_type = papi_get_entry_type_by_id( $args['entry_type'] ); if ( $entry_type instanceof Papi_Page_Type ) { $args['post_type'] = papi_to_array( $entry_type->post_type ); } else { $args['post_type'] = isset( $args['post_type'] ) ? $args['post_type'] : ''; } return $args; }
php
{ "resource": "" }
q256894
Papi_Query.parse_term_args
test
protected function parse_term_args( array $args ) { if ( isset( $args['taxonomy_type'] ) ) { $args['entry_type'] = $args['taxonomy_type']; unset( $args['taxonomy_type'] ); } $entry_type = papi_get_entry_type_by_id( $args['entry_type'] ); if ( $entry_type instanceof Papi_Taxonomy_Type ) { $args['taxonomy'] = papi_to_array( $entry_type->taxonomy ); } else { $args['taxonomy'] = isset( $args['taxonomy'] ) ? $args['taxonomy'] : ''; } return $args; }
php
{ "resource": "" }
q256895
Papi_Query.get_query_args
test
public function get_query_args() { $args = $this->args; if ( empty( $args['meta_query'] ) ) { // Add new meta key/value if `meta_key` or `meta_value` is empty. if ( empty( $args['meta_key'] ) || empty( $args['meta_value'] ) ) { $args['meta_key'] = papi_get_page_type_key(); $args['meta_value'] = $args['entry_type']; } else if ( papi_entry_type_exists( $args['entry_type'] ) ) { $item = [ 'key' => $args['meta_key'], 'value' => $args['meta_value'] ]; // Add `meta_compare` if set. if ( isset( $args['meta_compare'] ) ) { $item['compare'] = $args['meta_compare']; unset( $args['meta_compare'] ); } // Add new meta query item. $args['meta_query'][] = $item; // Add Papi entry/page type meta query. $args['meta_query'][] = [ 'key' => papi_get_page_type_key(), 'value' => $args['entry_type'] ]; // Add meta query relation when two query items. if ( isset( $args['relation'] ) ) { $args['meta_query']['relation'] = $args['relation']; } else { $args['meta_query']['relation'] = 'AND'; } unset( $args['meta_key'] ); unset( $args['meta_value'] ); } } else if ( papi_entry_type_exists( $args['entry_type'] ) ) { // Add Papi entry/page type meta query. $args['meta_query'][] = [ 'key' => papi_get_page_type_key(), 'value' => $args['entry_type'] ]; // Add meta query relation if not set. if ( ! isset( $args['meta_query']['relation'] ) ) { $args['meta_query']['relation'] = 'AND'; } } // Since the real query classes don't support // custom arguments the should be deleted. foreach ( array_keys( $this->default_args ) as $key ) { if ( isset( $args[$key] ) ) { unset( $args[$key] ); } } return $args; }
php
{ "resource": "" }
q256896
Papi_Query.get_result
test
public function get_result() { if ( ! method_exists( $this->query, 'query' ) ) { return []; } $this->parse_args( $this->args ); return $this->query->query( $this->get_query_args() ); }
php
{ "resource": "" }
q256897
Papi_Entry_Type.add_help_tabs
test
public function add_help_tabs() { $help = $this->help(); $screen = get_current_screen(); // No screen available. if ( $screen instanceof WP_Screen === false ) { return; } // Clean up all existing tabs. if ( ! $this->show_help_tabs || ! empty( $help ) ) { $screen->remove_help_tabs(); } // No new help tabs available. if ( empty( $help ) ) { return; } // Add help sidebar content. By default it will be disabled // since `help_sidebar` method returns false. $help_sidebar = $this->help_sidebar(); $help_sidebar = papi_maybe_get_callable_value( $help_sidebar ); $screen->set_help_sidebar( wpautop( $help_sidebar ) ); foreach ( $help as $key => $value ) { $args = [ 'id' => papi_html_name( $key ), 'title' => $key ]; if ( is_callable( $value ) ) { $args['callback'] = function () use ( $value ) { return wpautop( $value() ); }; } else { $args['content'] = wpautop( $value ); } $screen->add_help_tab( $args ); } }
php
{ "resource": "" }
q256898
Papi_Entry_Type.box
test
protected function box( $file_or_options = [], $properties = [] ) { if ( ! is_string( $file_or_options ) && ! is_array( $file_or_options ) && ! is_object( $file_or_options ) ) { return; } list( $options, $properties ) = papi_get_options_and_properties( $file_or_options, $properties, true ); // Check so we have a post the to add the box to. // @codeCoverageIgnoreStart if ( ! $this->load_boxes ) { return; } // @codeCoverageIgnoreEnd if ( is_callable( $properties ) ) { $properties = call_user_func( $properties ); } // Check and convert all non properties objects to properties objects. $properties = $this->convert_properties( $properties ); // Create a core box instance and add it to the boxes array. array_push( $this->boxes, new Papi_Core_Box( $options, $properties ) ); }
php
{ "resource": "" }
q256899
Papi_Entry_Type.call_parent_register
test
protected function call_parent_register() { $parent_class = get_parent_class( $this ); if ( ! method_exists( $parent_class, 'register' ) ) { return; } $rc = new ReflectionClass( $parent_class ); // Bail if not instantiable. if ( ! $rc->isinstantiable() ) { return; } $parent = $rc->newInstance(); $parent->register(); $this->boxes = $parent->get_boxes(); }
php
{ "resource": "" }